1
0
mirror of https://github.com/kalmarek/GroupRings.jl.git synced 2024-11-19 14:35:27 +01:00
GroupRings.jl/test/runtests.jl

331 lines
9.8 KiB
Julia
Raw Normal View History

2018-09-24 00:31:01 +02:00
using Test
2018-07-27 00:23:19 +02:00
using AbstractAlgebra
using GroupRings
2018-09-24 00:31:01 +02:00
using SparseArrays
2017-05-17 17:45:19 +02:00
2017-05-18 12:19:52 +02:00
@testset "GroupRings" begin
@testset "Constructors: PermutationGroup" begin
G = PermutationGroup(3)
2018-07-27 00:23:19 +02:00
@test isa(GroupRing(G), AbstractAlgebra.Ring)
2017-05-18 12:19:52 +02:00
@test isa(GroupRing(G), GroupRing)
2017-05-17 17:45:19 +02:00
2017-07-25 14:45:35 +02:00
RG = GroupRing(G)
@test isdefined(RG, :basis) == true
2017-05-18 12:19:52 +02:00
@test length(RG.basis) == 6
@test isdefined(RG, :basis_dict) == true
2017-07-25 14:45:35 +02:00
@test isdefined(RG, :pm) == false
2017-09-15 19:04:11 +02:00
@test isa(GroupRing(PermutationGroup(6), rand(1:6, 6,6)), GroupRing)
2017-07-25 14:45:35 +02:00
RG = GroupRing(G, fastm=true)
@test isdefined(RG, :pm) == true
@test RG.pm == zeros(Int, (6,6))
@test isa(complete!(RG), GroupRing)
@test all(RG.pm .> 0)
2017-07-25 14:45:35 +02:00
@test RG.pm == GroupRings.fastm!(GroupRing(G, fastm=false), fill=true).pm
2017-05-17 17:45:19 +02:00
2018-09-24 00:31:01 +02:00
@test RG.basis_dict == GroupRings.reverse_dict(collect(G))
2017-05-17 17:45:19 +02:00
2018-09-24 00:31:01 +02:00
@test isa(GroupRing(G, collect(G)), GroupRing)
S = collect(G)
2017-05-18 12:19:52 +02:00
pm = create_pm(S)
@test isa(GroupRing(G, S), GroupRing)
@test isa(GroupRing(G, S, pm), GroupRing)
2017-05-17 17:45:19 +02:00
2017-05-18 12:19:52 +02:00
A = GroupRing(G, S)
B = GroupRing(G, S, pm)
2017-05-17 17:45:19 +02:00
2017-05-18 12:19:52 +02:00
@test RG == A
@test RG == B
end
2017-05-17 17:45:19 +02:00
2017-05-18 12:19:52 +02:00
@testset "GroupRing constructors FreeGroup" begin
using Groups
F = FreeGroup(3)
S = gens(F)
2017-05-18 12:19:52 +02:00
append!(S, [inv(s) for s in S])
2017-05-17 17:45:19 +02:00
2017-05-18 12:19:52 +02:00
basis, sizes = Groups.generate_balls(S, F(), radius=4)
d = GroupRings.reverse_dict(basis)
@test_throws KeyError create_pm(basis)
pm = create_pm(basis, d, sizes[2])
2017-05-17 17:45:19 +02:00
2017-05-18 12:19:52 +02:00
@test isa(GroupRing(F, basis, pm), GroupRing)
@test isa(GroupRing(F, basis, d, pm), GroupRing)
2017-05-17 17:45:19 +02:00
2017-05-18 12:19:52 +02:00
A = GroupRing(F, basis, pm)
B = GroupRing(F, basis, d, pm)
@test A == B
2017-05-17 17:45:19 +02:00
RF = GroupRing(F, basis, d, create_pm(basis, d, check=false))
2018-09-24 00:31:01 +02:00
nz1 = count(!iszero, RF.pm)
@test nz1 > 1000
GroupRings.complete!(RF)
2018-09-24 00:31:01 +02:00
nz2 = count(!iszero, RF.pm)
@test nz2 > nz1
2017-09-10 21:46:36 +02:00
@test nz2 == 45469
2017-07-11 18:43:37 +02:00
g = B()
s = S[2]
g[s] = 1
@test g == B(s)
@test g[s^2] == 0
@test_throws KeyError g[s^10]
2017-05-18 12:19:52 +02:00
end
2017-05-17 17:45:19 +02:00
2017-05-18 12:19:52 +02:00
@testset "GroupRingElems constructors/basic manipulation" begin
G = PermutationGroup(3)
2017-07-25 14:45:35 +02:00
RG = GroupRing(G, fastm=true)
2017-05-18 12:19:52 +02:00
a = rand(6)
@test isa(GroupRingElem(a, RG), GroupRingElem)
@test isa(RG(a), GroupRingElem)
2018-09-24 00:31:01 +02:00
@test all(isa(RG(g), GroupRingElem) for g in G)
2017-05-18 12:19:52 +02:00
@test_throws String GroupRingElem([1,2,3], RG)
@test isa(RG(G([2,3,1])), GroupRingElem)
p = G([2,3,1])
a = RG(p)
2017-05-18 17:58:31 +02:00
@test length(a) == 1
2017-05-18 12:19:52 +02:00
@test isa(a.coeffs, SparseVector)
@test a.coeffs[5] == 1
@test a[5] == 1
@test a[p] == 1
2019-01-02 16:13:41 +01:00
@test string(a) == "(1,2,3)"
@test string(-a) == " - 1(1,2,3)"
2017-05-18 12:19:52 +02:00
@test RG([0,0,0,0,1,0]) == a
2017-05-18 17:58:31 +02:00
s = G([1,2,3])
@test a[s] == 0
a[s] = 2
@test a.coeffs[1] == 2
@test a[1] == 2
@test a[s] == 2
2019-01-02 16:13:41 +01:00
@test string(a) == "2() + (1,2,3)"
@test string(-a) == " - 2() - 1(1,2,3)"
2017-05-18 17:58:31 +02:00
@test length(a) == 2
2017-05-18 12:19:52 +02:00
end
@testset "Arithmetic" begin
G = PermutationGroup(3)
2017-07-25 14:45:35 +02:00
RG = GroupRing(G, fastm=true)
2017-05-18 12:19:52 +02:00
a = RG(ones(Int, order(G)))
@testset "scalar operators" begin
@test isa(-a, GroupRingElem)
@test (-a).coeffs == -(a.coeffs)
@test isa(2*a, GroupRingElem)
@test eltype(2*a) == typeof(2)
2018-09-24 00:31:01 +02:00
@test (2*a).coeffs == 2 .*(a.coeffs)
2017-05-18 12:19:52 +02:00
2017-09-14 17:33:00 +02:00
ww = "Scalar and coeffs are in different rings! Promoting result to Float64"
2017-05-18 12:19:52 +02:00
2017-09-14 17:33:00 +02:00
@test isa(2.0*a, GroupRingElem)
2018-10-01 10:57:55 +02:00
@test_logs (:warn, ww) eltype(2.0*a) == typeof(2.0)
@test_logs (:warn, ww) (2.0*a).coeffs == 2.0.*(a.coeffs)
2017-09-14 17:33:00 +02:00
2018-10-01 10:57:55 +02:00
@test_logs (:warn, ww) (a/2).coeffs == a.coeffs./2
2017-09-14 17:33:00 +02:00
b = a/2
@test isa(b, GroupRingElem)
@test eltype(b) == typeof(1/2)
@test (b/2).coeffs == 0.25*(a.coeffs)
2017-05-18 12:19:52 +02:00
@test isa(convert(Rational{Int}, a), GroupRingElem)
@test eltype(convert(Rational{Int}, a)) == Rational{Int}
@test convert(Rational{Int}, a).coeffs ==
convert(Vector{Rational{Int}}, a.coeffs)
b = convert(Rational{Int}, a)
@test isa(b//4, GroupRingElem)
@test eltype(b//4) == Rational{Int}
@test isa(b//big(4), RingElem)
2017-05-18 12:19:52 +02:00
@test eltype(b//(big(4)//1)) == Rational{BigInt}
@test isa(a//1, GroupRingElem)
@test eltype(a//1) == Rational{Int}
2018-08-13 20:47:04 +02:00
@test (1.0a)//1 == (1.0a)
2017-05-18 12:19:52 +02:00
end
@testset "Additive structure" begin
2018-09-24 00:31:01 +02:00
@test RG(ones(Int, order(G))) == sum(RG(g) for g in G)
2017-05-18 12:19:52 +02:00
a = RG(ones(Int, order(G)))
2018-09-24 00:31:01 +02:00
b = sum((-1)^parity(g)*RG(g) for g in G)
2017-05-18 17:58:31 +02:00
@test 1/2*(a+b).coeffs == [1.0, 0.0, 1.0, 0.0, 1.0, 0.0]
a = RG(1) + RG(perm"(2,3)") + RG(perm"(1,2,3)")
b = RG(1) - RG(perm"(1,2)(3)") - RG(perm"(1,2,3)")
@test a - b == RG(perm"(2,3)") + RG(perm"(1,2)(3)") + 2RG(perm"(1,2,3)")
@test 1//2*2a == a
@test a + 2a == (3//1)*a
@test 2a - (1//1)*a == a
2017-05-18 12:19:52 +02:00
end
@testset "Multiplicative structure" begin
2018-09-24 00:31:01 +02:00
for g in G, h in G
2017-05-18 12:19:52 +02:00
a = RG(g)
b = RG(h)
@test a*b == RG(g*h)
@test (a+b)*(a+b) == a*a + a*b + b*a + b*b
end
2017-05-18 17:58:31 +02:00
2018-09-24 00:31:01 +02:00
for g in G
2018-08-13 20:47:04 +02:00
@test star(RG(g)) == RG(inv(g))
@test (one(RG)-RG(g))*star(one(RG)-RG(g)) ==
2017-05-18 17:58:31 +02:00
2*one(RG) - RG(g) - RG(inv(g))
2018-08-13 20:47:04 +02:00
@test aug((one(RG)-RG(g))) == 0
2017-05-18 17:58:31 +02:00
end
2018-08-14 09:47:29 +02:00
a = RG(1) + RG(perm"(2,3)") + RG(perm"(1,2,3)")
b = RG(1) - RG(perm"(1,2)(3)") - RG(perm"(1,2,3)")
@test a*b == mul!(a,a,b)
2018-08-14 09:47:29 +02:00
@test aug(a) == 3
@test aug(b) == -1
@test aug(a)*aug(b) == aug(a*b) == aug(b*a)
2017-05-18 17:58:31 +02:00
2018-09-24 00:31:01 +02:00
z = sum((one(RG)-RG(g))*star(one(RG)-RG(g)) for g in G)
2018-08-13 20:47:04 +02:00
@test aug(z) == 0
2017-05-18 17:58:31 +02:00
2018-08-13 20:47:04 +02:00
@test supp(z) == parent(z).basis
@test supp(RG(1) + RG(perm"(2,3)")) == [G(), perm"(2,3)"]
2018-08-15 19:29:24 +02:00
@test supp(a) == [perm"(3)", perm"(2,3)", perm"(1,2,3)"]
2019-01-02 17:20:55 +01:00
end
@testset "HPC multiplicative operations" begin
G = PermutationGroup(5)
RG = GroupRing(G, fastm=true)
RG2 = GroupRing(G, fastm=false)
Z = RG()
W = RG()
for g in [rand(G) for _ in 1:30]
X = RG(g)
Y = -RG(inv(g))
for i in 1:10
X[rand(G)] += rand(1:3)
Y[rand(G)] -= rand(1:3)
end
@test X*Y ==
RG2(X)*RG2(Y) ==
GroupRings.mul!(Z, X, Y)
@test Z.coeffs == GroupRings.GRmul!(W.coeffs, X.coeffs, Y.coeffs, RG.pm) == W.coeffs
@test (2*X*Y).coeffs ==
GroupRings.GRfmac!(W.coeffs, X.coeffs, Y.coeffs, RG.pm) ==
GroupRings.mul!(2, X*Y).coeffs
end
2017-05-18 12:19:52 +02:00
end
end
2018-11-17 22:46:03 +01:00
@testset "SumOfSquares in group rings" begin
= star
G = FreeGroup(["g", "h", "k", "l"])
S = G.(G.gens)
S = [S; inv.(S)]
ID = G()
RADIUS=3
@time E_R, sizes = Groups.generate_balls(S, ID, radius=2*RADIUS);
@test sizes == [9, 65, 457, 3201, 22409, 156865]
E_rdict = GroupRings.reverse_dict(E_R)
pm = GroupRings.create_pm(E_R, E_rdict, sizes[RADIUS]; twisted=true);
RG = GroupRing(G, E_R, E_rdict, pm)
g = RG.basis[2]
h = RG.basis[3]
k = RG.basis[4]
l = RG.basis[5]
G = (1-RG(g))
@test G^2 == 2 - RG(g) - (RG(g))
G = (1-RG(g))
H = (1-RG(h))
K = (1-RG(k))
L = (1-RG(l))
GH = (1-RG(g*h))
KL = (1-RG(k*l))
X = (2 - (RG(g)) - RG(h))
Y = (2 - (RG(g*h)) - RG(k))
@test -(2 - RG(g*h) - (RG(g*h))) + 2G^2 + 2H^2 == X^2
@test (2 - RG(g*h) - (RG(g*h))) == GH^2
@test -(2 - RG(g*h*k) - (RG(g*h*k))) + 2GH^2 + 2K^2 == Y^2
@test -(2 - RG(g*h*k) - (RG(g*h*k))) +
2(GH^2 - 2G^2 - 2H^2) +
4G^2 + 4H^2 + 2K^2 ==
Y^2
@test GH^2 - 2G^2 - 2H^2 == - X^2
@test -(2 - RG(g*h*k) - (RG(g*h*k))) + 4G^2 + 4H^2 + 2K^2 == 2X^2 + Y^2
@test GH^2 == 2G^2 + 2H^2 - (2 - (RG(g)) - RG(h))^2
@test KL^2 == 2K^2 + 2L^2 - (2 - (RG(k)) - RG(l))^2
@test -(2 - (RG(g*h*k*l)) - RG(g*h*k*l)) + 2*GH^2 + 2*KL^2 ==
(2 - (RG(g*h)) - RG(k*l))^2
@test -(2 - (RG(g*h*k*l)) - RG(g*h*k*l)) +
2(2G^2 + 2H^2 - (2 - (RG(g)) - RG(h))^2) +
2(2K^2 + 2L^2 - (2 - (RG(k)) - RG(l))^2) ==
(2 - (RG(g*h)) - RG(k*l))^2
@test -(2 - (RG(g*h*k*l)) - RG(g*h*k*l)) +
2(2G^2 + 2H^2) +
2(2K^2 + 2L^2) ==
(2 - (RG(g*h)) - RG(k*l))^2 +
2(2 - (RG(g)) - RG(h))^2 +
2(2 - (RG(k)) - RG(l))^2
@test -(2 - (RG(g*h*k*l)) - RG(g*h*k*l)) +
2(2 - (RG(g*h*k)) - RG(g*h*k)) + 2L^2 ==
(2 - (RG(g*h*k)) - RG(l))^2
@test 2 - (RG(g*h*k)) - RG(g*h*k) ==
2GH^2 + 2K^2 - (2 - (RG(g*h)) - RG(k))^2
@test -(2 - (RG(g*h*k*l)) - RG(g*h*k*l)) +
2(2GH^2 + 2K^2 - (2 - (RG(g*h)) - RG(k))^2) + 2L^2 ==
(2 - (RG(g*h*k)) - RG(l))^2
@test -(2 - (RG(g*h*k*l)) - RG(g*h*k*l)) +
2(2GH^2 + 2K^2) + 2L^2 ==
(2 - (RG(g*h*k)) - RG(l))^2 +
2(2 - (RG(g*h)) - RG(k))^2
@test -(2 - (RG(g*h*k*l)) - RG(g*h*k*l)) +
8G^2 + 8H^2 + 4K^2 + 2L^2 ==
2018-11-24 14:57:44 +01:00
(2 - (RG(g*h*k)) - RG(l))^2 + 2(2 - (RG(g*h)) - RG(k))^2 + 4(2 - (RG(g)) - RG(h))^2
2018-11-17 22:46:03 +01:00
@test -(2 - (RG(g*h*k*l)) - RG(g*h*k*l)) +
2GH^2 + 2KL^2 == (2 - (RG(g*h)) - RG(k*l))^2
2018-11-24 14:57:44 +01:00
@test -(2 - (RG(g*h*k*l)) - RG(g*h*k*l)) + 2(2G^2 + 2H^2) + 2(2K^2 + 2L^2) ==
(2 - (RG(g*h)) - RG(k*l))^2 + 2(2 - (RG(k)) - RG(l))^2 + 2(2 - (RG(g)) - RG(h))^2
2018-11-17 22:46:03 +01:00
end
2017-05-17 17:45:19 +02:00
end