sympy / sympy

A computer algebra system written in pure Python
https://sympy.org/
Other
12.58k stars 4.33k forks source link

Derivative wrt to the real or imag part of a complex number #7019

Open twmr opened 11 years ago

twmr commented 11 years ago
I would expect the output of 

r = symbols('r', complex=True)
diff(r, re(r))

to be 1. However, 'diff' returns 0.

If I write r as x+I*y, which I would like to avoid, then diff(r,x) works as expected.

Original issue for #7019: http://code.google.com/p/sympy/issues/detail?id=3920 Original author: https://code.google.com/u/t.hisch@gmail.com/

asmeurer commented 11 years ago

It returns 0 because diff works symbolically, using those things that are in the expression, so re(r) is not there, hence, it gives 0. See the docstring of Derivative.

This requires some thought. We used this definition because that is what things like F(x, f(x), f'(x)).diff(f'(x)) mean (as opposed to some kind of chain rule). It may be a good idea to extend _diff_wrt to let it dispatch on diff. This also goes back to the whole dispatch question again.

Status: Valid
Labels: -Differentiation Type-Enhancement

Original comment: http://code.google.com/p/sympy/issues/detail?id=3920#c1 Original author: https://code.google.com/u/asmeurer@gmail.com/