Sympy does not seem to be able to simplify an expression where the square root of a square of a variable is involved:
In [28]: a = x**2
In [29]: b = a**(1/2)
In [30]: b
Out[30]:
0.5
⎛ 2⎞
⎝x ⎠
In [31]: b.simplify()
Out[31]:
0.5
⎛ 2⎞
⎝x ⎠
I do not get this to work with other variants of simplify, in particular I would have thought that b.powsimp() should work.
In [32]: b.powsimp()
Out[32]:
0.5
⎛ 2⎞
⎝x ⎠
Does anyone know why this does not work, or what I am doing wrong?
There are two problems with your example.
First
sqrt(x**2)==xonly for positive real numbers.Second, for SymPy
1/2and0.5are not the same things. The first is aRationalinstance, the second is afloatinstance.Finally, an example:
sympifytransforms python objects to more adequate SymPy objects.