1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-11-19 06:30:29 +01:00

Merge pull request #5 from kalmarek/aa_v0.7

Aa v0.7
This commit is contained in:
kalmarek 2019-10-30 19:38:33 +01:00 committed by GitHub
commit 752787b3ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 280 deletions

View File

@ -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);'

View File

@ -1,7 +1,7 @@
name = "Groups"
uuid = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
authors = ["Marek Kaluba <kalmar@amu.edu.pl>"]
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"

View File

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

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

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

View File

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

@ -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}}
@ -64,62 +64,35 @@
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)
@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])
@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