Simplify, how return code instead of TeX?

23 views
Skip to first unread message

Michał Pawłowski

unread,
Feb 10, 2021, 10:43:44 AM2/10/21
to sympy
Hi.

I'd like to generate code of simplified formula. I.E:

When I pass: 1+x+x**2+x**3
I'd like to have: x**3+x**2+x+1

Is it possible to achieve it?

Thanks
Mike

gu...@uwosh.edu

unread,
Feb 10, 2021, 1:59:55 PM2/10/21
to sympy
wrap your expression in a `print()` statement: `print(1+x+x**2+x**3)`.

Michał Pawłowski

unread,
Feb 10, 2021, 2:20:38 PM2/10/21
to sympy
Thank you. It works in this example. But if I'd like to do this:

print((x**2+1)*(x-1))

It prints me string without compute it. I'd like to have :

x**3-x**2+x-1

Is it possible?

Thanks Mike

gu...@uwosh.edu

unread,
Feb 10, 2021, 2:22:09 PM2/10/21
to sympy
`print(expand((x**2+1)*(x-1)))`

Michał Pawłowski

unread,
Feb 10, 2021, 2:24:13 PM2/10/21
to sympy
Thank you very much! :)
Reply all
Reply to author
Forward
0 new messages