Skip to content

Commit

Permalink
Merge branch 'RootFinding' of https://github.com/n0rbed/Symbolics.jl
Browse files Browse the repository at this point in the history
…into RootFinding
  • Loading branch information
n0rbed committed Aug 17, 2024
2 parents ee08310 + 01d1ef3 commit 0895f89
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Symbolics"
uuid = "0c5d862f-8b57-4792-8d23-62f2024744c7"
authors = ["Shashi Gowda <[email protected]>"]
version = "6.1.0"
version = "6.2.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -53,7 +53,7 @@ SymbolicsForwardDiffExt = "ForwardDiff"
SymbolicsGroebnerExt = "Groebner"
SymbolicsLuxCoreExt = "LuxCore"
SymbolicsNemoExt = "Nemo"
SymbolicsPreallocationToolsExt = "PreallocationTools"
SymbolicsPreallocationToolsExt = ["PreallocationTools", "ForwardDiff"]
SymbolicsSymPyExt = "SymPy"

[compat]
Expand All @@ -78,6 +78,7 @@ LogExpFunctions = "0.3"
LuxCore = "0.1.11"
MacroTools = "0.5"
NaNMath = "1"
Nemo = "0.45, 0.46"
PreallocationTools = "0.4"
PrecompileTools = "1"
RecipesBase = "1.1"
Expand Down
6 changes: 4 additions & 2 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Groebner = "0b43b601-686d-58a3-8a1c-6623616c7cd4"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
Groebner = "0b43b601-686d-58a3-8a1c-6623616c7cd4"
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"

[compat]
BenchmarkTools = "1.3"
Documenter = "1"
Groebner = "0.7"
Latexify = "0.15, 0.16"
Nemo = "0.45, 0.46"
OrdinaryDiffEq = "6.31"
Plots = "1.36"
StaticArrays = "1.5"
Expand Down
28 changes: 21 additions & 7 deletions docs/src/manual/solver.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Solver
The main `symbolic` solver for Symbolics.jl is `symbolic_solve`. Symbolic solving
means that it only uses analytical methods and manually solves equations for input variables.
It uses no numerical methods and only outputs exact solutions.

The main symbolic solver for Symbolics.jl is `symbolic_solve`. Symbolic solving
means that it only uses symbolic (algebraic) methods and outputs exact solutions.

```@docs
Symbolics.symbolic_solve
```
Expand All @@ -19,17 +20,20 @@ that this functionality is only used with floating point values if necessary. In
directly handles floating point values using standard factorizations.

### More technical details and examples

#### Technical details

The `symbolic_solve` function uses 4 hidden solvers in order to solve the user's input. Its base,
`solve_univar`, uses analytic solutions up to polynomials of degree 4 and factoring as its method
for solving univariate polynomials. The function's `solve_multipoly` uses GCD on the input polynomials then throws passes the result
to `solve_univar`. The function's `solve_multivar` uses Groebner basis and a separating form in order to create linear equations in the
input variables and a single high degree equation in the separating variable. Each equation resulting from the basis is then passed
to `solve_univar`. We can see that essentially, `solve_univar` is the building block of `symbolic_solve`.if the input is not a valid polynomial and can not be solved by the algorithm above, `symbolic_solve` passes
it to `ia_solve`, which attempts solving by attraction and isolation [^1]. This only works when the input is a single expression
input variables and a single high degree equation in the separating variable [^1]. Each equation resulting from the basis is then passed
to `solve_univar`. We can see that essentially, `solve_univar` is the building block of `symbolic_solve`. If the input is not a valid polynomial and can not be solved by the algorithm above, `symbolic_solve` passes
it to `ia_solve`, which attempts solving by attraction and isolation [^2]. This only works when the input is a single expression
and the user wants the answer in terms of a single variable. Say `log(x) - a == 0` gives us `[e^a]`.

#### Nice examples

```@example solver
using Symbolics, Nemo;
@variables x;
Expand All @@ -49,6 +53,16 @@ eqs = [x^2 + y + z - 1, x + y^2 + z - 1, x + y + z^2 - 1]
Symbolics.symbolic_solve(eqs, [x,y,z])
```

### Feature completeness

- [x] Linear and polynomial equations
- [x] Systems of linear and polynomial equations
- [x] Some transcendental functions
- [x] Systems of linear equations with parameters (via `symbolic_linear_solve`)
- [ ] Systems of polynomial equations with parameters
- [ ] Inequalities

# References
[^1]: [R. W. Hamming, Coding and Information Theory, ScienceDirect, 1980](https://www.sciencedirect.com/science/article/pii/S0747717189800070).

[^1] [Rouillier, F. Solving Zero-Dimensional Systems Through the Rational Univariate Representation. AAECC 9, 433–461 (1999).](https://doi.org/10.1007/s002000050114)
[^2]: [R. W. Hamming, Coding and Information Theory, ScienceDirect, 1980](https://www.sciencedirect.com/science/article/pii/S0747717189800070).
2 changes: 1 addition & 1 deletion ext/SymbolicsPreallocationToolsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module SymbolicsPreallocationToolsExt

using PreallocationTools
import PreallocationTools: _restructure, get_tmp
using Symbolics, PreallocationTools.ForwardDiff
using Symbolics, ForwardDiff

function get_tmp(dc::DiffCache, u::Type{X}) where {T,N, X<: ForwardDiff.Dual{T, Num, N}}
if length(dc.du) > length(dc.any_du)
Expand Down
2 changes: 1 addition & 1 deletion src/Symbolics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ using LogExpFunctions
include("logexpfunctions-lib.jl")

include("linear_algebra.jl")
export symbolic_linear_solve, solve_for

include("groebner_basis.jl")
export groebner_basis, is_groebner_basis
Expand All @@ -153,7 +154,6 @@ include("plot_recipes.jl")

include("semipoly.jl")

export lambertw

include("parsing.jl")
export parse_expr_to_symbolic
Expand Down
14 changes: 7 additions & 7 deletions src/solver/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ Currently, `symbolic_solve` supports
### `solve_univar` (uses factoring and analytic solutions up to degree 4)
```jldoctest
julia> @variables x a b;
julia> expr = expand((x + b)*(x^2 + 2x + 1)*(x^2 - a))
-a*b - a*x - 2a*b*x - 2a*(x^2) + b*(x^2) + x^3 - a*b*(x^2) - a*(x^3) + 2b*(x^3) + 2(x^4) + b*(x^4) + x^5
julia> Symbolics.symbolic_solve(expr, x)
julia> symbolic_solve(expr, x)
4-element Vector{Any}:
-1
-b
(1//2)*√(4a)
(-1//2)*√(4a)
julia> Symbolics.symbolic_solve(expr, x, dropmultiplicity=false)
julia> symbolic_solve(expr, x, dropmultiplicity=false)
5-element Vector{Any}:
-1
-1
Expand All @@ -49,7 +51,7 @@ julia> Symbolics.symbolic_solve(expr, x, dropmultiplicity=false)
(-1//2)*√(4a)
```
```jldoctest
julia> Symbolics.symbolic_solve(x^2 + a*x + 6, x)
julia> symbolic_solve(x^2 + a*x + 6, x)
2-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
(1//2)*(-a + √(-24 + a^2))
(1//2)*(-a - √(-24 + a^2))
Expand Down Expand Up @@ -108,13 +110,11 @@ julia> symbolic_solve(a*x^b + c, x)
((-c)^(1 / b)) / (a^(1 / b))
```
"""
function symbolic_solve(expr, x; dropmultiplicity=true, warns=true)
type_x = typeof(x)
function symbolic_solve(expr, x::T; dropmultiplicity=true, warns=true) where {T}
expr_univar = false
x_univar = false


if (type_x == Num || type_x == SymbolicUtils.BasicSymbolic{Real})
if (T == Num || T == SymbolicUtils.BasicSymbolic{Real})
x_univar = true
@assert is_singleton(unwrap(x)) "Expected a variable, got $x"
else
Expand Down

0 comments on commit 0895f89

Please sign in to comment.