ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 17 Apr 2012 17:35:54 -0500Differentiating Complex Conjugated Functionshttp://ask.sagemath.org/question/7780/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$.Tue, 30 Nov 2010 09:18:04 -0600http://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/Comment by d3banjan for <p>This is primarily a question of understanding the syntax of some output although there might be a bug hidden underneath. Consider the following code:</p>
<pre><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)
</code></pre>
<p>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?</p>
<p>I think I can narrow down the differences even further. Check it out:</p>
<pre><code>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))
</code></pre>
<p>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$.</p>
http://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/?comment=19902#post-id-19902@kcrisman - what does `D[0](conjugate)` mean?Tue, 17 Apr 2012 17:35:54 -0500http://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/?comment=19902#post-id-19902Comment by cswiercz for <p>This is primarily a question of understanding the syntax of some output although there might be a bug hidden underneath. Consider the following code:</p>
<pre><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)
</code></pre>
<p>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?</p>
<p>I think I can narrow down the differences even further. Check it out:</p>
<pre><code>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))
</code></pre>
<p>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$.</p>
http://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/?comment=22469#post-id-22469Depending 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.Tue, 30 Nov 2010 09:31:45 -0600http://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/?comment=22469#post-id-22469Answer by kcrisman for <p>This is primarily a question of understanding the syntax of some output although there might be a bug hidden underneath. Consider the following code:</p>
<pre><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)
</code></pre>
<p>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?</p>
<p>I think I can narrow down the differences even further. Check it out:</p>
<pre><code>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))
</code></pre>
<p>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$.</p>
http://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/?answer=11923#post-id-11923It 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](http://www.ginac.de/reference/classGiNaC_1_1fderivative.html). 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](http://www.mapleprimes.com/questions/36460-Symbolic-Differentiation-Complex-Conjugates). On the other hand, [Sympy](https://code.google.com/p/sympy/issues/detail?id=1655) allows this. If there is a consensus, a ticket should be opened, though!Mon, 03 Jan 2011 15:36:07 -0600http://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/?answer=11923#post-id-11923Comment by cswiercz for <p>It looks like Sage is (incorrectly? naively?) applying the chain rule to <code>conjugate(q(x,t))</code>, since <code>conjugate</code> is a pure symbolic thing in Sage a priori. In fact, the multiple variables are irrelevant:</p>
<pre><code>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))
</code></pre>
<p>Ginac (and hence Pynac) does not appear to support doing this - see <a href="http://www.ginac.de/reference/classGiNaC_1_1fderivative.html">this</a>. However, presumably one could implement a trivial conjugation to the <code>fderivative</code> or <code>tderivative</code> ... the problem is that I'm not sure whether we should automatically assume that this makes sense. See, for instance, the convoluted discussion at <a href="http://www.mapleprimes.com/questions/36460-Symbolic-Differentiation-Complex-Conjugates">The Maple equivalent of ask.sagemath</a>. On the other hand, <a href="https://code.google.com/p/sympy/issues/detail?id=1655">Sympy</a> allows this. If there is a consensus, a ticket should be opened, though!</p>
http://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/?comment=22336#post-id-22336Thanks 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.Wed, 05 Jan 2011 05:51:56 -0600http://ask.sagemath.org/question/7780/differentiating-complex-conjugated-functions/?comment=22336#post-id-22336