Christian Krause on Sun, 04 Feb 2024 11:31:34 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Fast evaluation of recursive functions


Hello,
I'm extensively using recursive function definitions and need to compute the first 0..N terms of them, for example

a(n)=if(n<2,1,a(n-1)+a(n-2))

for(n=0,100,print(a(n)))


The computation is very slow because PARI/GP apparently does not re-use previously computed terms. 

I found the following GP script which implements a cache: 
https://user42.tuxfamily.org/pari-memoize/index.html

However, I was wondering if there is any built-in support for caching (recursive) function values?

An alternative could be to calculate recursive function terms incrementally. Is there any syntax/pattern in GP available for this?

Cheers,
Christian