Published
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
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.
| Dimension | P(at origin at cap) | P(returned by cap) | Returned sample paths | P(ever returns) |
|---|---|---|---|---|
| 1 | 0.07958924 | 0.9204108 | 190/200 | 1 |
| 2 | 0.006334447 | 0.5832222 | 110/200 | 1 |
| 3 | 0.0006549233 | 0.3119375 | 66/200 | ≈ 0.34053733 |
Inspect the first seeded path in 2 dimensions
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
| Step | X | Y | P(first return at step) |
|---|---|---|---|
| 0 | 0 | 0 | 0.000000 |
| 1 | 1 | 0 | 0.000000 |
| 2 | 0 | 0 | 0.2500000 |
| 3 | -1 | 0 | 0.000000 |
| 4 | 0 | 0 | 0.07812500 |
| 5 | 0 | 1 | 0.000000 |
| 6 | 0 | 0 | 0.04296875 |
| 7 | 1 | 0 | 0.000000 |
| 8 | 2 | 0 | 0.02862549 |
| 9 | 1 | 0 | 0.000000 |
| 10 | 1 | 1 | 0.02104187 |
| 11 | 2 | 1 | 0.000000 |
| 12 | 3 | 1 | 0.01642513 |
| 13 | 4 | 1 | 0.000000 |
| 14 | 5 | 1 | 0.01335168 |
| 15 | 4 | 1 | 0.000000 |
| 16 | 4 | 0 | 0.01117482 |
| 17 | 4 | 1 | 0.000000 |
| 18 | 3 | 1 | 0.009561150 |
| 19 | 4 | 1 | 0.000000 |
| 20 | 4 | 2 | 0.008322472 |
| 21 | 3 | 2 | 0.000000 |
| 22 | 2 | 2 | 0.007345014 |
| 23 | 2 | 3 | 0.000000 |
| 24 | 3 | 3 | 0.006556213 |
| 25 | 4 | 3 | 0.000000 |
| 26 | 5 | 3 | 0.005907744 |
| 27 | 5 | 4 | 0.000000 |
| 28 | 5 | 5 | 0.005366263 |
| 29 | 4 | 5 | 0.000000 |
| 30 | 4 | 4 | 0.004908063 |
| 31 | 3 | 4 | 0.000000 |
| 32 | 2 | 4 | 0.004515858 |
| 33 | 1 | 4 | 0.000000 |
| 34 | 0 | 4 | 0.004176767 |
| 35 | 0 | 3 | 0.000000 |
| 36 | -1 | 3 | 0.003881004 |
| 37 | 0 | 3 | 0.000000 |
| 38 | 0 | 4 | 0.003621011 |
| 39 | 0 | 5 | 0.000000 |
| 40 | 0 | 6 | 0.003390867 |
| 41 | 0 | 7 | 0.000000 |
| 42 | 0 | 8 | 0.003185866 |
| 43 | 0 | 7 | 0.000000 |
| 44 | 0 | 6 | 0.003002227 |
| 45 | -1 | 6 | 0.000000 |
| 46 | -1 | 7 | 0.002836880 |
| 47 | -1 | 6 | 0.000000 |
| 48 | -1 | 7 | 0.002687307 |
| 49 | -1 | 6 | 0.000000 |
| 50 | -1 | 7 | 0.002551422 |
| 51 | 0 | 7 | 0.000000 |
| 52 | 1 | 7 | 0.002427488 |
| 53 | 0 | 7 | 0.000000 |
| 54 | 0 | 8 | 0.002314044 |
| 55 | 1 | 8 | 0.000000 |
| 56 | 0 | 8 | 0.002209855 |
| 57 | 1 | 8 | 0.000000 |
| 58 | 0 | 8 | 0.002113867 |
| 59 | 0 | 7 | 0.000000 |
| 60 | 0 | 6 | 0.002025179 |
| 61 | 0 | 7 | 0.000000 |
| 62 | 1 | 7 | 0.001943017 |
| 63 | 2 | 7 | 0.000000 |
| 64 | 1 | 7 | 0.001866707 |
| 65 | 1 | 6 | 0.000000 |
| 66 | 1 | 7 | 0.001795667 |
| 67 | 2 | 7 | 0.000000 |
| 68 | 2 | 6 | 0.001729385 |
| 69 | 2 | 7 | 0.000000 |
| 70 | 2 | 6 | 0.001667415 |
| 71 | 1 | 6 | 0.000000 |
| 72 | 2 | 6 | 0.001609362 |
| 73 | 2 | 5 | 0.000000 |
| 74 | 3 | 5 | 0.001554878 |
| 75 | 2 | 5 | 0.000000 |
| 76 | 2 | 4 | 0.001503655 |
| 77 | 3 | 4 | 0.000000 |
| 78 | 2 | 4 | 0.001455417 |
| 79 | 3 | 4 | 0.000000 |
| 80 | 3 | 3 | 0.001409920 |
| 81 | 4 | 3 | 0.000000 |
| 82 | 4 | 4 | 0.001366943 |
| 83 | 3 | 4 | 0.000000 |
| 84 | 3 | 3 | 0.001326290 |
| 85 | 3 | 4 | 0.000000 |
| 86 | 3 | 5 | 0.001287784 |
| 87 | 2 | 5 | 0.000000 |
| 88 | 3 | 5 | 0.001251263 |
| 89 | 3 | 4 | 0.000000 |
| 90 | 4 | 4 | 0.001216583 |
| 91 | 4 | 3 | 0.000000 |
| 92 | 5 | 3 | 0.001183614 |
| 93 | 4 | 3 | 0.000000 |
| 94 | 4 | 2 | 0.001152235 |
| 95 | 4 | 3 | 0.000000 |
| 96 | 5 | 3 | 0.001122337 |
| 97 | 5 | 4 | 0.000000 |
| 98 | 6 | 4 | 0.001093822 |
| 99 | 7 | 4 | 0.000000 |
| 100 | 7 | 3 | 0.001066600 |
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.