puzzle #23
In this lesson

Wide tables, equations, and code scroll sideways. Swipe, or Tab to focus them and use the left and right arrow keys.

Random walks in 1D, 2D, 3D

You will learn: Separate return at a time, return by a cap, and eventual recurrence across dimensions.

Start with: Random walk

Start at the origin of an integer lattice. At each step choose one of the 2d signed coordinate directions uniformly and move one unit. In one and two dimensions the walk eventually returns with probability one. In three dimensions the return probability is about 0.34053733. Extra space changes the infinite-time behavior.

But a simulation always stops somewhere. A walk that has not returned after one hundred steps has not demonstrated that it will never return. The experiment therefore separates return at the current time, first return by a chosen cap, and eventual return.

Compare the three dimensions

Probability of a first return by the observation cap00.20.40.60.81020406080100step capprobability returned by cap

Solid: one dimension. Long dashes: two. Dots: three. A return requires every coordinate to be zero after at least one step. The initial position is not counted as a return.

DimensionP(at origin at cap)P(returned by cap)Returned sample pathsP(ever returns)
10.079589240.9204108190/2001
20.0063344470.5832222110/2001
30.00065492330.311937566/200≈ 0.34053733

Inspect the first seeded path in 2 dimensions

Every coordinate of the inspected path over time−505020406080100stepcoordinate position

X is solid; Y uses long dashes; Z uses dots. Only coordinates present in the selected dimension are drawn. Open circles mark actual returns of the full walk, not individual coordinates crossing zero.

Final coordinates: (7, 3). First return at step 2; observed return steps: 2, 4, 6. A path that has not returned is censored here; that observation does not establish permanent escape.

Inspect coordinates and first-return probabilities
StepXYP(first return at step)
0000.000000
1100.000000
2000.2500000
3-100.000000
4000.07812500
5010.000000
6000.04296875
7100.000000
8200.02862549
9100.000000
10110.02104187
11210.000000
12310.01642513
13410.000000
14510.01335168
15410.000000
16400.01117482
17410.000000
18310.009561150
19410.000000
20420.008322472
21320.000000
22220.007345014
23230.000000
24330.006556213
25430.000000
26530.005907744
27540.000000
28550.005366263
29450.000000
30440.004908063
31340.000000
32240.004515858
33140.000000
34040.004176767
35030.000000
36-130.003881004
37030.000000
38040.003621011
39050.000000
40060.003390867
41070.000000
42080.003185866
43070.000000
44060.003002227
45-160.000000
46-170.002836880
47-160.000000
48-170.002687307
49-160.000000
50-170.002551422
51070.000000
52170.002427488
53070.000000
54080.002314044
55180.000000
56080.002209855
57180.000000
58080.002113867
59070.000000
60060.002025179
61070.000000
62170.001943017
63270.000000
64170.001866707
65160.000000
66170.001795667
67270.000000
68260.001729385
69270.000000
70260.001667415
71160.000000
72260.001609362
73250.000000
74350.001554878
75250.000000
76240.001503655
77340.000000
78240.001455417
79340.000000
80330.001409920
81430.000000
82440.001366943
83340.000000
84330.001326290
85340.000000
86350.001287784
87250.000000
88350.001251263
89340.000000
90440.001216583
91430.000000
92530.001183614
93430.000000
94420.001152235
95430.000000
96530.001122337
97540.000000
98640.001093822
99740.000000
100730.001066600
Simple symmetric nearest-neighbor walk on the unbounded integer lattice. At each step choose one of the 2d signed coordinate directions uniformly. There are no walls, absorbing outer boundaries, diagonal moves, or simultaneous moves along all axes. The finite return calculation uses exact path counts and a first-return recurrence; the eventual three-dimensional value is an established limiting constant.

The lattice has no outer boundary. There are no walls to reflect the path and no boundary at which it is declared lost. Each step changes exactly one coordinate by plus or minus one. In two dimensions this means north, south, east, or west; diagonal moves are excluded. In three dimensions there are six possibilities, not eight simultaneous coordinate-sign combinations.

The upper curves calculate the probability of at least one return by each step cap. The sample counts independently summarize seeded paths stopped at that same cap. The coordinate plot shows every coordinate of one inspected path. An open circle marks a return only when all coordinates are zero together; a single coordinate crossing zero is insufficient.

Three events that should not be conflated

Let Sₜ be position after t steps and T the first positive return time. “At the origin now” is Sₜ = 0. “Returned by now” is T ≤ t. “Ever returns” is T finite. A path can have returned at step two and be far from the origin at step one hundred, contributing to the second event but not the first.

At zero steps the walk is at the origin with probability one, while the probability of a positive return by that time is zero. At odd steps, being at the origin is impossible because the parity of the coordinate sum changes on every move. Return-by-cap probabilities do not drop on odd steps; they retain returns already achieved.

After one hundred steps, the exact probabilities of having returned are approximately 0.920411 in one dimension, 0.583222 in two, and 0.311938 in three. The corresponding probabilities of being at the origin at that exact time are much smaller: about 0.0795892, 0.00633445, and 0.000654923. Both columns describe the same walk model but different events.

Count returns before sampling them

Write uₜ for P(Sₜ = 0), with u₀ = 1, and fₜ for P(T = t). Every path at the origin at time t has a first return at some positive time k no greater than t. After that return, the remaining increments have the original walk law. Hence uₜ = Σ fₖ uₜ₋ₖ, where k runs from one through t. Solve for fₜ by subtracting the earlier terms from uₜ, then sum f₁ through fₜ to obtain the return-by-cap probability.

The implementation obtains uₜ by counting balanced positive and negative coordinate moves. For example, at two steps the second direction must reverse the first, giving u₂ = f₂ = 1/(2d). In one dimension, six of the sixteen four-step paths are at the origin, so u₄ = 6/16. Removing paths whose first return was at step two gives f₄ = 6/16 − (1/2)(1/2) = 1/8. Thus return by step four has probability 1/2 + 1/8 = 5/8.

The three four-step return-by-cap probabilities are 5/8, 21/64, and 5/24. These values provide small cases that can be verified by enumerating every signed-direction sequence. The broader implementation is checked against independent spatial path counting, including a separate process absorbed on its first return.

Make a prediction

If a two-dimensional path has not returned within the selected cap, does that contradict recurrence?

Explore the answer

No. Recurrence gives eventual return probability one, with no fixed finite deadline. The unreturned path is still unresolved at the observation cap.

What the infinite-time result says

Recurrence in one and two dimensions does not imply a finite expected return time; these unbounded symmetric walks have infinite mean positive return time. Three-dimensional transience means a positive probability of escaping forever, not that every path escapes. Its finite-cap curve approaches the eventual return probability from below.

Doyle and Snell’s Random Walks and Electric Networks develops the recurrence distinction and the three-dimensional constant. Levin, Peres, and Wilmer give the Markov-chain framework. Continue to the one-dimensional random walk for displacement and scaling, or the Ehrenfest urn to compare an unbounded lattice with a finite state space.

Reset all settings