I am trying to find the 1st and 2nd derivatives of the implicit function y = f(x)
which is defined by the equation: exp(sin(x)) - x * exp(sin(y)) = 0
SymPy calculates the 1st derivative and gives this answer:
But this expression can be written much simpler as:
(x * cos(x) - 1) / (x * cos(y))
using the fact that x = exp(sin(x)-sin(y))
The answer given for the 2nd derivative is also quite complicated.
Of course the second derivative can also be simplified
quite a lot using the same fact x = exp(sin(x)-sin(y)) .
How can I make/force SymPy apply these additional simplifications?
Is that possible even?
Here is my script.
#!/usr/bin/env python
# coding: utf-8
# ### Differentiating an implicit function using SymPy
# In[1]:
import sympy as sp
# In[2]:
sp.__version__
# In[3]:
sp.init_printing(use_latex='mathjax') # use pretty mathjax output
# In[4]:
sp.var('x y z')
F = sp.exp(sp.sin(x)) - x * sp.exp(sp.sin(y))
# In[5]:
f1 = sp.idiff( F, y, x ) # First derivative of y w.r.t. x
f1
# In[6]:
sp.simplify(f1)
# In[7]:
f2 = sp.idiff( F, y, x, 2) # Second derivative of y w.r.t. x
f2
sp.simplify(f2)
# In[ ]:
And also, here is an even simpler example which shows this undesired behavior.
#!/usr/bin/env python
# coding: utf-8
# ### Differentiating an implicit function using SymPy
# In[1]:
import sympy as sp
# In[2]:
sp.__version__
# In[3]:
sp.init_printing(use_latex='mathjax') # use pretty mathjax output
# In[4]:
sp.var('x y')
F = sp.ln(sp.sqrt(x**2 + y**2)) - sp.atan(y / x)
# In[5]:
f1 = sp.idiff( F, y, x ) # First derivative of y w.r.t. x
f1
# In[6]:
sp.simplify(f1)
# In[7]:
f2 = sp.idiff( F, y, x, 2) # Second derivative of y w.r.t. x
f2
sp.simplify(f2)
# In[ ]:
The second derivative here is given as:
This expression obviously can be simplified further even without using any special facts.


