<p>I have a polynomial library I wrote for other purposes. It also uses list of numbers, though it isn't a sparse representation so exponents are assumed. Can't click your link right now, on my phone, but if you don't have an example problem, could you post one for me to try with my library? Then id know whether I could offer any advice.</p>
<div class="gmail_quote">On May 2, 2012 3:08 PM, <<a href="mailto:joshua@anwu.org">joshua@anwu.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Hey all,<br>
<br>
Been playing around with some code to multiply polynomials to calculate dice probabilities.<br>
Is based on a paper by Doron Zeilberger that I read years ago and can't find at the moment.<br>
<br>
My first attempt represented polynomials as lists of coefficient/exponent pairs.<br>
I tried to make it completely functional, with no set! operations. You can see it here:<br>
<br>
<a href="https://github.com/TurtleKitty/Dice/blob/2fff16e198cb84d725c786ecc624fb9b9468e778/dice.rkt" target="_blank">https://github.com/TurtleKitty/Dice/blob/2fff16e198cb84d725c786ecc624fb9b9468e778/dice.rkt</a><br>
<br>
It worked, but only to a point. At 9 or 10 dice, it started blowing up the RAM in my machine.<br>
I swear I smelled smoke. It grabbed like 4G and slowed to a crawl.<br>
<br>
Knowing that the Perl and Javascript versions of this program can calculate distributions for 300 dice in the space of a heartbeat,<br>
I rewrote the thing to use vectors instead, and altered the polynomial multiplication function to use (begin) and (vector-set!):<br>
<br>
<a href="https://github.com/TurtleKitty/Dice/blob/67c2b49707132395f73b43afe111e3904b3898f2/dice.rkt" target="_blank">https://github.com/TurtleKitty/Dice/blob/67c2b49707132395f73b43afe111e3904b3898f2/dice.rkt</a><br>
<br>
It too now calculates three hundred dice without breaking a sweat, but... I feel dirty.<br>
Can anyone recommend a functional approach that won't melt my motherboard?<br>
I'm considering hashes, since they have the immutable version of hash-set that vectors seem to lack, but I thought I'd ask the experts.<br>
<br>
<br>
Thanks,<br>
turtlekitty<br>
(There might be a library for this already. This is more of an exercise for me than a utility.)<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote></div>