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

Commit

Permalink
Expression.is_callable: New
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Oct 17, 2021
1 parent b484d51 commit fad87c0
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3124,6 +3124,22 @@ cdef class Expression(Expression_abc):

return obj.is_square()

def is_callable(self):
r"""
Return ``True`` if ``self`` is a callable symbolic expression.
EXAMPLES::
sage: var('a x y z')
(a, x, y, z)
sage: f(x, y) = a + 2*x + 3*y + z
sage: f.is_callable()
True
sage: (a+2*x).is_callable()
False
"""
return isinstance(self.parent(), sage.rings.abc.CallableSymbolicExpressionRing)

def left_hand_side(self):
"""
If self is a relational expression, return the left hand side
Expand Down Expand Up @@ -4632,7 +4648,7 @@ cdef class Expression(Expression_abc):
symb = vars[0]
elif len(vars) == 0:
return self._parent(0)
elif sage.symbolic.callable.is_CallableSymbolicExpression(self):
elif self.is_callable():
return self.gradient()
else:
raise ValueError("No differentiation variable specified.")
Expand Down Expand Up @@ -12714,7 +12730,6 @@ cdef class Expression(Expression_abc):
sage: plot(f,0,1)
Graphics object consisting of 1 graphics primitive
"""
from sage.symbolic.callable import is_CallableSymbolicExpression
from sage.symbolic.ring import is_SymbolicVariable
from sage.plot.plot import plot

Expand All @@ -12730,7 +12745,7 @@ cdef class Expression(Expression_abc):
break

if param is None:
if is_CallableSymbolicExpression(self):
if self.is_callable():
A = self.arguments()
if len(A) == 0:
raise ValueError("function has no input arguments")
Expand Down

0 comments on commit fad87c0

Please sign in to comment.