Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sympy does not simplify enough

Tags:

python

sympy

From evaluation of an expression in sympy, I get the result of the left side:

However, I know that the right sight is a much nicer and cleaner way to simplify this expression. But as far as I tried, sympy is not able to simplify the left side to the right side.

Has anybody any idea how to simplify the left side in sympy such that I will get the right side? I tried already the simplify() function without success.

like image 647
thinkingeye Avatar asked Oct 18 '25 20:10

thinkingeye


1 Answers

If you suspect that something can be simplified in terms of some expression you can try nsimplify. In this case nsimplify will need a hint of what you expect it to be simplified in terms of. You could supply all radicals or just one of the two:

>>> eq=(14/(-root(50,3)-2+root(20,3))); eq
14/(-50**(1/3) - 2 + 20**(1/3))
>>> nsimplify(eq,eq.atoms(Pow))
-20**(1/3) - 2
>>> nsimplify(eq, [root(50,3)])
-20**(1/3)*(2*50**(1/3) + 10)/10
>>> nsimplify(eq, [root(20,3)])
-20**(1/3) - 2
>>> eq.equals(_)
True
like image 128
smichr Avatar answered Oct 21 '25 09:10

smichr