From 116439d074914ae5ddef5341fe0cf80ca12564d7 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Wed, 15 Mar 2023 17:20:52 +0100 Subject: [PATCH] move show functions to abstract.jl --- src/matrix_groups/SLn.jl | 20 ++++++-------------- src/matrix_groups/Spn.jl | 15 +++------------ src/matrix_groups/abstract.jl | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/matrix_groups/SLn.jl b/src/matrix_groups/SLn.jl index 72b9504..d95107e 100644 --- a/src/matrix_groups/SLn.jl +++ b/src/matrix_groups/SLn.jl @@ -21,22 +21,14 @@ end GroupsCore.ngens(SL::SpecialLinearGroup{N}) where {N} = N^2 - N -Base.show(io::IO, SL::SpecialLinearGroup{N,T}) where {N,T} = - print(io, "special linear group of $N×$N matrices over $T") +function Base.show(io::IO, ::SpecialLinearGroup{N,T}) where {N,T} + return print(io, "SL{$N,$T}") +end function Base.show( io::IO, ::MIME"text/plain", - sl::Groups.AbstractFPGroupElement{<:SpecialLinearGroup{N}} -) where {N} - - Groups.normalform!(sl) - - print(io, "SL{$N,$(eltype(sl))} matrix: ") - KnuthBendix.print_repr(io, word(sl), alphabet(sl)) - println(io) - Base.print_array(io, matrix_repr(sl)) + SL::SpecialLinearGroup{N,T}, +) where {N,T} + return print(io, "special linear group of $N×$N matrices over $T") end - -Base.show(io::IO, sl::Groups.AbstractFPGroupElement{<:SpecialLinearGroup}) = - KnuthBendix.print_repr(io, word(sl), alphabet(sl)) diff --git a/src/matrix_groups/Spn.jl b/src/matrix_groups/Spn.jl index 98f556a..d66c0af 100644 --- a/src/matrix_groups/Spn.jl +++ b/src/matrix_groups/Spn.jl @@ -21,20 +21,11 @@ end GroupsCore.ngens(Sp::SymplecticGroup) = length(Sp.gens) -Base.show(io::IO, ::SymplecticGroup{N}) where {N} = print(io, "group of $N×$N symplectic matrices") +Base.show(io::IO, ::SymplecticGroup{N,T}) where {N,T} = print(io, "Sp{$N,$T}") -function Base.show( - io::IO, - ::MIME"text/plain", - sp::Groups.AbstractFPGroupElement{<:SymplecticGroup{N}} -) where {N} - Groups.normalform!(sp) - print(io, "$N×$N symplectic matrix: ") - KnuthBendix.print_repr(io, word(sp), alphabet(sp)) - println(io) - Base.print_array(io, matrix_repr(sp)) +function Base.show(io::IO, ::MIME"text/plain", ::SymplecticGroup{N}) where {N} + return print(io, "group of $N×$N symplectic matrices") end - _offdiag_idcs(n) = ((i, j) for i in 1:n for j in 1:n if i ≠ j) function symplectic_gens(N, T=Int8) diff --git a/src/matrix_groups/abstract.jl b/src/matrix_groups/abstract.jl index d90613b..3caca2c 100644 --- a/src/matrix_groups/abstract.jl +++ b/src/matrix_groups/abstract.jl @@ -38,3 +38,29 @@ function Base.rand( S = gens(Mgroup) return prod(g -> rand(rng, Bool) ? g : inv(g), rand(rng, S, rand(rng, 1:30))) end + +function Base.show(io::IO, M::AbstractMatrixGroup) + g = gens(M, 1) + N = size(g, 1) + print(io, "H ⩽ GL{$N,$(eltype(g))}") +end + +function Base.show(io::IO, ::MIME"text/plain", M::AbstractMatrixGroup) + N = size(gens(M, 1), 1) + ng = GroupsCore.ngens(M) + print(io, "subgroup of $N×$N invertible matrices with $(ng) generators") +end + +Base.show(io::IO, mat::Groups.AbstractFPGroupElement{<:AbstractMatrixGroup}) = + KnuthBendix.print_repr(io, word(mat), alphabet(mat)) + +function Base.show( + io::IO, + ::MIME"text/plain", + mat::Groups.AbstractFPGroupElement{<:AbstractMatrixGroup{N}} +) where {N} + Groups.normalform!(mat) + KnuthBendix.print_repr(io, word(mat), alphabet(mat)) + println(io, " ∈ ", parent(mat)) + Base.print_array(io, matrix(mat)) +end