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

Commit

Permalink
derivative: try to find a common parent before casting to SR
Browse files Browse the repository at this point in the history
  • Loading branch information
dgulotta committed Mar 16, 2021
1 parent 5cb72aa commit 0dc171f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/sage/calculus/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

from .calculus import SR
from sage.symbolic.expression import Expression
from sage.misc.derivative import derivative_parse
from sage.structure.element import get_coercion_model

def simplify(f):
r"""
Expand Down Expand Up @@ -150,6 +152,13 @@ def derivative(f, *args, **kwds):
return f.derivative(*args, **kwds)
except AttributeError:
pass
try:
elts = [e for e in derivative_parse(args) if e is not None]
elts.append(f)
cm = get_coercion_model()
return cm.common_parent(*elts)(f).derivative(*args, **kwds)
except (AttributeError, TypeError):
pass
if not isinstance(f, Expression):
f = SR(f)
return f.derivative(*args, **kwds)
Expand Down

0 comments on commit 0dc171f

Please sign in to comment.