Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions src/ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,43 @@ https://doi.org/10.1007/b138611
"""
function standard_monomials end

"""
standard_monomials(I::PolynomialIdeal, vars, maxdegree::Integer)

Return the vector of *standard monomials* of the ideal `I` in the variables
`vars` of degree at most `maxdegree`. As the standard monomials form an order
ideal, the standard monomials of degree `d + 1` are obtained by multiplying
the standard monomials of degree `d` by each variable and keeping the standard
ones. The time complexity is therefore proportional to the number of standard
monomials and not to the number of monomials of degree at most `maxdegree`.
"""
function standard_monomials(I::PolynomialIdeal, vars, maxdegree::Integer)
compute_gröbner_basis!(I)
leading = [MP.exponents(MP.leading_monomial(p), vars) for p in I.p]
is_standard(e) = !any(l -> all(l .<= e), leading)
current = [zeros(Int, length(vars))]
if maxdegree < 0 || !is_standard(first(current))
empty!(current)
end
exponents = copy(current)
for _ in 1:maxdegree
next = Set{Vector{Int}}()
for e in current
for i in eachindex(vars)
f = copy(e)
f[i] += 1
if is_standard(f)
push!(next, f)
end
end
end
current = collect(next)
append!(exponents, current)
end
M = MP.monomial_type(prod(vars))
return MP.monomial_vector(M[prod(vars .^ e) for e in exponents])
end

function standard_monomials(I, vars = MP.variables(I))
compute_gröbner_basis!(I)
if isempty(I.p)
Expand All @@ -131,9 +168,6 @@ function standard_monomials(I, vars = MP.variables(I))
if any(Base.Fix2(<, 0), lv)
return nothing # Nonzero dimensional
end
return MP.monomials(
vars,
0:(sum(lv)-1),
m -> !any(Base.Fix2(MP.divides, m), mv),
)
# The exponent of `vars[i]` in a standard monomial is smaller than `lv[i]`
return standard_monomials(I, vars, sum(lv) - length(vars))
end
17 changes: 17 additions & 0 deletions test/groebner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,20 @@ end
S = @set x * y == 1 && x >= 0
@test MP.coefficient_type(typeof(S)) == Rational{BigInt}
end

@testset "standard_monomials up to a degree" begin
Mod.@polyvar x y
vars = MP.variables(x * y)
I = ideal(@set x^2 == 1)
@test standard_monomials(I, vars, 3) ==
MP.monomial_vector([1, x, y, x * y, y^2, x * y^2, y^3])
@test standard_monomials(I, vars, 0) == MP.monomial_vector([x^0])
@test isempty(standard_monomials(I, vars, -1))
# Zero-dimensional
V = @set x * y == 1 && x^2 == y
I = ideal(V)
@test standard_monomials(I, vars, 10) == standard_monomials(I, vars)
# The ideal contains `1`
I = ideal([x^0 + 0 * x * y])
@test isempty(standard_monomials(I, vars, 2))
end
Loading