Sage: Ticket #17701: diff(f,t) should work even with Function objects
https://trac.sagemath.org/ticket/17701
<pre class="wiki">sage: t = var('t')
sage: sage: f = function('f')(t)
sage: diff(f,x,x)
0
sage: desolve(diff(f,t) - (f+1)/(t+1), f)
(_C - 1/(t + 1))*(t + 1)
sage: sage: f = function('f')
sage: diff(f,t)
...
TypeError: unable to convert f to a symbolic expression
sage: diff(sin,t)
...
TypeError: unable to convert f to a symbolic expression
</pre><p>
The same error can be had with the simple <code>SR(sin)</code>, i.e., any function object in contrast to the resp. function call, which returns an <code>Expression</code>.
</p>
<p>
Since function objects can be used in other context it seems they should be part of symbolic expressions too. This ticket however will limit itself to giving a better error message in <code>SR.coerce</code> and handling <code>Function</code> objects in <code>calculus/functional.py:derivative()</code>.
</p>
<p>
See also <a class="needs_review ticket" href="https://trac.sagemath.org/ticket/15025" title="defect: automatically injected function does not work with desolve (needs_review)">#15025</a>
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/17701
Trac 1.1.6kcrismanFri, 30 Jan 2015 19:03:41 GMT
https://trac.sagemath.org/ticket/17701#comment:1
https://trac.sagemath.org/ticket/17701#comment:1
<p>
Possibly related to the shenanigans induced by the distinction at <a class="closed ticket" href="https://trac.sagemath.org/ticket/17447" title="enhancement: Clarify and complete documentation of function() (closed: fixed)">#17447</a>? So maybe user error (though obviously completely understandable given the terrible documentation for this)? Agreed on the uselessness of the error message, though presumably the traceback would help an experienced Sage developer... who is not the likely recipient of an error message on this, unfortunately! More like someone in calculus or ODE. Yuck.
</p>
TicketrwsSat, 31 Jan 2015 06:42:30 GMT
https://trac.sagemath.org/ticket/17701#comment:2
https://trac.sagemath.org/ticket/17701#comment:2
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/17701#comment:1" title="Comment 1">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
Possibly related to the shenanigans induced by the distinction at <a class="closed ticket" href="https://trac.sagemath.org/ticket/17447" title="enhancement: Clarify and complete documentation of function() (closed: fixed)">#17447</a>?
</p>
</blockquote>
<p>
That too but I think either <code>SR(f)</code> or <code>diff(f,t)</code> should work even with <code>NewSymbolicFunction</code>. If not improve the error message.
</p>
TicketrwsSun, 01 Feb 2015 15:51:19 GMTsummary changed
https://trac.sagemath.org/ticket/17701#comment:3
https://trac.sagemath.org/ticket/17701#comment:3
<ul>
<li><strong>summary</strong>
changed from <em>desolve TypeError snub</em> to <em>SR(f) or diff(f,t) should work even with NewSymbolicFunction</em>
</li>
</ul>
TicketrwsThu, 09 Jul 2015 14:09:46 GMTsummary, description, milestone changed
https://trac.sagemath.org/ticket/17701#comment:4
https://trac.sagemath.org/ticket/17701#comment:4
<ul>
<li><strong>summary</strong>
changed from <em>SR(f) or diff(f,t) should work even with NewSymbolicFunction</em> to <em>diff(f,t) should work even with Function objects</em>
</li>
<li><strong>description</strong>
modified (<a href="/ticket/17701?action=diff&version=4">diff</a>)
</li>
<li><strong>milestone</strong>
changed from <em>sage-6.5</em> to <em>sage-6.8</em>
</li>
</ul>
TicketrwsThu, 09 Jul 2015 14:59:25 GMT
https://trac.sagemath.org/ticket/17701#comment:5
https://trac.sagemath.org/ticket/17701#comment:5
<p>
However, having <code>diff(f,t)</code> a shortcut for <code>diff(f(t),t)</code> is less useful because the other instances of <code>f</code> in the argument to <code>desolve</code> would still have to be coerced. And it is impossible to know what is the variable there.
</p>
TicketrwsThu, 09 Jul 2015 15:17:36 GMTbranch set
https://trac.sagemath.org/ticket/17701#comment:6
https://trac.sagemath.org/ticket/17701#comment:6
<ul>
<li><strong>branch</strong>
set to <em>u/rws/diff_f_t__should_work_even_with_function_objects</em>
</li>
</ul>
TicketrwsThu, 09 Jul 2015 15:18:11 GMTstatus changed; commit, author set
https://trac.sagemath.org/ticket/17701#comment:7
https://trac.sagemath.org/ticket/17701#comment:7
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>commit</strong>
set to <em>0cecec3ff4c53e8e030311b4b55fc9e7d96a8cda</em>
</li>
<li><strong>author</strong>
set to <em>Ralf Stephan</em>
</li>
</ul>
<p>
New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="http://git.sagemath.org/sage.git/commit/?id=0cecec3ff4c53e8e030311b4b55fc9e7d96a8cda"><span class="icon"></span>0cecec3</a></td><td><code>17701: diff(f,t) should work even with Function objects</code>
</td></tr></table>
TicketrwsMon, 28 Mar 2016 12:38:55 GMTdescription changed
https://trac.sagemath.org/ticket/17701#comment:8
https://trac.sagemath.org/ticket/17701#comment:8
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/17701?action=diff&version=8">diff</a>)
</li>
</ul>
TickettscrimTue, 29 Mar 2016 19:26:49 GMTmilestone changed; reviewer set
https://trac.sagemath.org/ticket/17701#comment:9
https://trac.sagemath.org/ticket/17701#comment:9
<ul>
<li><strong>reviewer</strong>
set to <em>Travis Scrimshaw</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-6.8</em> to <em>sage-7.2</em>
</li>
</ul>
<p>
Should we expect this to work?
</p>
<pre class="wiki">sage: f = function('f')
sage: diff(f, x=x)
</pre><p>
Also, in an effort to be an uniform with python, could you make the error message start with a lowercase letter?
</p>
TicketnbruinThu, 31 Mar 2016 20:13:21 GMT
https://trac.sagemath.org/ticket/17701#comment:10
https://trac.sagemath.org/ticket/17701#comment:10
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/17701#comment:9" title="Comment 9">tscrim</a>:
</p>
<blockquote class="citation">
<p>
Should we expect this to work?
</p>
<pre class="wiki">sage: f = function('f')
sage: diff(f, x=x)
</pre></blockquote>
<p>
I'd say no. This would be significant feature creep into the interface of <code>diff</code>.
</p>
<p>
I am a little worried about
</p>
<pre class="wiki">sage: diff(f,x,x)
D[0, 0](f)(x, x) + 2*D[0, 1](f)(x, x) + D[1, 1](f)(x, x)
</pre><p>
where almost certainly a user who would type this would be hoping for
</p>
<pre class="wiki">D[0, 0](f)(x)
</pre><p>
I think the ambiguity in meaning when multiple arguments are given makes it safer to disallow it altogether.
</p>
<p>
I wouldn't mind if we wouldn't support this at all, but if we do, I recommend that we only allow repetition of a single argument variable, and interpret it as the n-th derivative of a univariate function evaluated at that argument
</p>
TicketrwsFri, 05 Aug 2016 07:53:00 GMTstatus changed
https://trac.sagemath.org/ticket/17701#comment:11
https://trac.sagemath.org/ticket/17701#comment:11
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
</ul>
TicketrwsSun, 06 Nov 2016 16:10:23 GMT
https://trac.sagemath.org/ticket/17701#comment:12
https://trac.sagemath.org/ticket/17701#comment:12
<p>
With Sage develop:
</p>
<pre class="wiki">sage: t = var('t')
sage: sage: f = function('f')(t)
sage: diff(f,x,x)
0
sage: desolve(diff(f,t) - (f+1)/(t+1), f)
(_C - 1/(t + 1))*(t + 1)
sage: sage: f = function('f')
sage: diff(f,t)
...
TypeError: unable to convert f to a symbolic expression
sage: diff(sin,t)
...
TypeError: unable to convert sin to a symbolic expression
</pre><p>
So an error does only happen with anonymous functions (<code>NewSymbolicFunction</code>) and bare <code>Function</code> objects.
</p>
<p>
With this branch there is
</p>
<pre class="wiki">sage: diff(sin,t)
cos(t)
sage: diff(f,t)
diff(f(t), t)
sage: diff(f,x,x)
D[0, 0](f)(x, x) + 2*D[0, 1](f)(x, x) + D[1, 1](f)(x, x)
</pre><p>
of which the latter has to be improved according to Nils.
</p>
TicketrwsSun, 06 Nov 2016 16:12:29 GMTdescription changed
https://trac.sagemath.org/ticket/17701#comment:13
https://trac.sagemath.org/ticket/17701#comment:13
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/17701?action=diff&version=13">diff</a>)
</li>
</ul>
Ticket