Derivative of a conjugate in sympy

我怕爱的太早我们不能终老 提交于 2019-12-07 18:58:13

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/17476704/derivative-of-a-conjugate-in-sympy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!