Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
17701: diff(f,t) should work even with Function objects
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Jul 9, 2015
1 parent 6bc31bd commit 0cecec3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/sage/calculus/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,21 @@ def derivative(f, *args, **kwds):
80*u^3*v^3
sage: derivative(f, [u, v, v])
80*u^3*v^3
Using function objects is possible::
sage: diff(sin,x)
cos(x)
sage: f = function('f')
sage: diff(f,x)
D[0](f)(x)
sage: _ = var("a,b,c")
sage: diff(f,a,b,c)
D[0, 1, 2](f)(a, b, c)
"""
from sage.symbolic.function import Function
if isinstance(f, Function):
f = f(*args)
try:
return f.derivative(*args, **kwds)
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/symbolic/integration/integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def integrate(expression, v=None, a=None, b=None, algorithm=None, hold=False):
sage: integrate(sin)
Traceback (most recent call last):
...
TypeError
TypeError: Could not coerce into SR: "sin" of type <class 'sage.functions.trig.Function_sin'>
sage: integrate(sin(x), x)
-cos(x)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/symbolic/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ cdef class SymbolicRing(CommutativeRing):
elif isinstance(x, (RingElement, Matrix)):
GEx_construct_pyobject(exp, x)
else:
raise TypeError
raise TypeError('Could not coerce into SR: "{0}" of type {1}'.format(repr(x), type(x)))

return new_Expression_from_GEx(self, exp)

Expand Down

0 comments on commit 0cecec3

Please sign in to comment.