Substitute function definitions in SymPy expressions #26575
-
Let's say I have an expression, such as import sympy as sp
f = sp.Function(sp.Symbol("f", real=True))
x, y = sp.symbols(("x","y"), real=True)
equation = sp.Eq(f(x+y), f(x)+y) # The functional equation f(x+y) = f(x)+y My question is: Is there any way to substitute this function with its definition, for example if I suddenly know that it's equation.subs(f(x), x+2) This returns Essentially, I am trying to make a "check" method to check if a given function actually satisfies the condition, where it for example would return True when given the above, since it satisfies it. (I know this is probably not possible completely in general covering all edge cases by Richardson's theorem, but it's gotta be possible to do the above(?)) Any help, links or anything is appreciated 🌟 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can do this with In [7]: a = Wild('a')
In [8]: f(x+y).replace(f(a), a+2)
Out[8]: x + y + 2
In [9]: equation.replace(f(a), a + 2)
Out[9]: True |
Beta Was this translation helpful? Give feedback.
You can do this with
replace
: