Skip to content

Commit

Permalink
Merge branch 'lg/supply-deform-base-via-generator' into 'master'
Browse files Browse the repository at this point in the history
supply deform base via generator

See merge request johannesflake/pbwdeformations.jl!35
  • Loading branch information
lgoettgens committed Apr 14, 2022
2 parents 1cbe0ec + da09c10 commit b778ef7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 75 deletions.
6 changes: 5 additions & 1 deletion src/Algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ coefficient_ring(A::Algebra{C}) where C <: RingElement = A.base_ring::parent_typ

coefficient_ring(a::AlgebraElem{C}) where C <: RingElement = coefficient_ring(parent(a))

parent_type(a::AlgebraElem{C}) where C <: RingElement = parent_type(typeof(a))

elem_type(A::Algebra{C}) where C <: RingElement = elem_type(typeof(A))

symbols(A::Algebra) = A.S

ngens(A::Algebra) = A.num_gens
Expand Down Expand Up @@ -235,7 +239,7 @@ function Base.:+(a::AlgebraElem{C1}, b::C2) where {C1 <: RingElement, C2 <: Ring
r.coeffs[end] = deepcopy(b)
r.monoms[end] = deepcopy(Int[])
else
r.coeffs[j] += b.coeffs[i]
r.coeffs[j] += b
end
zeroinds = findall(iszero, r.coeffs)
deleteat!(r.coeffs, zeroinds)
Expand Down
96 changes: 46 additions & 50 deletions src/SmashProductDeformLie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,36 +148,7 @@ end
#
###############################################################################

function pbwdeformsall_nvars(dimL::Int64, dimV::Int64, maxdeg::Int64)
n_kappa_entries = div(dimV*(dimV-1), 2)
dim_free_alg = sum(binomial(dimL + k - 1, k) for k in 0:maxdeg)

return n_kappa_entries * dim_free_alg, n_kappa_entries, dim_free_alg
end

function pbwdeformsall_vars(dimL::Int64, dimV::Int64, maxdeg::Int64)
# format: "c_{i,j,deg,[inds]}"
return ["c_{$i,$j,$deg,$(isempty(inds) ? "[]" : inds)}" for i in 1:dimV for j in i+1:dimV for deg in 0:maxdeg for inds=Combinatorics.with_replacement_combinations(1:dimL, deg)]
end

function pbwdeformsall_partition_vars(vars::Vector{T}, dimL::Int64, dimV::Int64, maxdeg::Int64) where T
_, n_kappa_entries, dim_free_alg = pbwdeformsall_nvars(dimL, dimV, maxdeg)
m = fill(Vector{T}[], dimV, dimV)
k = 0
for i in 1:dimV, j in i+1:dimV
offset = 0
m[i,j] = fill(T[], maxdeg+1)
for d in 0:maxdeg
curr = binomial(dimL + d - 1, d)
m[i,j][d+1] = vars[k*dim_free_alg+1+offset : k*dim_free_alg+offset+curr]
offset += curr
end
k += 1
end
return m
end

function coefficient_comparison(eq::AlgebraElem{C}) where C <: RingElement
@inline function coefficient_comparison(eq::AlgebraElem{C}) where C <: RingElement
return eq.coeffs
end

Expand Down Expand Up @@ -235,25 +206,54 @@ function indices_of_freedom(mat::SparseArrays.SparseMatrixCSC{T, Int64}) where T
end


function pbwdeforms_all(sp::SmashProductLie{C}, maxdeg::Int64; special_return::Type{T} = Nothing) where {C <: RingElement, T <: Union{Nothing, SparseMatrixCSC}}
abstract type DeformBase{C <: RingElement} end
struct DeformStdBase{C <: RingElement} <: DeformBase{C}
length :: Int
generator

function DeformStdBase{C}(sp::SmashProductLie{C}, maxdeg::Int) where C <: RingElement
dimL = sp.dimL
dimV = sp.dimV
R = coefficient_ring(sp.alg)
generator = (
begin
kappa = fill(sp.alg(0), dimV, dimV)
entry = prod(map(k -> sp.baseL[k], ind); init=sp.alg(1))
kappa[i,j] += entry
kappa[j,i] -= entry
kappa
end
for i in 1:dimV for j in i+1:dimV for d in 0:maxdeg for ind in Combinatorics.with_replacement_combinations(1:dimL, d)
)

length = div(dimV*(dimV-1), 2) * sum(binomial(dimL + k - 1, k) for k in 0:maxdeg)
return new{C}(length, generator)
end
end

function Base.length(base::DeformStdBase)
return base.length
end


function pbwdeforms_all(sp::SmashProductLie{C}, maxdeg::Int, DeformBaseType::Type{<: DeformBase{C}} = DeformStdBase{C}; special_return::Type{T} = Nothing) where {C <: RingElement, T <: Union{Nothing, SparseMatrixCSC}}
dimL = sp.dimL
dimV = sp.dimV

deform_base = DeformBaseType(sp, maxdeg)
nvars = length(deform_base)

@info "Constructing MPolyRing..."
R, vars = PolynomialRing(sp.coeff_ring, pbwdeformsall_vars(dimL, dimV, maxdeg))
nvars = length(vars)
R, vars = PolynomialRing(sp.coeff_ring, nvars)
var_lookup = Dict(vars[i] => i for i in 1:nvars)
var_mat = pbwdeformsall_partition_vars(vars, dimL, dimV, maxdeg)


@info "Changing SmashProductLie coeffcient type..."
new_sp = change_base_ring(R, sp)

@info "Constructing kappa..."
kappa = fill(new_sp.alg(0), dimV, dimV)
for i in 1:dimV, j in i+1:dimV, d in 0:maxdeg, (k, ind) in enumerate(Combinatorics.with_replacement_combinations(1:dimL, d))
kappa[i,j] += QuadraticQuoAlgebraElem{elem_type(R)}(new_sp.alg, [var_mat[i,j][d+1][k]], [ind])
kappa[j,i] -= QuadraticQuoAlgebraElem{elem_type(R)}(new_sp.alg, [var_mat[i,j][d+1][k]], [ind])
for (i, b) in enumerate(deform_base.generator)
kappa += vars[i] .* new_sp.alg.(b)
end

@info "Constructing deformation..."
Expand All @@ -274,7 +274,6 @@ function pbwdeforms_all(sp::SmashProductLie{C}, maxdeg::Int64; special_return::T
)
)


@info "Computing row-echelon form..."
lgs = Vector{Union{Nothing,SparseVector{fmpq, Int64}}}(nothing, nvars)
for v in iter
Expand All @@ -298,18 +297,15 @@ function pbwdeforms_all(sp::SmashProductLie{C}, maxdeg::Int64; special_return::T
kappas[l] = fill(sp.alg(0), dimV, dimV)
end
if freedom_deg > 0
for i in 1:dimV, j in i+1:dimV, d in 0:maxdeg, (k, ind) in enumerate(Combinatorics.with_replacement_combinations(1:dimL, d))
var_ind = var_lookup[var_mat[i,j][d+1][k]]
if iszero(mat[var_ind,var_ind])
l = findfirst(isequal(var_ind), freedom_ind)
kappas[l][i,j] += QuadraticQuoAlgebraElem{C}(sp.alg, [base_ring(sp.alg)(1)], [ind])
kappas[l][j,i] -= QuadraticQuoAlgebraElem{C}(sp.alg, [base_ring(sp.alg)(1)], [ind])
for (i, b) in enumerate(deform_base.generator)
if iszero(mat[i,i])
l = findfirst(isequal(i), freedom_ind)
kappas[l] += b
else
for col in var_ind+1:nvars
if !iszero(mat[var_ind,col])
l = findfirst(isequal(col), freedom_ind)
kappas[l][i,j] += QuadraticQuoAlgebraElem{C}(sp.alg, [-mat[var_ind,col]], [ind])
kappas[l][j,i] -= QuadraticQuoAlgebraElem{C}(sp.alg, [-mat[var_ind,col]], [ind])
for j in i+1:nvars
if !iszero(mat[i,j])
l = findfirst(isequal(j), freedom_ind)
kappas[l] += -mat[i,j] .* b
end
end
end
Expand Down
25 changes: 1 addition & 24 deletions test/SmashProductDeformLie-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,6 @@
end

@testset "pbwdeforms_all construction stuff" begin
@testset "pbwdeformsall_nvars tests" begin
for _ in 1:num_random_tests
a, b, c = PD.pbwdeformsall_nvars(rand(1:10), rand(1:10), rand(0:5))
@test a == b * c
end

for i in 1:10
@test PD.pbwdeformsall_nvars(1, i, 0) == (div(i*(i-1), 2), div(i*(i-1), 2), 1)
@test PD.pbwdeformsall_nvars(1, i, 1) == (2*div(i*(i-1), 2), div(i*(i-1), 2), 2)
@test PD.pbwdeformsall_nvars(5, i, 1) == (6*div(i*(i-1), 2), div(i*(i-1), 2), 6)
@test PD.pbwdeformsall_nvars(1, i, 2) == (3*div(i*(i-1), 2), div(i*(i-1), 2), 3)
@test PD.pbwdeformsall_nvars(3, i, 2) == (10*div(i*(i-1), 2), div(i*(i-1), 2), 10)
end
end

@testset "pbwdeformsall_vars tests" begin
for _ in 1:num_random_tests
nL, nV, maxdeg = rand(1:10), rand(1:10), rand(0:5)
l, _, _ = PD.pbwdeformsall_nvars(nL, nV, maxdeg)
@test l == length(PD.pbwdeformsall_vars(nL, nV, maxdeg))
end
end

@testset "coefficient_comparison tests" begin
A, (x,y,z) = free_algebra(QQ, ["x", "y", "z"])
eq = QQ(2//3)*x + 88*y*z - 12*x*z + 3*y + 0*z^4 - 2*y + 12*x*z
Expand Down Expand Up @@ -200,7 +177,7 @@
@test repr("text/plain", base[3][1,2]) == "8*x_3 + 16*x_1*x_2 + -32*x_1*x_2*x_3 + -4*x_3^3 + 16*x_1^2*x_2^2 + 8*x_1*x_2*x_3^2 + x_3^4"
end
if length(base) >= 4
@test repr("text/plain", base[4][1,2]) == "-96*x_3 + 64*x_1*x_2 + -64*x_1*x_2*x_3 + 40*x_3^3 + 320*x_1^2*x_2^2 + 208*x_1*x_2*x_3^2 + -288*x_1^2*x_2^2*x_3 + -96*x_1*x_2*x_3^3 + -6*x_3^5 + 64*x_1^3*x_2^3 + 48*x_1^2*x_2^2*x_3^2 + 12*x_1*x_2*x_3^4 + x_3^6"
@test repr("text/plain", base[4][1,2]) == "-96*x_3 + 64*x_1*x_2 + -64*x_1*x_2*x_3 + 40*x_3^3 + 320*x_1^2*x_2^2 + 208*x_1*x_2*x_3^2 + -288*x_1^2*x_2^2*x_3 + -96*x_1*x_2*x_3^3 + -6*x_3^5 + 64*x_1^3*x_2^3 + 48*x_1^2*x_2^2*x_3^2 + 12*x_1*x_2*x_3^4 + x_3^6"
end
end

Expand Down

0 comments on commit b778ef7

Please sign in to comment.