# How to expand a polynomial in Symbolics.jl?

**URL:** <https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530>\
**Category:** Specific Domains\
**Created:** [April 3, 2021, 10:31pm UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530 "2021-04-03T22:31:36Z")\
**Posts on this page:** 9\
**Page:** 1

<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:** [April 3, 2021, 10:31pm UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530/1 "2021-04-03T22:31:36Z")

</div>

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?

---

<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:** [April 3, 2021, 10:35pm UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530/2 "2021-04-03T22:35:55Z")

</div>

There’s an `expand` kwarg in `simplify`.

---

<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:** [April 3, 2021, 11:08pm UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530/3 "2021-04-03T23:08:39Z")

</div>

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?

---

<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:** [April 3, 2021, 11:48pm UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530/4 "2021-04-03T23:48:26Z")

</div>

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

---

<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:** [April 4, 2021, 6:58am UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530/5 "2021-04-04T06:58:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [April 4, 2021, 7:07am UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530/6 "2021-04-04T07:07:48Z")

</div>

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

---

<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:** [April 4, 2021, 7:12am UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530/7 "2021-04-04T07:12:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hdavid16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdavid16/32/11531_2.png) [@hdavid16](https://discourse.julialang.org/u/hdavid16)\
**Post date:** [May 12, 2021, 3:05am UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530/8 "2021-05-12T03:05:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [May 12, 2021, 4:28am UTC](https://discourse.julialang.org/t/how-to-expand-a-polynomial-in-symbolics-jl/58530/9 "2021-05-12T04:28:03Z")

</div>

You just need

```julia
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

```
