Problem (Buffon, 1777). A floor has parallel lines at distance . A needle of length is dropped at random. What is the probability that it crosses a line?
Answer. For a short needle (): . Dropping needles and counting crossings gives the estimate .
| Variant | Result |
|---|---|
| short needle, | |
| long needle, | |
| expected number of crossings, any | |
| Buffon’s noodle: any rigid curve of length | expected crossings , whatever its shape |
| Barbier’s theorem | every convex curve of constant width has perimeter |
| estimating with throws, | relative standard error : six digits need about throws |
| Laplace’s grid (two families of lines, cells , ) |
const double PI = acos(-1.0);
double buffonProb(double l, double d) { // probability that a needle of length l crosses a line (spacing d)
if (l <= d) return 2 * l / (PI * d);
double r = d / l;
return 1 + 2 / PI * (l / d * (1 - sqrt(1 - r * r)) - asin(r));
}
// Monte Carlo estimate of pi. The direction is sampled by rejection from the unit disk, so pi is never used.
double estimatePi(long long n, double l, double d, mt19937_64& rng) {
uniform_real_distribution<double> U(-1, 1), X(0, d / 2);
long long hits = 0;
for (long long i = 0; i < n; i++) {
double ux, uy, r2;
do { ux = U(rng); uy = U(rng); r2 = ux * ux + uy * uy; } while (r2 > 1 || r2 == 0);
double s = fabs(uy) / sqrt(r2); // |sin theta| of a uniform direction
hits += X(rng) <= l / 2 * s; // centre-to-nearest-line distance vs half the vertical extent
}
return 2 * l * n / (d * hits); // valid for l <= d
}Proof: the crossing probability, both cases
By symmetry let be the distance from the needle’s centre to the nearest line and its acute angle with the lines; both are uniform and independent. The needle crosses iff . Hence
If the minimum is always the second term and . If , let ; the integrand is on and after, giving with , which is the formula. The code’s sampler draws of a uniform direction because a uniform point of the unit disk has a uniform angle. Checked: closed form against Simpson integration of the integral for , and the Monte Carlo estimate within standard errors.
Proof: Buffon's noodle and Barbier's theorem
Let be the expected number of crossings of a rigid segment of length thrown at random. Cutting a segment into two pieces, each piece is itself thrown uniformly, and crossings add (a crossing at the joint has probability ), so by linearity of expectation . is monotone, so . A polygonal curve is a union of segments, each thrown uniformly, so its expected crossings are times its length; a rectifiable curve is a limit of inscribed polygons and the crossing counts converge, so the same holds. A circle of diameter crosses the lines exactly twice with probability , so , . For a needle crosses at most once, so its crossing probability equals its expected crossings , re-deriving Buffon’s formula.
Barbier. A convex curve of constant width , thrown on lines at spacing , crosses exactly twice with probability (its projection orthogonal to the lines is an interval of length exactly ). So and the perimeter is (the Reuleaux triangle included).
Error. The number of hits is binomial with ; has relative standard deviation , and has the same relative error to first order. For , and . Lazzarini’s 1901 claim of from 3408 throws is far beyond this accuracy (it stopped at a lucky moment).
Laplace’s grid. The needle misses both families iff it misses each. With independent uniform offsets in and and angle , the vertical extent must fit in and the horizontal in : , using and . The complement is the stated formula.