<div dir="ltr"><div><div><div><div>Would it make sense to use memoization more broadly for the definition of the factorial in the math lib, maybe with a `provide'd parameter to control how many values can be memoized?<br>
<a href="https://github.com/plt/racket/blob/master/collects/math/private/number-theory/factorial.rkt">https://github.com/plt/racket/blob/master/collects/math/private/number-theory/factorial.rkt</a><br><br></div><div>While building big numbers (around 800!) I had to redefine my own
factorial and binomial functions with memoization, otherwise it would
take too long.<br><br>Also, probably `binomial' could take advantage of this memoization, just like `permutations' does.<br></div><a href="https://github.com/plt/racket/blob/master/collects/math/private/number-theory/binomial.rkt">https://github.com/plt/racket/blob/master/collects/math/private/number-theory/binomial.rkt</a><br>
<br></div>Currently (in DrRacket, so not entirely accurate, but should be close enough):<br>> (time<br> (for ([n 100])<br> (binomial 10000 4000)))<br>cpu time: 4072 real time: 4075 gc time: 440<br>> (time<br>
(for ([n 10000])<br>
(binomial 800 400)))<br>cpu time: 9424 real time: 9430 gc time: 836<br>> (time (for ([i 1000])<br> (factorial 10000)))<br>cpu time: 11441 real time: 11630 gc time: 276<br><br><br></div>which makes it impractical in some cases.<br>
<br></div>Laurent<br></div>