Using SymEngine. Functions not defined

using SymEngine

julia> expand(a + 2(b+2)^2 + 2a + 3(a+1))

when I try to do this, I get error, expand not defined.

I think that means it’s not fiding SymEngine.

Need to define first the symbolic variables: a=symbols(:a); b=symbols(:b);

I tried that

using SyEngine

x=symbols(:x);
# get x as a result
expand((4x^2+3)(2x+5))

That fixed the differential function, doesn’t seem to help with expand. The other issue I have, is I’m not sure if there is a way to plot the output of diff(), other symbolic packages allow this with Gnuplots, but I don’t know of any that allow it with Plots.jl

This works perfectly fine:

julia> using SymEngine

julia> x = symbols(:x)
x

julia> expand((4x^2+3)(2x+5))
103 + 80*x + 16*x^2

Your post has a typo (using SyEngine instead of using SymEngine [note the m in Sym]), so maybe this is why it didn’t work?

Alternatively, you might have had some other package loaded that exports sa function called expaned which would lead to a name clash and require qualification of the function call (e.g. SymEngine.expand()).

In either case, and as a more general piece of advice, when you post questions on here it would be useful if you

  1. Start a completely fresh Julia REPL session
  2. Execute your code line by line in the REPL
  3. Post the full REPL session including all outputs (like I did above)

Assuming your problem here really was your typo, following this procedure would likely have lead you to discover the issue yourself, as your post would have looked like the following:

julia> using SyEngine
ERROR: ArgumentError: Package SyEngine not found in current path:
- Run `import Pkg; Pkg.add("SyEngine")` to install the SyEngine package.

Stacktrace:
 [1] require(::Module, ::Symbol) at ./loading.jl:893

julia> x = symbols(:x)
ERROR: UndefVarError: symbols not defined
Stacktrace:
 [1] top-level scope at REPL[2]:1

julia> expand((4x^2+3)(2x+5))
ERROR: UndefVarError: x not defined
Stacktrace:
 [1] top-level scope at REPL[3]:1

i.e. you would have immediately seen that the problem was in the first line, with SyEngine not being found, rather than with your call to expand. Similarly, if your problem had been a name clash, you should have seen something like:

julia> expand(x) = "the expand function exists already in this namespace!"
expand (generic function with 1 method)

julia> using SymEngine
WARNING: using SymEngine.expand in module Main conflicts with an existing identifier.

which at a minimum would have meant someone on this forum could have explained the problem to you immediately.

1 Like