Skip to content Skip to sidebar Skip to footer

Sympy: Get Functions From Expression

To get all variables from a sympy expression, one can call .free_symbols on the expression. I would like to retrieve all functions used in an expression. For example, from y in fro

Solution 1:

atoms does the trick:

for f in y.atoms(Function):
    print(f.func)

Solution 2:

For all functions, use atoms(Function).

In [40]: (f(x) + sin(x)).atoms(Function)
Out[40]: set([f(x), sin(x)])

For only undefined functions, use atoms(AppliedUndef).

In [41]: from sympy.core.function import AppliedUndef

In [42]: (f(x) + sin(x)).atoms(AppliedUndef)
Out[42]: set([f(x)])

Post a Comment for "Sympy: Get Functions From Expression"