Search code examples
sympyfractionssimplify

Sympy: Simplify small compound fraction with squares and roots


I have got the following situation (in Sympy 1.8):

from sympy import *
u = symbols('u') # not necessarily positive
term = sqrt(1/u**2)/sqrt(u**2)

The term renders as 2D form

How can I simplify this to 1/u**2, i.e. rendering ?

I have tried many functions from https://docs.sympy.org/latest/tutorial/simplification.html, and some arguments listed in https://docs.sympy.org/latest/modules/simplify/simplify.html but could not get it to work.


Solution

  • The variable needs to be declared as real number:

    u=symbols('u', real=True)
    

    Then the term is auto-simplified.

    (I suggested a corresponding Sympy documentation change.)