From ba9b964981b105f1df9f60d4200e19bee55fd417 Mon Sep 17 00:00:00 2001 From: n0rbed Date: Sat, 24 Aug 2024 10:48:40 +0300 Subject: [PATCH 1/3] bugs --- ext/SymbolicsGroebnerExt.jl | 1 + src/solver/main.jl | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/ext/SymbolicsGroebnerExt.jl b/ext/SymbolicsGroebnerExt.jl index 5e93b18ff..786f4e96e 100644 --- a/ext/SymbolicsGroebnerExt.jl +++ b/ext/SymbolicsGroebnerExt.jl @@ -187,6 +187,7 @@ function solve_zerodim(eqs::Vector, vars::Vector{Num}; dropmultiplicity=true, wa generating = true n_iterations = 1 separating_form = new_var + eqs = Symbolics.wrap.(eqs) while generating new_eqs = copy(eqs) diff --git a/src/solver/main.jl b/src/solver/main.jl index 10392fd3e..be9fd73a7 100644 --- a/src/solver/main.jl +++ b/src/solver/main.jl @@ -145,6 +145,11 @@ function symbolic_solve(expr, x::T; dropmultiplicity = true, warns = true) where expr = Vector{Num}(expr) end + if expr_univar && !x_univar + expr = [expr] + expr_univar = false + end + if x_univar sols = [] if expr_univar From 65689b38bebfa6b18dba3f856061c14a71ea4d10 Mon Sep 17 00:00:00 2001 From: n0rbed Date: Sun, 25 Aug 2024 02:54:25 +0300 Subject: [PATCH 2/3] some multipoly tests --- test/solver.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/solver.jl b/test/solver.jl index 1a66e8608..18da8e0ae 100644 --- a/test/solver.jl +++ b/test/solver.jl @@ -54,7 +54,7 @@ function check_approx(arr1, arr2) return true end -@variables x y z +@variables x y z a b c d e @testset "Invalid input" begin @test_throws AssertionError Symbolics.get_roots(x, x^2) @@ -172,6 +172,10 @@ end # expr = x^3 + sqrt(complex(-2//1))*x + 2 end +@testset "Multipoly solver" begin + @test isequal(symbolic_solve([x^2 - 1, x + 1], x)[1], -1) + @test isequal(symbolic_solve([x^2 - a^2, x + a], x)[1], -a) +end @testset "Multivar solver" begin @variables x y z @test isequal(symbolic_solve([x^4 - 1, x - 2], [x]), []) @@ -356,6 +360,7 @@ end # standby # @test Symbolics.(log(y) + x , x) == 1 + @test Symbolics.n_func_occ(log(a*x) + b, x) == 1 @test Symbolics.n_func_occ(log(x + sin((x^2 + x)/log(x))), x) == 3 @test Symbolics.n_func_occ(x^2 + x + x^3, x) == 1 @@ -373,7 +378,6 @@ end @testset "Isolate/Attract solve" begin - @variables a b c d e x lhs = ia_solve(a*x^b + c, x)[1] lhs2 = symbolic_solve(a*x^b + c, x)[1] rhs = Symbolics.term(^, -c.val/a.val, 1/b.val) @@ -510,8 +514,6 @@ using LambertW #Testing @testset "Algebraic solver tests" begin - - @variables x y z a b c function correctAns(solve_roots, known_roots) solve_roots = sort_roots(eval.(Symbolics.toexpr.(solve_roots))) known_roots = sort_roots(known_roots) From bf454dc1050628c3775b188439b90e5552f9329e Mon Sep 17 00:00:00 2001 From: n0rbed Date: Sun, 25 Aug 2024 03:42:21 +0300 Subject: [PATCH 3/3] precompiled nemo --- ext/SymbolicsGroebnerExt.jl | 3 +-- ext/SymbolicsNemoExt.jl | 13 +++++++++++++ test/solver.jl | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ext/SymbolicsGroebnerExt.jl b/ext/SymbolicsGroebnerExt.jl index 491c717aa..0d9c3f8fb 100644 --- a/ext/SymbolicsGroebnerExt.jl +++ b/ext/SymbolicsGroebnerExt.jl @@ -303,18 +303,17 @@ function Symbolics.solve_multivar(eqs::Vector, vars::Vector{Num}; dropmultiplici sol end +# Helps with precompilation time PrecompileTools.@setup_workload begin @variables a b c x y z equation1 = a*log(x)^b + c ~ 0 equation_actually_polynomial = sin(x^2 +1)^2 + sin(x^2 + 1) + 3 simple_linear_equations = [x - y, y + 2z] - expr_with_params = expand((x + b)*(x^2 + 2x + 1)*(x^2 - a)) equations_intersect_sphere_line = [x^2 + y^2 + z^2 - 9, x - 2y + 3, y - z] PrecompileTools.@compile_workload begin symbolic_solve(equation1, x) symbolic_solve(equation_actually_polynomial) symbolic_solve(simple_linear_equations, [x, y]) - symbolic_solve(expr_with_params, x, dropmultiplicity=false) symbolic_solve(equations_intersect_sphere_line, [x, y, z]) end end diff --git a/ext/SymbolicsNemoExt.jl b/ext/SymbolicsNemoExt.jl index 137a7660f..f40205289 100644 --- a/ext/SymbolicsNemoExt.jl +++ b/ext/SymbolicsNemoExt.jl @@ -1,5 +1,6 @@ module SymbolicsNemoExt using Nemo +import Symbolics.PrecompileTools if isdefined(Base, :get_extension) using Symbolics @@ -73,4 +74,16 @@ function Symbolics.gcd_use_nemo(poly1::Num, poly2::Num) return sym_gcd end + +# Helps with precompilation time +PrecompileTools.@setup_workload begin + @variables a b c x y z + expr_with_params = expand((x + b)*(x^2 + 2x + 1)*(x^2 - a)) + PrecompileTools.@compile_workload begin + symbolic_solve(expr_with_params, x, dropmultiplicity=false) + symbolic_solve(x^10 - a^10, x, dropmultiplicity=false) + symbolic_solve([x^2 - a^2, x + a], x) + end +end + end # module diff --git a/test/solver.jl b/test/solver.jl index 26f7bfaf8..6c9e4a905 100644 --- a/test/solver.jl +++ b/test/solver.jl @@ -175,6 +175,7 @@ end @testset "Multipoly solver" begin @test isequal(symbolic_solve([x^2 - 1, x + 1], x)[1], -1) @test isequal(symbolic_solve([x^2 - a^2, x + a], x)[1], -a) + @test isequal(symbolic_solve([x^20 - a^20, x + a], x)[1], -a) end @testset "Multivar solver" begin @variables x y z