Opened 5 years ago
Last modified 3 years ago
#17701 needs_work defect
diff(f,t) should work even with Function objects
Reported by:  rws  Owned by:  

Priority:  major  Milestone:  sage7.2 
Component:  calculus  Keywords:  
Cc:  Merged in:  
Authors:  Ralf Stephan  Reviewers:  Travis Scrimshaw 
Report Upstream:  N/A  Work issues:  
Branch:  u/rws/diff_f_t__should_work_even_with_function_objects (Commits)  Commit:  0cecec3ff4c53e8e030311b4b55fc9e7d96a8cda 
Dependencies:  Stopgaps: 
Description (last modified by )
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
The same error can be had with the simple SR(sin)
, i.e., any function object in contrast to the resp. function call, which returns an Expression
.
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 SR.coerce
and handling Function
objects in calculus/functional.py:derivative()
.
See also #15025
Change History (13)
comment:1 followup: ↓ 2 Changed 5 years ago by
comment:2 in reply to: ↑ 1 Changed 5 years ago by
comment:3 Changed 5 years ago by
 Summary changed from desolve TypeError snub to SR(f) or diff(f,t) should work even with NewSymbolicFunction
comment:4 Changed 5 years ago by
 Description modified (diff)
 Milestone changed from sage6.5 to sage6.8
 Summary changed from SR(f) or diff(f,t) should work even with NewSymbolicFunction to diff(f,t) should work even with Function objects
comment:5 Changed 5 years ago by
However, having diff(f,t)
a shortcut for diff(f(t),t)
is less useful because the other instances of f
in the argument to desolve
would still have to be coerced. And it is impossible to know what is the variable there.
comment:6 Changed 5 years ago by
 Branch set to u/rws/diff_f_t__should_work_even_with_function_objects
comment:7 Changed 5 years ago by
 Commit set to 0cecec3ff4c53e8e030311b4b55fc9e7d96a8cda
 Status changed from new to needs_review
New commits:
0cecec3  17701: diff(f,t) should work even with Function objects

comment:8 Changed 4 years ago by
 Description modified (diff)
comment:9 followup: ↓ 10 Changed 4 years ago by
 Milestone changed from sage6.8 to sage7.2
 Reviewers set to Travis Scrimshaw
Should we expect this to work?
sage: f = function('f') sage: diff(f, x=x)
Also, in an effort to be an uniform with python, could you make the error message start with a lowercase letter?
comment:10 in reply to: ↑ 9 Changed 4 years ago by
Replying to tscrim:
Should we expect this to work?
sage: f = function('f') sage: diff(f, x=x)
I'd say no. This would be significant feature creep into the interface of diff
.
I am a little worried about
sage: diff(f,x,x) D[0, 0](f)(x, x) + 2*D[0, 1](f)(x, x) + D[1, 1](f)(x, x)
where almost certainly a user who would type this would be hoping for
D[0, 0](f)(x)
I think the ambiguity in meaning when multiple arguments are given makes it safer to disallow it altogether.
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 nth derivative of a univariate function evaluated at that argument
comment:11 Changed 3 years ago by
 Status changed from needs_review to needs_work
comment:12 Changed 3 years ago by
With Sage develop:
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
So an error does only happen with anonymous functions (NewSymbolicFunction
) and bare Function
objects.
With this branch there is
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)
of which the latter has to be improved according to Nils.
comment:13 Changed 3 years ago by
 Description modified (diff)
Possibly related to the shenanigans induced by the distinction at #17447? 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.