Question

When I try to differentiate a symbol with SymPy I get the following

In : x=Symbol('x')
In : diff(x,x)
Out: 1

When I differentiate the symbol respect to its conjugate the result is

In [55]: diff(x,x.conjugate())
Out[55]: 0

However, when I try to differentiate the conjugate of the symbol SymPy doesn't do it

In : diff(x.conjugate(),x)
Out: Derivative(conjugate(x), x)

This is still correct, but the result should be zero. How can I make SimPy perform the derivative of a conjugate?

Was it helpful?

Solution

I'm not sure about the mathematics if diff(conjugate(x), x) should be zero. The fact that diff(x,x.conjugate()) gives zero has nothing to do with mathematics (and might even be considered a SymPy bug). It gives zero simply because x does not contain conjugate(x) (symbolically), so it sees it as a constant with respect to it. This is probably wrong, since x is not a constant with respect to conjugate(x). The fact that SymPy lets you take derivatives with respect to defined functions is probably a bug, actually. It is supposed to allow things like diff(f(x)**2, f(x)), where f = Function('f') is an undefined function, but for defined functions, it is probably mathematically incorrect (or at least not what you expect).

See http://docs.sympy.org/latest/modules/core.html?highlight=derivative#sympy.core.function.Derivative, particularly the section on derivatives wrt non-Symbols. To paraphrase, taking derivatives with respect to a function is just a notational convenience and does not represent a mathematical chain rule. Rather, something like diff(x, conjugate(x)) should be thought of as something like diff(x.subs(conjugate(x), dummy), dummy).subs(dummy, conjugate(x)).

Regarding conjugate(x).diff(x), this gives an unevaluated derivative because no derivative is defined for conjugate. I'm not sure if any closed-form answer is possible here anyway. Probably this is the most useful thing that SymPy could return. I can't find any good answers anywhere as to what a reasonable answer for this should be (you should ask on math SE to get a better answer about it).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top