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

Commit

Permalink
24283: Implement Expression.has_function(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Nov 27, 2017
1 parent dcce91f commit 68b6a58
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4915,6 +4915,65 @@ cdef class Expression(CommutativeRingElement):
cdef Expression p = self.coerce_in(pattern)
return self._gobj.has(p._gobj)

def has_function(self, arg, all=False):
"""
Return True if any or all function arguments are part
of this expression.
The argument must either be
- a function operator like ``sin``
- a Python list containing such operators
EXAMPLES::
sage: (1+sin(x)).has_function(sin)
True
sage: (1+x).has_function(sin)
False
sage: (1+sin(x)+cos(x)).has_function([sin,cos])
True
sage: (1+sin(x)+cos(x)).has_function([sin,tan])
True
sage: (1+sin(x)+cos(x)).has_function([sin,tan], all=True)
False
sage: (1+sin(x)+tan(x)).has_function([sin,tan], all=True)
True
sage: f = function('f')
sage: (f(x)+sin(x)+tan(x)).has_function([sin,tan,f], all=True)
True
sage: (1+x).has_function(x)
Traceback (most recent call last):
...
TypeError: argument must be function or list
sage: (1+sin(x)+cos(x)).has_function([sin,cos])
Traceback (most recent call last):
...
TypeError: arguments must be functions
"""
from .function import Function
cdef stdstring s
cdef vector[stdstring] vec
if isinstance(arg, Function):
s = arg.name()
vec = [s]
elif isinstance(arg, list):
for a in arg:
if isinstance(a, Function):
s = a.name()
vec.push_back(s)
else:
raise TypeError('arguments must be functions')
else:
raise TypeError('argument must be function or list')

sig_on()
try:
return has_function(self._gobj, vec, all is True)
finally:
sig_off()

def substitute(self, *args, **kwds):
"""
Substitute the given subexpressions in this expression.
Expand Down

0 comments on commit 68b6a58

Please sign in to comment.