|
| 1 | +/- |
| 2 | +Copyright (c) 2024 Enrico Z. Borba. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Enrico Z. Borba |
| 5 | +-/ |
| 6 | + |
| 7 | +import Mathlib.Probability.Density |
| 8 | +import Mathlib.Probability.Notation |
| 9 | +import Mathlib.MeasureTheory.Constructions.Prod.Integral |
| 10 | +import Mathlib.Analysis.SpecialFunctions.Integrals |
| 11 | +import Mathlib.Probability.Distributions.Uniform |
| 12 | + |
| 13 | +/-! |
| 14 | +
|
| 15 | +# Freek № 99: Buffon's Needle |
| 16 | +
|
| 17 | +This file proves Theorem 99 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/), also |
| 18 | +known as Buffon's Needle, which gives the probability of a needle of length `l > 0` crossing any |
| 19 | +one of infinite vertical lines spaced out `d > 0` apart. |
| 20 | +
|
| 21 | +The two cases are proven in `buffon_short` and `buffon_long`. |
| 22 | +
|
| 23 | +## Overview of the Proof |
| 24 | +
|
| 25 | +We define a random variable `B : Ω → ℝ × ℝ` with a uniform distribution on `[-d/2, d/2] × [0, π]`. |
| 26 | +This represents the needle's x-position and angle with respect to a vertical line. By symmetry, we |
| 27 | +need to consider only a single vertical line positioned at `x = 0`. A needle therefore crosses the |
| 28 | +vertical line if its projection onto the x-axis contains `0`. |
| 29 | +
|
| 30 | +We define a random variable `N : Ω → ℝ` that is `1` if the needle crosses a vertical line, and `0` |
| 31 | +otherwise. This is defined as `fun ω => Set.indicator (needleProjX l (B ω).1 (B ω).2) 1 0`. |
| 32 | +f |
| 33 | +As in many references, the problem is split into two cases, `l ≤ d` (`buffon_short`), and `d ≤ l` |
| 34 | +(`buffon_long`). For both cases, we show that |
| 35 | +```lean |
| 36 | +ℙ[N] = (d * π) ⁻¹ * |
| 37 | + ∫ θ in 0..π, |
| 38 | + ∫ x in Set.Icc (-d / 2) (d / 2) ∩ Set.Icc (-θ.sin * l / 2) (θ.sin * l / 2), 1 |
| 39 | +``` |
| 40 | +In the short case `l ≤ d`, we show that `[-l * θ.sin/2, l * θ.sin/2] ⊆ [-d/2, d/2]` |
| 41 | +(`short_needle_inter_eq`), and therefore the inner integral simplifies to |
| 42 | +```lean |
| 43 | +∫ x in (-θ.sin * l / 2)..(θ.sin * l / 2), 1 = θ.sin * l |
| 44 | +``` |
| 45 | +Which then concludes in the short case being `ℙ[N] = (2 * l) / (d * π)`. |
| 46 | +
|
| 47 | +In the long case, `l ≤ d` (`buffon_long`), we show the outer integral simplifies to |
| 48 | +```lean |
| 49 | +∫ θ in 0..π, min d (θ.sin * l) |
| 50 | +``` |
| 51 | +which can be expanded to |
| 52 | +```lean |
| 53 | +2 * ( |
| 54 | + ∫ θ in 0..(d / l).arcsin, min d (θ.sin * l) + |
| 55 | + ∫ θ in (d / l).arcsin..(π / 2), min d (θ.sin * l) |
| 56 | +) |
| 57 | +``` |
| 58 | +We then show the two integrals equal their respective values `l - √(l^2 - d^2)` and |
| 59 | +`(π / 2 - (d / l).arcsin) * d`. Then with some algebra we conclude |
| 60 | +```lean |
| 61 | +ℙ[N] = (2 * l) / (d * π) - 2 / (d * π) * (√(l^2 - d^2) + d * (d / l).arcsin) + 1 |
| 62 | +``` |
| 63 | +
|
| 64 | +## References |
| 65 | +
|
| 66 | +* https://en.wikipedia.org/wiki/Buffon%27s_needle_problem |
| 67 | +* https://www.math.leidenuniv.nl/~hfinkeln/seminarium/stelling_van_Buffon.pdf |
| 68 | +* https://www.isa-afp.org/entries/Buffons_Needle.html |
| 69 | +
|
| 70 | +-/ |
| 71 | + |
| 72 | +open MeasureTheory (MeasureSpace IsProbabilityMeasure Measure pdf.IsUniform) |
| 73 | +open ProbabilityTheory Real |
| 74 | + |
| 75 | +namespace BuffonsNeedle |
| 76 | + |
| 77 | +variable |
| 78 | + /- Probability theory variables. -/ |
| 79 | + {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] |
| 80 | + |
| 81 | + /- Buffon's needle variables. -/ |
| 82 | + |
| 83 | + /- |
| 84 | + - `d > 0` is the distance between parallel lines. |
| 85 | + - `l > 0` is the length of the needle. |
| 86 | + -/ |
| 87 | + (d l : ℝ) |
| 88 | + (hd : 0 < d) |
| 89 | + (hl : 0 < l) |
| 90 | + |
| 91 | + /- `B = (X, Θ)` is the joint random variable for the x-position and angle of the needle. -/ |
| 92 | + (B : Ω → ℝ × ℝ) |
| 93 | + (hBₘ : Measurable B) |
| 94 | + |
| 95 | + /- `B` is uniformly distributed on `[-d/2, d/2] × [0, π]`. -/ |
| 96 | + (hB : pdf.IsUniform B ((Set.Icc (-d / 2) (d / 2)) ×ˢ (Set.Icc 0 π)) ℙ) |
| 97 | + |
| 98 | +/-- |
| 99 | + Projection of a needle onto the x-axis. The needle's center is at x-coordinate `x`, of length |
| 100 | + `l` and angle `θ`. Note, `θ` is measured relative to the y-axis, that is, a vertical needle has |
| 101 | + `θ = 0`. |
| 102 | +-/ |
| 103 | +def needleProjX (x θ : ℝ) : Set ℝ := Set.Icc (x - θ.sin * l / 2) (x + θ.sin * l / 2) |
| 104 | + |
| 105 | +/-- |
| 106 | + The indicator function of whether a needle at position `⟨x, θ⟩ : ℝ × ℝ` crosses the line `x = 0`. |
| 107 | +
|
| 108 | + In order to faithfully model the problem, we compose `needleCrossesIndicator` with a random |
| 109 | + variable `B : Ω → ℝ × ℝ` with uniform distribution on `[-d/2, d/2] × [0, π]`. Then, by symmetry, |
| 110 | + the probability that the needle crosses `x = 0`, is the same as the probability of a needle |
| 111 | + crossing any of the infinitely spaced vertical lines distance `d` apart. |
| 112 | +-/ |
| 113 | +noncomputable def needleCrossesIndicator (p : ℝ × ℝ) : ℝ := |
| 114 | + Set.indicator (needleProjX l p.1 p.2) 1 0 |
| 115 | + |
| 116 | +/-- |
| 117 | + A random variable representing whether the needle crosses a line. |
| 118 | +
|
| 119 | + The line is at `x = 0`, and therefore a needle crosses the line if its projection onto the x-axis |
| 120 | + contains `0`. This random variable is `1` if the needle crosses the line, and `0` otherwise. |
| 121 | +-/ |
| 122 | +noncomputable def N : Ω → ℝ := needleCrossesIndicator l ∘ B |
| 123 | + |
| 124 | +/-- |
| 125 | + The possible x-positions and angle relative to the y-axis of a needle. |
| 126 | +-/ |
| 127 | +abbrev needleSpace: Set (ℝ × ℝ) := Set.Icc (-d / 2) (d / 2) ×ˢ Set.Icc 0 π |
| 128 | + |
| 129 | +lemma volume_needleSpace : ℙ (needleSpace d) = ENNReal.ofReal (d * π) := by |
| 130 | + simp_rw [MeasureTheory.Measure.volume_eq_prod, MeasureTheory.Measure.prod_prod, Real.volume_Icc, |
| 131 | + ENNReal.ofReal_mul hd.le] |
| 132 | + ring_nf |
| 133 | + |
| 134 | +lemma measurable_needleCrossesIndicator : Measurable (needleCrossesIndicator l) := by |
| 135 | + unfold needleCrossesIndicator |
| 136 | + refine Measurable.indicator measurable_const (IsClosed.measurableSet (IsClosed.inter ?l ?r)) |
| 137 | + all_goals simp only [tsub_le_iff_right, zero_add, ← neg_le_iff_add_nonneg'] |
| 138 | + case' l => refine' isClosed_le continuous_fst _ |
| 139 | + case' r => refine' isClosed_le (Continuous.neg continuous_fst) _ |
| 140 | + all_goals |
| 141 | + refine' Continuous.mul (Continuous.mul _ continuous_const) continuous_const |
| 142 | + simp_rw [← Function.comp_apply (f := Real.sin) (g := Prod.snd), |
| 143 | + Continuous.comp Real.continuous_sin continuous_snd] |
| 144 | + |
| 145 | +lemma stronglyMeasurable_needleCrossesIndicator : |
| 146 | + MeasureTheory.StronglyMeasurable (needleCrossesIndicator l) := by |
| 147 | + refine stronglyMeasurable_iff_measurable_separable.mpr |
| 148 | + ⟨measurable_needleCrossesIndicator l, {0, 1}, ?separable⟩ |
| 149 | + have range_finite : Set.Finite ({0, 1} : Set ℝ) := by |
| 150 | + simp only [Set.mem_singleton_iff, Set.finite_singleton, Set.Finite.insert] |
| 151 | + refine ⟨range_finite.countable, ?subset_closure⟩ |
| 152 | + rw [IsClosed.closure_eq range_finite.isClosed, Set.subset_def, Set.range] |
| 153 | + intro x ⟨p, hxp⟩ |
| 154 | + by_cases hp : 0 ∈ needleProjX l p.1 p.2 |
| 155 | + · simp_rw [needleCrossesIndicator, Set.indicator_of_mem hp, Pi.one_apply] at hxp |
| 156 | + apply Or.inr hxp.symm |
| 157 | + · simp_rw [needleCrossesIndicator, Set.indicator_of_not_mem hp] at hxp |
| 158 | + apply Or.inl hxp.symm |
| 159 | + |
| 160 | +lemma integrable_needleCrossesIndicator : |
| 161 | + MeasureTheory.Integrable (needleCrossesIndicator l) |
| 162 | + (Measure.prod |
| 163 | + (Measure.restrict ℙ (Set.Icc (-d / 2) (d / 2))) |
| 164 | + (Measure.restrict ℙ (Set.Icc 0 π))) := by |
| 165 | + have needleCrossesIndicator_nonneg p : 0 ≤ needleCrossesIndicator l p := by |
| 166 | + apply Set.indicator_apply_nonneg |
| 167 | + simp only [Pi.one_apply, zero_le_one, implies_true] |
| 168 | + have needleCrossesIndicator_le_one p : needleCrossesIndicator l p ≤ 1 := by |
| 169 | + unfold needleCrossesIndicator |
| 170 | + by_cases hp : 0 ∈ needleProjX l p.1 p.2 |
| 171 | + · simp_rw [Set.indicator_of_mem hp, Pi.one_apply, le_refl] |
| 172 | + · simp_rw [Set.indicator_of_not_mem hp, zero_le_one] |
| 173 | + refine' And.intro |
| 174 | + (stronglyMeasurable_needleCrossesIndicator l).aestronglyMeasurable |
| 175 | + ((MeasureTheory.hasFiniteIntegral_iff_norm (needleCrossesIndicator l)).mpr _) |
| 176 | + refine lt_of_le_of_lt (MeasureTheory.lintegral_mono (g := 1) ?le_const) ?lt_top |
| 177 | + case le_const => |
| 178 | + intro p |
| 179 | + simp only [Real.norm_eq_abs, abs_of_nonneg (needleCrossesIndicator_nonneg _), |
| 180 | + ENNReal.ofReal_le_one, Pi.one_apply] |
| 181 | + exact needleCrossesIndicator_le_one p |
| 182 | + case lt_top => |
| 183 | + simp_rw [Pi.one_apply, MeasureTheory.lintegral_const, one_mul, Measure.prod_restrict, |
| 184 | + Measure.restrict_apply MeasurableSet.univ, Set.univ_inter, Measure.prod_prod, Real.volume_Icc, |
| 185 | + neg_div, sub_neg_eq_add, add_halves, sub_zero, ← ENNReal.ofReal_mul hd.le, |
| 186 | + ENNReal.ofReal_lt_top] |
| 187 | + |
| 188 | +/-- |
| 189 | + This is a common step in both the short and the long case to simplify the expectation of the |
| 190 | + needle crossing a line to a double integral. |
| 191 | + ```lean |
| 192 | + ∫ (θ : ℝ) in Set.Icc 0 π, |
| 193 | + ∫ (x : ℝ) in Set.Icc (-d / 2) (d / 2) ∩ Set.Icc (-θ.sin * l / 2) (θ.sin * l / 2), 1 |
| 194 | + ``` |
| 195 | + The domain of the inner integral is simpler in the short case, where the intersection is |
| 196 | + equal to `Set.Icc (-θ.sin * l / 2) (θ.sin * l / 2)` by `short_needle_inter_eq`. |
| 197 | +-/ |
| 198 | +lemma buffon_integral : |
| 199 | + 𝔼[N l B] = (d * π) ⁻¹ * |
| 200 | + ∫ (θ : ℝ) in Set.Icc 0 π, |
| 201 | + ∫ (x : ℝ) in Set.Icc (-d / 2) (d / 2) ∩ Set.Icc (-θ.sin * l / 2) (θ.sin * l / 2), 1 := by |
| 202 | + simp_rw [N, Function.comp_apply] |
| 203 | + rw [ |
| 204 | + ← MeasureTheory.integral_map hBₘ.aemeasurable |
| 205 | + (stronglyMeasurable_needleCrossesIndicator l).aestronglyMeasurable, |
| 206 | + hB, ProbabilityTheory.cond, MeasureTheory.integral_smul_measure, volume_needleSpace d hd, |
| 207 | + ← ENNReal.ofReal_inv_of_pos (mul_pos hd Real.pi_pos), |
| 208 | + ENNReal.toReal_ofReal (inv_nonneg.mpr (mul_nonneg hd.le Real.pi_pos.le)), smul_eq_mul, |
| 209 | + ] |
| 210 | + refine' mul_eq_mul_left_iff.mpr (Or.inl _) |
| 211 | + have : MeasureTheory.IntegrableOn (needleCrossesIndicator l) |
| 212 | + (Set.Icc (-d / 2) (d / 2) ×ˢ Set.Icc 0 π) := by |
| 213 | + simp_rw [MeasureTheory.IntegrableOn, Measure.volume_eq_prod, ← Measure.prod_restrict, |
| 214 | + integrable_needleCrossesIndicator d l hd] |
| 215 | + rw [Measure.volume_eq_prod, MeasureTheory.setIntegral_prod _ this, |
| 216 | + MeasureTheory.integral_integral_swap ?integrable] |
| 217 | + case integrable => simp_rw [Function.uncurry_def, Prod.mk.eta, |
| 218 | + integrable_needleCrossesIndicator d l hd] |
| 219 | + simp only [needleCrossesIndicator, needleProjX, Set.mem_Icc] |
| 220 | + have indicator_eq (x θ : ℝ) : |
| 221 | + Set.indicator (Set.Icc (x - θ.sin * l / 2) (x + θ.sin * l / 2)) 1 0 = |
| 222 | + Set.indicator (Set.Icc (-θ.sin * l / 2) (θ.sin * l / 2)) (1 : ℝ → ℝ) x := by |
| 223 | + simp_rw [Set.indicator, Pi.one_apply, Set.mem_Icc, tsub_le_iff_right, zero_add, neg_mul] |
| 224 | + have : |
| 225 | + x ≤ Real.sin θ * l / 2 ∧ 0 ≤ x + Real.sin θ * l / 2 ↔ |
| 226 | + -(Real.sin θ * l) / 2 ≤ x ∧ x ≤ Real.sin θ * l / 2 := by |
| 227 | + rw [neg_div, and_comm, ← tsub_le_iff_right, zero_sub] |
| 228 | + by_cases h : x ≤ Real.sin θ * l / 2 ∧ 0 ≤ x + Real.sin θ * l / 2 |
| 229 | + · rw [if_pos h, if_pos (this.mp h)] |
| 230 | + · rw [if_neg h, if_neg (this.not.mp h)] |
| 231 | + simp_rw [indicator_eq, MeasureTheory.setIntegral_indicator measurableSet_Icc, Pi.one_apply] |
| 232 | + |
| 233 | +/-- |
| 234 | + From `buffon_integral`, in both the short and the long case, we have |
| 235 | + ```lean |
| 236 | + 𝔼[N l B] = (d * π)⁻¹ * |
| 237 | + ∫ (θ : ℝ) in Set.Icc 0 π, |
| 238 | + ∫ (x : ℝ) in Set.Icc (-d / 2) (d / 2) ∩ Set.Icc (-θ.sin * l / 2) (θ.sin * l / 2), 1 |
| 239 | + ``` |
| 240 | + With this lemma, in the short case, the inner integral's domain simplifies to |
| 241 | + `Set.Icc (-θ.sin * l / 2) (θ.sin * l / 2)`. |
| 242 | +-/ |
| 243 | +lemma short_needle_inter_eq (h : l ≤ d) (θ : ℝ) : |
| 244 | + Set.Icc (-d / 2) (d / 2) ∩ Set.Icc (-θ.sin * l / 2) (θ.sin * l / 2) = |
| 245 | + Set.Icc (-θ.sin * l / 2) (θ.sin * l / 2) := by |
| 246 | + rw [Set.Icc_inter_Icc, inf_eq_min, sup_eq_max, max_div_div_right zero_le_two, |
| 247 | + min_div_div_right zero_le_two, neg_mul, max_neg_neg, mul_comm, |
| 248 | + min_eq_right (mul_le_of_le_of_le_one_of_nonneg h θ.sin_le_one hl.le)] |
| 249 | + |
| 250 | +/-- |
| 251 | + Buffon's Needle, the short case (`l ≤ d`). The probability of the needle crossing a line |
| 252 | + equals `(2 * l) / (d * π)`. |
| 253 | +-/ |
| 254 | +theorem buffon_short (h : l ≤ d) : ℙ[N l B] = (2 * l) * (d * π)⁻¹ := by |
| 255 | + simp_rw [buffon_integral d l hd B hBₘ hB, short_needle_inter_eq d l hl h _, |
| 256 | + MeasureTheory.setIntegral_const, Real.volume_Icc, smul_eq_mul, mul_one, mul_comm (d * π)⁻¹ _, |
| 257 | + mul_eq_mul_right_iff] |
| 258 | + apply Or.inl |
| 259 | + ring_nf |
| 260 | + have : ∀ᵐ θ, θ ∈ Set.Icc 0 π → ENNReal.toReal (ENNReal.ofReal (θ.sin * l)) = θ.sin * l := by |
| 261 | + have (θ : ℝ) (hθ : θ ∈ Set.Icc 0 π) : 0 ≤ θ.sin * l := |
| 262 | + mul_nonneg (Real.sin_nonneg_of_mem_Icc hθ) hl.le |
| 263 | + simp_rw [ENNReal.toReal_ofReal_eq_iff, MeasureTheory.ae_of_all _ this] |
| 264 | + simp_rw [MeasureTheory.setIntegral_congr_ae measurableSet_Icc this, |
| 265 | + ← smul_eq_mul, integral_smul_const, smul_eq_mul, mul_comm, mul_eq_mul_left_iff, |
| 266 | + MeasureTheory.integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le Real.pi_pos.le, |
| 267 | + integral_sin, Real.cos_zero, Real.cos_pi, sub_neg_eq_add, one_add_one_eq_two, true_or] |
| 268 | + |
| 269 | +/-- |
| 270 | + The integrand in the long case is `min d (θ.sin * l)` and its integrability is necessary for |
| 271 | + the integral lemmas below. |
| 272 | +-/ |
| 273 | +lemma intervalIntegrable_min_const_sin_mul (a b : ℝ) : |
| 274 | + IntervalIntegrable (fun (θ : ℝ) => min d (θ.sin * l)) ℙ a b := by |
| 275 | + apply Continuous.intervalIntegrable |
| 276 | + exact Continuous.min continuous_const (Continuous.mul Real.continuous_sin continuous_const) |
| 277 | + |
| 278 | +/-- |
| 279 | + This equality is useful since `θ.sin` is increasing in `0..π / 2` (but not in `0..π`). |
| 280 | + Then, `∫ θ in (0)..π / 2, min d (θ.sin * l)` can be split into two adjacent integrals, at the |
| 281 | + point where `d = θ.sin * l`, which is `θ = (d / l).arcsin`. |
| 282 | +-/ |
| 283 | +lemma integral_min_eq_two_mul : |
| 284 | + ∫ θ in (0)..π, min d (θ.sin * l) = 2 * ∫ θ in (0)..π / 2, min d (θ.sin * l) := by |
| 285 | + rw [← intervalIntegral.integral_add_adjacent_intervals (b := π / 2) (c := π)] |
| 286 | + conv => lhs; arg 2; arg 1; intro θ; rw [← neg_neg θ, Real.sin_neg] |
| 287 | + simp_rw [intervalIntegral.integral_comp_neg fun θ => min d (-θ.sin * l), ← Real.sin_add_pi, |
| 288 | + intervalIntegral.integral_comp_add_right (fun θ => min d (θ.sin * l)), add_left_neg, |
| 289 | + (by ring : -(π / 2) + π = π / 2), two_mul] |
| 290 | + all_goals exact intervalIntegrable_min_const_sin_mul d l _ _ |
| 291 | + |
| 292 | +/-- |
| 293 | + The first of two adjacent integrals in the long case. In the range `(0)..(d / l).arcsin`, we |
| 294 | + have that `θ.sin * l ≤ d`, and thus the integral is `∫ θ in (0)..(d / l).arcsin, θ.sin * l`. |
| 295 | +-/ |
| 296 | +lemma integral_zero_to_arcsin_min : |
| 297 | + ∫ θ in (0)..(d / l).arcsin, min d (θ.sin * l) = (1 - √(1 - (d / l) ^ 2)) * l := by |
| 298 | + have : Set.EqOn (fun θ => min d (θ.sin * l)) (Real.sin · * l) (Set.uIcc 0 (d / l).arcsin) := by |
| 299 | + intro θ ⟨hθ₁, hθ₂⟩ |
| 300 | + have : 0 ≤ (d / l).arcsin := Real.arcsin_nonneg.mpr (div_nonneg hd.le hl.le) |
| 301 | + simp only [sup_eq_max, inf_eq_min, min_eq_left this, max_eq_right this] at hθ₁ hθ₂ |
| 302 | + have hθ_mem : θ ∈ Set.Ioc (-(π / 2)) (π / 2) := by |
| 303 | + exact ⟨lt_of_lt_of_le (neg_lt_zero.mpr (div_pos Real.pi_pos two_pos)) hθ₁, |
| 304 | + le_trans hθ₂ (d / l).arcsin_mem_Icc.right⟩ |
| 305 | + simp_rw [min_eq_right ((le_div_iff hl).mp ((Real.le_arcsin_iff_sin_le' hθ_mem).mp hθ₂))] |
| 306 | + rw [intervalIntegral.integral_congr this, intervalIntegral.integral_mul_const, integral_sin, |
| 307 | + Real.cos_zero, Real.cos_arcsin] |
| 308 | + |
| 309 | +/-- |
| 310 | + The second of two adjacent integrals in the long case. In the range `(d / l).arcsin..(π / 2)`, we |
| 311 | + have that `d ≤ θ.sin * l`, and thus the integral is `∫ θ in (d / l).arcsin..(π / 2), d`. |
| 312 | +-/ |
| 313 | +lemma integral_arcsin_to_pi_div_two_min (h : d ≤ l) : |
| 314 | + ∫ θ in (d / l).arcsin..(π / 2), min d (θ.sin * l) = (π / 2 - (d / l).arcsin) * d := by |
| 315 | + have : Set.EqOn (fun θ => min d (θ.sin * l)) (fun _ => d) (Set.uIcc (d / l).arcsin (π / 2)) := by |
| 316 | + intro θ ⟨hθ₁, hθ₂⟩ |
| 317 | + wlog hθ_ne_pi_div_two : θ ≠ π / 2 |
| 318 | + · simp only [ne_eq, not_not] at hθ_ne_pi_div_two |
| 319 | + simp only [hθ_ne_pi_div_two, Real.sin_pi_div_two, one_mul, min_eq_left h] |
| 320 | + simp only [sup_eq_max, inf_eq_min, min_eq_left (d / l).arcsin_le_pi_div_two, |
| 321 | + max_eq_right (d / l).arcsin_le_pi_div_two] at hθ₁ hθ₂ |
| 322 | + have hθ_mem : θ ∈ Set.Ico (-(π / 2)) (π / 2) := by |
| 323 | + exact ⟨le_trans (Real.arcsin_mem_Icc (d / l)).left hθ₁, lt_of_le_of_ne hθ₂ hθ_ne_pi_div_two⟩ |
| 324 | + simp_rw [min_eq_left ((div_le_iff hl).mp ((Real.arcsin_le_iff_le_sin' hθ_mem).mp hθ₁))] |
| 325 | + rw [intervalIntegral.integral_congr this, intervalIntegral.integral_const, smul_eq_mul] |
| 326 | + |
| 327 | +/-- |
| 328 | + Buffon's Needle, the long case (`d ≤ l`). |
| 329 | +-/ |
| 330 | +theorem buffon_long (h : d ≤ l) : |
| 331 | + ℙ[N l B] = (2 * l) / (d * π) - 2 / (d * π) * (√(l^2 - d^2) + d * (d / l).arcsin) + 1 := by |
| 332 | + simp only [ |
| 333 | + buffon_integral d l hd B hBₘ hB, MeasureTheory.integral_const, smul_eq_mul, mul_one, |
| 334 | + MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter, Set.Icc_inter_Icc, Real.volume_Icc, |
| 335 | + sup_eq_max, inf_eq_min, min_div_div_right zero_le_two d, max_div_div_right zero_le_two (-d), |
| 336 | + div_sub_div_same, neg_mul, max_neg_neg, sub_neg_eq_add, ← mul_two, |
| 337 | + mul_div_cancel_right₀ (min d (Real.sin _ * l)) two_ne_zero |
| 338 | + ] |
| 339 | + have : ∀ᵐ θ, θ ∈ Set.Icc 0 π → |
| 340 | + ENNReal.toReal (ENNReal.ofReal (min d (θ.sin * l))) = min d (θ.sin * l) := by |
| 341 | + have (θ : ℝ) (hθ : θ ∈ Set.Icc 0 π) : 0 ≤ min d (θ.sin * l) := by |
| 342 | + by_cases h : d ≤ θ.sin * l |
| 343 | + · rw [min_eq_left h]; exact hd.le |
| 344 | + · rw [min_eq_right (not_le.mp h).le]; exact mul_nonneg (Real.sin_nonneg_of_mem_Icc hθ) hl.le |
| 345 | + simp_rw [ENNReal.toReal_ofReal_eq_iff, MeasureTheory.ae_of_all _ this] |
| 346 | + rw [MeasureTheory.setIntegral_congr_ae measurableSet_Icc this, |
| 347 | + MeasureTheory.integral_Icc_eq_integral_Ioc, |
| 348 | + ← intervalIntegral.integral_of_le Real.pi_pos.le, integral_min_eq_two_mul, |
| 349 | + ← intervalIntegral.integral_add_adjacent_intervals |
| 350 | + (intervalIntegrable_min_const_sin_mul d l _ _) (intervalIntegrable_min_const_sin_mul d l _ _), |
| 351 | + integral_zero_to_arcsin_min d l hd hl, integral_arcsin_to_pi_div_two_min d l hl h] |
| 352 | + field_simp |
| 353 | + ring_nf |
| 354 | + |
| 355 | +end BuffonsNeedle |
0 commit comments