--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/717dfd84-7b24-4a28-83c5-19ba7ca53e97n%40googlegroups.com.
The following code may be useful -
def square_root_of_expr(expr):
"""
If expression is product of even powers then every power is
divided
by two and the product is returned. If some terms in product
are
not even powers the sqrt of the absolute value of the
expression is
returned. If the expression is a number the sqrt of the
absolute
value of the number is returned.
"""
if expr.is_number:
if expr > 0:
return sqrt(expr)
else:
return sqrt(-expr)
else:
expr = trigsimp(expr)
coef, pow_lst = sqf_list(expr)
if coef != S.One:
if coef.is_number:
coef = square_root_of_expr(coef)
else:
coef = sqrt(abs(coef)) # Product coefficient not
a number
for p in pow_lst:
f, n = p
if n % 2 != 0:
return sqrt(abs(expr)) # Product not all even
powers
else:
coef *= f ** (n / S(2)) # Positive sqrt of the
square of an expression
return coef
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/ad627534-58eb-4001-a76f-2aad0d6f16e8n%40googlegroups.com.