Skip to content

Commit

Permalink
fix module bug, fix remove, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelDavidMohr committed Oct 3, 2024
1 parent d8cbff3 commit 0278f81
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 85 deletions.
64 changes: 11 additions & 53 deletions src/siggb/affine_cells.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
function loc_closed_set(seq::Vector{T}, rep::Symbol) where {T<:MPolyRingElem}
function loc_closed_set(seq::Vector{T}) where {T<:MPolyRingElem}
@assert !isempty(seq) "cannot construct affine cell from no equations."
R = parent(first(seq))
codim_upper_bound = min(length(seq), ngens(R) - 1)
if rep == :full
hypplanes = empty(seq)
else
hypplanes = [random_lin_comb(gens(R)) for _ in 1:(ngens(R) - codim_upper_bound - 1)]
end
gb = saturate(vcat(seq, hypplanes), last(gens(R)))
return LocClosedSet(seq, [:seq for _ in 1:length(seq)],
T[], codim_upper_bound,
[last(gens(R))], [gb])
end

# for displaying
function Base.show(io::IO, lc::LocClosedSet)
string_rep_seq = variety_string_rep(lc.seq[findall(tg -> tg == :seq, lc.tags)])
string_rep_ineqn = variety_string_rep(lc.ineqns,
sep = "*", lpar = "(", rpar = ")")
if !isempty(lc.hull_eqns)
string_rep_hull = variety_string_rep(lc.hull_eqns)
print(io, "hull(" * string_rep_seq * "\\" * string_rep_ineqn * ", " * string_rep_hull * ")")
else
print(io, string_rep_seq * "\\" * string_rep_ineqn)
end
gb = saturate(seq, last(gens(R)))
return LocClosedSet(seq, codim_upper_bound, [gb])
end

# basic data
Expand All @@ -48,44 +28,28 @@ function is_empty_set(X::LocClosedSet)
return false
end

function is_equidimensional(X::LocClosedSet, rep::Symbol)
if rep == :full
return all(gb -> codim(gb) == X.codim_upper_bound, X.gbs)
else
R = ring(X)
return all(gb -> codim(gb) == ngens(R) - 1, X.gbs)
end
function is_equidimensional(X::LocClosedSet)
return all(gb -> codim(gb) == X.codim_upper_bound, X.gbs)
end

# core functions
function add_to_output!(res::Vector{C},
X::C, rep::Symbol) where C<:LocClosedSet
X::C) where C<:LocClosedSet

if is_empty_set(X)
@info "empty component"
return true
elseif is_equidimensional(X, rep)
elseif is_equidimensional(X)
@info "component with $(num_eqns(X)) eqns done"
push!(res, X)
return true
end
return false
end

function add_hyperplanes!(X::LocClosedSet, new_codim_ub::Int)
R = ring(X)
n_new_hypplanes = X.codim_upper_bound - new_codim_ub
iszero(n_new_hypplanes) && return
new_hypplanes = [random_lin_comb(gens(R)) for _ in 1:n_new_hypplanes]
X.gbs = [saturate(vcat(gb, new_hypplanes), last(gens(R)))
for gb in X.gbs]
return
end

function add_inequation!(X::LocClosedSet, h::P;
known_zds=P[]::Vector{P}) where P
R = ring(X)
push!(X.ineqns, h)
for (i, gb) in enumerate(X.gbs)
X.gbs[i] = saturate(vcat(gb, known_zds), h)
end
Expand All @@ -110,7 +74,7 @@ function split(X::LocClosedSet, g::MPolyRingElem)
col_gbs = X_min_g.gbs
hull_gbs = Vector{typeof(g)}[]
R = ring(X)
for (i, (X_gb, col_gb)) in enumerate(zip(X.gbs, col_gbs))
for (X_gb, col_gb) in zip(X.gbs, col_gbs)
if one(R) in col_gb
@info "equation vanishes on one GB"
tim = @elapsed new_gb = saturate(vcat(X_gb, [g]), last(gens(R)))
Expand All @@ -120,6 +84,7 @@ function split(X::LocClosedSet, g::MPolyRingElem)
end
sort(col_gb, by = p -> total_degree(p))
H_rand = filter(!iszero, normal_form(random_lin_combs(col_gb), X_gb))
isempty(H_rand) && continue
gbs = remove(X_gb, H_rand, known_eqns = [g])
for gb in gbs
push!(hull_gbs, gb)
Expand Down Expand Up @@ -151,18 +116,11 @@ function remove(gb::Vector{P},
push!(res, gb1)
tim = @elapsed G = filter(!iszero,
normal_form(random_lin_combs(gb1), gb))
gbs2 = remove(gb, H[2:end])
gbs2 = remove(gb, H[2:end], known_eqns = known_eqns)
for gb2 in gbs2
gbs3 = remove(gb2, G)
gbs3 = remove(gb2, G, known_eqns = vcat(known_eqns, [h]))
append!(res, gbs3)
end
# @info "normal form time $(tim)"
# for (i, htil) in enumerate(H[2:end])
# tim = @elapsed Grem = filter(!iszero, normal_form(G .* htil, gb))
# @info "constructing new equations time $(tim)"
# new_gbs = remove(gb, Grem, known_eqns=known_eqns)
# append!(res, new_gbs)
# end
return res
end

Expand Down
2 changes: 1 addition & 1 deletion src/siggb/module.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function construct_module_core(sig::Sig{N},
@inbounds row_ops = tr_mat.col_inds_and_coeffs[row_ind]
@inbounds for (j, coeff) in row_ops
j_sig = tr_mat.row_ind_to_sig[j]
index(j_sig) != idx && continue
cmp_ind_str(index(j_sig), idx, ind_ord) && continue
j_sig_mod = construct_module(j_sig, basis, basis_ht,
mat_index,
tr, vchar,
Expand Down
38 changes: 10 additions & 28 deletions src/siggb/siggb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ end

#---------------- functions for splitting --------------------#

function _sig_decomp(sys::Vector{T}; info_level::Int=0, rep=:full) where {T <: MPolyRingElem}
function _sig_decomp(sys::Vector{T}; info_level::Int=0) where {T <: MPolyRingElem}

# data structure setup/conversion
sys_mons, sys_coeffs, basis_ht, char, shift = input_setup(sys)
Expand All @@ -280,7 +280,7 @@ function _sig_decomp(sys::Vector{T}; info_level::Int=0, rep=:full) where {T <: M
R = parent(first(sys))
timer = new_timer()
lc_sets = sig_decomp!(basis, pairset, basis_ht, char, shift,
tags, ind_order, tr, R, timer, rep)
tags, ind_order, tr, R, timer)
@info timer
return lc_sets
end
Expand All @@ -296,14 +296,13 @@ function sig_decomp!(basis::Basis{N},
ind_order::IndOrder,
tr::SigTracer,
R::MPolyRing,
timer::Timings,
rep::Symbol) where {N, Char, Shift}
timer::Timings) where {N, Char, Shift}

# compute ideal
eqns = [convert_to_pol(R, [basis_ht.exponents[mdx] for mdx in basis.monomials[i]],
basis.coefficients[i])
for i in 1:basis.input_load]
X = loc_closed_set(eqns, rep)
X = loc_closed_set(eqns)

queue = [(basis, pairset, tags, ind_order, X, SyzInfo[], tr)]
result = LocClosedSet[]
Expand All @@ -312,12 +311,8 @@ function sig_decomp!(basis::Basis{N},
bs, ps, tgs, ind_ord, lc_set, syz_queue, tr = popfirst!(queue)
neqns = num_eqns(lc_set)
filter!(gb -> !(one(R) in gb), lc_set.gbs)
@info "starting component, $(length(queue)) remaining, $(neqns) equations, upper bound $(lc_set.codim_upper_bound)"
if any(isone, lc_set.hull_eqns)
@info "is empty set"
@info "------------------------------------------"
continue
elseif add_to_output!(result, lc_set, rep)
@info "starting component, $(length(queue)) remaining, $(neqns) equations"
if add_to_output!(result, lc_set)
@info "done"
@info "------------------------------------------"
continue
Expand All @@ -337,13 +332,12 @@ function sig_decomp!(basis::Basis{N},
tr, ps,
zd_ind, tgs,
ind_ord,
lc_set, rep)
lc_set)
timer.comp_lc_time += tim
pushfirst!(queue, (bs, ps, tgs, ind_ord, lc_set_hull, syz_queue, tr))
pushfirst!(queue, (bs2, ps2, tgs2, ind_ord2, lc_set_nz, SyzInfo[], tr2))
else
@info "finished component"
@assert all(gb -> num_eqns(lc_set) == codim(gb), lc_set.gbs)
push!(result, lc_set)
end
@info "------------------------------------------"
Expand Down Expand Up @@ -456,8 +450,7 @@ function split!(basis::Basis{N},
zd_ind::SigIndex,
tags::Tags,
ind_order::IndOrder,
lc_set::LocClosedSet,
rep::Symbol) where N
lc_set::LocClosedSet) where N


@inbounds begin
Expand All @@ -468,10 +461,7 @@ function split!(basis::Basis{N},

# component with nonzero condition
sorted_inds = collect(1:basis.input_load)
to_del = findall(idx -> basis.is_red[idx] || gettag(tags, idx) == :hull, sorted_inds)
push!(to_del, zd_ind)
unique!(sort!(to_del))
deleteat!(sorted_inds, to_del)
deleteat!(sorted_inds, zd_ind)
sort!(sorted_inds, by = ind -> ind_order.ord[ind])

sys2_mons = copy(basis.monomials[sorted_inds])
Expand All @@ -480,8 +470,6 @@ function split!(basis::Basis{N},
basis_ht, def_tg=:split,
trace=Val(true))

ind_ord2 = new_ind_order(basis2)

# hull component
zd_deg = basis_ht.exponents[first(cofac_mons_hsh)].deg

Expand All @@ -500,16 +488,10 @@ function split!(basis::Basis{N},

# new components
lc_set_hull, lc_set_nz = split(lc_set, h)
lc_set_nz.seq = lc_set.seq[sorted_inds]
push!(lc_set_hull.seq, h)
push!(lc_set_hull.tags, :hull)
push!(lc_set_hull.hull_eqns, h)

deleteat!(lc_set_nz.seq, to_del)
deleteat!(lc_set_nz.tags, to_del)
new_codim_ub = min(lc_set.codim_upper_bound, num_eqns(lc_set) - 1)
if rep != :full
add_hyperplanes!(lc_set_nz, new_codim_ub)
end
lc_set_nz.codim_upper_bound = new_codim_ub
end

Expand Down
3 changes: 0 additions & 3 deletions src/siggb/typedefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,7 @@ const IndConn = Dict{SigIndex, Vector{SigIndex}}
# For output of decomp algorithms
mutable struct LocClosedSet{T<:MPolyRingElem}
seq::Vector{T}
tags::Vector{Symbol}
hull_eqns::Vector{T}
codim_upper_bound::Int
ineqns::Vector{T}
gbs::Vector{Vector{T}}
end

Expand Down

0 comments on commit 0278f81

Please sign in to comment.