From 1227fb540e21b3c4bc8acb761666df56af60fb9b Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Thu, 22 Feb 2024 17:08:09 +0100 Subject: [PATCH] turn demo perm_grp_algebra.jl into testset --- src/types.jl | 3 + test/Project.toml | 2 + test/perm_grp_algebra.jl | 148 +++++++++++++++++++-------------------- test/runtests.jl | 18 +++-- 4 files changed, 87 insertions(+), 84 deletions(-) diff --git a/src/types.jl b/src/types.jl index d0e16b9..877d2fc 100644 --- a/src/types.jl +++ b/src/types.jl @@ -57,6 +57,9 @@ function AlgebraElement( end coeffs(a::AlgebraElement) = a.coeffs +function coeffs(x::AlgebraElement, b::AbstractBasis) + return coeffs(coeffs(x), basis(parent(x)), b) +end Base.parent(a::AlgebraElement) = a.parent Base.eltype(a::AlgebraElement) = valtype(coeffs(a)) diff --git a/test/Project.toml b/test/Project.toml index b90c1e4..2b1bb26 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,7 +1,9 @@ [deps] Groups = "5d8bd718-bd84-11e8-3b40-ad14f4a32557" GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" PermutationGroups = "8bc5a954-2dfc-11e9-10e6-cd969bffa420" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StarAlgebras = "0c0c59c1-dc5f-42e9-9a8b-b5dc384a6cd1" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/perm_grp_algebra.jl b/test/perm_grp_algebra.jl index 220d349..f392c1a 100644 --- a/test/perm_grp_algebra.jl +++ b/test/perm_grp_algebra.jl @@ -1,104 +1,98 @@ -using Pkg -Pkg.activate(@__DIR__) - -using Revise -using StarAlgebras -import StarAlgebras as SA using PermutationGroups -import PermutationGroups.AP as AP +using Random SA.star(x::Number) = x' -SA.star(g::AP.AbstractPermutation) = inv(g) - -G = PermGroup(perm"(1,2,3,4,5,6)", perm"(1,2)") -g, h = rand(G, 2) +SA.star(g::PermutationGroups.AP.AbstractPermutation) = inv(g) -db = SA.DiracBasis{UInt32}(G) -RG = SA.StarAlgebra(G, db) +@testset "POC: group algebra" begin + G = PermGroup(perm"(1,2,3,4,5,6)", perm"(1,2)") + g = Permutation(perm"(1,4,3,6)(2,5)", G) + h = Permutation(perm"(2,4,5,1)", G) -ad = SA.AugmentedBasis(db) + db = SA.DiracBasis{UInt32}(G) + @test SA.mstructure(db) == SA.DiracMStructure(*) + @test SA.mstructure(db)(g, h) == SA.Dirac(g * h) -ad[SA.AugmentedDirac(h)] + @test db[g] isa SA.Dirac + @test_throws MethodError db[db[g]] -IG = SA.StarAlgebra(G, ad) + xcfs = SA.SparseCoefficients([one(G), g], [1, -1]) + ycfs = SA.SparseCoefficients([one(G), inv(g)], [1, -1]) + xycfs = SA.SparseCoefficients([one(G), g, inv(g)], [2, -1, -1]) -xcfs = SA.SparseCoefficients([one(G), g], [1, -1]) -x = SA.AlgebraElement(xcfs, RG) + zcfs = SA.SparseCoefficients([one(G), h], [1, -1]) + xzcfs = SA.SparseCoefficients([one(G), g, h, g * h], [1, -1, -1, 1]) -ycfs = SA.SparseCoefficients([one(G), inv(g)], [1, -1]) -y = SA.AlgebraElement(ycfs, RG) + RG = SA.StarAlgebra(G, db) -zcfs = SA.SparseCoefficients([one(G), h], [1, -1]) -z = SA.AlgebraElement(zcfs, RG) + x = SA.AlgebraElement(xcfs, RG) + y = SA.AlgebraElement(ycfs, RG) + xy = SA.AlgebraElement(xycfs, RG) + @test x != y + @test x' == y + @test x * y == xy -xycfs = SA.SparseCoefficients([one(G), g, inv(g)], [2, -1, -1]) -xy = SA.AlgebraElement(xycfs, RG) + z = SA.AlgebraElement(zcfs, RG) + xz = SA.AlgebraElement(xzcfs, RG) + @test x * z == xz -xzcfs = SA.SparseCoefficients([one(G), g, h, g * h], [1, -1, -1, 1]) -xz = SA.AlgebraElement(xzcfs, RG) + @testset "Augmented basis" begin -@assert x != y -@assert x' == y -@assert SA.mstructure(basis(RG))(g, h) == SA.Dirac(g * h) -@assert x * y == xy -@assert x * z == xz + ad = SA.AugmentedBasis(db) + @test SA.mstructure(ad) == SA.AugmentedMStructure(SA.mstructure(db)) + @test ad[SA.AugmentedDirac(h)] isa SA.AugmentedDirac -axcfs = SA.coeffs(coeffs(x), basis(RG), basis(IG)) -aycfs = SA.coeffs(coeffs(y), basis(RG), basis(IG)) -azcfs = SA.coeffs(coeffs(z), basis(RG), basis(IG)) -ax = SA.AlgebraElement(axcfs, IG) -ay = SA.AlgebraElement(aycfs, IG) -az = SA.AlgebraElement(azcfs, IG) + IG = SA.StarAlgebra(G, ad) -@assert coeffs(ax * ay) == SA.coeffs(coeffs(x * y), basis(RG), basis(IG)) -@assert coeffs(ax * az) == SA.coeffs(coeffs(x * z), basis(RG), basis(IG)) + axcfs = SA.coeffs(x, basis(IG)) + aycfs = SA.coeffs(y, basis(IG)) + azcfs = SA.coeffs(z, basis(IG)) + ax = SA.AlgebraElement(axcfs, IG) + ay = SA.AlgebraElement(aycfs, IG) + az = SA.AlgebraElement(azcfs, IG) -rcfs = SA.SparseCoefficients(rand(G, 100), rand(-2:2, 100)) -r = SA.AlgebraElement(rcfs, RG) -scfs = SA.SparseCoefficients(rand(G, 100), rand(-2:2, 100)) -s = SA.AlgebraElement(scfs, RG) + @test coeffs(ax * ay) == SA.coeffs(x * y, basis(IG)) + @test coeffs(ax * az) == SA.coeffs(x * z, basis(IG)) + end -@time r * s + @testset "Random elements" begin + rcfs = SA.SparseCoefficients(rand(G, 10), rand(-2:2, 10)) + r = SA.AlgebraElement(rcfs, RG) + scfs = SA.SparseCoefficients(rand(G, 10), rand(-2:2, 10)) + s = SA.AlgebraElement(scfs, RG) -aug(r) -aug(s) -@assert aug(r * s) == aug(r) * aug(s) + @test aug(r * s) == aug(r) * aug(s) + end + @testset "Fixed Basis" begin + m = PermutationGroups.order(UInt16, G) + fb = SA.FixedBasis(collect(G), SA.DiracMStructure(*), (m, m)) -m = PermutationGroups.order(UInt16, G) -fb = SA.FixedBasis(collect(G), SA.DiracMStructure(*), (m, m)) -fRG = SA.StarAlgebra(G, fb) + @test fb[fb[g]] == g -fr = SA.AlgebraElement(coeffs(rcfs, basis(RG), basis(fRG)), fRG) -fs = SA.AlgebraElement(coeffs(scfs, basis(RG), basis(fRG)), fRG) + fRG = SA.StarAlgebra(G, fb) -@assert aug(fr) == aug(r) -@assert aug(fs) == aug(s) + rcfs = SA.SparseCoefficients(rand(G, 10), rand(-2:2, 10)) + r = SA.AlgebraElement(rcfs, RG) + scfs = SA.SparseCoefficients(rand(G, 10), rand(-2:2, 10)) + s = SA.AlgebraElement(scfs, RG) -@assert aug(fr * fs) == aug(fr) * aug(fs) + @test coeffs(r, basis(fRG)) isa SparseVector -r * s -fr * fs -frs = SA.AlgebraElement(coeffs(coeffs(r * s), basis(RG), basis(fRG)), fRG) -@assert fr * fs == frs + fr = SA.AlgebraElement(coeffs(r, basis(fRG)), fRG) + fs = SA.AlgebraElement(coeffs(s, basis(fRG)), fRG) -fr * fs -frs - -let mt = SA.mstructure(basis(fRG)).table - count(i -> isassigned(mt, i), eachindex(mt)), length(mt) -end -using BenchmarkTools -@btime $(star(r)) * $s -@btime $(star(fr)) * $fs + @test aug(fr) == aug(r) + @test aug(fs) == aug(s) + @test aug(fr * fs) == aug(fr) * aug(fs) -star(star(fr)) + rs_cfs = coeffs(r * s, basis(fRG)) + @test rs_cfs isa AbstractVector + @test fr * fs == SA.AlgebraElement(rs_cfs, fRG) -@btime star($fr) -@btime star($r) -@edit star(fr) + a, b = let mt = SA.mstructure(basis(fRG)).table + count(i -> isassigned(mt, i), eachindex(mt)), length(mt) + end + @test a ≤ b + end -mulN(a, b, N) = [a * b for i in 1:N] - -# using Profile - -@profview mulN(fr, fs, 1000) +end diff --git a/test/runtests.jl b/test/runtests.jl index 01cb81c..3b301c6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,14 +1,18 @@ -using StarAlgebras using Test +using StarAlgebras +import StarAlgebras as SA using LinearAlgebra using SparseArrays + +include("perm_grp_algebra.jl") + include("test_example_words.jl") -@testset "StarAlgebras" begin - include("mtables.jl") - include("constructors.jl") - include("arithmetic.jl") +# @testset "StarAlgebras" begin +# include("mtables.jl") +# include("constructors.jl") +# include("arithmetic.jl") - include("sum_of_squares.jl") -end +# include("sum_of_squares.jl") +# end