[Larceny-users] using macros to handcode random walk in arbitrary dimension
Marijn Schouten (hkBst)
hkBst at gentoo.org
Tue May 5 12:18:12 EDT 2009
Hi,
I am trying to write a program that will iterate over all random walks of a
certain fixed depth on a grid of a certain dimension DIM. There are exactly
(expt (* 2 (DIM)) depth)) such random walks and I would like to calculate the
mean squared length of them at a certain depth. The answer is depth. The
algorithm should thus act as the identity function on natural numbers, if given
depth and returning the mean squared length of random walks of that depth.
The function
(define (walk-f depth)
(let step ((d 0) (x 0) (y 0) #;(z 0))
(cond ((< d depth)
(let ((d+1 (+ d 1)))
(+
(step d+1 (+ x 1) y)
(+
(step d+1 (- x 1) y)
(+ (step d+1 x (+ y 1))
(step d+1 x (- y 1))) ))))
(else
(L2-norm x y)))))
calculates the total squared length. Assuming dimension 2 I performed some
optimizations. I have written syntax-case macro code that should construct this
function for arbitrary dimension, except I cannot get it to work. I have
attached the complete program (68 lines) with the offending code commented out.
I would really appreciate some help with this.
Thanks,
Marijn
--
If you cannot read my mind, then listen to what I say.
Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-{lisp,ml} on FreeNode
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: stripped-randomwalk.scm
Url: http://lists.ccs.neu.edu/pipermail/larceny-users/attachments/20090505/f9138d07/attachment.txt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
Url : http://lists.ccs.neu.edu/pipermail/larceny-users/attachments/20090505/f9138d07/attachment.pgp
More information about the Larceny-users
mailing list