Simplifying Simps with Square Root
I have an expression that I think could be simplified somewhat, and for some reason sympy is not doing what I think is a simple simplification. My example code looks like this:
# coding: utf-8
# In[1]:
from __future__ import division
from sympy import *
init_printing()
# In[3]:
d, R, c = symbols('d R c', Positive = True, Real = True)
Δt = symbols('\Delta_t', Real = True)
# In[4]:
Δt = (1/c**2)*(-R*c+sqrt(c**2*(R+d)**2))
Δt
# In[5]:
simplify(Δt)
I've posted the code above for the fun of cut and paste ... The graphical output from iPython looks like this:
I expected the end result to be as follows:
I thought that based on how I defined the variables, simplifications would occur, at least sqrt ((R + d) ** 2) ... What am I doing wrong?
source to share
To expand on @ user5402's answer, SymPy only makes simplifications that are valid for common complex numbers by default. In particular, it sqrt(x**2) = x
is generally not true. This is true if x
positive. Installing x
both Symbol('x', positive=True)
reports SymPy, that this is so.
source to share