Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Who does not trust enough will not be trusted. -- Lao Tsu


interests / rec.puzzles / Re: Caching (memoization) in (Gauche, Lisp, Scheme) and Python

SubjectAuthor
* Caching (memoization) in (Gauche, Lisp, Scheme) and Pythonhenh...@gmail.com
`- Re: Caching (memoization) in (Gauche, Lisp, Scheme) and Pythonduncan smith

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

<6a2dbb68-6ebd-46f0-8857-ebbf0416b6d9n@googlegroups.com>

  copy mid

https://novabbs.com/interests/article-flat.php?id=491&group=rec.puzzles#491

  copy link   Newsgroups: rec.puzzles
X-Received: by 2002:a05:622a:406:b0:35c:b76f:909f with SMTP id n6-20020a05622a040600b0035cb76f909fmr11828949qtx.432.1663518327113;
Sun, 18 Sep 2022 09:25:27 -0700 (PDT)
X-Received: by 2002:a05:620a:15e:b0:6ce:d179:1045 with SMTP id
e30-20020a05620a015e00b006ced1791045mr7688712qkn.59.1663518326948; Sun, 18
Sep 2022 09:25:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: rec.puzzles
Date: Sun, 18 Sep 2022 09:25:26 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=2601:648:8600:6f70:0:0:0:a597;
posting-account=YjTkGAoAAAA4_fbAISfvtIqrYbghMeBx
NNTP-Posting-Host: 2601:648:8600:6f70:0:0:0:a597
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6a2dbb68-6ebd-46f0-8857-ebbf0416b6d9n@googlegroups.com>
Subject: Caching (memoization) in (Gauche, Lisp, Scheme) and Python
From: henha...@gmail.com (henh...@gmail.com)
Injection-Date: Sun, 18 Sep 2022 16:25:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2255
 by: henh...@gmail.com - Sun, 18 Sep 2022 16:25 UTC

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.

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

<R3JVK.36388$ocy7.14318@fx38.iad>

  copy mid

https://novabbs.com/interests/article-flat.php?id=492&group=rec.puzzles#492

  copy link   Newsgroups: rec.puzzles
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx38.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Subject: Re: Caching (memoization) in (Gauche, Lisp, Scheme) and Python
Content-Language: en-GB
Newsgroups: rec.puzzles
References: <6a2dbb68-6ebd-46f0-8857-ebbf0416b6d9n@googlegroups.com>
From: dun...@invalid.invalid (duncan smith)
In-Reply-To: <6a2dbb68-6ebd-46f0-8857-ebbf0416b6d9n@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 29
Message-ID: <R3JVK.36388$ocy7.14318@fx38.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Sun, 18 Sep 2022 18:03:29 UTC
Organization: blocknews - www.blocknews.net
Date: Sun, 18 Sep 2022 19:03:27 +0100
X-Received-Bytes: 2413
 by: duncan smith - Sun, 18 Sep 2022 18:03 UTC

On 18/09/2022 17:25, henh...@gmail.com wrote:
>
> 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.

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

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor