'Equivalent mathematical symbolic expressions are not equal in sympy [duplicate]
I'm trying to debug (and understand) why these two expressions ($r_1$ and $r_2$) are not equivalent in sympy:
import sympy as sp
B, V, m, q = sp.symbols('B V m q', positive = True, real = True)
r1 = (1/B)*(2*V*m/q)**(1/2)
r2 = (2*V*m/(q*B**2))**(1/2)
# returns false
r1 == r2
# returns false also
r1.simplify() == r1.simplify()
The only difference that I can see is that in the first case, B is raised to 1 and in the second, B is not raised to one (explicitly). I have read the sympy FAQ and various questions which have suggested to set real=True and positive=True to deal with the square root issue, but that doesn't seem to be working here.
Anyone have any suggestions?
Solution 1:[1]
Aha!
I think I discovered how to check for equality,
r1.equals(r2)
Returns True (as expected)!
Thanks all...
Source: This SO answer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Firas |

