From 6ab18d02830346c2720ce3cd385327c0d908b9f3 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Sat, 10 Oct 2020 12:55:02 +0200 Subject: [PATCH] allow arbitrary actions in orbit_decomposition (defaults to ^) --- src/orbitdata.jl | 57 +++++++++++++++++++++++++++++------------------- src/sqadjop.jl | 6 ++--- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/orbitdata.jl b/src/orbitdata.jl index 151b82b..5f2d397 100644 --- a/src/orbitdata.jl +++ b/src/orbitdata.jl @@ -58,9 +58,14 @@ function orthSVD(M::AbstractMatrix{T}) where {T<:AbstractFloat} return fact.U[:,1:M_rank] end -orbit_decomposition(G::Group, E::AbstractVector, rdict=GroupRings.reverse_dict(E)) = orbit_decomposition(collect(G), E, rdict) +orbit_decomposition( + G::Group, + E::AbstractVector, + rdict = GroupRings.reverse_dict(E); + op = ^, +) = orbit_decomposition(collect(G), E, rdict; op=op) -function orbit_decomposition(elts::AbstractVector{<:GroupElem}, E::AbstractVector, rdict=GroupRings.reverse_dict(E)) +function orbit_decomposition(elts::AbstractVector{<:GroupElem}, E::AbstractVector, rdict=GroupRings.reverse_dict(E); op=^) tovisit = trues(size(E)); orbits = Vector{Vector{Int}}() @@ -71,7 +76,7 @@ function orbit_decomposition(elts::AbstractVector{<:GroupElem}, E::AbstractVecto if tovisit[i] g = E[i] Threads.@threads for j in eachindex(elts) - orbit[j] = rdict[elts[j](g)] + orbit[j] = rdict[op(g, elts[j])] end tovisit[orbit] .= false push!(orbits, unique(orbit)) @@ -139,7 +144,7 @@ end function perm_repr(g::GroupElem, E::Vector, E_dict) p = Vector{Int}(undef, length(E)) for (i,elt) in enumerate(E) - p[i] = E_dict[g(elt)] + p[i] = E_dict[elt^g] end return p end @@ -178,29 +183,33 @@ end # ############################################################################### -function (g::GroupRingElem)(y::GroupRingElem) +function Base.:^(y::GroupRingElem, g::GroupRingElem, op = ^) res = parent(y)() for elt in GroupRings.supp(g) - res += g[elt]*elt(y) + res += g[elt] * ^(y, elt, op) end return res end -function (g::GroupElem)(y::GroupRingElem) +function Base.:^(y::GroupRingElem, g::GroupElem, op = ^) RG = parent(y) result = zero(RG, eltype(y.coeffs)) for (idx, c) in enumerate(y.coeffs) if !iszero(c) - result[g(RG.basis[idx])] = c + result[op(RG.basis[idx], g)] = c end end return result end -function (g::GroupElem)(y::GroupRingElem{T, <:SparseVector}) where T +function Base.:^( + y::GroupRingElem{T,<:SparseVector}, + g::GroupElem, + op = ^, +) where {T} RG = parent(y) - index = [RG.basis_dict[g(RG.basis[idx])] for idx in y.coeffs.nzind] + index = [RG.basis_dict[op(RG.basis[idx], g)] for idx in y.coeffs.nzind] result = GroupRingElem(sparsevec(index, y.coeffs.nzval, y.coeffs.n), RG) @@ -213,28 +222,29 @@ end # ############################################################################### -function (p::Generic.Perm)(A::MatAlgElem) - length(p.d) == size(A, 1) == size(A,2) || throw("Can't act via $p on matrix of size $(size(A))") +function Base.:^(A::MatAlgElem, p::Generic.Perm) + length(p.d) == size(A, 1) == size(A, 2) || + throw("Can't act via $p on matrix of size $(size(A))") result = similar(A) - @inbounds for i in 1:size(A, 1) - for j in 1:size(A, 2) - result[p[i], p[j]] = A[i,j] # action by permuting rows and colums/conjugation + @inbounds for i = 1:size(A, 1) + for j = 1:size(A, 2) + result[p[i], p[j]] = A[i, j] # action by permuting rows and colums/conjugation end end return result end -function (g::WreathProductElem{N})(A::MatAlgElem) where N +function Base.:^(A::MatAlgElem, g::WreathProductElem{N}) where {N} # @assert N == size(A,1) == size(A,2) - flips = ntuple(i->(g.n[i].d[1]==1 && g.n[i].d[2]==2 ? 1 : -1), N) + flips = ntuple(i -> (g.n[i].d[1] == 1 && g.n[i].d[2] == 2 ? 1 : -1), N) result = similar(A) R = base_ring(parent(A)) tmp = R(1) - @inbounds for i = 1:size(A,1) - for j = 1:size(A,2) + @inbounds for i = 1:size(A, 1) + for j = 1:size(A, 2) x = A[i, j] - if flips[i]*flips[j] == 1 + if flips[i] * flips[j] == 1 result[g.p[i], g.p[j]] = x else result[g.p[i], g.p[j]] = -x @@ -250,7 +260,7 @@ end # ############################################################################### -function (g::GroupElem)(a::Automorphism) +function Base.:^(a::Automorphism, g::GroupElem) Ag = parent(a)(g) Ag_inv = inv(Ag) res = append!(Ag, a, Ag_inv) @@ -261,10 +271,11 @@ end function (A::AutGroup)(g::WreathProductElem) isa(A.objectGroup, FreeGroup) || throw("Not an Aut(Fₙ)") - parent(g).P.n == length(A.objectGroup.gens) || throw("No natural embedding of $(parent(g)) into $A") + parent(g).P.n == length(A.objectGroup.gens) || + throw("No natural embedding of $(parent(g)) into $A") elt = one(A) Id = one(parent(g.n.elts[1])) - for i in 1:length(g.p.d) + for i = 1:length(g.p.d) if g.n.elts[i] != Id push!(elt, Groups.flip(i)) end diff --git a/src/sqadjop.jl b/src/sqadjop.jl index 310cf97..a7eaf2a 100644 --- a/src/sqadjop.jl +++ b/src/sqadjop.jl @@ -19,7 +19,7 @@ function Sq(RG::GroupRing, N::Integer) sq = RG() for σ in Alt_N - GroupRings.addeq!(sq, *(σ(Δ₂), σ(Δ₂), false)) + GroupRings.addeq!(sq, *(Δ₂^σ, Δ₂^σ, false)) end return sq÷factorial(N-2) end @@ -30,7 +30,7 @@ function Adj(RG::GroupRing, N::Integer) Δ₂ = length(S₂)*one(RG, ℤ) - RG(S₂, ℤ); Alt_N = [g for g in SymmetricGroup(N) if parity(g) == 0] - Δ₂s = Dict(σ=>σ(Δ₂) for σ in Alt_N) + Δ₂s = Dict(σ=>Δ₂^σ for σ in Alt_N) adj = RG() for σ in Alt_N @@ -52,7 +52,7 @@ function Op(RG::GroupRing, N::Integer) Δ₂ = length(S₂)*one(RG, ℤ) - RG(S₂, ℤ); Alt_N = [g for g in SymmetricGroup(N) if parity(g) == 0] - Δ₂s = Dict(σ=>σ(Δ₂) for σ in Alt_N) + Δ₂s = Dict(σ=>Δ₂^σ for σ in Alt_N) op = RG() for σ in Alt_N