From 998a9cdf43a8bac4e09b408da0138ff085a96a72 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 30 Oct 2019 16:22:58 +0100 Subject: [PATCH 1/3] remove MltGrp/AddGrp --- src/DirectPower.jl | 96 ------------------------------ test/DirectPower-tests.jl | 120 -------------------------------------- test/WreathProd-tests.jl | 47 ++++----------- 3 files changed, 10 insertions(+), 253 deletions(-) diff --git a/src/DirectPower.jl b/src/DirectPower.jl index 26fd545..9b3e7f2 100644 --- a/src/DirectPower.jl +++ b/src/DirectPower.jl @@ -1,100 +1,4 @@ export DirectPowerGroup, DirectPowerGroupElem -export MultiplicativeGroup, MltGrp, MltGrpElem -export AdditiveGroup, AddGrp, AddGrpElem - -############################################################################### -# -# MltGrp/MltGrpElem & AddGrp/AddGrpElem -# (a thin wrapper for multiplicative/additive group of a Ring) -# -############################################################################### - -for (Gr, Elem) in [(:MltGrp, :MltGrpElem), (:AddGrp, :AddGrpElem)] - @eval begin - struct $Gr{T<:AbstractAlgebra.Ring} <: AbstractAlgebra.Group - obj::T - end - - struct $Elem{T<:AbstractAlgebra.RingElem} <: AbstractAlgebra.GroupElem - elt::T - end - - ==(g::$Elem, h::$Elem) = g.elt == h.elt - ==(G::$Gr, H::$Gr) = G.obj == H.obj - - elem_type(::Type{$Gr{T}}) where T = $Elem{elem_type(T)} - eltype(::Type{$Gr{T}}) where T = $Elem{elem_type(T)} - parent_type(::Type{$Elem{T}}) where T = $Gr{parent_type(T)} - parent(g::$Elem) = $Gr(parent(g.elt)) - length(G::$Gr{<:AbstractAlgebra.Ring}) = order(G.obj) - end -end - -MultiplicativeGroup = MltGrp -AdditiveGroup = AddGrp - -(G::MltGrp)(g::MltGrpElem) = MltGrpElem(G.obj(g.elt)) - -function (G::MltGrp)(g) - r = (G.obj)(g) - isunit(r) || throw(DomainError( - "Cannot coerce to multplicative group: $r is not invertible!")) - return MltGrpElem(r) -end - -(G::AddGrp)(g) = AddGrpElem((G.obj)(g)) - -(G::MltGrp)() = MltGrpElem(G.obj(1)) -(G::AddGrp)() = AddGrpElem(G.obj()) - -inv(g::MltGrpElem) = MltGrpElem(inv(g.elt)) -inv(g::AddGrpElem) = AddGrpElem(-g.elt) - -for (Elem, op) in ([:MltGrpElem, :*], [:AddGrpElem, :+]) - @eval begin - - ^(g::$Elem, n::Integer) = $Elem(op(g.elt, n)) - - function *(g::$Elem, h::$Elem) - parent(g) == parent(h) || throw(DomainError( - "Cannot multiply elements of different parents")) - return $Elem($op(g.elt,h.elt)) - end - end -end - -show(io::IO, G::MltGrp) = print(io, "The multiplicative group of $(G.obj)") -show(io::IO, G::AddGrp) = print(io, "The additive group of $(G.obj)") - -show(io::IO, g::Union{MltGrpElem, AddGrpElem}) = show(io, g.elt) - -gens(F::AbstractAlgebra.Field) = elem_type(F)[gen(F)] - -order(G::AddGrp{<:AbstractAlgebra.GFField}) = order(G.obj) - -order(G::MltGrp{<:AbstractAlgebra.GFField}) = order(G.obj) - 1 - - -function iterate(G::AddGrp, s=0) - if s >= order(G) - return nothing - else - g, s = iterate(G.obj,s) - return G(g), s - end -end - -function iterate(G::MltGrp, s=0) - if s > order(G) - return nothing - else - g, s = iterate(G.obj, s) - if g == G.obj() - g, s = iterate(G.obj, s) - end - return G(g), s - end -end ############################################################################### # diff --git a/test/DirectPower-tests.jl b/test/DirectPower-tests.jl index 120634c..95116e0 100644 --- a/test/DirectPower-tests.jl +++ b/test/DirectPower-tests.jl @@ -72,129 +72,9 @@ @test elem_type(G×G×G) == DirectPowerGroupElem{3, elem_type(G)} @test parent_type(typeof((G×G)(g,g^2))) == Groups.DirectPowerGroup{2, typeof(G)} @test parent(DirectPowerGroupElem((g,g^2,g^3))) == DirectPowerGroup(G,3) - - F = AdditiveGroup(GF(13)) - - @test elem_type(F×F) == - DirectPowerGroupElem{2, Groups.AddGrpElem{AbstractAlgebra.gfelem{Int}}} - @test parent_type(typeof((F×F)(1,5))) == - Groups.DirectPowerGroup{2, Groups.AddGrp{AbstractAlgebra.GFField{Int}}} - parent((F×F)(1,5)) == DirectPowerGroup(F,2) - - F = MultiplicativeGroup(GF(13)) - - @test elem_type(F×F) == - DirectPowerGroupElem{2, Groups.MltGrpElem{AbstractAlgebra.gfelem{Int}}} - @test parent_type(typeof((F×F)(1,5))) == - Groups.DirectPowerGroup{2, Groups.MltGrp{AbstractAlgebra.GFField{Int}}} - parent((F×F)(1,5)) == DirectPowerGroup(F,2) - end - - @testset "Additive/Multiplicative groups" begin - - R, x = PolynomialRing(QQ, "x") - F, a = NumberField(x^3 + x + 1, "a") - G = PermutationGroup(3) - - @testset "MltGrp basic functionality" begin - Gr = MltGrp(F) - @test Gr(a) isa MltGrpElem - g = Gr(a) - @test deepcopy(g) isa MltGrpElem - @test inv(g) == Gr(a^-1) - @test Gr() == Gr(1) - @test inv(g)*g == Gr() - end - - @testset "AddGrp basic functionality" begin - Gr = AddGrp(F) - @test Gr(a) isa AddGrpElem - g = Gr(a) - @test deepcopy(g) isa AddGrpElem - @test inv(g) == Gr(-a) - @test Gr() == Gr(0) - @test inv(g)*g == Gr() - end - end - - @testset "Direct Product of Multiplicative Groups" begin - - R, x = PolynomialRing(QQ, "x") - F, a = NumberField(x^3 + x + 1, "a") - FF = Groups.DirectPowerGroup(MltGrp(F),2) - - @test FF([a,1]) isa GroupElem - @test FF([a,1]) isa DirectPowerGroupElem - @test FF([a,1]) isa DirectPowerGroupElem{2, MltGrpElem{elem_type(F)}} - @test_throws DomainError FF(1,0) - @test_throws DomainError FF([0,1]) - @test_throws DomainError FF([1,0]) - - @test MltGrp(F) isa AbstractAlgebra.Group - @test MltGrp(F) isa MultiplicativeGroup - @test DirectPowerGroup(MltGrp(F), 2) isa AbstractAlgebra.Group - @test DirectPowerGroup(MltGrp(F), 2) isa DirectPowerGroup{2, MltGrp{typeof(F)}} - - F, a = NumberField(x^3 + x + 1, "a") - FF = DirectPowerGroup(MltGrp(F), 2) - - @test FF(a,a+1) == FF([a,a+1]) - @test FF([1,a+1])*FF([a,a]) == FF(a,a^2+a) - x, y = FF([1,a]), FF([a^2,1]) - @test x*y == FF([a^2, a]) - @test inv(x) == FF([1,-a^2-1]) - - @test parent(x) == FF - end - - @testset "Direct Product of Additive Groups" begin - - R, x = PolynomialRing(QQ, "x") - F, a = NumberField(x^3 + x + 1, "a") - - # Additive Group - @test AddGrp(F) isa AbstractAlgebra.Group - @test AddGrp(F) isa AdditiveGroup - @test DirectPowerGroup(AddGrp(F), 2) isa AbstractAlgebra.Group - @test DirectPowerGroup(AddGrp(F), 2) isa DirectPowerGroup{2, AddGrp{typeof(F)}} - - FF = DirectPowerGroup(AdditiveGroup(F), 2) - - @test FF([0,a]) isa AbstractAlgebra.GroupElem - @test FF(F(0),a) isa DirectPowerGroupElem - @test FF(0,0) isa DirectPowerGroupElem{2, AddGrpElem{elem_type(F)}} - - @test FF(F(1),a+1) == FF([1,a+1]) - - @test FF([F(1),a+1])*FF([a,a]) == FF(1+a,2a+1) - - x, y = FF([1,a]), FF([a^2,1]) - @test x*y == FF(a^2+1, a+1) - @test inv(x) == FF([F(-1),-a]) - - @test parent(x) == FF end @testset "Misc" begin - F = GF(5) - - FF = DirectPowerGroup(AdditiveGroup(F),2) - @test order(FF) == 25 - - elts = vec(collect(FF)) - @test length(elts) == 25 - @test all([g*inv(g) == FF() for g in elts]) - @test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts) - - FF = DirectPowerGroup(MultiplicativeGroup(F), 3) - @test order(FF) == 64 - - elts = vec(collect(FF)) - @test length(elts) == 64 - @test all([g*inv(g) == FF() for g in elts]) - @test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts) - - G = PermutationGroup(3) GG = Groups.DirectPowerGroup(G,3) @test order(GG) == 216 diff --git a/test/WreathProd-tests.jl b/test/WreathProd-tests.jl index 0781574..d251536 100644 --- a/test/WreathProd-tests.jl +++ b/test/WreathProd-tests.jl @@ -64,40 +64,26 @@ end @testset "Group arithmetic" begin - B4 = Groups.WreathProduct(AdditiveGroup(GF(3)), PermutationGroup(4)) + B4 = Groups.WreathProduct(PermutationGroup(3), PermutationGroup(4)) - x = B4((0,1,2,0), perm"(1,2,3)(4)") - @test inv(x) == B4((1,0,2,0), perm"(1,3,2)(4)") + id, a, b = perm"(3)", perm"(1,2)(3)", perm"(1,2,3)" - y = B4((1,0,1,2), perm"(1,4)(2,3)") - @test inv(y) == B4((1,2,0,2), perm"(1,4)(2,3)") + x = B4((id,a,b,id), perm"(1,2,3)(4)") + @test inv(x) == B4((inv(b),id, a,id), perm"(1,3,2)(4)") - @test x*y == B4((0,2,0,2), perm"(1,3,4)(2)") + y = B4((a,id,a,b), perm"(1,4)(2,3)") + @test inv(y) == B4((inv(b), a,id, a), perm"(1,4)(2,3)") - @test y*x == B4((1,2,2,2), perm"(1,4,2)(3)") + @test x*y == B4((id,id,b*a,b), perm"(1,3,4)(2)") + @test y*x == B4(( a, b, id,b), perm"(1,4,2)(3)") + @test inv(x)*y == B4((inv(b)*a,a,a,b), perm"(1,2,4)(3)") + @test y*inv(x) == B4((a,a,a,id), perm"(1,4,3)(2)") - @test inv(x)*y == B4((2,1,2,2), perm"(1,2,4)(3)") - - @test y*inv(x) == B4((1,2,1,0), perm"(1,4,3)(2)") - @test (x*y)^6 == ((x*y)^2)^3 - end @testset "Iteration" begin - B3_a = Groups.WreathProduct(AdditiveGroup(GF(3)), S_3) - @test order(B3_a) == 3^3*6 - @test collect(B3_a) isa Vector{ - WreathProductElem{3, AddGrpElem{AbstractAlgebra.gfelem{Int}}, perm{Int}}} - - B3_m = Groups.WreathProduct(MultiplicativeGroup(GF(3)), S_3) - @test order(B3_m) == 2^3*6 - @test collect(B3_m) isa Vector{ - WreathProductElem{3, MltGrpElem{AbstractAlgebra.gfelem{Int}}, perm{Int}}} - - @test length(Set([B3_a, B3_m, B3_a])) == 2 - Wr = WreathProduct(PermutationGroup(2),PermutationGroup(4)) elts = collect(Wr) @@ -108,18 +94,5 @@ @test all([g*inv(g) == Wr() for g in elts]) @test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts) end - - @testset "Misc" begin - B3_a = Groups.WreathProduct(AdditiveGroup(GF(3)), S_3) - @test string(B3_a) == "Wreath Product of The additive group of Finite field F_3 by Permutation group over 3 elements" - - @test string(B3_a(perm"(1,3)")) == "([0,0,0]≀(1,3))" - - B3_m = Groups.WreathProduct(MultiplicativeGroup(GF(3)), S_3) - @test string(B3_m) == "Wreath Product of The multiplicative group of Finite field F_3 by Permutation group over 3 elements" - - @test string(B3_m(perm"(1,3)")) == "([1,1,1]≀(1,3))" - - end end From 8a42e33b6dcbe33fc3cf4f5e19adb6853b5c3593 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 30 Oct 2019 16:25:09 +0100 Subject: [PATCH 2/3] =?UTF-8?q?update=20to=20AA-v0.7=20=E2=86=92=20bump=20?= =?UTF-8?q?to=20v0.2.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project.toml | 5 ++++- src/AutGroup.jl | 8 ++++---- src/WreathProducts.jl | 20 ++++++++++---------- test/DirectPower-tests.jl | 6 +++--- test/WreathProd-tests.jl | 10 +++++----- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Project.toml b/Project.toml index 39cbdee..c0b99d1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Groups" uuid = "5d8bd718-bd84-11e8-3b40-ad14f4a32557" authors = ["Marek Kaluba "] -version = "0.2.2" +version = "0.2.3" [deps] AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" @@ -13,3 +13,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Test"] + +[compat] +AbstractAlgebra = "^0.7.0" diff --git a/src/AutGroup.jl b/src/AutGroup.jl index 6c80552..8ca68aa 100644 --- a/src/AutGroup.jl +++ b/src/AutGroup.jl @@ -19,7 +19,7 @@ struct FlipAut end struct PermAut - perm::Generic.perm{Int8} + perm::Generic.Perm{Int8} end struct Identity end @@ -130,7 +130,7 @@ function flip_autsymbol(i::Integer; pow::Integer=1) end end -function perm_autsymbol(p::Generic.perm{I}; pow::Integer=one(I)) where I<:Integer +function perm_autsymbol(p::Generic.Perm{I}; pow::Integer=one(I)) where I<:Integer if pow != 1 p = p^pow end @@ -143,8 +143,8 @@ function perm_autsymbol(p::Generic.perm{I}; pow::Integer=one(I)) where I<:Intege return id_autsymbol() end -function perm_autsymbol(a::Vector{T}) where T<:Integer - return perm_autsymbol(perm(Vector{Int8}(a), false)) +function perm_autsymbol(a::Vector{<:Integer}) + return perm_autsymbol(Generic.Perm(Vector{Int8}(a), false)) end function domain(G::AutGroup{N}) where N diff --git a/src/WreathProducts.jl b/src/WreathProducts.jl index 562f45c..37e19e6 100644 --- a/src/WreathProducts.jl +++ b/src/WreathProducts.jl @@ -29,12 +29,12 @@ struct WreathProduct{N, T<:Group, PG<:Generic.PermGroup} <: Group end end -struct WreathProductElem{N, T<:GroupElem, P<:Generic.perm} <: GroupElem +struct WreathProductElem{N, T<:GroupElem, P<:Generic.Perm} <: GroupElem n::DirectPowerGroupElem{N, T} p::P function WreathProductElem(n::DirectPowerGroupElem{N,T}, p::P, - check::Bool=true) where {N, T, P<:Generic.perm} + check::Bool=true) where {N, T, P<:Generic.Perm} if check N == length(p.d) || throw(DomainError( "Can't form WreathProductElem: lengths differ")) @@ -69,19 +69,19 @@ function (G::WreathProduct{N})(g::WreathProductElem{N}) where {N} end @doc doc""" - (G::WreathProduct)(n::DirectPowerGroupElem, p::Generic.perm) + (G::WreathProduct)(n::DirectPowerGroupElem, p::Generic.Perm) > Creates an element of wreath product `G` by coercing `n` and `p` to `G.N` and > `G.P`, respectively. """ -(G::WreathProduct)(n::DirectPowerGroupElem, p::Generic.perm) = WreathProductElem(n,p) +(G::WreathProduct)(n::DirectPowerGroupElem, p::Generic.Perm) = WreathProductElem(n,p) (G::WreathProduct)() = WreathProductElem(G.N(), G.P(), false) @doc doc""" - (G::WreathProduct)(p::Generic.perm) + (G::WreathProduct)(p::Generic.Perm) > Returns the image of permutation `p` in `G` via embedding `p -> (id,p)`. """ -(G::WreathProduct)(p::Generic.perm) = G(G.N(), p) +(G::WreathProduct)(p::Generic.Perm) = G(G.N(), p) @doc doc""" (G::WreathProduct)(n::DirectPowerGroupElem) @@ -144,7 +144,7 @@ end # ############################################################################### -(p::perm)(n::DirectPowerGroupElem) = DirectPowerGroupElem(n.elts[p.d]) +(p::Generic.Perm)(n::DirectPowerGroupElem) = DirectPowerGroupElem(n.elts[p.d]) @doc doc""" *(g::WreathProductElem, h::WreathProductElem) @@ -152,7 +152,7 @@ end > > `g*h = (g.n*g.p(h.n), g.p*h.p)`, > -> where `g.p(h.n)` denotes the action of `g.p::Generic.perm` on +> where `g.p(h.n)` denotes the action of `g.p::Generic.Perm` on > `h.n::DirectPowerGroupElem` via standard permutation of coordinates. """ function *(g::WreathProductElem, h::WreathProductElem) @@ -188,7 +188,7 @@ end function iterate(G::WreathProduct, state) state_N, p, state_P = state res = iterate(G.N, state_N) - + if res == nothing resP = iterate(G.P, state_P) if resP == nothing @@ -200,7 +200,7 @@ function iterate(G::WreathProduct, state) else n, state_N = res end - + return G(n,p), (state_N, p, state_P) end diff --git a/test/DirectPower-tests.jl b/test/DirectPower-tests.jl index 95116e0..1409ece 100644 --- a/test/DirectPower-tests.jl +++ b/test/DirectPower-tests.jl @@ -23,7 +23,7 @@ g = perm"(1,2,3)" @test GG(g, g^2) isa GroupElem - @test GG(g, g^2) isa Groups.DirectPowerGroupElem{2, Generic.perm{Int64}} + @test GG(g, g^2) isa Groups.DirectPowerGroupElem{2, Generic.Perm{Int64}} h = GG(g,g^2) @@ -46,7 +46,7 @@ GG = G×G i = perm"(1,3)" g = perm"(1,2,3)" - + h = GG(g,g^2) k = GG(g^3, g^2) @@ -57,7 +57,7 @@ @test h*k == GG(g,g) @test h*inv(h) == (G×G)() - + w = GG(g,i)*GG(i,g) @test w == GG(perm"(1,2)(3)", perm"(2,3)") @test w == inv(w) diff --git a/test/WreathProd-tests.jl b/test/WreathProd-tests.jl index d251536..670842f 100644 --- a/test/WreathProd-tests.jl +++ b/test/WreathProd-tests.jl @@ -15,8 +15,8 @@ @test Groups.WreathProductElem(aa, b) isa AbstractAlgebra.GroupElem x = Groups.WreathProductElem(aa, b) @test x isa Groups.WreathProductElem - @test x isa - Groups.WreathProductElem{3, perm{Int}, perm{Int}} + @test x isa + Groups.WreathProductElem{3, Generic.Perm{Int}, Generic.Perm{Int}} @test B3.N == Groups.DirectPowerGroup(S_2, 3) @test B3.P == S_3 @@ -35,7 +35,7 @@ @testset "Types" begin B3 = Groups.WreathProduct(S_2, S_3) - @test elem_type(B3) == Groups.WreathProductElem{3, perm{Int}, perm{Int}} + @test elem_type(B3) == Groups.WreathProductElem{3, Generic.Perm{Int}, Generic.Perm{Int}} @test parent_type(typeof(B3())) == Groups.WreathProduct{3, parent_type(typeof(B3.N.group())), Generic.PermGroup{Int}} @@ -87,8 +87,8 @@ Wr = WreathProduct(PermutationGroup(2),PermutationGroup(4)) elts = collect(Wr) - @test elts isa Vector{Groups.WreathProductElem{4, perm{Int}, perm{Int}}} - @test order(Wr) == 2^4*factorial(4) + @test elts isa Vector{Groups.WreathProductElem{4, Generic.Perm{Int}, Generic.Perm{Int}}} + @test order(Wr) == 2^4*factorial(4) @test length(elts) == order(Wr) @test all([g*inv(g) == Wr() for g in elts]) From 0f58561d506941235dc0b8f6fbd0dcaf0c6dc8a1 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 30 Oct 2019 16:28:22 +0100 Subject: [PATCH 3/3] update travis --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2bc2bb0..ec9d8e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ os: julia: - 1.0 - 1.1 + - 1.2 + - 1.3 - nightly notifications: email: true @@ -19,7 +21,3 @@ matrix: # - julia -e 'Pkg.clone(pwd()); Pkg.build("Groups"); Pkg.test("Groups"; coverage=true)' codecov: true - -# after_success: - # push coverage results to Coveralls - #- julia -e 'using Pkg; Pkg.build(); Pkg.test(coverage=true);'