From f2d2d4ee527ddd59fe461c2a60b74506ca931696 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Sat, 18 Dec 2021 19:34:04 +0100 Subject: [PATCH] prettier printing for FPGroups --- src/types.jl | 17 +++++++++++++---- test/AutFn.jl | 2 +- test/fp_groups.jl | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/types.jl b/src/types.jl index 4855192..a5002ae 100644 --- a/src/types.jl +++ b/src/types.jl @@ -225,12 +225,21 @@ function FPGroup( return FPGroup(G.gens, rels, rws) end +function Base.show(io::IO, ::MIME"text/plain", G::FPGroup) + print(io, "Finitely presented group generated by:\n\t{") + Base.print_array(io, permutedims(gens(G))) + println(io, " },") + println(io, "subject to relations:") + return Base.print_array(io, relations(G)) +end + function Base.show(io::IO, G::FPGroup) print(io, "⟨") - join(io, gens(G), ", ") - print(io, " | ") - join(io, relations(G), ", ") - return print(io, "⟩") + Base.print_array(io, permutedims(gens(G))) + println(io, " | ") + print(io, "\t ") + Base.print_array(io, permutedims(relations(G))) + return print(io, " ⟩") end Base.show(io::IO, ::Type{<:FPGroup{T}}) where {T} = diff --git a/test/AutFn.jl b/test/AutFn.jl index c9b47c5..793b685 100644 --- a/test/AutFn.jl +++ b/test/AutFn.jl @@ -96,7 +96,7 @@ @test evaluate(g*h) == evaluate(h*g) @test (g*h).savedhash == zero(UInt) - @test sprint(show, typeof(g)) == "Automorphism{FreeGroup{Symbol}, …}" + @test sprint(show, typeof(g)) == "Automorphism{FreeGroup{Symbol, KnuthBendix.LenLex{Symbol}}, …}" a = g*h b = h*g diff --git a/test/fp_groups.jl b/test/fp_groups.jl index 4e4f624..0fb5b1e 100644 --- a/test/fp_groups.jl +++ b/test/fp_groups.jl @@ -14,7 +14,7 @@ G = FPGroup(F, [a*b=>b*a, a*c=>c*a, b*c=>c*b]) @test G isa FPGroup - @test sprint(show, G) == "⟨a, b, c | a*b => b*a, a*c => c*a, b*c => c*b⟩" + @test sprint(show, G) == "⟨ a b c | \n\t a*b => b*a a*c => c*a b*c => c*b ⟩" @test rand(G) isa FPGroupElement f = a*c*b