[plt-scheme] random walk

From: Marijn Schouten (hkBst) (hkBst at gentoo.org)
Date: Fri May 29 11:08:08 EDT 2009


I'm trying to write a macro that writes a function that sums the L2-lengths of
all (random) walks of depth d on a square grid of dimension DIM. In dimension 2
that function should look like this:

(define (walk 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))) ))))
	   (+ (* x x) (* y y)) ) )))

(walk d) starts at the origin, (x,y) = (0,0), and recursively walks a step in
all 2DIM directions, returning the L2-length when depth d is reached and summing
all those lengths. It is not hard to prove that (walk depth) is equal to (expt
(* 2 (DIM)) depth) but this random walk length summer is only the starting point
for doing more interesting things.

I'm looking for a macro that will write the `walk' function given the dimension.

Attached is an attempt that I cannot seem to get working.



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.racket-lang.org/users/archive/attachments/20090529/c4416dd4/attachment.ksh>
-------------- 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.racket-lang.org/users/archive/attachments/20090529/c4416dd4/attachment.sig>

Posted on the users mailing list.