Since i want square roots to be simplified, I've come across this workaround:
from sympy import sqrt, factor, simplify
_sqrt = sqrt
sqrt = lambda x: factor(simplify(_sqrt(x)))
# do maths operations with sqrt...
But it's too slow and I don't think it's the most suitable method one can use So is there any other way to work with square roots and simplify them - automatically -
SymPy automatically simplifies rational arguments to
sqrt
, but it is possible to write rationals in a manner such that they are not explicitly rational (as in your previous post):sqrt
will only simplify an explicit Rational argument. Expansion of the base of the argument reveals that it is a Rational and thesqrt
will simplify it:Better than
expand
in such cases where you need to flatten an expression involving powers is the_mexpand
function: