Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New section in solver documentation (Expressions we can not solve) and updated symbolic_solve docstring #1258

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/src/manual/solver.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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)
Expand All @@ -69,6 +69,12 @@ Symbolics.symbolic_solve(eqs, [x,y,z])

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
Expand Down
16 changes: 14 additions & 2 deletions src/solver/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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> Symbolics.symbolic_to_float.(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
Expand Down
Loading