I would say that you should use doit but I just tried that and it crashed: In [*9*]: e=Function('g')(Function('f')(x1,x2),Function('h' )(x1,x2)).diff(x1)
In [*10*]: e Out[*10*]: ⎛ ∂ ⎞│ ⎛ ∂ ⎞│ ⎛ ∂ ⎞│ ⎛ ∂ ⎜───(f(ξ₁, x[2]))⎟│ ⋅⎜───(g(ξ₁, h(x[1], x[2])))⎟│ + ⎜───(g(f(x[1], x[2]), ξ₂))⎟│ ⋅⎜───(h(ξ₁ ⎝∂ξ₁ ⎠│ξ₁=x[1] ⎝∂ξ₁ ⎠│ξ₁=f(x[1], x[2]) ⎝∂ξ₂ ⎠│ξ₂=h(x[1], x[2]) ⎝∂ξ₁ ⎞│ , x[2]))⎟│ ⎠│ξ₁=x[1] In [*11*]: e.doit() Fatal Python error: Cannot recover from stack overflow. Thread 0x000070000994b000 (most recent call first): File "/Users/enojb/.local/lib/python3.5/threading.py", line 293 in wait File "/Users/enojb/.local/lib/python3.5/threading.py", line 549 in wait File "/Users/enojb/current/sympy/35venv/lib/python3.5/site-packages/IPython/core/history.py", line 829 in run File "/Users/enojb/current/sympy/35venv/lib/python3.5/site-packages/IPython/core/history.py", line 58 in needs_sqlite File "</Users/enojb/current/sympy/35venv/lib/python3.5/site-packages/decorator.py:decorator-gen-24>", line 2 in run File "/Users/enojb/.local/lib/python3.5/threading.py", line 914 in _bootstrap_inner File "/Users/enojb/.local/lib/python3.5/threading.py", line 882 in _bootstrap Current thread 0x00007fffae5cf380 (most recent call first): File "/Users/enojb/current/sympy/sympy/sympy/core/symbol.py", line 284 in assumptions0 File "/Users/enojb/current/sympy/sympy/sympy/core/symbol.py", line 274 in _hashable_content File "/Users/enojb/current/sympy/sympy/sympy/core/symbol.py", line 381 in _hashable_content File "/Users/enojb/current/sympy/sympy/sympy/core/expr.py", line 133 in __eq__ File "/Users/enojb/current/sympy/sympy/sympy/core/basic.py", line 343 in __eq__ File "/Users/enojb/current/sympy/sympy/sympy/core/containers.py", line 97 in __eq__ File "/Users/enojb/current/sympy/sympy/sympy/core/expr.py", line 134 in __eq__ File "/Users/enojb/current/sympy/sympy/sympy/core/cache.py", line 94 in wrapper File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 2291 in <listcomp> File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 2291 in _hashable_content File "/Users/enojb/current/sympy/sympy/sympy/core/expr.py", line 109 in __hash__ File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 2286 in __hash__ File "/Users/enojb/current/sympy/sympy/sympy/core/cache.py", line 94 in wrapper File "/Users/enojb/current/sympy/sympy/sympy/core/expr.py", line 196 in __mul__ File "/Users/enojb/current/sympy/sympy/sympy/core/decorators.py", line 129 in binary_op_wrapper File "/Users/enojb/current/sympy/sympy/sympy/core/decorators.py", line 91 in __sympifyit_wrapper File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 618 in _eval_derivative File "/Users/enojb/current/sympy/sympy/sympy/core/basic.py", line 1724 in _visit_eval_derivative_scalar File "/Users/enojb/current/sympy/sympy/sympy/core/basic.py", line 1719 in _accept_eval_derivative File "/Users/enojb/current/sympy/sympy/sympy/core/basic.py", line 1743 in _eval_derivative_n_times File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 1427 in __new__ File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 1598 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 2242 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 1600 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 2242 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 1600 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 2242 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 1600 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 2242 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 1600 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 2242 in doit ... File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 2242 in doit File "/Users/enojb/current/sympy/sympy/sympy/core/function.py", line 1600 in doit ... Abort trap: 6 On Sun, 25 Aug 2019 at 01:13, Mathieu Lamarre <mathieu.lama...@gmail.com> wrote: > Simple example of multivariate chain rule: > print(Function('g')(Function('f')(x1,x2)).diff(x1)) > > Gives the expected: > > [image: diff1.PNG] > > Derivative(f(x1, x2), x1)*Derivative(g(f(x1, x2)), f(x1, x2)) > > > Adding another function h: > > print(Function('g')(Function('f')(x1,x2),Function('h')(x1,x2)).diff(x1)) > > Gives the expected answer but with extra _xi_1 and _xi_2 symbols: > > [image: diff.PNG] > > Derivative(f(x1, x2), x1)*Subs(Derivative(g(_xi_1, h(x1, x2)), _xi_1), _xi_1, > f(x1, x2)) + Derivative(h(x1, x2), x1)*Subs(Derivative(g(f(x1, x2), _xi_2), > _xi_2), _xi_2, h(x1, x2)) > > > This is annoying for subsequent substitutions, for instance to switch from > the function notation to simple symbols. > Also, for more complex equations, the numbering of the automatic xi > symbols is hard to predict. > > Is there a way to change this behavior? i.e. do not get the Subs and > _xi_%d above > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sympy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/b8b84555-2132-430c-be51-b0c47d99e3bb%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/b8b84555-2132-430c-be51-b0c47d99e3bb%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxTcr%2B7ndR570bZszV05CviQs49UdqKLEN-ocT1KEwZZOA%40mail.gmail.com.