From 46c95dbb83d409029ef39d9e9edc483c9473e489 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 15 Mar 2023 18:26:45 +0100 Subject: [PATCH] add general matrix groups --- src/matrix_groups/MatrixGroups.jl | 3 ++- src/matrix_groups/matrix_generators.jl | 36 ++++++++++++++++++++++++++ src/matrix_groups/matrix_group.jl | 25 ++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/matrix_groups/matrix_generators.jl create mode 100644 src/matrix_groups/matrix_group.jl diff --git a/src/matrix_groups/MatrixGroups.jl b/src/matrix_groups/MatrixGroups.jl index 486baf1..64ad756 100644 --- a/src/matrix_groups/MatrixGroups.jl +++ b/src/matrix_groups/MatrixGroups.jl @@ -9,10 +9,11 @@ import GroupsCore.Random # GroupsCore rand using ..Groups using Groups.KnuthBendix -export SpecialLinearGroup, SymplecticGroup +export MatrixGroup, SpecialLinearGroup, SymplecticGroup include("abstract.jl") +include("matrix_group.jl") include("SLn.jl") include("Spn.jl") diff --git a/src/matrix_groups/matrix_generators.jl b/src/matrix_groups/matrix_generators.jl new file mode 100644 index 0000000..2a4975c --- /dev/null +++ b/src/matrix_groups/matrix_generators.jl @@ -0,0 +1,36 @@ +struct MatrixElt{N,T,N²} <: Groups.GSymbol + id::Symbol + inv::Bool + mat::StaticArrays.SMatrix{N,N,T,N²} + + function MatrixElt{N,T}( + id::Symbol, + mat::AbstractMatrix, + inv::Bool = false, + ) where {N,T} + n = LinearAlgebra.checksquare(mat) + @assert N == n + @assert !iszero(LinearAlgebra.det(mat)) + return new{N,T,N^2}(id, inv, mat) + end +end + +function MatrixElt{N}( + id::Symbol, + mat::AbstractMatrix, + inv::Bool = false, +) where {N} + return MatrixElt{N,eltype(mat)}(id, mat, inv) +end + +Base.show(io::IO, m::MatrixElt) = print(io, m.id, m.inv ? "⁻¹" : "") + +Base.:(==)(m::MatrixElt, n::MatrixElt) = m.mat == n.mat + +Base.hash(m::MatrixElt, h::UInt) = hash(m.mat, hash(typeof(m), h)) + +function Base.inv(m::MatrixElt{N,T}) where {N,T} + return MatrixElt{N,T}(m.id, round.(T, inv(m.mat)), !m.inv) +end + +matrix(m::MatrixElt) = m.mat diff --git a/src/matrix_groups/matrix_group.jl b/src/matrix_groups/matrix_group.jl new file mode 100644 index 0000000..51355db --- /dev/null +++ b/src/matrix_groups/matrix_group.jl @@ -0,0 +1,25 @@ +include("matrix_generators.jl") + +struct MatrixGroup{N,T,R,S} <: AbstractMatrixGroup{N,T} + base_ring::R + alphabet::Alphabet{S} + gens::Vector{S} +end + +function MatrixGroup{N}( + gens::AbstractVector{<:AbstractMatrix{T}}, + base_ring = T, +) where {N,T} + S = map(enumerate(gens)) do (i, mat) + id = Symbol('m', Groups.subscriptify(i)) + return MatrixElt{N}(id, mat) + end + alphabet = Alphabet(S) + + R = typeof(base_ring) + St = eltype(S) + + return MatrixGroup{N,T,R,St}(base_ring, alphabet, S) +end + +GroupsCore.ngens(M::MatrixGroup) = length(M.gens)