| 1 | module |
| 2 | |
| 3 | public import Mathlib |
| 4 | |
| 5 | @[expose] public section |
| 6 | |
| 7 | /-! |
| 8 | # Lemma 37: generic integral helpers |
| 9 | |
| 10 | `continuousOn_of_lip`: a Lipschitz-type bound on a set gives `ContinuousOn`. |
| 11 | `shift_bound`: comparing `∫_{a+w}^{b+w} K` with `∫_a^b J` when `K ≈ J` on the overlap and both are |
| 12 | bounded on the two boundary strips of length `w`. |
| 13 | -/ |
| 14 | |
| 15 | set_option linter.style.header false |
| 16 | |
| 17 | namespace E424 |
| 18 | |
| 19 | lemma continuousOn_of_lip {s : Set ℝ} {f : ℝ → ℝ} {C : ℝ} |
| 20 | (h : ∀ x ∈ s, ∀ y ∈ s, |f x - f y| ≤ C * |x - y|) : ContinuousOn f s := by |
| 21 | intro x hx |
| 22 | rw [Metric.continuousWithinAt_iff] |
| 23 | intro ε hε |
| 24 | have hpos : (0 : ℝ) < |C| + 1 := by positivity |
| 25 | refine ⟨ε / (|C| + 1), div_pos hε hpos, fun y hy hyx => ?_⟩ |
| 26 | rw [Real.dist_eq] at hyx ⊢ |
| 27 | have hd : |y - x| * (|C| + 1) < ε := (lt_div_iff₀ hpos).1 hyx |
| 28 | have h1 := h y hy x hx |
| 29 | have h2 : C * |y - x| ≤ |C| * |y - x| := mul_le_mul_of_nonneg_right (le_abs_self C) (abs_nonneg _) |
| 30 | have h3 : 0 ≤ |y - x| := abs_nonneg _ |
| 31 | nlinarith [abs_nonneg C] |
| 32 | |
| 33 | lemma shift_bound {K J : ℝ → ℝ} {a b w ε M : ℝ} (hw : 0 ≤ w) (hwb : a + w ≤ b) (hε : 0 ≤ ε) |
| 34 | (hKc : ContinuousOn K (Set.Icc (a + w) (b + w))) (hJc : ContinuousOn J (Set.Icc a b)) |
| 35 | (hKJ : ∀ z ∈ Set.Icc (a + w) b, |K z - J z| ≤ ε) |
| 36 | (hK : ∀ z ∈ Set.Icc b (b + w), |K z| ≤ M) (hJ : ∀ z ∈ Set.Icc a (a + w), |J z| ≤ M) : |
| 37 | |(∫ z in (a + w)..(b + w), K z) - ∫ z in a..b, J z| ≤ ε * (b - a) + 2 * M * w := by |
| 38 | have i1 : IntervalIntegrable K MeasureTheory.volume (a + w) b := |
| 39 | (hKc.mono (Set.Icc_subset_Icc le_rfl (by linarith))).intervalIntegrable_of_Icc hwb |
| 40 | have i2 : IntervalIntegrable K MeasureTheory.volume b (b + w) := |
| 41 | (hKc.mono (Set.Icc_subset_Icc (by linarith) le_rfl)).intervalIntegrable_of_Icc (by linarith) |
| 42 | have i3 : IntervalIntegrable J MeasureTheory.volume a (a + w) := |
| 43 | (hJc.mono (Set.Icc_subset_Icc le_rfl (by linarith))).intervalIntegrable_of_Icc (by linarith) |
| 44 | have i4 : IntervalIntegrable J MeasureTheory.volume (a + w) b := |
| 45 | (hJc.mono (Set.Icc_subset_Icc (by linarith) le_rfl)).intervalIntegrable_of_Icc hwb |
| 46 | rw [← intervalIntegral.integral_add_adjacent_intervals i1 i2, |
| 47 | ← intervalIntegral.integral_add_adjacent_intervals i3 i4] |
| 48 | have e1 := intervalIntegral.integral_sub i1 i4 |
| 49 | have habw : |b - (a + w)| = b - (a + w) := abs_of_nonneg (by linarith) |
| 50 | have habw2 : |b + w - b| = w := by rw [show b + w - b = w by ring]; exact abs_of_nonneg hw |
| 51 | have habw3 : |b + w - b| = w := by rw [show b + w - b = w by ring]; exact abs_of_nonneg hw |
| 52 | have habw4 : |a + w - a| = w := by rw [show a + w - a = w by ring]; exact abs_of_nonneg hw |
| 53 | have b1 : |∫ z in (a + w)..b, (K z - J z)| ≤ ε * (b - (a + w)) := by |
| 54 | have := intervalIntegral.norm_integral_le_of_norm_le_const (a := a + w) (b := b) (C := ε) |
| 55 | (f := fun z => K z - J z) (fun z hz => by |
| 56 | rw [Set.uIoc_of_le hwb] at hz |
| 57 | rw [Real.norm_eq_abs] |
| 58 | exact hKJ z ⟨hz.1.le, hz.2⟩) |
| 59 | rw [Real.norm_eq_abs, habw] at this |
| 60 | exact this |
| 61 | have b2 : |∫ z in b..(b + w), K z| ≤ M * w := by |
| 62 | have := intervalIntegral.norm_integral_le_of_norm_le_const (a := b) (b := b + w) (C := M) |
| 63 | (f := K) (fun z hz => by |
| 64 | rw [Set.uIoc_of_le (by linarith)] at hz |
| 65 | rw [Real.norm_eq_abs] |
| 66 | exact hK z ⟨hz.1.le, hz.2⟩) |
| 67 | rw [Real.norm_eq_abs, habw2] at this |
| 68 | exact this |
| 69 | have b3 : |∫ z in a..(a + w), J z| ≤ M * w := by |
| 70 | have := intervalIntegral.norm_integral_le_of_norm_le_const (a := a) (b := a + w) (C := M) |
| 71 | (f := J) (fun z hz => by |
| 72 | rw [Set.uIoc_of_le (by linarith)] at hz |
| 73 | rw [Real.norm_eq_abs] |
| 74 | exact hJ z ⟨hz.1.le, hz.2⟩) |
| 75 | rw [Real.norm_eq_abs, habw4] at this |
| 76 | exact this |
| 77 | have hsplit : (∫ z in (a + w)..b, K z) + (∫ z in b..(b + w), K z) |
| 78 | - ((∫ z in a..(a + w), J z) + ∫ z in (a + w)..b, J z) |
| 79 | = (∫ z in (a + w)..b, (K z - J z)) + (∫ z in b..(b + w), K z) - ∫ z in a..(a + w), J z := by |
| 80 | rw [e1]; ring |
| 81 | rw [hsplit] |
| 82 | have hεw : ε * (b - (a + w)) ≤ ε * (b - a) := mul_le_mul_of_nonneg_left (by linarith) hε |
| 83 | rw [abs_le] at b1 b2 b3 ⊢ |
| 84 | constructor <;> nlinarith [b1.1, b1.2, b2.1, b2.2, b3.1, b3.2] |
| 85 | |
| 86 | /-- Two differences of absolute values: `||A - B| - |A' - B'|| ≤ p + q` from `|A - A'| ≤ p`, `|B - B'| ≤ q`. -/ |
| 87 | lemma abs_abs_sub_le {A A' B B' p q : ℝ} (h1 : |A - A'| ≤ p) (h2 : |B - B'| ≤ q) : |
| 88 | |(|A - B| - |A' - B'|)| ≤ p + q := by |
| 89 | refine (abs_abs_sub_abs_le_abs_sub _ _).trans ?_ |
| 90 | rw [show A - B - (A' - B') = (A - A') - (B - B') by ring, abs_le] |
| 91 | have h1' := abs_le.1 h1 |
| 92 | have h2' := abs_le.1 h2 |
| 93 | constructor <;> linarith [h1'.1, h1'.2, h2'.1, h2'.2] |
| 94 | |
| 95 | /-- `||A - B| - |A - C|| ≤ |B - C|`. -/ |
| 96 | lemma abs_abs_sub_le_self {A B C : ℝ} : |(|A - B| - |A - C|)| ≤ |B - C| := by |
| 97 | refine (abs_abs_sub_abs_le_abs_sub _ _).trans (le_of_eq ?_) |
| 98 | rw [show A - B - (A - C) = C - B by ring, abs_sub_comm] |
| 99 | |
| 100 | end E424 |
| 101 | |