Groups.jl/src/matrix_groups/abstract.jl

41 lines
1.3 KiB
Julia
Raw Normal View History

2023-03-15 17:11:22 +01:00
abstract type AbstractMatrixGroup{N,T} <: Groups.AbstractFPGroup end
const MatrixGroupElement{N,T} = Groups.AbstractFPGroupElement{<:AbstractMatrixGroup{N,T}}
2022-10-14 01:14:38 +02:00
Base.isone(g::MatrixGroupElement{N,T}) where {N,T} =
2023-03-15 16:51:22 +01:00
isone(word(g)) || isone(matrix(g))
2022-10-14 01:14:38 +02:00
function Base.:(==)(m1::M1, m2::M2) where {M1<:MatrixGroupElement,M2<:MatrixGroupElement}
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)
end
2022-10-14 01:14:38 +02:00
Base.size(m::MatrixGroupElement{N}) where {N} = (N, N)
Base.eltype(m::MatrixGroupElement{N,T}) where {N,T} = T
# three structural assumptions about matrix groups
Groups.word(sl::MatrixGroupElement) = sl.word
Base.parent(sl::MatrixGroupElement) = sl.parent
Groups.alphabet(M::MatrixGroup) = M.alphabet
Groups.rewriting(M::MatrixGroup) = alphabet(M)
2023-03-15 16:51:22 +01:00
Base.hash(m::MatrixGroupElement, h::UInt) =
hash(matrix(m), hash(parent(m), h))
2023-03-15 16:51:22 +01:00
function matrix(m::MatrixGroupElement{N,T}) where {N,T}
if isone(word(m))
2022-10-14 01:14:38 +02:00
return StaticArrays.SMatrix{N,N,T}(LinearAlgebra.I)
end
A = alphabet(parent(m))
2023-03-15 16:51:22 +01:00
return prod(matrix(A[l]) for l in word(m))
end
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
)
Mgroup = rs[]
S = gens(Mgroup)
2023-03-15 17:11:22 +01:00
return prod(g -> rand(rng, Bool) ? g : inv(g), rand(rng, S, rand(rng, 1:30)))
end