# Square root of a fraction

I have the following variable and function:

var('r')
f = function('f')(r)


with an equation given by:

eq = sqrt(-1/(f^2*sin(r)^2))-1/sqrt(-f^2*sin(r)^2)


which, in LaTeX expression, looks like:

\begin{equation} \sqrt{-\frac{1}{f\left(r\right)^{2} \sin\left(r\right)^{2}}} - \frac{1}{\sqrt{-f\left(r\right)^{2} \sin\left(r\right)^{2}}} \end{equation}

In principle, this should be equal to zero. However,

bool(eq==0)


gives me False. I have tried with .simplify_full() and following the suggestion in here, I have used ._sympy_().simplify():

eq = eq._sympy_().simplify()
bool(eq==0)


but I still get False. Am I missing something?

edit retag close merge delete

Sort by » oldest newest most voted

By doing

$\sqrt{-\frac{1}{f\left(r\right)^{2} \sin\left(r\right)^{2}}} - \frac{1}{\sqrt{-f\left(r\right)^{2} \sin\left(r\right)^{2}}} = \frac{i}{\sqrt{f\left(r\right)^{2} \sin\left(r\right)^{2}}}-\frac{1}{i\sqrt{f\left(r\right)^{2} \sin\left(r\right)^{2}}} = \frac{2i}{\sqrt{f\left(r\right)^{2} \sin\left(r\right)^{2}}}$

I wouldn't expect bool(eq==0) to return True.

You can deal with square roots using canonicalize_radical().

eq.canonicalize_radical()


returns $\frac{2 i}{f\left(r\right) \sin\left(r\right)}$.

more

I have realized that my problem here was of mathematical nature rather than computational. I was assuming that

$-\frac{a}{b} =\frac{a}{-b}$ $\implies$ $\sqrt{-\frac{a}{b}}=\sqrt{\frac{a}{-b}}$ $\implies$ $\frac{\sqrt{-a}}{\sqrt{b}}=\frac{\sqrt{a}}{\sqrt{-b}}$

However, if we consider only the positive branches of the square roots, the last equality does not hold.

more