Re: what's it worth to write a short program for polynomial multiplication?
- From: rjf <fateman@xxxxxxxxx>
- Date: Mon, 16 Jun 2008 14:07:17 -0700 (PDT)
On Jun 16, 11:00 am, Dan Christensen <j...@xxxxxx> wrote:
[Dan] Here's the equivalent code:
c = collections.defaultdict(int)
for ea in a:
for eb in b:
c[ea+eb] += a[ea]*b[eb]
The only cryptic line is the first, which defines a hash table
whose default value is 0.
Dan
Dan's note reminded me that there are other (in my opinion, very non-
lispy) ways of writing loops in ANSI standard Common Lisp. I rarely
use them, but they make possible the following code..
(setf ans (make-hash-table))
(loop for ea being the hash-index of a using (hash-value c1) do
(loop for eb being the hash-index of b using (hash-value c2) do
(incf (gethash (+ ea eb) ans 0) (* c1 c2))))
.
- References:
- what's it worth to write a short program for polynomial multiplication?
- From: rjf
- Re: what's it worth to write a short program for polynomial multiplication?
- From: Herman Rubin
- Re: what's it worth to write a short program for polynomial multiplication?
- From: rjf
- Re: what's it worth to write a short program for polynomial multiplication?
- From: Herman Rubin
- Re: what's it worth to write a short program for polynomial multiplication?
- From: rjf
- Re: what's it worth to write a short program for polynomial multiplication?
- From: Christopher Creutzig
- Re: what's it worth to write a short program for polynomial multiplication?
- From: rjf
- Re: what's it worth to write a short program for polynomial multiplication?
- From: Christopher Creutzig
- Re: what's it worth to write a short program for polynomial multiplication?
- From: rjf
- Re: what's it worth to write a short program for polynomial multiplication?
- From: Dan Christensen
- what's it worth to write a short program for polynomial multiplication?
- Prev by Date: Re: Maxima question (bigfloat computation of zeta function)
- Next by Date: definite integral score
- Previous by thread: Re: what's it worth to write a short program for polynomial multiplication?
- Next by thread: Re: what's it worth to write a short program for polynomial multiplication?
- Index(es):
Relevant Pages
|