Skip to content

Commit

Permalink
Merge pull request #1355 from AayushSabharwal/as/no-error-ia-solve
Browse files Browse the repository at this point in the history
feat: allow using `ia_solve` without Nemo
  • Loading branch information
n0rbed authored Nov 10, 2024
2 parents 8c518c2 + fb10307 commit 195c95d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/solver/ia_main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ function isolate(lhs, var; warns=true, conditions=[], complex_roots = true, peri
roots = []
new_var = gensym()
new_var = (@variables $new_var)[1]
lhs_roots = solve_univar(lhs - new_var, var)
if Base.get_extension(Symbolics, :SymbolicsNemoExt) !== nothing
lhs_roots = solve_univar(lhs - new_var, var)
else
a, b, islin = linear_expansion(lhs - new_var, var)
if islin
lhs_roots = [-b / a]
else
lhs_roots = [RootsOf(lhs - new_var, var)]
if warns
@warn "Nemo is required to properly solve this expression. Execute `using Nemo` to enable this functionality."
end
end
end

for i in eachindex(lhs_roots)
for j in eachindex(rhs)
Expand Down
10 changes: 10 additions & 0 deletions test/solver.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
using Symbolics
import Symbolics: ssqrt, slog, scbrt, symbolic_solve, ia_solve, postprocess_root

@testset "ia_solve without Nemo" begin
@test Base.get_extension(Symbolics, :SymbolicsNemoExt) === nothing
@variables x
roots = ia_solve(log(2 + x), x)
@test substitute(roots[1], Dict()) == -1.0
roots = @test_warn ["Nemo", "required"] ia_solve(log(2 + x^2), x)
@test operation(roots[1]) == Symbolics.RootsOf
end

using Groebner, Nemo
E = Base.MathConstants.e

Expand Down

0 comments on commit 195c95d

Please sign in to comment.