From 1597784ac5d81d22a20de5596f0149979116bdd3 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Tue, 10 Apr 2018 13:14:45 +0200 Subject: [PATCH] add the standard linear representation for Automorphisms --- src/AutGroup.jl | 22 +++++++++++++++++++++ src/Groups.jl | 2 +- test/AutGroup-tests.jl | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/AutGroup.jl b/src/AutGroup.jl index 57defe2..6903aee 100644 --- a/src/AutGroup.jl +++ b/src/AutGroup.jl @@ -365,3 +365,25 @@ function reduce!(W::Automorphism) return W end + +function linear_repr(A::Automorphism{N}, hom=matrix_repr) where N + return reduce(*, hom(Identity(), N, 1), linear_repr.(A.symbols, N, hom)) +end + +linear_repr(a::AutSymbol, n::Int, hom) = hom(a.typ, n, a.pow) + +function matrix_repr(a::Union{RTransvect, LTransvect}, n::Int, pow) + x = eye(n) + x[a.i,a.j] = pow + return x +end + +function matrix_repr(a::FlipAut, n::Int, pow) + x = eye(n) + x[a.i,a.i] = -1^pow + return x +end + +matrix_repr(a::PermAut, n::Int, pow) = eye(n)[:, (a.perm^pow).d] + +matrix_repr(a::Identity, n::Int, pow) = eye(n) diff --git a/src/Groups.jl b/src/Groups.jl index a3be501..cf94eaa 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -4,7 +4,7 @@ module Groups using Nemo import Nemo: Group, GroupElem, Ring import Nemo: parent, parent_type, elem_type -import Nemo: elements, order, gens +import Nemo: elements, order, gens, matrix_repr import Base: length, ==, hash, show, convert import Base: inv, reduce, *, ^ diff --git a/test/AutGroup-tests.jl b/test/AutGroup-tests.jl index e7a1589..5e6acb7 100644 --- a/test/AutGroup-tests.jl +++ b/test/AutGroup-tests.jl @@ -207,4 +207,48 @@ @test length(unique(B_2)) == 1777 end + @testset "linear_repr tests" begin + N = 3 + G = AutGroup(FreeGroup(N)) + S = unique([gens(G); inv.(gens(G))]) + R = 3 + + @test Groups.linear_repr(G()) isa Matrix{Float64} + @test Groups.linear_repr(G()) == eye(N) + + M = eye(N) + M[1,2] = 1 + ϱ₁₂ = G(Groups.rmul_autsymbol(1,2)) + λ₁₂ = G(Groups.rmul_autsymbol(1,2)) + + @test Groups.linear_repr(ϱ₁₂) == M + @test Groups.linear_repr(λ₁₂) == M + + M[1,2] = -1 + + @test Groups.linear_repr(ϱ₁₂^-1) == M + @test Groups.linear_repr(λ₁₂^-1) == M + + M = eye(N) + M[2,2] = -1 + ε₂ = G(Groups.flip_autsymbol(2)) + + @test Groups.linear_repr(ε₂) == M + @test Groups.linear_repr(ε₂^2) == eye(N) + + M = [0.0 0.0 1.0; 1.0 0.0 0.0; 0.0 1.0 0.0] + σ = G(Groups.perm_autsymbol([2,3,1])) + @test Groups.linear_repr(σ) == M + @test Groups.linear_repr(σ^3) == eye(3) + @test Groups.linear_repr(σ)^3 ≈ eye(3) + + function test_homomorphism(S, r) + for elts in Iterators.product([[g for g in S] for _ in 1:r]...) + prod(Groups.linear_repr.(elts)) == Groups.linear_repr(prod(elts)) || error("linear representaton test failed at $elts") + end + return 0 + end + + @test test_homomorphism(S, R) == 0 + end end