mathlib — Monte Carlo

π estimation and optional 1D integration. ← Back to hub

1 π estimation

Estimate π by Monte Carlo: sample points in [-1,1]² and count those inside the unit circle (ratio × 4 ≈ π).

—
Sample points in [-1,1]²; blue inside circle, red outside (same seed as estimate).

2 1D integration (optional)

∫₀¹ x² dx = 1/3 by Monte Carlo uniform sampling. Shown when WASM exports integrateXSquared.

—