From fb103072e12e6e81464b376a7a05bc0e69a4d75d Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Sun, 10 Nov 2024 19:30:33 +0530 Subject: [PATCH] feat: allow using `ia_solve` without Nemo --- src/solver/ia_main.jl | 14 +++++++++++++- test/solver.jl | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/solver/ia_main.jl b/src/solver/ia_main.jl index ae0e6e717..6f9329cce 100644 --- a/src/solver/ia_main.jl +++ b/src/solver/ia_main.jl @@ -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) diff --git a/test/solver.jl b/test/solver.jl index 1c82a899b..357f7b260 100644 --- a/test/solver.jl +++ b/test/solver.jl @@ -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