2017-06-06 12:15:06 +02:00
|
|
|
push!(LOAD_PATH, "./")
|
|
|
|
|
|
|
|
using Nemo
|
|
|
|
using Groups
|
|
|
|
using WreathProducts
|
|
|
|
|
|
|
|
using GroupRings
|
2017-06-06 16:20:44 +02:00
|
|
|
using PropertyT
|
2017-06-06 12:15:06 +02:00
|
|
|
|
|
|
|
import Nemo.elements
|
|
|
|
|
|
|
|
using JLD
|
|
|
|
|
2017-06-08 19:51:48 +02:00
|
|
|
include("Projections.jl")
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Iterator protocol for Nemo.FinField
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
type FFEltsIter{T<:Nemo.FinField}
|
|
|
|
all::Int
|
|
|
|
field::T
|
|
|
|
|
|
|
|
function FFEltsIter(F::T)
|
|
|
|
return new(Int(characteristic(F)^degree(F)), F)
|
2017-06-06 12:15:06 +02:00
|
|
|
end
|
|
|
|
end
|
2017-06-08 19:51:48 +02:00
|
|
|
FFEltsIter{T<:Nemo.FinField}(F::T) = FFEltsIter{T}(F)
|
|
|
|
|
|
|
|
import Base: start, next, done, eltype, length
|
|
|
|
|
|
|
|
Base.start(A::FFEltsIter) = (zero(A.field), 0)
|
|
|
|
Base.next(A::FFEltsIter, state) = next_ffelem(state...)
|
|
|
|
Base.done(A::FFEltsIter, state) = state[2] >= A.all
|
|
|
|
Base.eltype(::Type{FFEltsIter}) = elem_type(A.field)
|
|
|
|
Base.length(A::FFEltsIter) = A.all
|
|
|
|
|
|
|
|
function next_ffelem(f::Nemo.FinFieldElem, c::Int)
|
|
|
|
if c == 0
|
|
|
|
return (f, (f, 1))
|
|
|
|
elseif c == 1
|
|
|
|
f = one(parent(f))
|
|
|
|
return (f, (f, 2))
|
|
|
|
else
|
|
|
|
f = gen(parent(f))*f
|
|
|
|
return (f, (f, c+1))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
import Nemo.elements
|
|
|
|
elements(F::Nemo.FinField) = FFEltsIter(F)
|
|
|
|
|
2017-06-08 19:59:18 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Action of Premutations on Nemo.MatElem
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-06-06 12:15:06 +02:00
|
|
|
|
2017-06-08 19:59:18 +02:00
|
|
|
function (p::Nemo.perm)(A::Nemo.MatElem)
|
|
|
|
length(p.d) == A.r == A.c || throw("Can't act via $p on matrix of size ($(A.r), $(A.c))")
|
|
|
|
R = parent(A)
|
|
|
|
inv_p = inv(p)
|
|
|
|
return R(Nemo.matrix_repr(p))*A*R(Nemo.matrix_repr(inv_p))
|
2017-06-06 12:15:06 +02:00
|
|
|
end
|
|
|
|
|
2017-06-08 20:04:04 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Orbit stuff
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-06-06 12:15:06 +02:00
|
|
|
|
|
|
|
function orbit_decomposition(G::Nemo.Group, E::Vector, rdict=GroupRings.reverse_dict(E))
|
|
|
|
|
|
|
|
elts = collect(elements(G))
|
|
|
|
|
|
|
|
tovisit = trues(E);
|
|
|
|
orbits = Vector{Set{Int}}()
|
|
|
|
|
2017-06-08 16:49:10 +02:00
|
|
|
for i in 1:endof(E)
|
2017-06-06 12:15:06 +02:00
|
|
|
if tovisit[i]
|
|
|
|
orbit = Set{Int}()
|
|
|
|
a = E[i]
|
|
|
|
for g in elts
|
|
|
|
idx = rdict[g(a)]
|
|
|
|
tovisit[idx] = false
|
|
|
|
push!(orbit,idx)
|
|
|
|
end
|
|
|
|
push!(orbits, orbit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return orbits
|
|
|
|
end
|
|
|
|
|
2017-06-08 20:04:04 +02:00
|
|
|
function orbit_spvector(vect::AbstractVector, orbits)
|
|
|
|
orb_vector = spzeros(length(orbits))
|
2017-06-06 12:15:06 +02:00
|
|
|
|
2017-06-08 20:04:04 +02:00
|
|
|
for (i,o) in enumerate(orbits)
|
|
|
|
k = vect[collect(o)]
|
|
|
|
val = k[1]
|
|
|
|
@assert all(k .== val)
|
|
|
|
orb_vector[i] = val
|
|
|
|
end
|
2017-06-06 12:15:06 +02:00
|
|
|
|
2017-06-08 20:04:04 +02:00
|
|
|
return orb_vector
|
2017-06-06 12:15:06 +02:00
|
|
|
end
|
|
|
|
|
2017-06-08 20:04:04 +02:00
|
|
|
function orbit_constraint(cnstrs::Vector{Vector{Vector{Int64}}}, n)
|
|
|
|
result = spzeros(n,n)
|
|
|
|
for cnstr in cnstrs
|
|
|
|
for p in cnstr
|
|
|
|
result[p[1],p[2]] += 1.0
|
|
|
|
end
|
2017-06-06 12:15:06 +02:00
|
|
|
end
|
2017-06-08 20:04:04 +02:00
|
|
|
return 1/length(cnstrs)*result
|
2017-06-06 12:15:06 +02:00
|
|
|
end
|
|
|
|
|
2017-06-08 20:03:22 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Matrix- and C*-representations
|
|
|
|
#
|
|
|
|
###############################################################################
|
2017-06-06 12:15:06 +02:00
|
|
|
|
2017-06-08 20:03:22 +02:00
|
|
|
function matrix_repr(g::WreathProductElem, E, E_dict)
|
|
|
|
rep_matrix = spzeros(Int, length(E), length(E))
|
|
|
|
for (i,e) in enumerate(E)
|
|
|
|
j = E_dict[g(e)]
|
|
|
|
rep_matrix[i,j] = 1
|
2017-06-06 12:15:06 +02:00
|
|
|
end
|
2017-06-08 20:03:22 +02:00
|
|
|
return rep_matrix
|
2017-06-06 12:15:06 +02:00
|
|
|
end
|
|
|
|
|
2017-06-06 16:19:46 +02:00
|
|
|
function Cstar_repr(x::GroupRingElem, matrix_reps)
|
|
|
|
res = zeros(matrix_reps[1])
|
|
|
|
for i in 1:length(parent(x).basis)
|
|
|
|
res += x.coeffs[i]*matrix_reps[i]
|
|
|
|
end
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
2017-06-06 12:15:06 +02:00
|
|
|
function orthSVD(M::AbstractMatrix)
|
|
|
|
M = full(M)
|
|
|
|
fact = svdfact(M)
|
|
|
|
sings = fact[:S]
|
|
|
|
M_rank = sum(fact[:S] .> maximum(size(M))*eps(eltype(fact[:S])))
|
|
|
|
Ufactor = fact[:U]
|
|
|
|
return Ufactor[:,1:M_rank]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Uπ_matrices(P_matrices; orth=orthSVD)
|
|
|
|
U_p_matrices = Vector{Array{Float64,2}}()
|
2017-06-08 16:49:10 +02:00
|
|
|
for (i,p_mat) in enumerate(P_matrices)
|
2017-06-06 12:15:06 +02:00
|
|
|
U_p = orth(p_mat)
|
|
|
|
push!(U_p_matrices, U_p)
|
|
|
|
end
|
|
|
|
return U_p_matrices
|
|
|
|
end
|
|
|
|
|
2017-06-08 20:05:43 +02:00
|
|
|
|
|
|
|
function compute_orbit_data{T<:GroupElem}(logger, name::String, G::Group, S::Vector{T}, AutS; radius=2)
|
2017-06-06 12:15:06 +02:00
|
|
|
isdir(name) || mkdir(name)
|
|
|
|
|
2017-06-06 18:48:15 +02:00
|
|
|
info(logger, "Generating ball of radius 4")
|
2017-06-08 16:49:10 +02:00
|
|
|
@time E4, sizes = Groups.generate_balls(S, G(), radius=2*radius);
|
2017-06-08 21:38:58 +02:00
|
|
|
if isa(G, Nemo.Ring)
|
|
|
|
Id = one(G)
|
|
|
|
else
|
|
|
|
Id = G()
|
|
|
|
end
|
2017-06-06 18:48:15 +02:00
|
|
|
info(logger, "Reverse dict")
|
2017-06-06 12:15:06 +02:00
|
|
|
@time E_dict = GroupRings.reverse_dict(E4)
|
|
|
|
|
2017-06-06 18:48:15 +02:00
|
|
|
info(logger, "Product matrix")
|
2017-06-06 17:53:03 +02:00
|
|
|
@time pm = GroupRings.create_pm(E4, E_dict, sizes[radius], twisted=true)
|
|
|
|
RG = GroupRing(G, E4, E_dict, pm)
|
|
|
|
Δ = PropertyT.splaplacian(RG, S)
|
2017-06-06 18:48:15 +02:00
|
|
|
@assert GroupRings.augmentation(Δ) == 0
|
2017-06-07 11:07:37 +02:00
|
|
|
save(joinpath(name, "delta.jld"), "Δ", Δ.coeffs)
|
2017-06-06 16:22:05 +02:00
|
|
|
save(joinpath(name, "pm.jld"), "pm", pm)
|
2017-06-06 12:15:06 +02:00
|
|
|
|
2017-06-08 20:05:43 +02:00
|
|
|
info(logger, "Decomposing E into orbits of $(Aut_S)")
|
|
|
|
@time orbs = orbit_decomposition(AutS, E4, E_dict)
|
2017-06-06 16:22:50 +02:00
|
|
|
@assert sum(length(o) for o in orbs) == length(E4)
|
|
|
|
save(joinpath(name, "orbits.jld"), "orbits", orbs)
|
2017-06-06 12:15:06 +02:00
|
|
|
|
2017-06-06 18:48:15 +02:00
|
|
|
info(logger, "Action matrices")
|
2017-06-06 17:53:03 +02:00
|
|
|
E2 = E4[1:sizes[radius]]
|
2017-06-08 20:05:43 +02:00
|
|
|
@time AutS_matrixreps = [matrix_repr(g, E2, E_dict) for g in elements(AutS)]
|
2017-06-06 12:15:06 +02:00
|
|
|
|
2017-06-06 18:48:15 +02:00
|
|
|
info(logger, "Projections")
|
2017-06-08 20:05:43 +02:00
|
|
|
@time AutS_mps = rankOne_projections(AutS);
|
2017-06-06 12:15:06 +02:00
|
|
|
|
2017-06-08 20:05:43 +02:00
|
|
|
@time π_E_projections = [Cstar_repr(p, AutS_matrixreps) for p in AutS_mps]
|
2017-06-06 12:15:06 +02:00
|
|
|
|
2017-06-06 18:48:15 +02:00
|
|
|
info(logger, "Uπs...")
|
2017-06-06 12:15:06 +02:00
|
|
|
@time Uπs = Uπ_matrices(π_E_projections);
|
|
|
|
|
2017-06-06 16:23:36 +02:00
|
|
|
multiplicities = [size(U,2) for U in Uπs];
|
2017-06-06 18:48:15 +02:00
|
|
|
info(logger, "multiplicities = $multiplicities")
|
2017-06-08 20:05:43 +02:00
|
|
|
dimensions = [Int(p[AutS()]*Int(order(AutS))) for p in AutS_mps];
|
2017-06-06 18:48:15 +02:00
|
|
|
info(logger, "dimensions = $dimensions")
|
2017-06-06 17:53:03 +02:00
|
|
|
@assert dot(multiplicities, dimensions) == sizes[radius]
|
2017-06-06 12:15:06 +02:00
|
|
|
|
|
|
|
save(joinpath(name, "U_pis.jld"), "Uπs", Uπs, "dims", dimensions)
|
2017-06-06 16:23:36 +02:00
|
|
|
return 0
|
2017-06-06 12:15:06 +02:00
|
|
|
end
|