Skip to content

Commit

Permalink
Merge pull request #1367 from n0rbed/quick_fix
Browse files Browse the repository at this point in the history
Support symbolic_solve([equations])
  • Loading branch information
ChrisRackauckas authored Nov 18, 2024
2 parents 95e0190 + 58ff391 commit 2bc3c54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/solver/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ function symbolic_solve(expr, x::T; dropmultiplicity = true, warns = true) where
end

function symbolic_solve(expr; x...)
if expr isa Vector
expr = convert(Vector{Any}, expr)
for i in eachindex(expr)
expr[i] = expr[i] isa Equation ? expr[i].lhs - expr[i].rhs : expr[i]
end
else
expr = expr isa Equation ? expr.lhs - expr.rhs : expr
end


r = filter_poly.(expr)
subs, filtered = r isa Tuple ? r : (map(t -> t[1], r), map(t -> t[2], r))

Expand Down
8 changes: 8 additions & 0 deletions test/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,26 @@ end
@test check_equal(r_novar, arr_known_roots)

eqs = [x-y-z, x+y-z^2, x^2 + y^2 - 1]
eqs_in_equation_form = [x-y ~ z, x+y-z^2 ~ 0, x^2 + y^2 ~ 1]
arr_calcd_roots = sort_arr(symbolic_solve(eqs, [x,y,z]), [x,y,z])
r_novar = sort_arr(symbolic_solve(eqs_in_equation_form), [x,y,z])
r_eq = sort_arr(symbolic_solve(eqs_in_equation_form, [x,y,z]), [x,y,z])
arr_known_roots = sort_arr([Dict(x => 0, y=>1, z=>-1), Dict(x=>1, y=>0, z=>1),
Dict(x=>(1/2)*(-2-sqrt(2)*im), y=>(1/2)*(-2+sqrt(2)*im), z=>-sqrt(2)*im),
Dict(x=>(1/2)*(-2+sqrt(2)*im), y=>(1/2)*(-2-sqrt(2)*im), z=>sqrt(2)*im)], [x,y,z])
@test check_approx(arr_calcd_roots, arr_known_roots)
@test check_approx(r_novar, arr_known_roots)
@test check_approx(r_eq, arr_known_roots)

eqs = [x^2, y, z]
eqs_in_equation_form = [x^2 ~ 0, y ~ 0, z ~ 0]
arr_calcd_roots = sort_arr(symbolic_solve(eqs, [x,y,z], dropmultiplicity=false), [x,y,z])
r_novar = sort_arr(symbolic_solve(eqs, dropmultiplicity=false), [x,y,z])
r_eq_novar = sort_arr(symbolic_solve(eqs_in_equation_form, dropmultiplicity=false), [x,y,z])
arr_known_roots = sort_arr([Dict(x=>0, y=>0, z=>0), Dict(x=>0, y=>0, z=>0)], [x,y,z])
@test check_equal(arr_calcd_roots, arr_known_roots)
@test check_equal(r_novar, arr_known_roots)
@test check_equal(r_eq_novar, arr_known_roots)

eqs = [y^2 - 1, x]
arr_calcd_roots = sort_arr(symbolic_solve(eqs, [x,y]), [x,y])
Expand Down

0 comments on commit 2bc3c54

Please sign in to comment.