Symbolics 'solve' command undefined

I have copied code from the Symbolics package as shown, but I get the ‘solve’ function is undefined. I must be doing something wrong but I do not see what mistake i am m
aking. Any help would be appreciated. Thank you

What version? Since it was released last week and requires Julia v1.10 you need to be up to date to use it

That might be it, I will update Julia.

Thank you :slight_smile:

Ok, so I have installed Julia 1.10, I still have the exact same response?

try updating the packages. e.g., enter the Pkg repl and enter up

This still does not work. Can someone confirm please that it works for them?

So for me it also doesn’t work:

julia> Pkg.activate(;temp=true); Pkg.add("Symbolics"); using Symbolics
# ...
    Updating `/tmp/jl_PdF79T/Project.toml`
  [0c5d862f] + Symbolics v6.4.0
# ...
julia> @variables x
1-element Vector{Num}:
 x

julia> solve(x^2-9,x)
ERROR: UndefVarError: `solve` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[4]:1

julia> Symbolics.sol<Tab>
solve_for
solve_multipoly
solve_multivar
solve_univar

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 4800H with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores) 

Should solve exist? I don’t see it in the docs at first glance. symbolic_solve which I see in the docs does exist:

julia> symbolic_solve(x^2-9,x)
ERROR: "Nemo is required. Execute `using Nemo` to enable this functionality."
Stacktrace:
 [1] factor_use_nemo(poly::Num)
   @ Symbolics ~/.julia/packages/Symbolics/e7UFe/src/solver/nemo_stuff.jl:14
 [2] solve_univar(expression::Num, x::Num; dropmultiplicity::Bool)
   @ Symbolics ~/.julia/packages/Symbolics/e7UFe/src/solver/main.jl:260
 [3] symbolic_solve(expr::Num, x::Num; dropmultiplicity::Bool, warns::Bool)
   @ Symbolics ~/.julia/packages/Symbolics/e7UFe/src/solver/main.jl:156
 [4] symbolic_solve(expr::Num, x::Num)
   @ Symbolics ~/.julia/packages/Symbolics/e7UFe/src/solver/main.jl:113
 [5] top-level scope
   @ REPL[6]:1

The only exported function starting with solv is solve_for which is deprecated:

julia> solve_for(x^2-9,x)
┌ Warning: solve_for is deprecated, please use symbolic_linear_solve instead.
│   caller = top-level scope at REPL[7]:1
└ @ Core REPL[7]:1
ERROR: AssertionError: islinear
...

There are some more functions starting with symbolic:

julia> symbolic
symbolic_linear_solve
symbolic_solve
symbolics_to_sympy

And with Nemo.jl, symbolic_solve solves the equation:

julia> using Nemo;
julia> symbolic_solve(x^2-9,x)
2-element Vector{BigInt}:
  3
 -3
1 Like

Nope, this still doesn’t work at all, exactly the same outcome

Make sure you update your packages including Symbolics and Nemo. Then this works:

julia> using Symbolics

julia> import Nemo

julia> @variables x;

julia> symbolic_solve([x-1, x^2-1], x)
1-element Vector{BigInt}:
 1

To be extra sure it’ll work, you could create a clean virtual environment and install Symbolics and Nemo. Then it has to work.

2 Likes

I can also confirm that it works in a fresh environment with Julia 1.10.5 when you just ] add Symbolics Nemo.

julia> using Symbolics

julia> import Nemo

Welcome to Nemo version 0.46.2

Nemo comes with absolutely no warranty whatsoever

julia> @variables x;

julia> symbolic_solve([x-1, x^2-1], x)
1-element Vector{BigInt}:
 1
2 Likes

Hello @Paul_Warburton & @abraemer .
1- the function is called symbolic_solve, all the other functions you’ve mentioned do not exist except for solve_for which is now renamed to symbolic_linear_solve and only solves linear equations.

2- To use symbolic_solve you need Symbolics.jl v6.3 or above. Please make sure you’re using the correct versions.

(@v1.10) pkg> status Symbolics
Status `~/.julia/environments/v1.10/Project.toml`
  [0c5d862f] Symbolics v6.3.0 `../../../code/julia/Symbolics.jl`

3- Read error messages! using your examples:

julia> using Symbolics

julia> @variables x
1-element Vector{Num}:
 x

julia> symbolic_solve(x^2-9,x)
ERROR: "Nemo is required. Execute `using Nemo` to enable this functionality."

The error tells me to execute using Nemo, so ill listen

julia> using Nemo

Welcome to Nemo version 0.45.7

Nemo comes with absolutely no warranty whatsoever

julia> symbolic_solve(x^2-9,x)
2-element Vector{BigInt}:
  3
 -3

Hope this helps.

4 Likes

@Yassin_ElBedwihy we should add a !!! note to the solver docs page about handling the extension package usage with this. I can see there that it doesn’t have an explicit call out, and that would be a very helpful thing to highlight.

Thanks Yassin,

I believe I have the updated components, but it still does not work.

I would really like to use symbolics for a project I am working on, I just don’t know what else to do?

Please advise what else might be causing this issue?

Cheers, Paul

The expand command works but the symbolic_linear_solve command still says it is undefine, just like previously. This is not caused by outdated software, everything is at least of versions specified as required.

Further up you showed output from a jupyter notebook, whereas in your last post you showed that Symbolics is up to date in the default/global environment (v1.10) in your REPL. Maybe the notebook is using a different, local environment with an older Symbolics.jl version?

Have you ran the commands that work for others here in the REPL or only in the notebook? If the latter, what output does ] status (or using Pkg; Pkg.status()) give in the notebook?

You are VERY clever, somehow I still have the old versions in Notebook. Julia v1.9 and Symbolics v5.1.0. I will try and update them in notebooks as that is what I am using. Thank you :slight_smile:

That is it! It is working, I needed to update Julia and Symbolics in Notebook! I was updating it in REPL, whatever that means! Thank you everyone for your patience :slight_smile:

2 Likes

Glad you found the issue. To clarify, there seem to have been two issues.

  1. It looks like you had multiple Julia versions installed (totally fine) but have either selected the wrong kernel (1.9 instead of 1.10) or didn’t have a 1.10 kernel to begin with.

  2. By default, jupyter notebooks use the Julia environment (Project.toml) that is closest to the notebook file (e.g. in the same folder). It seems that in this environment, Symbolics.jl was out of date. The REPL on the other hand always uses the global environment by default. This is the one you see in your REPL screenshot. (Of course, in both cases, you can override the default and choose a specific environment explicitly)