Random Walk Return Probability
In a symmetric random walk on Z, starting at 0, each step goes +1 or -1 with equal probability 1/2. Let R(2n) be the probability of being at position 0 after exactly 2n steps. Find R(20) as a reduc...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
An L-expression is defined as any one of the following:
a natural number;
the symbol $A$;
the symbol $Z$;
the symbol $S$;
a pair of L-expressions $u, v$, which is written as $u(v)$.
An L-expression can be transformed according to the following rules:
$A(x) \to x + 1$ for any natural number $x$;
$Z(u)(v) \to v$ for any L-expressions $u, v$;
$S(u)(v)(w) \to v(u(v)(w))$ for any L-expressions $u, v, w$.
For example, after applying all possible rules, the L-expression $S(Z)(A)(0)$ is transformed to the number $1$: $$S(Z)(A)(0) \to A(Z(A)(0)) \to A(0) \to 1.$$ Similarly, the L-expression $S(S)(S(S))(S(Z))(A)(0)$ is transformed to the number $6$ after applying all possible rules.
Find the result of the L-expression $S(S)(S(S))(S(S))(S(Z))(A)(0)$ after applying all possible rules. Give the last nine digits as your answer.
Note: it can be proved that the L-expression in question can only be transformed a finite number of times, and the final result does not depend on the order of the transformations.
Problem 909: Random Walk Return Probability
Mathematical Analysis
Counting Paths
Theorem. .
Proof. A walk of steps consists of steps to the right and steps to the left. The position at time is . For this to equal 0, we need . The number of such paths is (choosing which steps go right). Each path has probability .
Evaluation at
Simplification. Compute .
and . Since is odd (its prime factorization is ):
Central Binomial Coefficient
The central binomial coefficient has the generating function:
and the asymptotic:
This gives the well-known asymptotic for the return probability:
Consequences of (3)
Theorem (Polya’s Recurrence). The symmetric random walk on is recurrent: the walker returns to the origin with probability 1.
Proof. The expected number of returns is . Since returns are not independent, we use the stronger result: the probability of eventual return is where is the first-return probability, and . By the relation between the generating functions: where . At : , so , proving recurrence.
First-Return Probability
The first-return probability satisfies:
This follows from the ballot problem / cycle lemma.
Verification Table
| approx | |||||
|---|---|---|---|---|---|
| 1 | 2 | 4 | 1/2 | 0.5000 | 0.5642 |
| 2 | 6 | 16 | 3/8 | 0.3750 | 0.3989 |
| 3 | 20 | 64 | 5/16 | 0.3125 | 0.3257 |
| 5 | 252 | 1024 | 63/256 | 0.2461 | 0.2523 |
| 10 | 184756 | 46189/262144 | 0.1762 | 0.1784 |
The approximation is remarkably accurate even for small .
Higher-Dimensional Generalization
In dimensions, . The walk is recurrent iff (Polya, 1921).
Complexity Analysis
- Direct computation: to compute and .
- Stirling approximation: for an approximate answer.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
/*
* Problem 909: Random Walk Return Probability
*
* R(2n) = C(2n, n) / 4^n. For n = 10: R(20) = 184756 / 1048576.
* Reduce to lowest terms: 46189 / 262144. Answer: p + q = 308333.
*
* Two methods:
* 1. Direct computation with gcd reduction
* 2. Iterative C(2n,n) with 2-adic valuation tracking
*
* Key result: R(2n) ~ 1/sqrt(pi*n) (Stirling). The walk on Z is recurrent
* because sum R(2n) diverges.
*/
int main() {
int n = 10;
// Compute C(2n, n)
long long num = 1;
for (int i = 1; i <= n; i++) {
num *= (n + i);
num /= i;
}
// num = C(20, 10) = 184756
long long den = 1LL << (2 * n); // 4^n = 2^{2n} = 1048576
long long g = __gcd(num, den);
long long p = num / g; // 46189
long long q = den / g; // 262144
// Verify
assert(p == 46189);
assert(q == 262144);
assert(__gcd(p, q) == 1); // fully reduced
cout << p + q << endl; // 308333
// Verify small cases
// R(2) = C(2,1)/4 = 2/4 = 1/2, p+q = 3
assert(__gcd(2LL, 4LL) == 2);
// R(4) = C(4,2)/16 = 6/16 = 3/8, p+q = 11
long long g2 = __gcd(6LL, 16LL);
assert(6 / g2 == 3 && 16 / g2 == 8);
return 0;
}
"""
Problem 909: Random Walk Return Probability
Symmetric random walk on Z starting at 0. R(2n) = probability of being
at 0 after 2n steps. Find R(20) = p/q in lowest terms, compute p + q.
Key formula: R(2n) = C(2n, n) / 4^n
Asymptotic: R(2n) ~ 1 / sqrt(pi * n)
Methods:
1. Direct computation with gcd reduction
2. Exact combinatorial verification
3. Monte Carlo simulation (verification)
"""
from math import comb, gcd, sqrt, pi
import random
def return_prob_exact(n: int):
"""Compute R(2n) = C(2n,n) / 4^n as reduced fraction (p, q)."""
num = comb(2 * n, n)
den = 4 ** n
g = gcd(num, den)
return num // g, den // g
def solve(n: int = 10):
"""Return p + q where R(2n) = p/q reduced."""
p, q = return_prob_exact(n)
return p + q
def return_prob_brute(n: int) -> float:
"""Count paths of 2n steps returning to 0, brute-force for small n."""
count = 0
total = 0
# Enumerate all 2^(2n) paths (only feasible for small n)
for mask in range(1 << (2 * n)):
pos = 0
for step in range(2 * n):
if mask & (1 << step):
pos += 1
else:
pos -= 1
if pos == 0:
count += 1
total += 1
return count / total
def return_prob_monte_carlo(n: int, trials: int = 500000) -> float:
"""Estimate R(2n) by simulation."""
random.seed(42)
returns = 0
for _ in range(trials):
pos = 0
for _ in range(2 * n):
pos += random.choice([-1, 1])
if pos == 0:
returns += 1
return returns / trials
# Solve
ans = solve(10)
# Verify known values
assert return_prob_exact(1) == (1, 2) # R(2) = 1/2
assert return_prob_exact(2) == (3, 8) # R(4) = 3/8
assert return_prob_exact(3) == (5, 16) # R(6) = 5/16
# Verify with brute force for small n
for test_n in [1, 2, 3, 4]:
p, q = return_prob_exact(test_n)
brute = return_prob_brute(test_n)
assert abs(p / q - brute) < 1e-12, f"n={test_n}: exact={p/q}, brute={brute}"
# Verify specific answer
p, q = return_prob_exact(10)
assert p == 46189 and q == 262144
assert ans == 308333
print(ans)