Skip to content

Commit 743abce

Browse files
committed
Add support for orthogonal basis
1 parent 7475ece commit 743abce

File tree

2 files changed

+57
-34
lines changed

2 files changed

+57
-34
lines changed

src/dependence.jl

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -260,58 +260,81 @@ function BasisDependence{StaircaseDependence}(
260260
full_basis, index_map = _full_basis(basis)
261261
function dependence(full_index)
262262
i = index_map[full_index]
263-
return if isnothing(i)
263+
return if iszero(i)
264264
TRIVIAL
265265
else
266266
is_dependent!(r, i) ? DEPENDENT : INDEPENDENT
267267
end
268268
end
269-
d = StaircaseDependence[]
270269
# This sieve of [LLR08, Algorithm 1] is a performance improvement but not only.
271270
# It also ensures that the standard monomials have the "staircase structure".
272-
function is_corner_multiple(mono, indices, dependence)
273-
for i in eachindex(dependence)
274-
if is_dependent(dependence[i]) &&
275-
MP.divides(full_basis.monomials[indices[i]], mono) # TODO tol
271+
corners = Int[]
272+
function is_corner_multiple(mono)
273+
for corner in corners
274+
if MP.divides(full_basis[corner], mono) # TODO tol
276275
return true
277276
end
278277
end
279278
return false
280279
end
281-
keep = Int[]
282280
# Compute standard monomials and corners
283-
for i in eachindex(full_basis)
284-
if !is_corner_multiple(full_basis[i], keep, d)
285-
push!(keep, i)
286-
push!(d, StaircaseDependence(true, dependence(i)))
281+
keep = falses(length(full_basis))
282+
d = Vector{StaircaseDependence}(undef, length(full_basis))
283+
for (i, mono) in enumerate(full_basis)
284+
if !is_corner_multiple(mono)
285+
keep[i] = true
286+
dep = dependence(i)
287+
d[i] = StaircaseDependence(true, dep)
288+
if is_dependent(dep)
289+
push!(corners, i)
290+
end
287291
end
288292
end
289-
full_basis = typeof(full_basis)(full_basis.monomials[keep])
290-
new_basis = MB.MonomialBasis(
291-
eltype(basis.monomials)[
292-
full_basis.monomials[i] * shift for
293-
i in eachindex(d) if !is_dependent(d[i]) for shift in vars
294-
],
295-
)
296-
full_basis, I1, I2 = MB.merge_bases(full_basis, new_basis)
297-
deps = Vector{StaircaseDependence}(undef, length(full_basis.monomials))
298-
for (i, mono) in enumerate(full_basis.monomials)
299-
if iszero(I1[i])
300-
@assert !iszero(I2[i])
301-
if is_corner_multiple(mono, 1:(i-1), view(deps, 1:(i-1)))
302-
std = false
303-
else
304-
# If it was not seen before, it means it is outside the basis
305-
# so it is trivial standard
306-
@assert isnothing(_index(basis, mono))
307-
std = true
293+
new_basis = eltype(MB.generators(full_basis))[]
294+
new_deps = StaircaseDependence[]
295+
for (i, mono) in enumerate(full_basis)
296+
if keep[i] && is_standard(d[i])
297+
for shift in vars
298+
shifted = mono * shift
299+
j = _index(full_basis, shifted)
300+
if isnothing(j)
301+
push!(new_basis, shifted)
302+
push!(new_deps, StaircaseDependence(
303+
is_corner_multiple(shifted),
304+
TRIVIAL,
305+
))
306+
else
307+
keep[j] = true
308+
d[j] = StaircaseDependence(false, dependence(j))
309+
end
308310
end
309-
deps[i] = StaircaseDependence(std, dependence(mono))
311+
end
312+
end
313+
I = findall(keep)
314+
bd = BasisDependence(full_basis[I], d[I])
315+
display(bd)
316+
@show new_basis
317+
if isempty(new_basis)
318+
return bd
319+
else
320+
return MB.merge_bases(
321+
bd,
322+
BasisDependence(MB.MonomialBasis(new_basis), new_deps),
323+
)
324+
end
325+
end
326+
327+
function MB.merge_bases(b1::BasisDependence, b2::BasisDependence)
328+
basis, I1, I2 = MB.merge_bases(b1.basis, b2.basis)
329+
deps = Vector{StaircaseDependence}(undef, length(basis))
330+
for i in eachindex(basis)
331+
if iszero(I1[i])
332+
deps[i] = b2.dependence[I2[i]]
310333
else
311-
deps[i] = d[I1[i]]
334+
deps[i] = b1.dependence[I1[i]]
312335
end
313336
end
314-
return BasisDependence(full_basis, deps)
337+
return BasisDependence(basis, deps)
315338
end
316339

317340
function _exponents(monos, i)

test/null.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function test_partial_commutative_fix(x, y)
1919
1 0 0 0 # x^2
2020
]
2121
monos = MP.monomials((x, y), 0:2)
22-
for basis in [MB.MonomialBasis(monos), MB.OrthonormalCoefficientsBasis(monos)]
22+
for basis in [MB.MonomialBasis(monos)] #, MB.OrthonormalCoefficientsBasis(monos)]
2323
null = MM.MacaulayNullspace(matrix, basis, 1e-8)
2424
D = MM.StaircaseDependence
2525
solver = MM.StaircaseSolver{Float64}(max_partial_iterations = 1)

0 commit comments

Comments
 (0)