Recursive function #27558
Replies: 4 comments 3 replies
-
You have expressed this in a different way but I think essentially what it boils down to is that you want to be able to solve this functional equation: In [53]: Eq(f(x), e(x))
Out[53]:
⎧ x for x > 50
f(x) = ⎨
⎩f(x + 1) otherwise I don't think SymPy has any capability to solve something like this. There is rsolve for simple recurrences but I don't expect it can handle anything with Piecewise like this: In [61]: rsolve(Eq(f(x+1), 2*f(x) + 1), f(x), {f(0): 1})
Out[61]:
x
2⋅2 - 1 More generally functional equations are not something where I am aware of there being any particularly general algorithms. I think that there was an old issue about this and the conclusion was that it is probably not worth trying to make a general functional equation solver. Possibly there could be something useful for particular classes (like for recurrences) but the example given does not seem like something that would particularly generalise into a meaningful class of problems. |
Beta Was this translation helpful? Give feedback.
-
Okay, I'm working on implementing this. |
Beta Was this translation helpful? Give feedback.
-
Created PR: #27565 |
Beta Was this translation helpful? Give feedback.
-
I don't understand what it is that you are really trying to do here. The idea needs to be clarified before creating a PR. |
Beta Was this translation helpful? Give feedback.
- 819B
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, how can I define a recursive function in SymPy? For example,
e = sympy.Lambda(x, sympy.Piecewise((x, sympy.Gt(x, 50)), (f(x + 1), True)))
wheref
=e
. I would like to be able to use this for simplification; for example, the above should be able to be transformed intoe = sympy.Lambda(x, 50)
.I tried this, but it just emits a RecursionError when invoking it.
Beta Was this translation helpful? Give feedback.
All reactions