Robert Pollak
Robert Pollak

Reputation: 4165

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.

Upvotes: 0

Views: 60

Answers (1)

Robert Pollak
Robert Pollak

Reputation: 4165

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.)

Upvotes: 1

Related Questions