1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-25 02:05:30 +01:00

move from G() to Base.one(G)

This commit is contained in:
kalmarek 2019-11-14 09:21:11 +01:00
parent 32e968a79b
commit dd4ed1497c
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
10 changed files with 45 additions and 44 deletions

View File

@ -192,7 +192,7 @@ SAut(G::Group) = AutGroup(G, special=true)
Automorphism{N}(s::AutSymbol) where N = Automorphism{N}(AutSymbol[s])
function (G::AutGroup{N})() where N
function Base.one(G::AutGroup{N}) where N
id = Automorphism{N}(id_autsymbol())
id.parent = G
return id

View File

@ -96,8 +96,8 @@ end
(G::DirectPowerGroup{N})(a::Vararg{GrEl, N}) where {N, GrEl} = DirectPowerGroupElem(G.group.(a))
function (G::DirectPowerGroup{N})() where N
return DirectPowerGroupElem(ntuple(i->G.group(),N))
function Base.one(G::DirectPowerGroup{N}) where N
return DirectPowerGroupElem(ntuple(i->one(G.group),N))
end
(G::DirectPowerGroup)(g::DirectPowerGroupElem) = G(g.elts)
@ -192,7 +192,7 @@ length(G::DirectPowerGroup) = order(G)
function iterate(G::DirectPowerGroup{N}) where N
elts = collect(G.group)
indices = CartesianIndices(ntuple(i -> order(G.group), N))
idx, s = iterate(indices)
g = DirectPowerGroupElem(ntuple(i -> elts[idx[i]], N))

View File

@ -58,7 +58,7 @@ FPGroup(H::FreeGroup) = FPGroup([FPSymbol(s) for s in H.gens])
#
###############################################################################
function (G::FPGroup)()
function Base.one(G::FPGroup)
id = FPGroupElem(FPSymbol[])
id.parent = G
return id
@ -66,7 +66,7 @@ end
function (G::FPGroup)(w::GWord)
if length(w) == 0
return G()
return one(G)
end
if eltype(w.symbols) == FreeSymbol
@ -175,7 +175,7 @@ function /(G::FPGroup, newrels::Vector{FPGroupElem})
"Can not form quotient group: $r is not an element of $G"))
end
H = deepcopy(G)
newrels = Dict(H(r) => H() for r in newrels)
newrels = Dict(H(r) => one(H) for r in newrels)
add_rels!(H, newrels)
return H
end
@ -186,6 +186,6 @@ function /(G::FreeGroup, rels::Vector{FreeGroupElem})
"Can not form quotient group: $r is not an element of $G"))
end
H = FPGroup(G)
H.rels = Dict(H(rel) => H() for rel in unique(rels))
H.rels = Dict(H(rel) => one(H) for rel in unique(rels))
return H
end

View File

@ -52,7 +52,7 @@ FreeGroup(a::Vector) = FreeGroup(FreeSymbol.(a))
#
###############################################################################
function (G::FreeGroup)()
function Base.one(G::FreeGroup)
id = FreeGroupElem(FreeSymbol[])
id.parent = G
return id

View File

@ -15,6 +15,8 @@ export elements
using LinearAlgebra
using Markdown
Base.one(G::Generic.PermGroup) = G(collect(1:G.n), false)
###############################################################################
#
# ParentType / ObjectType definition
@ -280,7 +282,7 @@ function power_by_squaring(W::GWord, p::Integer)
if p < 0
return power_by_squaring(inv(W), -p)
elseif p == 0
return parent(W)()
return one(parent(W))
elseif p == 1
return W
elseif p == 2
@ -425,7 +427,7 @@ end
#
###############################################################################
function generate_balls(S::AbstractVector{T}, Id::T=parent(first(S))();
function generate_balls(S::AbstractVector{T}, Id::T=one(parent(first(S)));
radius=2, op=*) where T<:GroupElem
sizes = Int[]
B = [Id]

View File

@ -75,20 +75,20 @@ end
"""
(G::WreathProduct)(n::DirectPowerGroupElem, p::Generic.Perm) = WreathProductElem(n,p)
(G::WreathProduct)() = WreathProductElem(G.N(), G.P(), false)
Base.one(G::WreathProduct) = WreathProductElem(one(G.N), one(G.P), false)
@doc doc"""
(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(one(G.N), p)
@doc doc"""
(G::WreathProduct)(n::DirectPowerGroupElem)
> Returns the image of `n` in `G` via embedding `n -> (n,())`. This is the
> embedding that makes the sequence `1 -> N -> G -> P -> 1` exact.
"""
(G::WreathProduct)(n::DirectPowerGroupElem) = G(n, G.P())
(G::WreathProduct)(n::DirectPowerGroupElem) = G(n, one(G.P))
(G::WreathProduct)(n,p) = G(G.N(n), G.P(p))

View File

@ -140,12 +140,12 @@
= Groups.r_multiply(A(f), [f], reduced=false)
@test Groups.simplifyperms!() == false
@test ^2 == A()
@test ^2 == one(A)
a = A(Groups.rmul_autsymbol(1,2))*Groups.flip_autsymbol(2)
b = Groups.flip_autsymbol(2)*A(inv(Groups.rmul_autsymbol(1,2)))
@test a*b == b*a
@test a^3 * b^3 == A()
@test a^3 * b^3 == one(A)
g,h = Groups.gens(A)[[1,8]] # (g, h) = (ϱ₁₂, ϱ₃₂)
@test Groups.domain(A) == NTuple{4, FreeGroupElem}(gens(A.objectGroup))
@ -201,7 +201,7 @@
G = AutGroup(FreeGroup(N), special=true)
S = gens(G)
S_inv = [G(), S..., [inv(s) for s in S]...]
S_inv = [one(G), S..., [inv(s) for s in S]...]
S_inv = unique(S_inv)
B_2 = [i*j for (i,j) in Base.product(S_inv, S_inv)]
@test length(B_2) == 2401
@ -214,8 +214,8 @@
S = unique([gens(G); inv.(gens(G))])
R = 3
@test Groups.linear_repr(G()) isa Matrix{Int}
@test Groups.linear_repr(G()) == Matrix{Int}(I, N, N)
@test Groups.linear_repr(one(G)) isa Matrix{Int}
@test Groups.linear_repr(one(G)) == Matrix{Int}(I, N, N)
M = Matrix{Int}(I, N, N)
M[1,2] = 1

View File

@ -13,12 +13,12 @@
@test (G×G)×G == (G×G)×G
GG = DirectPowerGroup(G,2)
@test (G×G)() isa GroupElem
@test (G×G)((G(), G())) isa GroupElem
@test (G×G)([G(), G()]) isa GroupElem
@test one(G×G) isa GroupElem
@test (G×G)((one(G), one(G))) isa GroupElem
@test (G×G)([one(G), one(G)]) isa GroupElem
@test Groups.DirectPowerGroupElem((G(), G())) == (G×G)()
@test GG(G(), G()) == (G×G)()
@test Groups.DirectPowerGroupElem((one(G), one(G))) == one(G×G)
@test GG(one(G), one(G)) == one(G×G)
g = perm"(1,2,3)"
@ -37,8 +37,8 @@
@test h[1] == g
@test h[2] == g^2
h = GG(g, G())
@test h == GG(g, G())
h = GG(g, one(G))
@test h == GG(g, one(G))
end
@testset "Basic arithmetic" begin
@ -51,17 +51,17 @@
k = GG(g^3, g^2)
@test h^2 == GG(g^2,g)
@test h^6 == GG()
@test h^6 == one(GG)
@test h*h == h^2
@test h*k == GG(g,g)
@test h*inv(h) == (G×G)()
@test h*inv(h) == one(G×G)
w = GG(g,i)*GG(i,g)
@test w == GG(perm"(1,2)(3)", perm"(2,3)")
@test w == inv(w)
@test w^2 == w*w == GG()
@test w^2 == w*w == one(GG)
end
@testset "elem/parent_types" begin
@ -83,7 +83,7 @@
elts = vec(collect(GG))
@test length(elts) == 216
@test all([g*inv(g) == GG() for g in elts])
@test all([g*inv(g) == one(GG) for g in elts])
@test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts)
end
end

View File

@ -1,4 +1,3 @@
@testset "Groups.FreeSymbols" begin
s = Groups.FreeSymbol(:s)
t = Groups.FreeSymbol(:t)
@ -45,7 +44,7 @@ end
G = FreeGroup(["s", "t"])
@testset "elements constructors" begin
@test isa(G(), FreeGroupElem)
@test isa(one(G), FreeGroupElem)
@test eltype(G.gens) == Groups.FreeSymbol
@test length(G.gens) == 2
@test eltype(gens(G)) == FreeGroupElem
@ -76,17 +75,17 @@ end
end
@testset "reductions" begin
@test length(G().symbols) == 0
@test length((G()*G()).symbols) == 0
@test G() == G()*G()
@test length(one(G).symbols) == 0
@test length((one(G)*one(G)).symbols) == 0
@test one(G) == one(G)*one(G)
w = deepcopy(s)
push!(w.symbols, (s^-1).symbols[1])
@test Groups.reduce!(w) == parent(w)()
@test Groups.reduce!(w) == one(parent(w))
o = (t*s)^3
@test o == t*s*t*s*t*s
p = (t*s)^-3
@test p == s^-1*t^-1*s^-1*t^-1*s^-1*t^-1
@test o*p == parent(o*p)()
@test o*p == one(parent(o*p))
w = FreeGroupElem([o.symbols..., p.symbols...])
w.parent = G
@test Groups.reduce!(w).symbols ==Vector{Groups.FreeSymbol}([])
@ -123,7 +122,7 @@ end
@test findfirst(c*t, c) == 0
w = s*t*s^-1
subst = Dict{FreeGroupElem, FreeGroupElem}(w => s^1, s*t^-1 => t^4)
@test Groups.replace(c, 1, s*t, G()) == s^-1*t^-1
@test Groups.replace(c, 1, s*t, one(G)) == s^-1*t^-1
@test Groups.replace(c, 1, w, subst[w]) == s*t^-1
@test Groups.replace(s*c*t^-1, 1, w, subst[w]) == s^2*t^-2
@test Groups.replace(t*c*t, 2, w, subst[w]) == t*s

View File

@ -24,8 +24,8 @@
@test B3(aa, b) == Groups.WreathProductElem(aa, b)
w = B3(aa, b)
@test B3(w) == w
@test B3(b) == Groups.WreathProductElem(B3.N(), b)
@test B3(aa) == Groups.WreathProductElem(aa, S_3())
@test B3(b) == Groups.WreathProductElem(one(B3.N), b)
@test B3(aa) == Groups.WreathProductElem(aa, one(S_3))
@test B3((a^0 ,a, a^2), b) isa WreathProductElem
@ -37,10 +37,10 @@
@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}}
@test parent_type(typeof(one(B3))) == Groups.WreathProduct{3, parent_type(typeof(one(B3.N.group))), Generic.PermGroup{Int}}
@test parent(B3()) == Groups.WreathProduct(S_2,S_3)
@test parent(B3()) == B3
@test parent(one(B3)) == Groups.WreathProduct(S_2,S_3)
@test parent(one(B3)) == B3
end
@testset "Basic operations on WreathProductElem" begin
@ -91,7 +91,7 @@
@test order(Wr) == 2^4*factorial(4)
@test length(elts) == order(Wr)
@test all([g*inv(g) == Wr() for g in elts])
@test all((g*inv(g) == one(Wr) for g in elts))
@test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts)
end