# Differentiating Complex Conjugated Functions

This is primarily a question of understanding the syntax of some output although there might be a bug hidden underneath. Consider the following code:

sage: var('x,t')
sage: q = function('q',x,t)
sage: f = q*q.conjugate()
sage: print f.derivative(x,1)
q(x, t)*D[0](conjugate)(q(x, t))*D[0](q)(x, t) + conjugate(q(x,t))*D[0](q)(x, t)


The answer is supposed to be $d/dx(q\bar{q}) = q_x \bar{q} + q \bar{q}_x$. The second term in the Sage output is correct but I'm having trouble deciphering the first term. Any thoughts?

I think I can narrow down the differences even further. Check it out:

sage: print q.conjugate().derivative(x,1)
D[0](conjugate)(q(x, t))*D[0](q)(x, t)
sage print q.derivative(x,1).conjugate()
conjugate(D[0](q)(x, t))


The independence of order isn't the issue: $q = u + iv$ means that $q_x = u_x + iv_x$, $\bar{q} = u - iv$. So $\bar{q_x} = u_x - iv_x$ and $(\bar{q})_x = (u - iv)_x = u_x - iv_x$.

edit retag close merge delete

Depending on the problem you could just define a new function called qbar as long as you don't expect to conjugate an entire expression. Such is my own case and I got the result I wanted.

( 2010-11-30 09:31:45 -0500 )edit

@kcrisman - what does D[0](conjugate) mean?

( 2012-04-17 17:35:54 -0500 )edit

Sort by » oldest newest most voted

It looks like Sage is (incorrectly? naively?) applying the chain rule to conjugate(q(x,t)), since conjugate is a pure symbolic thing in Sage a priori. In fact, the multiple variables are irrelevant:

sage: r = function('r',x)
sage: g = r*r.conjugate()
sage: g.derivative(x)
r(x)*D[0](conjugate)(r(x))*D[0](r)(x) + conjugate(r(x))*D[0](r)(x)

sage: r.conjugate().derivative(x)
D[0](conjugate)(r(x))*D[0](r)(x)
sage: r.derivative().conjugate()
conjugate(D[0](r)(x))


Ginac (and hence Pynac) does not appear to support doing this - see this. However, presumably one could implement a trivial conjugation to the fderivative or tderivative ... the problem is that I'm not sure whether we should automatically assume that this makes sense. See, for instance, the convoluted discussion at The Maple equivalent of ask.sagemath. On the other hand, Sympy allows this. If there is a consensus, a ticket should be opened, though!

more

Thanks for the resources. Looking at the Sage source, it seems like a lot of tests for the built-in symbolic functions use conjugate so I imagine that major changes to its behavior could result in broken doctests. It might also boil down to changing the way function._conjugate_ behaves. If anyone else suggests on ask.sage that this is a major issue then I'll post a ticket.

( 2011-01-05 05:51:56 -0500 )edit