Skip to content

Commit 7475ece

Browse files
committed
Add support for orthonormal basis
1 parent aa0f5b0 commit 7475ece

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

src/dependence.jl

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,21 @@ function Base.convert(
219219
return BasisDependence{StaircaseDependence}(d, d.basis)
220220
end
221221

222+
_full_basis(basis::MB.AbstractPolynomialBasis) = basis, eachindex(basis)
223+
224+
function _full_basis(basis::MB.AbstractMonomialBasis)
225+
full = MB.maxdegree_basis(
226+
typeof(basis),
227+
MP.variables(basis),
228+
MP.maxdegree(basis.monomials),
229+
)
230+
index_map = Int[
231+
something(_index(basis, full[i]), 0)
232+
for i in eachindex(full)
233+
]
234+
return full, index_map
235+
end
236+
222237
"""
223238
function BasisDependence{StaircaseDependence}(
224239
is_dependent::Function,
@@ -236,40 +251,39 @@ Foundations of Computational Mathematics 8 (2008): 607-647.
236251
"""
237252
function BasisDependence{StaircaseDependence}(
238253
r,
239-
basis::MB.MonomialBasis{M},
240-
) where {M}
241-
if isempty(basis.monomials)
254+
basis::MB.AbstractPolynomialBasis,
255+
)
256+
if isempty(basis)
242257
return BasisDependence(basis, StaircaseDependence[])
243258
end
244-
function dependence(mono)
245-
i = _index(basis, mono)
259+
vars = MP.variables(basis)
260+
full_basis, index_map = _full_basis(basis)
261+
function dependence(full_index)
262+
i = index_map[full_index]
246263
return if isnothing(i)
247264
TRIVIAL
248265
else
249266
is_dependent!(r, i) ? DEPENDENT : INDEPENDENT
250267
end
251268
end
252-
vars = MP.variables(basis)
253-
full_basis =
254-
MB.maxdegree_basis(typeof(basis), vars, MP.maxdegree(basis.monomials))
255269
d = StaircaseDependence[]
256270
# This sieve of [LLR08, Algorithm 1] is a performance improvement but not only.
257271
# It also ensures that the standard monomials have the "staircase structure".
258272
function is_corner_multiple(mono, indices, dependence)
259273
for i in eachindex(dependence)
260274
if is_dependent(dependence[i]) &&
261-
MP.divides(full_basis.monomials[indices[i]], mono)
275+
MP.divides(full_basis.monomials[indices[i]], mono) # TODO tol
262276
return true
263277
end
264278
end
265279
return false
266280
end
267281
keep = Int[]
268282
# Compute standard monomials and corners
269-
for (i, mono) in enumerate(full_basis.monomials)
270-
if !is_corner_multiple(mono, keep, d)
283+
for i in eachindex(full_basis)
284+
if !is_corner_multiple(full_basis[i], keep, d)
271285
push!(keep, i)
272-
push!(d, StaircaseDependence(true, dependence(mono)))
286+
push!(d, StaircaseDependence(true, dependence(i)))
273287
end
274288
end
275289
full_basis = typeof(full_basis)(full_basis.monomials[keep])

test/null.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ function test_partial_commutative_fix(x, y)
1818
0 0 1 0 # x * y
1919
1 0 0 0 # x^2
2020
]
21-
basis = MB.MonomialBasis(MP.monomials((x, y), 0:2))
22-
null = MM.MacaulayNullspace(matrix, basis, 1e-8)
23-
D = MM.StaircaseDependence
24-
solver = MM.StaircaseSolver{Float64}(max_partial_iterations = 1)
25-
shift_solver = MM.ShiftNullspace{D}(solver)
26-
sol = MM.solve(null, shift_solver)
27-
return testelements(sol, [[1, 1], [-1, 1]], 1e-8)
21+
monos = MP.monomials((x, y), 0:2)
22+
for basis in [MB.MonomialBasis(monos), MB.OrthonormalCoefficientsBasis(monos)]
23+
null = MM.MacaulayNullspace(matrix, basis, 1e-8)
24+
D = MM.StaircaseDependence
25+
solver = MM.StaircaseSolver{Float64}(max_partial_iterations = 1)
26+
shift_solver = MM.ShiftNullspace{D}(solver)
27+
sol = MM.solve(null, shift_solver)
28+
testelements(sol, [[1, 1], [-1, 1]], 1e-8)
29+
end
30+
return
2831
end
2932

3033
function test_dependent_border(x, y)

0 commit comments

Comments
 (0)