# Symbolic algebra elaboration?

Hi all …

My daughter is in the first scientific high school, here in Italy. Yesterday, we were to see the expansion of (x+y)^7 with tartaglia triangle method … very nice … but I’d like to use Julia to do other symbolic algebric expansions …

So, what package i could use in Julia?

Thank you very much for help.

1 Like

You can use SymEngine.jl

julia> using SymEngine

julia> @vars x,y
(x, y)

julia> expand((x+y)^7 )
7*x*y^6 + 21*x^2*y^5 + 35*x^3*y^4 + 35*x^4*y^3 + 21*x^5*y^2 + 7*x^6*y + x^7 + y^7

6 Likes

Thank you very much, it works perfectly …
but i have another question. How can i print the result, this one …

julia> expand( ( a * b^2 + a^2 * b) ^ 7 )
a^7*b^14 + 7*a^8*b^13 + 21*a^9*b^12 + 35*a^10*b^11 + 35*a^11*b^10 + 21*a^12*b^9 + 7*a^13*b^8 + a^14*b^7


… in a better graphically pretty print … as if the professor had written it on the blackboard ?

Many thanks.

If you are using Jupyter you can try Latexify:

julia> using Latexify

julia> latexify(expand( ( a * b^2 + a^2 * b) ^ 7 ))
L"$a^{7} \cdot b^{14} + 7 \cdot a^{8} \cdot b^{13} + 21 \cdot a^{9} \cdot b^{12} + 35 \cdot a^{10} \cdot b^{11} + 35 \cdot a^{11} \cdot b^{10} + 21 \cdot a^{12} \cdot b^{9} + 7 \cdot a^{13} \cdot b^{8} + a^{14} \cdot b^{7}$"



(Jupyter should render it nicely, at least according to the docs!)

3 Likes

Another package you can use is my Reduce.jl package for this:

julia> using Reduce; expand(:((x+y)^7))
:(x ^ 7 + 7 * x ^ 6 * y + 21 * x ^ 5 * y ^ 2 + 35 * x ^ 4 * y ^ 3 + 35 * x ^ 3 * y ^ 4 + 21 * x ^ 2 * y ^ 5 + 7 * x * y ^ 6 + y ^ 7)


It allows you to symbolically manipulate Julia Expr objects directly.

4 Likes
2 Likes

I had never been able to find the documentation for SymEngine… is it the same as SymPy at user level?

For me, all I need is explained in the README.md, I don’t know if all functions of SymEngine (C++) were implemented .