@@ -5524,6 +5524,65 @@ cdef class Expression(Expression_abc):
55245524 cdef Expression p = self .coerce_in(pattern)
55255525 return self ._gobj.has(p._gobj)
55265526
5527+ def has_function (self , arg , all = False ):
5528+ """
5529+ Return True if any or all function arguments are part
5530+ of this expression.
5531+
5532+ The argument must either be
5533+
5534+ - a function operator like ``sin``
5535+
5536+ - a Python list containing such operators
5537+
5538+ EXAMPLES::
5539+
5540+ sage: (1+sin(x)).has_function(sin)
5541+ True
5542+ sage: (1+x).has_function(sin)
5543+ False
5544+ sage: (1+sin(x)+cos(x)).has_function([sin,cos])
5545+ True
5546+ sage: (1+sin(x)+cos(x)).has_function([sin,tan])
5547+ True
5548+ sage: (1+sin(x)+cos(x)).has_function([sin,tan], all=True)
5549+ False
5550+ sage: (1+sin(x)+tan(x)).has_function([sin,tan], all=True)
5551+ True
5552+ sage: f = function('f')
5553+ sage: (f(x)+sin(x)+tan(x)).has_function([sin,tan,f], all=True)
5554+ True
5555+ sage: (1+x).has_function(x)
5556+ Traceback (most recent call last):
5557+ ...
5558+ TypeError: argument must be function or list
5559+ sage: (1+sin(x)+cos(x)).has_function([sin,cos,x])
5560+ Traceback (most recent call last):
5561+ ...
5562+ TypeError: arguments must be functions
5563+ """
5564+ from .function import Function
5565+ cdef stdstring s
5566+ cdef vector[stdstring] vec
5567+ if isinstance (arg, Function):
5568+ s = arg.name()
5569+ vec = [s]
5570+ elif isinstance (arg, list ):
5571+ for a in arg:
5572+ if isinstance (a, Function):
5573+ s = a.name()
5574+ vec.push_back(s)
5575+ else :
5576+ raise TypeError (' arguments must be functions' )
5577+ else :
5578+ raise TypeError (' argument must be function or list' )
5579+
5580+ sig_on()
5581+ try :
5582+ return has_function(self ._gobj, vec, all is True )
5583+ finally :
5584+ sig_off()
5585+
55275586 def substitute (self , *args , **kwds ):
55285587 """
55295588 Substitute the given subexpressions in this expression.
0 commit comments