2023-03-15 17:11:22 +01:00
|
|
|
|
abstract type AbstractMatrixGroup{N,T} <: Groups.AbstractFPGroup end
|
2023-03-15 18:32:27 +01:00
|
|
|
|
const MatrixGroupElement{N,T} =
|
|
|
|
|
Groups.AbstractFPGroupElement{<:AbstractMatrixGroup{N,T}}
|
2022-04-02 14:21:42 +02:00
|
|
|
|
|
2023-03-15 18:32:27 +01:00
|
|
|
|
function Base.isone(g::MatrixGroupElement{N,T}) where {N,T}
|
|
|
|
|
return isone(word(g)) || isone(matrix(g))
|
|
|
|
|
end
|
2022-04-02 14:21:42 +02:00
|
|
|
|
|
2023-03-15 18:32:27 +01:00
|
|
|
|
function Base.:(==)(
|
|
|
|
|
m1::M1,
|
|
|
|
|
m2::M2,
|
|
|
|
|
) where {M1<:MatrixGroupElement,M2<:MatrixGroupElement}
|
2022-04-02 14:21:42 +02:00
|
|
|
|
parent(m1) === parent(m2) || return false
|
|
|
|
|
word(m1) == word(m2) && return true
|
2023-03-15 16:51:22 +01:00
|
|
|
|
return matrix(m1) == matrix(m2)
|
2022-04-02 14:21:42 +02:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-15 18:32:27 +01:00
|
|
|
|
Base.size(::MatrixGroupElement{N}) where {N} = (N, N)
|
|
|
|
|
Base.size(::MatrixGroupElement{N}, d) where {N} = ifelse(d::Integer <= 2, N, 1)
|
|
|
|
|
Base.eltype(::MatrixGroupElement{N,T}) where {N,T} = T
|
2022-04-02 14:21:42 +02:00
|
|
|
|
|
|
|
|
|
# three structural assumptions about matrix groups
|
2023-03-15 18:32:27 +01:00
|
|
|
|
Groups.word(m::MatrixGroupElement) = m.word
|
|
|
|
|
Base.parent(m::MatrixGroupElement) = m.parent
|
|
|
|
|
Groups.alphabet(M::AbstractMatrixGroup) = M.alphabet
|
|
|
|
|
Groups.rewriting(M::AbstractMatrixGroup) = alphabet(M)
|
2022-04-02 14:21:42 +02:00
|
|
|
|
|
2023-03-15 18:32:27 +01:00
|
|
|
|
Base.hash(m::MatrixGroupElement, h::UInt) = hash(matrix(m), hash(parent(m), h))
|
2022-04-02 14:21:42 +02:00
|
|
|
|
|
2023-03-15 16:51:22 +01:00
|
|
|
|
function matrix(m::MatrixGroupElement{N,T}) where {N,T}
|
2022-04-02 14:43:52 +02:00
|
|
|
|
if isone(word(m))
|
2022-10-14 01:14:38 +02:00
|
|
|
|
return StaticArrays.SMatrix{N,N,T}(LinearAlgebra.I)
|
2022-04-02 14:43:52 +02:00
|
|
|
|
end
|
2022-04-02 14:21:42 +02:00
|
|
|
|
A = alphabet(parent(m))
|
2023-03-15 16:51:22 +01:00
|
|
|
|
return prod(matrix(A[l]) for l in word(m))
|
2022-04-02 14:21:42 +02:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-15 18:32:27 +01:00
|
|
|
|
function Base.convert(
|
|
|
|
|
::Type{M},
|
|
|
|
|
m::MatrixGroupElement,
|
|
|
|
|
) where {M<:AbstractMatrix}
|
|
|
|
|
return convert(M, matrix(m))
|
|
|
|
|
end
|
|
|
|
|
(M::Type{<:AbstractMatrix})(m::MatrixGroupElement) = convert(M, m)
|
|
|
|
|
|
2022-04-02 14:21:42 +02:00
|
|
|
|
function Base.rand(
|
|
|
|
|
rng::Random.AbstractRNG,
|
2023-03-15 17:11:22 +01:00
|
|
|
|
rs::Random.SamplerTrivial{<:AbstractMatrixGroup},
|
2022-10-14 01:14:38 +02:00
|
|
|
|
)
|
2022-04-02 14:21:42 +02:00
|
|
|
|
Mgroup = rs[]
|
|
|
|
|
S = gens(Mgroup)
|
2023-03-15 18:32:27 +01:00
|
|
|
|
return prod(
|
|
|
|
|
g -> rand(rng, Bool) ? g : inv(g),
|
|
|
|
|
rand(rng, S, rand(rng, 1:30)),
|
|
|
|
|
)
|
2022-04-02 14:21:42 +02:00
|
|
|
|
end
|
2023-03-15 17:20:52 +01:00
|
|
|
|
|
|
|
|
|
function Base.show(io::IO, M::AbstractMatrixGroup)
|
|
|
|
|
g = gens(M, 1)
|
|
|
|
|
N = size(g, 1)
|
2023-03-15 18:32:27 +01:00
|
|
|
|
return print(io, "H ⩽ GL{$N,$(eltype(g))}")
|
2023-03-15 17:20:52 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Base.show(io::IO, ::MIME"text/plain", M::AbstractMatrixGroup)
|
|
|
|
|
N = size(gens(M, 1), 1)
|
|
|
|
|
ng = GroupsCore.ngens(M)
|
2023-03-15 18:32:27 +01:00
|
|
|
|
return print(
|
|
|
|
|
io,
|
|
|
|
|
"subgroup of $N×$N invertible matrices with $(ng) generators",
|
|
|
|
|
)
|
2023-03-15 17:20:52 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-15 18:32:27 +01:00
|
|
|
|
function Base.show(
|
|
|
|
|
io::IO,
|
|
|
|
|
mat::Groups.AbstractFPGroupElement{<:AbstractMatrixGroup},
|
|
|
|
|
)
|
|
|
|
|
return KnuthBendix.print_repr(io, word(mat), alphabet(mat))
|
|
|
|
|
end
|
2023-03-15 17:20:52 +01:00
|
|
|
|
|
|
|
|
|
function Base.show(
|
|
|
|
|
io::IO,
|
|
|
|
|
::MIME"text/plain",
|
2023-03-15 18:32:27 +01:00
|
|
|
|
mat::Groups.AbstractFPGroupElement{<:AbstractMatrixGroup{N}},
|
2023-03-15 17:20:52 +01:00
|
|
|
|
) where {N}
|
|
|
|
|
Groups.normalform!(mat)
|
|
|
|
|
KnuthBendix.print_repr(io, word(mat), alphabet(mat))
|
|
|
|
|
println(io, " ∈ ", parent(mat))
|
2023-03-15 18:32:27 +01:00
|
|
|
|
return Base.print_array(io, matrix(mat))
|
2023-03-15 17:20:52 +01:00
|
|
|
|
end
|