# Solve equation in Symbolics.jl

**URL:** <https://discourse.julialang.org/t/solve-equation-in-symbolics-jl/119302>\
**Category:** General Usage\
**Tags:** question, package, symbolics\
**Created:** [September 11, 2024, 11:04pm UTC](https://discourse.julialang.org/t/solve-equation-in-symbolics-jl/119302 "2024-09-11T23:04:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [September 11, 2024, 11:04pm UTC](https://discourse.julialang.org/t/solve-equation-in-symbolics-jl/119302/1 "2024-09-11T23:04:34Z")

</div>

Symbolics.jl can’t solve this equation but if I multiply both sides by `x^3` then it can. Wolfram Alpha can solve both. Symbolics.jl’s docs say it can do polynomial equations; do these count? What’s the problem?

```julia
  [2edaba10] Nemo v0.46.2
  [0c5d862f] Symbolics v6.11.0

using Symbolics, Nemo
@variables x y
julia> symbolic_solve(1/x^2 ~ 1/y^2 - 2/x^3 * (x-y), x)
┌ Warning: This expression cannot be solved with the methods available to ia_solve. Try a numerical method instead.
└ @ Symbolics ~/.julia/packages/Symbolics/6WqId/src/solver/ia_main.jl:176

julia> symbolic_solve( (1/x^2 * x^3 ~ (1/y^2 - 2/x^3 * (x-y)) * x^3), x)
[ Info: Assuming (y^2) != 0
[ Info: Assuming (y^2) != 0
2-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
 y
 -2y

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 12, 2024, 1:35am UTC](https://discourse.julialang.org/t/solve-equation-in-symbolics-jl/119302/2 "2024-09-12T01:35:11Z")

</div>

Create an issue: [Issues · JuliaSymbolics/Symbolics.jl · GitHub](https://github.com/JuliaSymbolics/Symbolics.jl/issues)

Not clear to me: Why is Nemo needed?

This code is easier to copy and paste:

```julia
using Symbolics, Nemo

@variables x y
symbolic_solve(1/x^2 ~ 1/y^2 - 2/x^3 * (x-y), x)
# symbolic_solve( (1/x^2 * x^3 ~ (1/y^2 - 2/x^3 * (x-y)) * x^3), x)

```

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [September 12, 2024, 8:26am UTC](https://discourse.julialang.org/t/solve-equation-in-symbolics-jl/119302/3 "2024-09-12T08:26:55Z")

</div>

Nemo is needed to enable a package extension in Symbolics. The problem is that only polynomial equations can be solved, so you need to multiply out any denominators. Here’s a quick way to reproduce the problem.

```julia
julia> using Symbolics, Nemo

julia> @variables x;

julia> symbolic_solve(x ~ 1/x, x) # denominators cannot be handled
┌ Warning: This expression cannot be solved with the methods available to ia_solve. Try a numerical method instead.
└ @ Symbolics ~/.julia/packages/Symbolics/e7UFe/src/solver/ia_main.jl:176

julia> symbolic_solve(x^2 ~ 1, x) # multiply both sides by `x` to get polynomials
2-element Vector{BigInt}:
 -1
  1

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 12, 2024, 8:54am UTC](https://discourse.julialang.org/t/solve-equation-in-symbolics-jl/119302/4 "2024-09-12T08:54:54Z")

</div>

> [@greatpet](#):
>
> The problem is that only polynomial equations can be solved, so you need to multiply out any denominators.

So should the issue be fixed in Symbolics or in Nemo?

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [September 12, 2024, 9:51am UTC](https://discourse.julialang.org/t/solve-equation-in-symbolics-jl/119302/5 "2024-09-12T09:51:24Z")

</div>

It should be fixed in Symbolics, since Nemo is used as a backend. But since their [recent feature announcement](https://discourse.julialang.org/t/new-symbolic-solver-for-symbolics-jl/118466) mentions “multivariate polynomial solving”, I understand that is a feature limitation not a bug.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [September 12, 2024, 10:37am UTC](https://discourse.julialang.org/t/solve-equation-in-symbolics-jl/119302/6 "2024-09-12T10:37:45Z")

</div>

There isn’t a reason this cannot be handled via some normalization pass that occurs before the solve and then fixes the solution after the solve. Definitely worth an issue

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [September 12, 2024, 2:43pm UTC](https://discourse.julialang.org/t/solve-equation-in-symbolics-jl/119302/7 "2024-09-12T14:43:49Z")

</div>

Issue submitted:

> <https://github.com/JuliaSymbolics/Symbolics.jl/issues/1269>
>
> \`symbolic\_solve\` fails for some equations involving rational functions, unless t…he user manually multiplies out denominators to convert the equations into polynomial equations. Example below. Can the conversion be automated?
> \`\`\`
> julia\> using Symbolics, Nemo
> 
> julia\> @variables x;
> 
> julia\> symbolic\_solve(x ~ 1/x, x) # denominators cannot be handled
> ┌ Warning: This expression cannot be solved with the methods available to ia\_solve. Try a numerical method instead.
> └ @ Symbolics ~/.julia/packages/Symbolics/e7UFe/src/solver/ia\_main.jl:176
> 
> julia\> symbolic\_solve(x^2 ~ 1, x) # multiply both sides by \`x\` to get polynomials
> 2-element Vector{BigInt}:
> -1
> 1
> \`\`\`
> 
> (Julia 1.10.5, Symbolics 6.4.0, Nemo 0.45.7, SymbolicUtils 3.5.0)
