From a6aabf45417fadd46523caf891dde644297ae8a2 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Mon, 20 Apr 2020 02:02:57 +0200 Subject: [PATCH 1/4] even more tests --- src/DirectPower.jl | 4 ++-- src/symbols.jl | 5 +++-- test/FreeGroup-tests.jl | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/DirectPower.jl b/src/DirectPower.jl index ec0140f..fe87840 100644 --- a/src/DirectPower.jl +++ b/src/DirectPower.jl @@ -65,7 +65,7 @@ parent(g::DirectPowerGroupElem{N, T}) where {N,T} = # ############################################################################### -size(g::DirectPowerGroupElem{N}) where N = (N,) +Base.size(g::DirectPowerGroupElem{N}) where N = (N,) Base.IndexStyle(::Type{DirectPowerGroupElem}) = Base.LinearFast() Base.getindex(g::DirectPowerGroupElem, i::Int) = g.elts[i] @@ -188,7 +188,7 @@ end ############################################################################### order(G::DirectPowerGroup{N}) where N = order(G.group)^N -length(G::DirectPowerGroup) = order(G) +Base.length(G::DirectPowerGroup) = order(G) function iterate(G::DirectPowerGroup{N}) where N elts = collect(G.group) diff --git a/src/symbols.jl b/src/symbols.jl index dd766ff..e13435c 100644 --- a/src/symbols.jl +++ b/src/symbols.jl @@ -3,8 +3,9 @@ change_pow(s::S, n::Integer) where S<:GSymbol = S(s.id, n) function Base.iterate(s::GS, i=1) where GS<:GSymbol return i <= abs(s.pow) ? (GS(s.id, sign(s.pow)), i+1) : nothing end -Base.length(s::GSymbol) = abs(s.pow) -Base.size(s::GSymbol) = (length(s), ) +Base.size(s::GSymbol) = (abs(s.pow), ) +Base.length(s::GSymbol) = first(size(s)) + Base.eltype(s::GS) where GS<:GSymbol = GS Base.isone(s::GSymbol) = iszero(s.pow) diff --git a/test/FreeGroup-tests.jl b/test/FreeGroup-tests.jl index fae5c6d..3a1863f 100644 --- a/test/FreeGroup-tests.jl +++ b/test/FreeGroup-tests.jl @@ -38,6 +38,7 @@ end @test length(FreeGroupElem(t)) == 2 @test Groups.FreeSymbol(:s, 1) != Groups.FreeSymbol(:s, 2) @test Groups.FreeSymbol(:s, 1) != Groups.FreeSymbol(:t, 1) + @test collect(Groups.FreeSymbol(:s, 2)) == [i for i in Groups.FreeSymbol(:s, 2)] == [s, s] end @testset "FreeGroup" begin @@ -52,8 +53,10 @@ end @test eltype(gens(G)) == FreeGroupElem @test length(gens(G)) == 2 - @test collect(s*t) == Groups.syllables(s*t) tt, ss = Groups.FreeSymbol(:t), Groups.FreeSymbol(:s) + @test Groups.GroupWord([tt, inv(tt)]) isa FreeGroupElem + + @test collect(s*t) == Groups.syllables(s*t) @test collect(t^2) == [tt, tt] ttinv = Groups.FreeSymbol(:t, -1) w = t^-2*s^3*t^2 @@ -66,7 +69,8 @@ end @test collect(ttinv) == [ttinv] - @test Groups.GroupWord([tt, inv(tt)]) isa FreeGroupElem + @test isone(t^0) + @test !isone(t^1) end @testset "internal arithmetic" begin @@ -80,6 +84,13 @@ end tt = deepcopy(t) @test string(Groups.lmul!(tt, tt, inv(tt))) == "(id)" + w = deepcopy(t) + @test length(Groups.rmul!(w, t)) == 2 + @test length(Groups.lmul!(w, inv(t))) == 1 + w = AbstractAlgebra.mul!(w, w, s) + @test length(w) == 2 + @test length(Groups.lmul!(w, inv(s))) == 3 + tt = deepcopy(t) push!(tt, inv(t_symb)) @test string(tt) == "t*t^-1" @@ -150,7 +161,7 @@ end @test findlast(s^-1*t^-1, c) == 3 @test findprev(s, s*t*s*t, 4) == 3 @test findprev(s*t, s*t*s*t, 2) == 1 - @test findlast(t^2*s, c) === nothing + @test findprev(Groups.FreeSymbol(:t, 2), c, 4) === nothing w = s*t*s^-1 subst = Dict{FreeGroupElem, FreeGroupElem}(w => s^1, s*t^-1 => t^4) From cdbd483e9e58351d2879d10432abe445cc4c7dfa Mon Sep 17 00:00:00 2001 From: kalmarek Date: Mon, 20 Apr 2020 02:41:24 +0200 Subject: [PATCH 2/4] more tests for AutGroup --- src/AutGroup.jl | 2 +- src/DirectPower.jl | 7 +----- test/AutGroup-tests.jl | 49 ++++++++++++++++++++++++++---------------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/AutGroup.jl b/src/AutGroup.jl index 232d98d..dcbb1e1 100644 --- a/src/AutGroup.jl +++ b/src/AutGroup.jl @@ -262,7 +262,7 @@ end function show(io::IO, G::AutGroup) print(io, "Automorphism Group of $(G.objectGroup)\n") - print(io, "Generated by $(join(G.gens, ","))") + print(io, "Generated by $(gens(G))") end ############################################################################### diff --git a/src/DirectPower.jl b/src/DirectPower.jl index fe87840..567444e 100644 --- a/src/DirectPower.jl +++ b/src/DirectPower.jl @@ -31,11 +31,6 @@ function DirectPower(G::DirectPowerGroup{N}, H::Group) where N return DirectPowerGroup(G.group, N+1) end -function DirectPower(R::AbstractAlgebra.Ring, n::Int) - @warn "Creating DirectPower of the multilplicative group!" - return DirectPowerGroup(MultiplicativeGroup(R), n) -end - struct DirectPowerGroupElem{N, T<:GroupElem} <: GroupElem elts::NTuple{N,T} end @@ -188,7 +183,6 @@ end ############################################################################### order(G::DirectPowerGroup{N}) where N = order(G.group)^N -Base.length(G::DirectPowerGroup) = order(G) function iterate(G::DirectPowerGroup{N}) where N elts = collect(G.group) @@ -212,3 +206,4 @@ function iterate(G::DirectPowerGroup{N}, state) where N end eltype(::Type{DirectPowerGroup{N, G}}) where {N, G} = DirectPowerGroupElem{N, elem_type(G)} +Base.length(G::DirectPowerGroup) = order(G) diff --git a/test/AutGroup-tests.jl b/test/AutGroup-tests.jl index 17fefcf..54cc0f0 100644 --- a/test/AutGroup-tests.jl +++ b/test/AutGroup-tests.jl @@ -6,13 +6,17 @@ @test_throws MethodError Groups.AutSymbol(:a) @test_throws MethodError Groups.AutSymbol(:a, 1) f = Groups.AutSymbol(:a, 1, Groups.FlipAut(2)) - @test isa(f, Groups.GSymbol) - @test isa(f, Groups.AutSymbol) - @test isa(Groups.AutSymbol(perm"(4)"), Groups.AutSymbol) - @test isa(Groups.AutSymbol(perm"(1,2,3,4)"), Groups.AutSymbol) - @test isa(Groups.transvection_R(1,2), Groups.AutSymbol) - @test isa(Groups.transvection_R(3,4), Groups.AutSymbol) - @test isa(Groups.flip(3), Groups.AutSymbol) + @test f isa Groups.GSymbol + @test f isa Groups.AutSymbol + @test Groups.AutSymbol(perm"(4)") isa Groups.AutSymbol + @test Groups.AutSymbol(perm"(1,2,3,4)") isa Groups.AutSymbol + @test Groups.transvection_R(1,2) isa Groups.AutSymbol + @test Groups.transvection_R(3,4) isa Groups.AutSymbol + @test Groups.flip(3) isa Groups.AutSymbol + + @test Groups.id_autsymbol() isa Groups.AutSymbol + @test inv(Groups.id_autsymbol()) isa Groups.AutSymbol + @test inv(Groups.id_autsymbol()) == Groups.id_autsymbol() end a,b,c,d = gens(FreeGroup(4)) @@ -88,35 +92,44 @@ @test isa(Automorphism{3}(f), Automorphism) @test isa(AutGroup(FreeGroup(3)), AbstractAlgebra.Group) @test isa(AutGroup(FreeGroup(1)), Groups.AbstractFPGroup) + A = AutGroup(FreeGroup(1)) - @test isa(Groups.gens(A), Vector{Automorphism{1}}) + @test Groups.gens(A) isa Vector{Automorphism{1}} @test length(Groups.gens(A)) == 1 + @test length(Groups.gens(Aut(FreeGroup(1)))) == 1 + @test Groups.gens(A) == [A(Groups.flip(1))] + A = AutGroup(FreeGroup(1), special=true) - @test length(Groups.gens(A)) == 0 + @test isempty(Groups.gens(A)) + @test Groups.gens(SAut(FreeGroup(1))) == Automorphism{1}[] + A = AutGroup(FreeGroup(2)) @test length(Groups.gens(A)) == 7 Agens = Groups.gens(A) + @test A(first(Agens)) isa Automorphism - @test isa(A(Groups.transvection_R(1,2)), Automorphism) + @test A(Groups.transvection_R(1,2)) isa Automorphism @test A(Groups.transvection_R(1,2)) in Agens - @test isa(A(Groups.transvection_R(2,1)), Automorphism) + @test A(Groups.transvection_R(2,1)) isa Automorphism @test A(Groups.transvection_R(2,1)) in Agens - @test isa(A(Groups.transvection_R(1,2)), Automorphism) + @test A(Groups.transvection_R(1,2)) isa Automorphism @test A(Groups.transvection_R(1,2)) in Agens - @test isa(A(Groups.transvection_R(2,1)), Automorphism) + @test A(Groups.transvection_R(2,1)) isa Automorphism @test A(Groups.transvection_R(2,1)) in Agens - @test isa(A(Groups.flip(1)), Automorphism) + @test A(Groups.flip(1)) isa Automorphism @test A(Groups.flip(1)) in Agens - @test isa(A(Groups.flip(2)), Automorphism) + @test A(Groups.flip(2)) isa Automorphism @test A(Groups.flip(2)) in Agens - @test isa(A(Groups.AutSymbol(perm"(1,2)")), Automorphism) + @test A(Groups.AutSymbol(perm"(1,2)")) isa Automorphism @test A(Groups.AutSymbol(perm"(1,2)")) in Agens + + @test A(Groups.id_autsymbol()) isa Automorphism end A = AutGroup(FreeGroup(4)) @@ -144,8 +157,8 @@ @test f²^2 == one(A) @test !isone(f²) - a = A(Groups.transvection_L(1,2))*Groups.flip(2) - b = Groups.flip(2)*A(inv(Groups.transvection_L(1,2))) + a = A(Groups.λ(1,2))*Groups.ε(2) + b = Groups.ε(2)*A(inv(Groups.λ(1,2))) @test a*b == b*a @test a^3 * b^3 == one(A) g,h = Groups.gens(A)[[1,8]] # (g, h) = (ϱ₁₂, ϱ₃₂) From 834a8eb107ed811b401ca0cdd0f1c38de06be558 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Mon, 20 Apr 2020 02:41:38 +0200 Subject: [PATCH 3/4] bump version to 0.4.1 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 58a8539..2ff5726 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Groups" uuid = "5d8bd718-bd84-11e8-3b40-ad14f4a32557" authors = ["Marek Kaluba "] -version = "0.4.0" +version = "0.4.1" [deps] AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" From 51f3ad6cdb31f7d28ca18ae5cf0281a8f17f35ba Mon Sep 17 00:00:00 2001 From: kalmarek Date: Mon, 20 Apr 2020 02:44:28 +0200 Subject: [PATCH 4/4] test for abelianize of Identity --- test/AutGroup-tests.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/AutGroup-tests.jl b/test/AutGroup-tests.jl index 54cc0f0..50621e2 100644 --- a/test/AutGroup-tests.jl +++ b/test/AutGroup-tests.jl @@ -266,6 +266,8 @@ @test Groups.abelianize(σ^3) == Matrix{Int}(I, N, N) @test Groups.abelianize(σ)^3 == Matrix{Int}(I, N, N) + @test Groups.abelianize(G(Groups.id_autsymbol())) == Matrix{Int}(I, N, N) + function test_homomorphism(S, r) for elts in Iterators.product([[g for g in S] for _ in 1:r]...) prod(Groups.abelianize.(elts)) == Groups.abelianize(prod(elts)) || error("linear representaton test failed at $elts")