Solving recurrence equations
RESequence
is a tool external to Leibniz that uses Leibniz contexts as its user interface. It is a simple numerical tool that solves recurrence equations. It reads the equations to be solved from a Leibniz context in the form of labelled rules, which it compiles to Pharo code.
More sophisticated numerical tools, such as ODE solvers, could be interfaced with Leibniz in the same way. They could also generate and use code in other (more efficient) languages than Pharo.
The inputs to a recurrence equation solver are:
- a list of recurrence equations
- a list of initial values for each variable
RESequence
reads the equations from a Leibniz context but takes the initial values as standard Pharo arrays. This is most convenient for this specific use case, because it permits the last-minute choice of floating-point vs. exact arithmetic: just write the initial values as floating-point constants or as integer/fraction constants. However, an external tool can read any data it wants from a Leibniz context, including the initial values.
Example: Fibonacci numbers
The Fibonacci numbers
starting with
These rules are sufficient to compute any Fibonacci number in Leibniz, e.g.
Using RESequence
we find:
sequence := RESequence context: (thisSnippet page lzSubcontext: #fibonacci) rules: #('fibonacciRecurrence') initialValues: (Dictionary with: #F -> #(1 1)). sequence addSteps: 10. sequence