-1

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
    Could you add your example as reproducible code (as text, not as image)? That way, people trying to help you aren't obliged to type everything again. – JohanC Oct 30 '21 at 21:15
  • As JohanC says, please post the code as formatted text. [See here for a post on why](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question). [See here for details on formatting](https://stackoverflow.com/help/formatting). – tjheslin1 Oct 31 '21 at 11:42
  • Oh I'm sorry I'm new posting on programming forums so I didn't think about it. Thanks anyway I think someone may have found what I did wrong :) – Lorenzo Javier Guillermo Alfon Nov 01 '21 at 00:56

1 Answers1

0

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)

smichr
  • 16,948
  • 2
  • 27
  • 34