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

Merge pull request #9 from kalmarek/v0.4.1

even more tests
This commit is contained in:
kalmarek 2020-04-20 02:48:54 +02:00 committed by GitHub
commit a5fd4421d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 32 deletions

View File

@ -1,7 +1,7 @@
name = "Groups"
uuid = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
authors = ["Marek Kaluba <kalmar@amu.edu.pl>"]
version = "0.4.0"
version = "0.4.1"
[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"

View File

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

View File

@ -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
@ -65,7 +60,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 +183,6 @@ end
###############################################################################
order(G::DirectPowerGroup{N}) where N = order(G.group)^N
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)

View File

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

View File

@ -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 ^2 == one(A)
@test !isone()
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) = (ϱ₁₂, ϱ₃₂)
@ -253,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")

View File

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