Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Caching (memoization) in (Gauche, Lisp, Scheme) and Python

5 views
Skip to first unread message

henh...@gmail.com

unread,
Sep 18, 2022, 12:25:28 PM9/18/22
to

So... for a few days i've been revising this Code (in Gauche / Lisp / Scheme) to make it run faster.. and last night i could improve it enough to give me the result i wanted in 72 minutes or so (on my slow PC at home).


( Maybe... within a few months, i'll write the same program in Python .... to see if it runs 10 or 20 times faster. )


this was the first time i've used Caching (memoization). ----- instead of calculating (at run-time) Factorial(x) and Combination(x,y) millions of times, i made 2 tables in advance... A simple Table-lookup (Vector-ref in Scheme) seems 100 -- 1000 times faster.


One thought i had was... Maybe Python's Factorial(x) and Combination(x,y) (in Numpy ?) are already so fast that... i don't have to do the Caching (memoization) ???



--- the 1st change i made (to make it run faster) was to rewrite the Recursive Factorial(x) into iterative (tail-recursive) Factorial(x, val) and that one simple change made it (the whole program) noticeably faster.

duncan smith

unread,
Sep 18, 2022, 2:03:32 PM9/18/22
to
Memoization / table lookup will give you a significant speed up as long
as you're generating enough factorials / binomial coefficients.
Depending on what you're doing you might find the functions in
scipy.special useful,

https://docs.scipy.org/doc/scipy/reference/special.html

particularly the gammaln and related functions. You will need to install
scipy unless you've already done so.

Duncan
0 new messages