Python Development, memoized functions.

Antti Karttunen antti.karttunen at gmail.com
Thu Jan 4 13:02:47 CET 2007


Jon Awbrey wrote:

>o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o~~~~~~~~~o
>
>people who prefer could always say "memorandization",
>not to be confused with "mirandization".
>
>
Memoing, memoization, memorization,  memorandization or caching,
in any case, after my proof-of-concept that implementing
N->Z functions in such way is possible in Python,
we can assume the existence of a "memoizating" decorator
with just name M, so that A000045 could then just have a line like:

%o A000045 (Python) @M def A000045(n):  if(n < 2): return(n) else: 
return(A000045(n-1)+A000045(n-2))

and this is then to be interpreted as
@M
def A000045(n):  if(n < 2): return(n) else: 
return(A000045(n-1)+A000045(n-2))

(where the exact implementation of M-decorator would be given in a separate
file appendix of OEIS (like transforms.txt, etc.), containing possibly also
some higher-order functionals, like those for computing records, 
positions of distinct values, etc.)

Another idea is that we can tacitly assume that such
a decorator should be used whenever the Python-definition
uses recursion that would take aions to compute in ordinary way.

I leave the implementation of practical, robust version of
such decorator for somebody more experienced in Python.
For a similar thing in Scheme, see the definition of definec macro
for example in:
http://www.research.att.com/~njas/sequences/a126000.scm.txt



Cheers,

Antti







More information about the SeqFan mailing list