Why some symbolic expressions don´t get simplified?

67 views Asked by At

Hi I was working on a model for oscilation problems with Lagrangian mechanichs for my Classical Mechanics I course.

My problem is the following:

When I try to Simplify some expressions like the one in the image below, sympy just shows the division and doesn´t reduce the expression.

I was wondering whether this is some kind of limitation of SymPy (probably that´s not the case) or is just me missing something. enter image description here

1

There are 1 answers

1
smichr On

If SymPy doesn't know enough about the variables (like whether they are positive or zero) then it doesn't make a simplification. For sqrt you will get better results if you indicate that the variables are positive. Alternatively, you can use posify on the expression before attempting the simplification.

>>> from sympy import symbols
>>> x,y = symbols('x y', positive=True)
>>> sqrt(x/y)/sqrt(y/x)
x/y

This would not be true if x were positive and y were negative (in which case the answer would be -x/y)