Markov chains & Monte Carlo
When you can't solve an integral, you can sometimes sample it. Monte Carlo trades a proof for a stream of random draws; Markov chains let you sample even from distributions you can only evaluate up to a constant. Here's the core idea, three constants estimated by dice, an honest limit (simulation can't prove a number irrational), and how far the - and-adic cousins actually go.
1 · Monte Carlo — trade proof for samples
Replace an expectation you can't compute with an average over random draws. If are i.i.d.,
The law of large numbers guarantees convergence; the CLT gives the error bars. The remarkable part: that rate does not depend on the dimension. A grid costs points to hold resolution in dimensions; Monte Carlo doesn't care. This is the other side of the curse of dimensionality from the L² deep dive — when space is too big to grid, you sample it instead.
2 · Three constants from dice
— darts. Throw points uniformly in the unit square; the fraction landing in the quarter disk is the area ratio:
— uniforms until you cross 1. Let with . A small miracle: . Average the stopping counts.
— the Euler–Mascheroni constant. Use the integral identity and read it as an expectation over an exponential:
That expectation is worth seeing. The integrand is positive left of and slightly negative to the right; the small positive remainder is exactly. Slide the upper limit and watch the signed area settle onto it.
The integrand e−x(−ln x). Left of x = 1 it's positive (−ln x > 0); right of 1 it goes slightly negative. The net signed area is γ ≈ 0.5772 — slide b out and the running area settles onto it. (The curve spikes integrably to +∞ as x → 0; it's clipped here.)
Try it — the Monte Carlo lab
All three at once, seeded so the run is reproducible. Push the sample count up and watch the absolute error fall like .
| constant | estimate | true | abs error |
|---|---|---|---|
| π | 3.20640 | 3.14159 | 0.06481 |
| e | 2.73240 | 2.71828 | 0.01412 |
| γ | 0.56638 | 0.57722 | 0.01083 |
Seeded and reproducible. Watch the error shrink roughly like 1/√N as you raise the sample count — the same √N law for all three.
3 · √2 — where simulation honestly stops
Simulation can estimate a number to many digits, but it can never prove that number is irrational — no finite sample distinguishes an irrational from a rational sitting nanometers away. This is a place to be honest: experiment suggests, proof decides. The proof is the classic descent — assume in lowest terms, then
contradicting "lowest terms." What computation can show honestly: the continued fraction never terminates or falls into a rational, and by Weyl's theorem the fractional parts equidistribute on — something no rational multiple ever does. Evidence points; the argument settles it.
4 · Markov chains — memory of length one
A Markov chain forgets everything but its current state:
The row-stochastic matrix pushes the distribution forward,. A stationary distribution is a fixed point, — a left eigenvector with eigenvalue 1 (the spectral theme again). Under irreducibility and aperiodicity, the chain forgets its start entirely: regardless of where it began.
5 · MCMC — sampling the unsamplable
To sample a target you can only evaluate up to a constant, build a Markov chain whose stationary distribution is , then run it. The trick that guarantees stationarity is detailed balance:
Metropolis–Hastings proposes a move and accepts it with probability
where only the ratio of appears, so the unknown normalizing constant cancels. This is the engine under Bayesian posteriors — the bridge to QBism and decision theory (P2): beliefs you can actually compute with, not just write down.
6 · Variance reduction & advanced simulation
The rate is slow — halving the error costs four times the samples. So sharpen the estimator, not the sample size:
- Importance sampling — draw where is large, reweight by the density ratio.
- Control variates — subtract a correlated quantity of known mean. The optimal coefficient is — the very projection from the L² deep dive.
- Antithetic variates — pair with ; the negative correlation cancels variance.
- Stratification — sample each region in proportion, removing between-stratum noise.
- Quasi-Monte Carlo — low-discrepancy sequences (Sobol, Halton) reach error , beating .
The building blocks underneath: inverse-transform sampling and rejection sampling — both ways of bending uniform noise into the shape you want.
7 · q- and p-adic analogs — do they exist?
An honest answer, since you asked. There is no standard "-Monte Carlo," but the neighbors are real: quantum walks are the unitary cousin of the random walk, and quantum Monte Carlo is a genuine (and different) family of methods for sampling quantum systems in physics. So the random walk has a quantum analog; the Monte Carlo method doesn't have a clean -deformation.
The -adic side is firmer: p-adic (ultrametric) probability and random walks are a real, if specialized, field — p-adic Brownian motion, ultrametric diffusion, hierarchical relaxation (Vladimirov–Volovich–Zelenov; Khrennikov). Distances are non-Archimedean, so "nearby" means "in the same fine branch of a tree," and diffusion happens across that tree. It sits right next to the p-adic shelf in the program — Koblitz and friends — and it's where this deep dive quietly hands off to the number-theory thread.
Study these — derivation cards
Reconstruct before you flip. The matching spaced-repetition deck lives in the Obsidian vault.