The five-dimensional Watson integral
Find a closed form for the five-dimensional Watson integral W5 ≈ 0.2312616250, which fixes the return probability of a random walk on Z^5.

| 1 | """What W5 measures: a simple random walk on Z^5 ever comes back to where it started with probability 1 - 1/(5 W5), |
| 2 | about 0.135; most walks drift away for good. Drawn: the distance from home of real (seeded) walks of 36 steps. Seven |
| 3 | are the first seeds that never came back in those steps (faint); one is the first seed whose walk is home for the first |
| 4 | time at step 36 (the field's colour).""" |
| 5 | import math |
| 6 | import random |
| 7 | from pathlib import Path |
| 8 | |
| 9 | import kit |
| 10 | |
| 11 | W5 = 0.23126162496804623574 # the README's value |
| 12 | assert abs(1 - 1 / (5 * W5) - 0.13518) < 5e-6 # the README's return probability |
| 13 | T = 36 |
| 14 | |
| 15 | |
| 16 | def distances(seed): |
| 17 | """Distance from the origin after each of T steps of the walk with this seed.""" |
| 18 | rng, pos, out = random.Random(seed), [0] * 5, [0.0] |
| 19 | for _ in range(T): |
| 20 | pos[rng.randrange(5)] += rng.choice((-1, 1)) |
| 21 | out.append(math.sqrt(sum(x * x for x in pos))) |
| 22 | return out |
| 23 | |
| 24 | |
| 25 | came_back = next(d for d in map(distances, range(10 ** 6)) if d[-1] == 0 and all(d[1:-1])) |
| 26 | away = [d for d in map(distances, range(100)) if all(d[1:])][:7] |
| 27 | assert len(away) == 7 |
| 28 | |
| 29 | x0, x1, base, top = 40, 600, 250, 36 |
| 30 | m = max(max(d) for d in away + [came_back]) |
| 31 | pts = lambda d: [(x0 + (x1 - x0) * t / T, base - (base - top) * v / m) for t, v in enumerate(d)] |
| 32 | body = kit.line(x0, base, x1, base, 'faint-s', 2) # home: distance 0 |
| 33 | body += ''.join(kit.polyline(pts(d), 'faint-s', 2) for d in away) |
| 34 | body += kit.polyline(pts(came_back), 'f-s', 3.5) |
| 35 | body += kit.dot(x0, base, 7, 'ink') + kit.dot(x1, base, 9, 'f') |
| 36 | kit.write(__file__, 'physics-astronomy', body, label='walks on Z⁵, distance from home · ~0.135 return') |