Skip to content

Commit

Permalink
solve now supports input of type Equation
Browse files Browse the repository at this point in the history
  • Loading branch information
n0rbed committed Jul 30, 2024
1 parent 96a470a commit 76111e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ext/SymbolicsGroebnerExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function Symbolics.is_groebner_basis(polynomials::Vector{Num}; kwargs...)
Groebner.isgroebner(polynoms; kwargs...)
end

function Symbolics.solve_multivar(eqs::Vector{Num}, vars::Vector{Num}, mult=false)
function Symbolics.solve_multivar(eqs::Vector, vars::Vector{Num}, mult=false)

# Reference: Rouillier, F. Solving Zero-Dimensional Systems
# Through the Rational Univariate Representation.
Expand Down
19 changes: 11 additions & 8 deletions src/solver/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,16 @@ function solve(expr, x, multiplicities=false)

if !(expr isa Vector)
expr_univar = true
expr = expr isa Equation ? expr.lhs - expr.rhs : expr
check_expr_validity(expr)
else
for e in expr
check_expr_validity(e)
expr = Vector{Any}(expr)
for i in eachindex(expr)
expr[i] = expr[i] isa Equation ? expr[i].lhs - expr[i].rhs : expr[i]
check_expr_validity(expr[i])
!check_poly_inunivar(expr[i], x) && throw("Solve can not solve this input currently")
end
expr = Vector{Num}(expr)
end


Expand All @@ -136,12 +141,10 @@ function solve(expr, x, multiplicities=false)
if expr_univar
sols = check_poly_inunivar(expr, x) ? solve_univar(expr, x, multiplicities) : ia_solve(expr, x)
else
exprs_ispoly = []
for e in expr
push!(e, check_poly_inunivar(e, x))
for i in eachindex(expr)
!check_poly_inunivar(expr[i], x) && throw("Solve can not solve this input currently")
end

sols = all(exprs_ispoly) ? solve_multipoly(expr, x, multiplicities) : throw("Solve can not solve this input currently")
sols = solve_multipoly(expr, x, multiplicities)
end

sols = map(postprocess_root, sols)
Expand Down Expand Up @@ -284,6 +287,6 @@ function solve_multipoly(polys::Vector, x::Num, mult=false)
end


function solve_multivar(eqs::Vector{Num}, vars::Vector{Num}, mult=false)
function solve_multivar(eqs::Vector, vars::Vector{Num}, mult=false)
throw("Groebner bases engine is required. Execute `using Groebner` to enable this functionality.")
end

0 comments on commit 76111e4

Please sign in to comment.