remove MltGrp/AddGrp

This commit is contained in:
kalmarek 2019-10-30 16:22:58 +01:00
parent 572e7e046f
commit 998a9cdf43
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
3 changed files with 10 additions and 253 deletions

View File

@ -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
###############################################################################
#

View File

@ -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

View File

@ -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