How to expand a polynomial in Symbolics.jl?

I’m trying out the package Symbolics.jl. There is a “simplify” function, but not “expand” which is ubiquitous among other CASs. Is this functionality still to be implemented, or hidden somewhere?

1 Like

There’s an expand kwarg in simplify.

The current manual lists these kwargs:

simplify(x; polynorm=false,
            threaded=false,
            thread_subtree_cutoff=100,
            rewriter=nothing)

I don’t see “expand”. Maybe I should switch to the development version on github?

The manual is behind: polynorm was renamed to expand because that is more clear for what it’s doing.

I tried again. The keyword doesn’t seem to have been renamed (yet), but more importantly a full expansion is not performed.

(@v1.6) pkg> add https://github.com/JuliaSymbolics/Symbolics.jl.git

julia> @variables x y z

julia> simplify((x+y+z)^3, polynorm=true)
x^3 + y^3 + z^3 + 3x*(y^2 + z^2) + 3y*(x^2 + z^2) + 3z*(x^2 + y^2) + 6x*y*z

julia> simplify((x+y+z)^3, expand=true)
ERROR: MethodError: no method matching simplify(::SymbolicUtils.Pow{Real, 
SymbolicUtils.Add{Real, Int64, Dict{Any, Number}, Nothing}, Int64, Nothing}; 
expand=true)
...

I understand that a full expansion may not be the intended result of this keyword argument, so this is not necessarily a bug, but a full expansion happens to be what I need.

Do you have the newest version? The package is constantly being updated.

I just did

] rm Symbolics

and reinstalled from the master branch on github, half an hour ago, but I suppose some development code may not have been merged into the master branch yet.

polynorm = true is working on the stable version (v0.1.2)

You just need

julia> expand( (x + y + z)^3 )
x^3 + y^3 + z^3 + 3x*(y^2) + 3x*(z^2) + 3y*(x^2) + 3y*(z^2) + 3z*(x^2) + 3z*(y^2) + 6x*y*z
2 Likes