Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Groebner extension, partially fix ordering #1324

Merged
merged 3 commits into from
Oct 26, 2024
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ DocStringExtensions = "0.9"
DomainSets = "0.6, 0.7"
DynamicPolynomials = "0.5, 0.6"
ForwardDiff = "0.10.36"
Groebner = "0.5, 0.6, 0.7"
Groebner = "0.8"
IfElse = "0.1"
LaTeXStrings = "1.3"
LambertW = "1.0.0"
Expand Down
11 changes: 9 additions & 2 deletions ext/SymbolicsGroebnerExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ julia> @variables x y;
julia> groebner_basis([x*y^2 + x, x^2*y + y])
```
"""
function Symbolics.groebner_basis(polynomials::Vector{Num}; kwargs...)
function Symbolics.groebner_basis(polynomials::Vector{Num}; ordering=InputOrdering(), kwargs...)
polynoms, pvar2sym, sym2term = Symbolics.symbol_to_poly(polynomials)
basis = Groebner.groebner(polynoms; kwargs...)
sym2term_for_groebner = Dict{Any,Any}(v1 => k for (k, (v1, v2)) in sym2term)
all_sym_vars = Groebner.ordering_variables(ordering)
missed = setdiff(all_sym_vars, Set(collect(keys(sym2term_for_groebner))))
for var in missed
sym2term_for_groebner[var] = var
end
ordering = Groebner.ordering_transform(ordering, sym2term_for_groebner )
basis = Groebner.groebner(polynoms; ordering=ordering, kwargs...)
PolyType = symtype(first(polynomials))
Symbolics.poly_to_symbol(basis, pvar2sym, sym2term, PolyType)
end
Expand Down
8 changes: 8 additions & 0 deletions test/extensions/groebner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,13 @@ truebasis = [
basis = groebner_basis(system)
@test isequal(expand.(basis), truebasis)

# issues/1323
@variables t S(t) R(t)
sys = [-12 + 5S, 2 + 5R]
@test isequal(expand.(groebner_basis(sys, ordering=Lex(S, R))), [2//5 + R, -12//5 + S])
sys = [S^2 + 2*R^2 - 1, S*R - 1]
res = [(1//2) - (1//2)*(R^2) + R^4, S - R + (2//1)*(R^3)]
@test isequal(expand.(groebner_basis(sys, ordering=Lex(S, R))), res)

# Groebner does not yet work with constant ideals
@test_broken groebner_basis([1])
Loading