From a40fa9bfde40178fe290c1dd442aa2ccb65888c0 Mon Sep 17 00:00:00 2001 From: n0rbed Date: Wed, 4 Sep 2024 08:52:15 +0300 Subject: [PATCH 1/2] updated docs --- docs/src/manual/solver.md | 16 +++++++++++++++- src/solver/main.jl | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/src/manual/solver.md b/docs/src/manual/solver.md index 7b4a33013..ffe2fd0ef 100644 --- a/docs/src/manual/solver.md +++ b/docs/src/manual/solver.md @@ -60,9 +60,23 @@ Symbolics.symbolic_solve(eqs, [x,y,z]) - [x] Some transcendental functions - [x] Systems of linear equations with parameters (via `symbolic_linear_solve`) - [ ] Equations with radicals -- [ ] Systems of polynomial equations with parameters and positive dimensional systems +- [x] Systems of polynomial equations with parameters and positive dimensional systems - [ ] Inequalities +### Expressions we can not solve (but aim to) +``` +# Mathematica + +In[1]:= Reduce[x^2 - x - 6 > 0, x] +Out[1]= x < -2 || x > 3 + +In[2]:= Reduce[x+a > 0, x] +Out[2]= a \[Element] Reals && x > -a + +In[3]:= Solve[x^(x) + 3 == 0, x] +Out[3]= {{x -> (I \[Pi] + Log[3])/ProductLog[I \[Pi] + Log[3]]}} +``` + # References [^1]: [Rouillier, F. Solving Zero-Dimensional Systems Through the Rational Univariate Representation. AAECC 9, 433–461 (1999).](https://doi.org/10.1007/s002000050114) diff --git a/src/solver/main.jl b/src/solver/main.jl index 99199fb64..e3675e2ad 100644 --- a/src/solver/main.jl +++ b/src/solver/main.jl @@ -3,8 +3,8 @@ Base.:^(a::Complex{<:Real}, b::Num) = Symbolics.Pow(a, b) symbolic_solve(expr, x; dropmultiplicity=true, warns=true) `symbolic_solve` is a function which attempts to solve input equations/expressions symbolically using various methods. -There are 2 required arguments and 1 optional argument. +## Arguments - expr: Could be a single univar expression in the form of a poly or multiple univar expressions or multiple multivar polys or a transcendental nonlinear function. - x: Could be a single variable or an array of variables which should be solved @@ -13,7 +13,7 @@ There are 2 required arguments and 1 optional argument. - warns (optional): When invalid expressions or cases are inputted, should the solver warn you of such cases before returning nothing? if this is set to false, the solver returns nothing. By default, warns are set to true. -It can take a single variable, a vector of variables, a single expression, an array of expressions. +## Supported input The base solver (`symbolic_solve`) has multiple solvers which chooses from depending on the the type of input (multiple/uni var and multiple/single expression) only after ensuring that the input is valid. @@ -129,6 +129,18 @@ julia> symbolic_solve(log(x+1)+log(x-1), x) julia> symbolic_solve(a*x^b + c, x) ((-c)^(1 / b)) / (a^(1 / b)) ``` + +### Evaluating output (converting to floats) +If you want to evaluate the exact expressions found by `symbolic_solve`, you can do the following: +```jldoctest +julia> roots = symbolic_solve(2^(x+1) + 5^(x+3), x) +1-element Vector{SymbolicUtils.BasicSymbolic{Real}}: + (-slog(2) - log(complex(-1)) + 3slog(5)) / (slog(2) - slog(5)) + +julia> eval.(Symbolics.toexpr.(roots)) +1-element Vector{Complex{BigFloat}}: + -4.512941594732059759689023145584186058252768936052415430071569066192919491762214 + 3.428598090438030380369414618548038962770087500755160535832807433942464545729382im +``` """ function symbolic_solve(expr, x::T; dropmultiplicity = true, warns = true) where {T} expr_univar = false From d25be131299d6c167041fddf0f89c3f1fafd7188 Mon Sep 17 00:00:00 2001 From: n0rbed Date: Mon, 9 Sep 2024 03:18:52 +0300 Subject: [PATCH 2/2] symbolic_to_float --- src/solver/main.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver/main.jl b/src/solver/main.jl index 59c8940d8..e9d3f3aeb 100644 --- a/src/solver/main.jl +++ b/src/solver/main.jl @@ -137,7 +137,7 @@ julia> roots = symbolic_solve(2^(x+1) + 5^(x+3), x) 1-element Vector{SymbolicUtils.BasicSymbolic{Real}}: (-slog(2) - log(complex(-1)) + 3slog(5)) / (slog(2) - slog(5)) -julia> eval.(Symbolics.toexpr.(roots)) +julia> Symbolics.symbolic_to_float.(roots) 1-element Vector{Complex{BigFloat}}: -4.512941594732059759689023145584186058252768936052415430071569066192919491762214 + 3.428598090438030380369414618548038962770087500755160535832807433942464545729382im ```