1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-11-19 14:35:28 +01:00
Groups.jl/test/FreeGroup-tests.jl

189 lines
6.1 KiB
Julia
Raw Normal View History

2017-05-15 10:12:46 +02:00
@testset "Groups.FreeSymbols" begin
2019-01-03 03:37:37 +01:00
s = Groups.FreeSymbol(:s)
t = Groups.FreeSymbol(:t)
@testset "constructors" begin
2019-01-03 03:37:37 +01:00
@test isa(Groups.FreeSymbol(:aaaaaaaaaaaaaaaa), Groups.GSymbol)
@test Groups.FreeSymbol(:abc).pow == 1
2017-05-15 10:12:46 +02:00
@test isa(s, Groups.FreeSymbol)
@test isa(t, Groups.FreeSymbol)
end
@testset "eltary functions" begin
@test length(s) == 1
@test Groups.change_pow(s, 0) == Groups.change_pow(t, 0)
@test length(Groups.change_pow(s, 0)) == 0
@test inv(s).pow == -1
2019-01-03 03:37:37 +01:00
@test Groups.FreeSymbol(:s, 3) == Groups.change_pow(s, 3)
@test Groups.FreeSymbol(:s, 3) != Groups.FreeSymbol(:t, 3)
2017-05-15 10:12:46 +02:00
@test Groups.change_pow(inv(s), -3) == inv(Groups.change_pow(s, 3))
end
@testset "powers" begin
s⁴ = Groups.change_pow(s,4)
@test s⁴.pow == 4
2019-01-03 03:37:37 +01:00
@test Groups.change_pow(s, 4) == Groups.FreeSymbol(:s, 4)
2017-05-15 10:12:46 +02:00
end
end
2017-07-23 17:06:34 +02:00
@testset "FreeGroupSymbols manipulation" begin
2017-05-15 10:12:46 +02:00
s = Groups.FreeSymbol("s")
2019-01-03 03:37:37 +01:00
t = Groups.FreeSymbol(:t, -2)
2017-05-15 10:12:46 +02:00
@test isa(Groups.GroupWord(s), Groups.GWord{Groups.FreeSymbol})
@test isa(Groups.GroupWord(s), FreeGroupElem)
2017-07-23 17:06:34 +02:00
@test isa(FreeGroupElem(s), Groups.GWord)
@test isa(convert(FreeGroupElem, s), Groups.GWord)
@test isa(convert(FreeGroupElem, s), FreeGroupElem)
@test isa(Vector{FreeGroupElem}([s,t]), Vector{FreeGroupElem})
@test length(FreeGroupElem(s)) == 1
@test length(FreeGroupElem(t)) == 2
@test Groups.FreeSymbol(:s, 1) != Groups.FreeSymbol(:s, 2)
@test Groups.FreeSymbol(:s, 1) != Groups.FreeSymbol(:t, 1)
2020-04-20 02:02:57 +02:00
@test collect(Groups.FreeSymbol(:s, 2)) == [i for i in Groups.FreeSymbol(:s, 2)] == [s, s]
2017-05-15 10:12:46 +02:00
end
@testset "FreeGroup" begin
2018-07-30 15:20:37 +02:00
@test isa(FreeGroup(["s", "t"]), AbstractAlgebra.Group)
2017-05-15 10:12:46 +02:00
G = FreeGroup(["s", "t"])
2020-04-20 00:36:35 +02:00
s, t = gens(G)
2017-05-15 10:12:46 +02:00
@testset "elements constructors" begin
2019-11-14 09:21:11 +01:00
@test isa(one(G), FreeGroupElem)
2017-05-15 10:12:46 +02:00
@test eltype(G.gens) == Groups.FreeSymbol
@test length(G.gens) == 2
2018-07-30 08:30:27 +02:00
@test eltype(gens(G)) == FreeGroupElem
@test length(gens(G)) == 2
2017-05-15 10:12:46 +02:00
2020-04-20 00:36:35 +02:00
tt, ss = Groups.FreeSymbol(:t), Groups.FreeSymbol(:s)
2020-04-20 02:02:57 +02:00
@test Groups.GroupWord([tt, inv(tt)]) isa FreeGroupElem
@test collect(s*t) == Groups.syllables(s*t)
2020-04-20 00:36:35 +02:00
@test collect(t^2) == [tt, tt]
ttinv = Groups.FreeSymbol(:t, -1)
w = t^-2*s^3*t^2
@test collect(w) == [inv(tt), inv(tt), ss, ss, ss, tt, tt]
@test w[1] == inv(tt)
@test w[2] == inv(tt)
@test w[3] == ss
@test w[3:5] == [ss, ss, ss]
@test w[end] == tt
@test collect(ttinv) == [ttinv]
2020-04-20 02:02:57 +02:00
@test isone(t^0)
@test !isone(t^1)
2020-04-20 00:36:35 +02:00
end
2017-05-15 10:12:46 +02:00
@testset "internal arithmetic" begin
@test (s*s).symbols == (s^2).symbols
@test hash([t^1,s^1]) == hash([t^2*inv(t),s*inv(s)*s])
2019-01-03 03:37:37 +01:00
t_symb = Groups.FreeSymbol(:t)
2017-05-15 10:12:46 +02:00
tt = deepcopy(t)
@test string(Groups.rmul!(tt, tt, inv(tt))) == "(id)"
2017-05-15 10:12:46 +02:00
tt = deepcopy(t)
@test string(Groups.lmul!(tt, tt, inv(tt))) == "(id)"
2020-04-20 02:02:57 +02:00
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"
tt = deepcopy(t)
pushfirst!(tt, inv(t_symb))
@test string(tt) == "t^-1*t"
2017-05-15 10:12:46 +02:00
tt = deepcopy(t)
append!(tt, inv(t))
@test string(tt) == "t*t^-1"
tt = deepcopy(t)
prepend!(tt, inv(t))
@test string(tt) == "t^-1*t"
2017-05-15 10:12:46 +02:00
tt = deepcopy(t)
append!(tt, s, inv(t))
@test string(tt) == "t*s*t^-1"
2020-04-20 03:25:25 +02:00
o = one(t)
o_inv = inv(o)
@test o == o_inv
@test o !== o_inv
Groups.rmul!(o, t)
@test o != o_inv
2017-05-15 10:12:46 +02:00
end
@testset "reductions" begin
2019-11-14 09:21:11 +01:00
@test length(one(G).symbols) == 0
@test length((one(G)*one(G)).symbols) == 0
@test one(G) == one(G)*one(G)
2017-05-15 10:12:46 +02:00
w = deepcopy(s)
2020-03-25 05:25:02 +01:00
push!(Groups.syllables(w), (s^-1).symbols[1])
2019-11-14 09:21:11 +01:00
@test Groups.reduce!(w) == one(parent(w))
2017-05-15 10:12:46 +02:00
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
2019-11-14 09:21:11 +01:00
@test o*p == one(parent(o*p))
2017-05-15 10:12:46 +02:00
w = FreeGroupElem([o.symbols..., p.symbols...])
w.parent = G
@test Groups.syllables(Groups.reduce(w)) == Vector{Groups.FreeSymbol}([])
2017-05-15 10:12:46 +02:00
end
@testset "Group operations" begin
2017-05-15 10:12:46 +02:00
@test parent(s) == G
@test parent(s) === parent(deepcopy(s))
@test isa(s*t, FreeGroupElem)
@test parent(s*t) == parent(s^2)
@test s*s == s^2
@test inv(s*s) == inv(s^2)
@test inv(s)^2 == inv(s^2)
@test inv(s)*inv(s) == inv(s^2)
@test inv(s*t) == inv(t)*inv(s)
w = s*t*s^-1
@test inv(w) == s*t^-1*s^-1
@test (t*s*t^-1)^10 == t*s^10*t^-1
@test (t*s*t^-1)^-10 == t*s^-10*t^-1
end
@testset "replacements" begin
2019-01-03 03:37:37 +01:00
a = Groups.FreeSymbol(:a)
b = Groups.FreeSymbol(:b)
@test Groups.issubsymbol(a, Groups.change_pow(a,2)) == true
@test Groups.issubsymbol(a, Groups.change_pow(a,-2)) == false
@test Groups.issubsymbol(b, Groups.change_pow(a,-2)) == false
@test Groups.issubsymbol(inv(b), Groups.change_pow(b,-2)) == true
2017-07-05 16:26:35 +02:00
2017-05-15 10:12:46 +02:00
c = s*t*s^-1*t^-1
2020-03-25 05:25:02 +01:00
@test findfirst(s^-1*t^-1, c) == 3
@test findnext(s^-1*t^-1, c*s^-1,3) == 3
@test findnext(s^-1*t^-1, c*s^-1*t^-1, 4) == 5
2020-03-25 05:25:02 +01:00
@test findfirst(c, c*t) === nothing
@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
2020-04-20 02:02:57 +02:00
@test findprev(Groups.FreeSymbol(:t, 2), c, 4) === nothing
2017-05-15 10:12:46 +02:00
w = s*t*s^-1
subst = Dict{FreeGroupElem, FreeGroupElem}(w => s^1, s*t^-1 => t^4)
2020-03-25 05:25:02 +01:00
@test Groups.replace(c, s*t=>one(G)) == s^-1*t^-1
@test Groups.replace(c, w=>subst[w]) == s*t^-1
@test Groups.replace(s*c*t^-1, w=>subst[w]) == s^2*t^-2
@test Groups.replace(t*c*t, w=>subst[w]) == t*s
@test Groups.replace(s*c*s*c*s, subst) == s*t^4*s*t^4*s
2017-07-05 16:21:16 +02:00
G = FreeGroup(["x", "y"])
2018-07-30 08:30:27 +02:00
x,y = gens(G)
2017-07-05 16:21:16 +02:00
2020-03-25 05:25:02 +01:00
@test Groups.replace(x*y^9, y^2=>y) == x*y^5
@test Groups.replace(x^3, x^2=>y) == x*y
@test Groups.replace(y*x^3*y, x^2=>y) == y*x*y^2
2017-05-15 10:12:46 +02:00
end
end