Sage: Ticket #10982: symbolic derivatives should be able to have non-variable arguments
https://trac.sagemath.org/ticket/10982
<p>
Here is an example from the french sagebook to compute the laplacian in polar, that no longer works with version 4.6 of Sage
</p>
<pre class="wiki">sage: x, y, r, t = var('x, y, r, t'); f = function('f', x, y)
sage: F = f(x = r*cos(t), y = r*sin(t))
sage: d = (diff(F,r,2) + diff(F,t,2)/r**2 + diff(F,r)/r)
sage: d.simplify_full()
---------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
NotImplementedError: arguments must be distinct variables
</pre><p>
With older versions, you got it :
</p>
<pre class="wiki">sage: d.simplify_full()
D[0, 0](f)(r, t) + D[1, 1](f)(r, t)
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/10982
Trac 1.1.6kcrismanTue, 22 Mar 2011 15:21:33 GMTkeywords, summary changed; cc set
https://trac.sagemath.org/ticket/10982#comment:1
https://trac.sagemath.org/ticket/10982#comment:1
<ul>
<li><strong>cc</strong>
<em>kcrisman</em> added
</li>
<li><strong>keywords</strong>
<em>simplify</em> <em>maxima</em> <em>symbolic</em> <em>derivative</em> added; <em>simplify_full</em> removed
</li>
<li><strong>summary</strong>
changed from <em>regression</em> to <em>symbolic derivatives should be able to have non-variable arguments</em>
</li>
</ul>
<p>
I don't know that this is necessarily a regression so much as having made some choices about what is 'allowed' to be a symbolic derivative. We don't allow (for reasons that are unclear to me, because I still don't understand why we changed how we represent symbolic derivatives) arguments that are not just variables, unlike here where they are expressions.
</p>
<p>
It's the conversion to Maxima that is failing, by the way.
</p>
<pre class="wiki">sage: d.simplify()
---------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
NotImplementedError: arguments must be distinct variables
</pre><p>
This even happens with trying to simplify (send to Maxima)
</p>
<pre class="wiki">sage: diff(F,r).simplify()
<boom>
</pre><p>
This is at least tangentially related to <a class="closed ticket" href="https://trac.sagemath.org/ticket/6840" title="defect: [with patch, positive review] Fix documentation for Sage Notebook (closed: fixed)">#6840</a> and <a class="needs_work ticket" href="https://trac.sagemath.org/ticket/6756" title="enhancement: Implement ``diff`` format symbolic derivative in new symbolics (needs_work)">#6756</a>, though probably not directly.
</p>
TicketburcinTue, 22 Mar 2011 15:42:58 GMT
https://trac.sagemath.org/ticket/10982#comment:2
https://trac.sagemath.org/ticket/10982#comment:2
<p>
AFAIK, <a class="closed ticket" href="https://trac.sagemath.org/ticket/7377" title="enhancement: Symbolic Ring to Maxima via EclObject (closed: fixed)">#7377</a> improves the conversion of derivatives to maxima. It might fix this as well.
</p>
TicketkcrismanTue, 22 Mar 2011 16:18:48 GMT
https://trac.sagemath.org/ticket/10982#comment:3
https://trac.sagemath.org/ticket/10982#comment:3
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/10982#comment:2" title="Comment 2">burcin</a>:
</p>
<blockquote class="citation">
<p>
AFAIK, <a class="closed ticket" href="https://trac.sagemath.org/ticket/7377" title="enhancement: Symbolic Ring to Maxima via EclObject (closed: fixed)">#7377</a> improves the conversion of derivatives to maxima. It might fix this as well.
</p>
</blockquote>
<p>
Nice idea! Unfortunately, it seems to have the same problem.
</p>
TicketnbruinTue, 22 Mar 2011 16:52:13 GMT
https://trac.sagemath.org/ticket/10982#comment:4
https://trac.sagemath.org/ticket/10982#comment:4
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/10982#comment:3" title="Comment 3">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/10982#comment:2" title="Comment 2">burcin</a>:
</p>
<blockquote class="citation">
<p>
AFAIK, <a class="closed ticket" href="https://trac.sagemath.org/ticket/7377" title="enhancement: Symbolic Ring to Maxima via EclObject (closed: fixed)">#7377</a> improves the conversion of derivatives to maxima. It might fix this as well.
</p>
</blockquote>
<p>
Nice idea! Unfortunately, it seems to have the same problem.
</p>
</blockquote>
<p>
but see <a class="ext-link" href="http://trac.sagemath.org/sage_trac/ticket/7377#comment:54"><span class="icon"></span>http://trac.sagemath.org/sage_trac/ticket/7377#comment:54</a> for some ideas on how to improve this. The concerns about "at" in maxima are ungrounded: It's the documentation that is wrong and this will be fixed in the new version. It would be quite straightforward to extend the support to general derivatives, including conversion to/from maxima (we'll have to see how much trouble the "at" expressions give further down the line, of course). Furthermore, the conversion is easier to do with <a class="closed ticket" href="https://trac.sagemath.org/ticket/7377" title="enhancement: Symbolic Ring to Maxima via EclObject (closed: fixed)">#7377</a> but it's not required. You could already do this in the old setup.
</p>
TicketkcrismanTue, 22 Mar 2011 19:00:16 GMT
https://trac.sagemath.org/ticket/10982#comment:5
https://trac.sagemath.org/ticket/10982#comment:5
<p>
Thanks for that comment reference. I think you are right that this could work out. You are also right that "Sage support for functional derivatives is only rudimentary." This largely changed when the <code>D[0]</code> notation was introduced.
</p>
TicketzimmermaWed, 23 Mar 2011 15:01:32 GMTcc changed
https://trac.sagemath.org/ticket/10982#comment:6
https://trac.sagemath.org/ticket/10982#comment:6
<ul>
<li><strong>cc</strong>
<em>zimmerma</em> added
</li>
</ul>
TicketdsmThu, 31 May 2012 02:51:13 GMT
https://trac.sagemath.org/ticket/10982#comment:7
https://trac.sagemath.org/ticket/10982#comment:7
<p>
This seems to work for me in 5.0:
</p>
<pre class="wiki">
sage: x, y, r, t = var('x, y, r, t')
sage: f = function('f', x, y)
sage: F = f(x = r*cos(t), y = r*sin(t))
sage: d = (diff(F,r,2) + diff(F,t,2)/r**2 + diff(F,r)/r)
sage: d.simplify()
(sin(t)*D[1, 1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0, 1](f)(r*cos(t), r*sin(t)))*sin(t) + (sin(t)*D[0, 1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0, 0](f)(r*cos(t), r*sin(t)))*cos(t) + (sin(t)*D[1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0](f)(r*cos(t), r*sin(t)))/r - ((r*sin(t)*D[0, 1](f)(r*cos(t), r*sin(t)) - r*cos(t)*D[1, 1](f)(r*cos(t), r*sin(t)))*r*cos(t) - (r*sin(t)*D[0, 0](f)(r*cos(t), r*sin(t)) - r*cos(t)*D[0, 1](f)(r*cos(t), r*sin(t)))*r*sin(t) + r*sin(t)*D[1](f)(r*cos(t), r*sin(t)) + r*cos(t)*D[0](f)(r*cos(t), r*sin(t)))/r^2
sage: d.simplify_full()
D[0, 0](f)(r*cos(t), r*sin(t)) + D[1, 1](f)(r*cos(t), r*sin(t))
sage: diff(F,r).simplify()
sin(t)*D[1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0](f)(r*cos(t), r*sin(t))
sage: diff(F,r).simplify_full()
sin(t)*D[1](f)(r*cos(t), r*sin(t)) + cos(t)*D[0](f)(r*cos(t), r*sin(t))
</pre><p>
Although I'm too lazy to bisect to find out when it started working again, it'd probably be a good idea to add a doctest to make sure that it stays that way. Not quite sure where to put it, though.
</p>
TicketdsmThu, 31 May 2012 03:11:25 GMT
https://trac.sagemath.org/ticket/10982#comment:8
https://trac.sagemath.org/ticket/10982#comment:8
<p>
Hmm. On second thought, I may have spoken too quickly:
</p>
<blockquote>
<p>
D[0, 0](f)(r*cos(t), r*sin(t)) + D[1, 1](f)(r*cos(t), r*sin(t))
</p>
</blockquote>
<p>
and
</p>
<blockquote>
<p>
D[0, 0](f)(r, t) + D[1, 1](f)(r, t)
</p>
</blockquote>
<p>
are a little different. Not incompatible, because the functions are abstract, but still not the same. Do we want to recover the original representation?
</p>
TicketnbruinThu, 31 May 2012 08:29:10 GMT
https://trac.sagemath.org/ticket/10982#comment:9
https://trac.sagemath.org/ticket/10982#comment:9
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/10982#comment:8" title="Comment 8">dsm</a>:
</p>
<blockquote class="citation">
<blockquote>
<p>
D[0, 0](f)(r, t) + D[1, 1](f)(r, t)
</p>
</blockquote>
</blockquote>
<p>
Wow, Sage before 4.6 was just plain wrong. We'll excuse casamayou, since superficially it looks like what one would sloppily write in a calculus book (the coordinate transformation implicitly assumed).
</p>
<p>
The formula for d is the expression for the laplacian in polar coordinates, so it should be equal to
</p>
<pre class="wiki">(diff(f,x,x)+diff(f,y,y)).subs(x=r*cos(t),y=r*sin(t))
</pre><p>
which is what 5.0 verifies.
</p>
<p>
I'm pretty sure <a class="closed ticket" href="https://trac.sagemath.org/ticket/12796" title="enhancement: Allow more general evaluation of FDerivativeOperator (closed: fixed)">#12796</a> fixed this, since this kind of computation was the point of that ticket.
I think this ticket can be closed. Add a doctest if you think the current tests are insufficient.
</p>
TicketjdemeyerTue, 13 Aug 2013 15:35:53 GMTmilestone changed
https://trac.sagemath.org/ticket/10982#comment:10
https://trac.sagemath.org/ticket/10982#comment:10
<ul>
<li><strong>milestone</strong>
changed from <em>sage-5.11</em> to <em>sage-5.12</em>
</li>
</ul>
Ticketvbraun_spamThu, 30 Jan 2014 21:20:52 GMTmilestone changed
https://trac.sagemath.org/ticket/10982#comment:11
https://trac.sagemath.org/ticket/10982#comment:11
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.1</em> to <em>sage-6.2</em>
</li>
</ul>
Ticketvbraun_spamTue, 06 May 2014 15:20:58 GMTmilestone changed
https://trac.sagemath.org/ticket/10982#comment:12
https://trac.sagemath.org/ticket/10982#comment:12
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.2</em> to <em>sage-6.3</em>
</li>
</ul>
Ticketvbraun_spamSun, 10 Aug 2014 16:51:03 GMTmilestone changed
https://trac.sagemath.org/ticket/10982#comment:13
https://trac.sagemath.org/ticket/10982#comment:13
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.3</em> to <em>sage-6.4</em>
</li>
</ul>
Ticket