Poincaré conjecture: the Lean proof, cleaned up together
The 2026 Lean proof of the Poincaré conjecture after Morgan and Tian, 3 million lines, cleaned up together: smaller, faster to build, more readable, the theorems unchanged

| 1 | /- |
| 2 | Provenance and modification notice (recorded 2026-09-29). |
| 3 | Source: https://github.com/qinz1yang/differential-geometry |
| 4 | DifferentialGeometry/Analysis/ODE/Flow/JointContinuity.lean |
| 5 | Comparison revision: 1b535dd102b94cc42b107cca27059687888f08b3. |
| 6 | Changes: Imports, module paths, and namespaces were adapted to the subject-organized PoincareLib library. |
| 7 | License: Apache-2.0. Source licenses and notices are retained under |
| 8 | PoincareConjecture/provenance/2026-09-29/licenses/. |
| 9 | See PoincareConjecture/MODIFICATIONS.md for the reviewed source mapping. |
| 10 | -/ |
| 11 | |
| 12 | /- |
| 13 | Copyright (c) 2026 The DifferentialGeometry contributors. |
| 14 | Released under Apache 2.0 license. |
| 15 | |
| 16 | Adapted from DifferentialGeometry/Analysis/ODE/Flow/JointContinuity.lean |
| 17 | at revision 1b535dd102b94cc42b107cca27059687888f08b3. |
| 18 | Original SHA-256: 27333b49e308d2b7723e08f9a0ec075099cee7d9586937bb1e7893561cafba45 |
| 19 | Changes: library paths and namespaces. |
| 20 | -/ |
| 21 | import PoincareLib.Analysis.ODE.LocalFlow.GlobalExistence |
| 22 | |
| 23 | |
| 24 | noncomputable section |
| 25 | |
| 26 | open Set Function Filter Metric Asymptotics Real |
| 27 | open scoped Topology NNReal ContDiff |
| 28 | |
| 29 | namespace Poincare.ODE.LocalFlow |
| 30 | |
| 31 | section JointContinuity |
| 32 | |
| 33 | variable {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] [CompleteSpace G] |
| 34 | |
| 35 | omit [CompleteSpace G] in |
| 36 | private theorem linearODE_apriori_bound |
| 37 | {A : ℝ → (G →L[ℝ] G)} {a b α β c M : ℝ} |
| 38 | (_hαβ : α ≤ β) (hα_lt : a < α) (hβ_lt : β < b) |
| 39 | (hc_mem : c ∈ Icc α β) (hM_nn : 0 ≤ M) |
| 40 | (hA_bd : ∀ s ∈ Icc α β, ‖A s‖ ≤ M) |
| 41 | {Z : ℝ → G} (hZ_deriv : ∀ t ∈ Ioo a b, HasDerivAt Z (A t (Z t)) t) |
| 42 | (t : ℝ) (ht : t ∈ Icc α β) : |
| 43 | ‖Z t‖ ≤ ‖Z c‖ * Real.exp (M * (β - α)) := by |
| 44 | have hsub : Icc α β ⊆ Ioo a b := fun s hs => |
| 45 | ⟨lt_of_lt_of_le hα_lt hs.1, lt_of_le_of_lt hs.2 hβ_lt⟩ |
| 46 | have hZ_cont : ContinuousOn Z (Icc α β) := fun s hs => |
| 47 | ((hZ_deriv s (hsub hs)).continuousAt).continuousWithinAt |
| 48 | have hZ_deriv_within_right : ∀ s ∈ Icc α β, HasDerivWithinAt Z (A s (Z s)) (Ici s) s := |
| 49 | fun s hs => ((hZ_deriv s (hsub hs)).hasDerivWithinAt) |
| 50 | have hZ'_bound : ∀ s ∈ Icc α β, ‖A s (Z s)‖ ≤ M * ‖Z s‖ + 0 := by |
| 51 | intro s hs |
| 52 | have h1 : ‖A s (Z s)‖ ≤ ‖A s‖ * ‖Z s‖ := (A s).le_opNorm (Z s) |
| 53 | have h2 : ‖A s‖ * ‖Z s‖ ≤ M * ‖Z s‖ := |
| 54 | mul_le_mul_of_nonneg_right (hA_bd s hs) (norm_nonneg _) |
| 55 | linarith |
| 56 | rcases le_total c t with hct | htc |
| 57 | · have hsub' : Icc c t ⊆ Icc α β := fun s hs => |
| 58 | ⟨le_trans hc_mem.1 hs.1, le_trans hs.2 ht.2⟩ |
| 59 | have hZ_cont_ct : ContinuousOn Z (Icc c t) := hZ_cont.mono hsub' |
| 60 | have hZ_deriv_within_right_ct : |
| 61 | ∀ s ∈ Ico c t, HasDerivWithinAt Z (A s (Z s)) (Ici s) s := |
| 62 | fun s hs => hZ_deriv_within_right s (hsub' (Ico_subset_Icc_self hs)) |
| 63 | have hZ'_bound_ct : ∀ s ∈ Ico c t, ‖A s (Z s)‖ ≤ M * ‖Z s‖ + 0 := |
| 64 | fun s hs => hZ'_bound s (hsub' (Ico_subset_Icc_self hs)) |
| 65 | have habs := norm_le_gronwallBound_of_norm_deriv_right_le hZ_cont_ct |
| 66 | hZ_deriv_within_right_ct (le_refl _) hZ'_bound_ct t (right_mem_Icc.mpr hct) |
| 67 | rw [gronwallBound_ε0] at habs |
| 68 | have h_mono : M * (t - c) ≤ M * (β - α) := by |
| 69 | apply mul_le_mul_of_nonneg_left _ hM_nn |
| 70 | linarith [ht.2, hc_mem.1] |
| 71 | have h_exp_mono : Real.exp (M * (t - c)) ≤ Real.exp (M * (β - α)) := |
| 72 | Real.exp_le_exp.mpr h_mono |
| 73 | calc ‖Z t‖ ≤ ‖Z c‖ * Real.exp (M * (t - c)) := habs |
| 74 | _ ≤ ‖Z c‖ * Real.exp (M * (β - α)) := |
| 75 | mul_le_mul_of_nonneg_left h_exp_mono (norm_nonneg _) |
| 76 | · set W : ℝ → G := fun s => Z (2 * c - s) with hW_def |
| 77 | have h_t_le_c : t ≤ c := htc |
| 78 | have h_2ctmt_ge_c : c ≤ 2 * c - t := by linarith |
| 79 | have h_dom_sub : ∀ s ∈ Icc c (2 * c - t), 2 * c - s ∈ Icc α β := by |
| 80 | intro s hs |
| 81 | refine ⟨?_, ?_⟩ |
| 82 | · have h_eq : 2 * c - (2 * c - t) = t := by ring |
| 83 | linarith [ht.1, hs.2] |
| 84 | · have h_eq : 2 * c - c = c := by ring |
| 85 | linarith [hc_mem.2, hs.1] |
| 86 | have hW_cont : ContinuousOn W (Icc c (2 * c - t)) := by |
| 87 | apply ContinuousOn.comp hZ_cont (s := Icc c (2 * c - t)) |
| 88 | (t := Icc α β) (f := fun s => 2 * c - s) |
| 89 | · exact (continuous_const.sub continuous_id).continuousOn |
| 90 | · exact h_dom_sub |
| 91 | have hW_deriv : ∀ s ∈ Icc c (2 * c - t), |
| 92 | HasDerivAt W (-(A (2 * c - s) (Z (2 * c - s)))) s := by |
| 93 | intro s hs |
| 94 | have hs_mem : (2 * c - s) ∈ Ioo a b := hsub (h_dom_sub s hs) |
| 95 | have hd : HasDerivAt Z (A (2 * c - s) (Z (2 * c - s))) (2 * c - s) := |
| 96 | hZ_deriv (2 * c - s) hs_mem |
| 97 | have h_chain : HasDerivAt (fun s => 2 * c - s) (-1 : ℝ) s := by |
| 98 | have h := (hasDerivAt_const s (2 * c)).sub (hasDerivAt_id s) |
| 99 | have hfun : (fun _ : ℝ => 2 * c) - id = fun r => 2 * c - r := by |
| 100 | funext r |
| 101 | rfl |
| 102 | rw [hfun, zero_sub] at h |
| 103 | exact h |
| 104 | have hd' : HasDerivAt (Z ∘ (fun s => 2 * c - s)) |
| 105 | ((-1 : ℝ) • A (2 * c - s) (Z (2 * c - s))) s := hd.scomp s h_chain |
| 106 | have hZ_eq : (Z ∘ (fun s => 2 * c - s)) = W := rfl |
| 107 | rw [hZ_eq] at hd' |
| 108 | have h_smul_eq : ((-1 : ℝ) • A (2 * c - s) (Z (2 * c - s)) : G) = |
| 109 | -(A (2 * c - s) (Z (2 * c - s))) := by |
| 110 | rw [neg_one_smul] |
| 111 | rw [h_smul_eq] at hd' |
| 112 | exact hd' |
| 113 | have hW_deriv_within_right : |
| 114 | ∀ s ∈ Icc c (2 * c - t), |
| 115 | HasDerivWithinAt W (-(A (2 * c - s) (Z (2 * c - s)))) (Ici s) s := |
| 116 | fun s hs => (hW_deriv s hs).hasDerivWithinAt |
| 117 | have hW'_bound : ∀ s ∈ Ico c (2 * c - t), |
| 118 | ‖-(A (2 * c - s) (Z (2 * c - s)))‖ ≤ M * ‖W s‖ + 0 := by |
| 119 | intro s hs |
| 120 | have h_in : 2 * c - s ∈ Icc α β := h_dom_sub s (Ico_subset_Icc_self hs) |
| 121 | have h1 : ‖A (2 * c - s) (Z (2 * c - s))‖ ≤ ‖A (2 * c - s)‖ * ‖Z (2 * c - s)‖ := |
| 122 | (A _).le_opNorm _ |
| 123 | have h2 : ‖A (2 * c - s)‖ * ‖Z (2 * c - s)‖ ≤ M * ‖Z (2 * c - s)‖ := |
| 124 | mul_le_mul_of_nonneg_right (hA_bd _ h_in) (norm_nonneg _) |
| 125 | have hWs_eq : W s = Z (2 * c - s) := rfl |
| 126 | rw [hWs_eq, norm_neg] |
| 127 | linarith |
| 128 | have hW_init : ‖W c‖ ≤ ‖Z c‖ := by |
| 129 | have h_eq : W c = Z c := by |
| 130 | change Z (2 * c - c) = Z c |
| 131 | have : 2 * c - c = c := by ring |
| 132 | rw [this] |
| 133 | rw [h_eq] |
| 134 | have habs := norm_le_gronwallBound_of_norm_deriv_right_le hW_cont |
| 135 | (fun s hs => hW_deriv_within_right s (Ico_subset_Icc_self hs)) hW_init |
| 136 | hW'_bound (2 * c - t) (right_mem_Icc.mpr h_2ctmt_ge_c) |
| 137 | rw [gronwallBound_ε0] at habs |
| 138 | have hW_eq_Z : W (2 * c - t) = Z t := by |
| 139 | change Z (2 * c - (2 * c - t)) = Z t |
| 140 | have : 2 * c - (2 * c - t) = t := by ring |
| 141 | rw [this] |
| 142 | rw [hW_eq_Z] at habs |
| 143 | have h_sub : (2 * c - t) - c = c - t := by ring |
| 144 | rw [h_sub] at habs |
| 145 | have h_mono : M * (c - t) ≤ M * (β - α) := by |
| 146 | apply mul_le_mul_of_nonneg_left _ hM_nn |
| 147 | linarith [hc_mem.2, ht.1] |
| 148 | have h_exp_mono : Real.exp (M * (c - t)) ≤ Real.exp (M * (β - α)) := |
| 149 | Real.exp_le_exp.mpr h_mono |
| 150 | calc ‖Z t‖ ≤ ‖Z c‖ * Real.exp (M * (c - t)) := habs |
| 151 | _ ≤ ‖Z c‖ * Real.exp (M * (β - α)) := |
| 152 | mul_le_mul_of_nonneg_left h_exp_mono (norm_nonneg _) |
| 153 | |
| 154 | omit [CompleteSpace G] in |
| 155 | theorem linearODE_gronwall_forward |
| 156 | {A₁ A₂ : ℝ → (G →L[ℝ] G)} {Z₁ Z₂ : ℝ → G} {h₀ β K η : ℝ} |
| 157 | (hK_nn : 0 ≤ K) |
| 158 | (hZ₁_cont : ContinuousOn Z₁ (Icc h₀ β)) |
| 159 | (hZ₂_cont : ContinuousOn Z₂ (Icc h₀ β)) |
| 160 | (hZ₁_deriv : ∀ t ∈ Icc h₀ β, HasDerivAt Z₁ (A₁ t (Z₁ t)) t) |
| 161 | (hZ₂_deriv : ∀ t ∈ Icc h₀ β, HasDerivAt Z₂ (A₂ t (Z₂ t)) t) |
| 162 | (hA₁_bd : ∀ t ∈ Icc h₀ β, ‖A₁ t‖ ≤ K) |
| 163 | (hdiff_bd : ∀ t ∈ Icc h₀ β, ‖(A₂ t - A₁ t) (Z₂ t)‖ ≤ η) |
| 164 | (t : ℝ) (ht : t ∈ Icc h₀ β) : |
| 165 | ‖Z₁ t - Z₂ t‖ ≤ gronwallBound ‖Z₁ h₀ - Z₂ h₀‖ K η (t - h₀) := by |
| 166 | let v : ℝ → G → G := fun s y => A₁ s y |
| 167 | let Knn : ℝ≥0 := ⟨K, hK_nn⟩ |
| 168 | have hv_lip : ∀ s ∈ Ico h₀ β, LipschitzOnWith Knn (v s) (univ : Set G) := by |
| 169 | intro s hs |
| 170 | have h_lip : LipschitzWith Knn (A₁ s) := |
| 171 | (A₁ s).lipschitzWith_of_opNorm_le (hA₁_bd s (Ico_subset_Icc_self hs)) |
| 172 | exact h_lip.lipschitzOnWith |
| 173 | have hZ₁_deriv_right : ∀ s ∈ Ico h₀ β, HasDerivWithinAt Z₁ (A₁ s (Z₁ s)) (Ici s) s := |
| 174 | fun s hs => (hZ₁_deriv s (Ico_subset_Icc_self hs)).hasDerivWithinAt |
| 175 | have hZ₂_deriv_right : ∀ s ∈ Ico h₀ β, HasDerivWithinAt Z₂ (A₂ s (Z₂ s)) (Ici s) s := |
| 176 | fun s hs => (hZ₂_deriv s (Ico_subset_Icc_self hs)).hasDerivWithinAt |
| 177 | have f_bound : ∀ s ∈ Ico h₀ β, dist (A₁ s (Z₁ s)) (v s (Z₁ s)) ≤ 0 := by |
| 178 | intro s _; change dist (A₁ s (Z₁ s)) (A₁ s (Z₁ s)) ≤ 0; rw [dist_self] |
| 179 | have g_bound : ∀ s ∈ Ico h₀ β, dist (A₂ s (Z₂ s)) (v s (Z₂ s)) ≤ η := by |
| 180 | intro s hs |
| 181 | have hsmem : s ∈ Icc h₀ β := Ico_subset_Icc_self hs |
| 182 | change dist (A₂ s (Z₂ s)) (A₁ s (Z₂ s)) ≤ η |
| 183 | rw [dist_eq_norm] |
| 184 | have h_eq : A₂ s (Z₂ s) - A₁ s (Z₂ s) = (A₂ s - A₁ s) (Z₂ s) := by |
| 185 | simp [sub_apply] |
| 186 | rw [h_eq] |
| 187 | exact hdiff_bd s hsmem |
| 188 | have hres := dist_le_of_approx_trajectories_ODE_of_mem (v := v) (s := fun _ => univ) |
| 189 | (K := Knn) (f := Z₁) (g := Z₂) (f' := fun s => A₁ s (Z₁ s)) |
| 190 | (g' := fun s => A₂ s (Z₂ s)) |
| 191 | (a := h₀) (b := β) (εf := 0) (εg := η) (δ := ‖Z₁ h₀ - Z₂ h₀‖) |
| 192 | hv_lip hZ₁_cont hZ₁_deriv_right f_bound (fun _ _ => mem_univ _) |
| 193 | hZ₂_cont hZ₂_deriv_right g_bound (fun _ _ => mem_univ _) |
| 194 | (by rw [dist_eq_norm]) |
| 195 | have := hres t ht |
| 196 | rw [dist_eq_norm] at this |
| 197 | rw [zero_add] at this |
| 198 | exact this |
| 199 | |
| 200 | omit [CompleteSpace G] in |
| 201 | theorem linearODE_gronwall_backward |
| 202 | {A₁ A₂ : ℝ → (G →L[ℝ] G)} {Z₁ Z₂ : ℝ → G} {α h₀ K η : ℝ} |
| 203 | (hαh₀ : α ≤ h₀) (hK_nn : 0 ≤ K) |
| 204 | (hZ₁_cont : ContinuousOn Z₁ (Icc α h₀)) |
| 205 | (hZ₂_cont : ContinuousOn Z₂ (Icc α h₀)) |
| 206 | (hZ₁_deriv : ∀ t ∈ Icc α h₀, HasDerivAt Z₁ (A₁ t (Z₁ t)) t) |
| 207 | (hZ₂_deriv : ∀ t ∈ Icc α h₀, HasDerivAt Z₂ (A₂ t (Z₂ t)) t) |
| 208 | (hA₁_bd : ∀ t ∈ Icc α h₀, ‖A₁ t‖ ≤ K) |
| 209 | (hdiff_bd : ∀ t ∈ Icc α h₀, ‖(A₂ t - A₁ t) (Z₂ t)‖ ≤ η) |
| 210 | (t : ℝ) (ht : t ∈ Icc α h₀) : |
| 211 | ‖Z₁ t - Z₂ t‖ ≤ gronwallBound ‖Z₁ h₀ - Z₂ h₀‖ K η (h₀ - t) := by |
| 212 | set W₁ : ℝ → G := fun s => Z₁ (2 * h₀ - s) |
| 213 | set W₂ : ℝ → G := fun s => Z₂ (2 * h₀ - s) |
| 214 | set B₁ : ℝ → (G →L[ℝ] G) := fun s => -A₁ (2 * h₀ - s) |
| 215 | set B₂ : ℝ → (G →L[ℝ] G) := fun s => -A₂ (2 * h₀ - s) |
| 216 | have h_h₀_le_2h₀mα : h₀ ≤ 2 * h₀ - α := by linarith |
| 217 | have h_dom_swap : ∀ s ∈ Icc h₀ (2 * h₀ - α), 2 * h₀ - s ∈ Icc α h₀ := by |
| 218 | intro s hs |
| 219 | refine ⟨by linarith [hs.2], by linarith [hs.1]⟩ |
| 220 | have hW₁_cont : ContinuousOn W₁ (Icc h₀ (2 * h₀ - α)) := by |
| 221 | apply ContinuousOn.comp hZ₁_cont (s := Icc h₀ (2 * h₀ - α)) |
| 222 | (t := Icc α h₀) (f := fun s => 2 * h₀ - s) |
| 223 | · exact (continuous_const.sub continuous_id).continuousOn |
| 224 | · exact h_dom_swap |
| 225 | have hW₂_cont : ContinuousOn W₂ (Icc h₀ (2 * h₀ - α)) := by |
| 226 | apply ContinuousOn.comp hZ₂_cont (s := Icc h₀ (2 * h₀ - α)) |
| 227 | (t := Icc α h₀) (f := fun s => 2 * h₀ - s) |
| 228 | · exact (continuous_const.sub continuous_id).continuousOn |
| 229 | · exact h_dom_swap |
| 230 | have hW₁_deriv : ∀ s ∈ Icc h₀ (2 * h₀ - α), HasDerivAt W₁ (B₁ s (W₁ s)) s := by |
| 231 | intro s hs |
| 232 | have hd : HasDerivAt Z₁ (A₁ (2 * h₀ - s) (Z₁ (2 * h₀ - s))) (2 * h₀ - s) := |
| 233 | hZ₁_deriv (2 * h₀ - s) (h_dom_swap s hs) |
| 234 | have h_chain : HasDerivAt (fun s => 2 * h₀ - s) (-1 : ℝ) s := by |
| 235 | have h := (hasDerivAt_const s (2 * h₀)).sub (hasDerivAt_id s) |
| 236 | have hfun : (fun _ : ℝ => 2 * h₀) - id = fun r => 2 * h₀ - r := by |
| 237 | funext r |
| 238 | rfl |
| 239 | rw [hfun, zero_sub] at h |
| 240 | exact h |
| 241 | have hd' : HasDerivAt (Z₁ ∘ (fun s => 2 * h₀ - s)) |
| 242 | ((-1 : ℝ) • A₁ (2 * h₀ - s) (Z₁ (2 * h₀ - s))) s := hd.scomp s h_chain |
| 243 | have hZ₁_eq : (Z₁ ∘ (fun s => 2 * h₀ - s)) = W₁ := rfl |
| 244 | rw [hZ₁_eq] at hd' |
| 245 | have hW₁s_eq : W₁ s = Z₁ (2 * h₀ - s) := rfl |
| 246 | have hB₁s_eq : B₁ s = -A₁ (2 * h₀ - s) := rfl |
| 247 | have h_eq : ((-1 : ℝ) • A₁ (2 * h₀ - s) (Z₁ (2 * h₀ - s)) : G) = B₁ s (W₁ s) := by |
| 248 | rw [hB₁s_eq, hW₁s_eq, neg_apply, neg_one_smul] |
| 249 | rw [h_eq] at hd' |
| 250 | exact hd' |
| 251 | have hW₂_deriv : ∀ s ∈ Icc h₀ (2 * h₀ - α), HasDerivAt W₂ (B₂ s (W₂ s)) s := by |
| 252 | intro s hs |
| 253 | have hd : HasDerivAt Z₂ (A₂ (2 * h₀ - s) (Z₂ (2 * h₀ - s))) (2 * h₀ - s) := |
| 254 | hZ₂_deriv (2 * h₀ - s) (h_dom_swap s hs) |
| 255 | have h_chain : HasDerivAt (fun s => 2 * h₀ - s) (-1 : ℝ) s := by |
| 256 | have h := (hasDerivAt_const s (2 * h₀)).sub (hasDerivAt_id s) |
| 257 | have hfun : (fun _ : ℝ => 2 * h₀) - id = fun r => 2 * h₀ - r := by |
| 258 | funext r |
| 259 | rfl |
| 260 | rw [hfun, zero_sub] at h |
| 261 | exact h |
| 262 | have hd' : HasDerivAt (Z₂ ∘ (fun s => 2 * h₀ - s)) |
| 263 | ((-1 : ℝ) • A₂ (2 * h₀ - s) (Z₂ (2 * h₀ - s))) s := hd.scomp s h_chain |
| 264 | have hZ₂_eq : (Z₂ ∘ (fun s => 2 * h₀ - s)) = W₂ := rfl |
| 265 | rw [hZ₂_eq] at hd' |
| 266 | have hW₂s_eq : W₂ s = Z₂ (2 * h₀ - s) := rfl |
| 267 | have hB₂s_eq : B₂ s = -A₂ (2 * h₀ - s) := rfl |
| 268 | have h_eq : ((-1 : ℝ) • A₂ (2 * h₀ - s) (Z₂ (2 * h₀ - s)) : G) = B₂ s (W₂ s) := by |
| 269 | rw [hB₂s_eq, hW₂s_eq, neg_apply, neg_one_smul] |
| 270 | rw [h_eq] at hd' |
| 271 | exact hd' |
| 272 | have hB₁_bd : ∀ s ∈ Icc h₀ (2 * h₀ - α), ‖B₁ s‖ ≤ K := by |
| 273 | intro s hs |
| 274 | change ‖-A₁ (2 * h₀ - s)‖ ≤ K |
| 275 | rw [norm_neg] |
| 276 | exact hA₁_bd _ (h_dom_swap s hs) |
| 277 | have hdiff_bd' : ∀ s ∈ Icc h₀ (2 * h₀ - α), ‖(B₂ s - B₁ s) (W₂ s)‖ ≤ η := by |
| 278 | intro s hs |
| 279 | have h_in : 2 * h₀ - s ∈ Icc α h₀ := h_dom_swap s hs |
| 280 | have h_eq : B₂ s - B₁ s = -(A₂ (2 * h₀ - s) - A₁ (2 * h₀ - s)) := by |
| 281 | change -A₂ (2 * h₀ - s) - (-A₁ (2 * h₀ - s)) = |
| 282 | -(A₂ (2 * h₀ - s) - A₁ (2 * h₀ - s)) |
| 283 | abel |
| 284 | rw [h_eq] |
| 285 | have hW₂s : W₂ s = Z₂ (2 * h₀ - s) := rfl |
| 286 | rw [hW₂s, neg_apply, norm_neg] |
| 287 | exact hdiff_bd _ h_in |
| 288 | have hres := linearODE_gronwall_forward (A₁ := B₁) (A₂ := B₂) (Z₁ := W₁) (Z₂ := W₂) |
| 289 | (h₀ := h₀) (β := 2 * h₀ - α) (K := K) (η := η) hK_nn |
| 290 | hW₁_cont hW₂_cont hW₁_deriv hW₂_deriv hB₁_bd hdiff_bd' (2 * h₀ - t) |
| 291 | ⟨by linarith [ht.2], by linarith [ht.1]⟩ |
| 292 | have h_W_init : ‖W₁ h₀ - W₂ h₀‖ = ‖Z₁ h₀ - Z₂ h₀‖ := by |
| 293 | have hW₁h : W₁ h₀ = Z₁ h₀ := by |
| 294 | change Z₁ (2 * h₀ - h₀) = Z₁ h₀ |
| 295 | have : 2 * h₀ - h₀ = h₀ := by ring |
| 296 | rw [this] |
| 297 | have hW₂h : W₂ h₀ = Z₂ h₀ := by |
| 298 | change Z₂ (2 * h₀ - h₀) = Z₂ h₀ |
| 299 | have : 2 * h₀ - h₀ = h₀ := by ring |
| 300 | rw [this] |
| 301 | rw [hW₁h, hW₂h] |
| 302 | have h_W_t : W₁ (2 * h₀ - t) - W₂ (2 * h₀ - t) = Z₁ t - Z₂ t := by |
| 303 | change Z₁ (2 * h₀ - (2 * h₀ - t)) - Z₂ (2 * h₀ - (2 * h₀ - t)) = Z₁ t - Z₂ t |
| 304 | have h_eq : 2 * h₀ - (2 * h₀ - t) = t := by ring |
| 305 | rw [h_eq] |
| 306 | have h_time : 2 * h₀ - t - h₀ = h₀ - t := by ring |
| 307 | rw [h_time, h_W_init] at hres |
| 308 | have h_lhs : ‖W₁ (2 * h₀ - t) - W₂ (2 * h₀ - t)‖ = ‖Z₁ t - Z₂ t‖ := by |
| 309 | rw [h_W_t] |
| 310 | rw [h_lhs] at hres |
| 311 | exact hres |
| 312 | |
| 313 | theorem linearODESolution_continuousOn |
| 314 | {F G : Type*} [NormedAddCommGroup F] [NormedAddCommGroup G] [NormedSpace ℝ G] [CompleteSpace G] |
| 315 | {A : F → ℝ → (G →L[ℝ] G)} {h₀ : ℝ} {Z₀ : F → G} |
| 316 | {a b : ℝ} (h₀_mem : h₀ ∈ Set.Ioo a b) |
| 317 | {U : Set F} (hU : IsOpen U) |
| 318 | (hA_cont : ContinuousOn (Function.uncurry A) (U ×ˢ Set.Ioo a b)) |
| 319 | (hZ₀_cont : ContinuousOn Z₀ U) : |
| 320 | ContinuousOn |
| 321 | (Function.uncurry (linearODESolution A a b h₀ Z₀)) |
| 322 | (U ×ˢ Set.Ioo a b) := by |
| 323 | set Z : F → ℝ → G := linearODESolution A a b h₀ Z₀ with hZ_def |
| 324 | have hZ_exists : ∀ x ∈ U, HasLinearODESolution A a b h₀ Z₀ x := fun x hx => |
| 325 | hasLinearODESolution_of_continuousOn h₀_mem hA_cont hx |
| 326 | have hZ_deriv : ∀ x ∈ U, ∀ t ∈ Ioo a b, HasDerivAt (Z x) (A x t (Z x t)) t := by |
| 327 | intro x hx t ht |
| 328 | exact linearODESolution_hasDerivAt_of_hasSolution A a b h₀ Z₀ (hZ_exists x hx) ht |
| 329 | have hZ_cont_t : ∀ x ∈ U, ContinuousOn (Z x) (Ioo a b) := by |
| 330 | intro x hx t ht |
| 331 | exact ((hZ_deriv x hx t ht).continuousAt).continuousWithinAt |
| 332 | have hZ_init : ∀ x, Z x h₀ = Z₀ x := fun x => linearODESolution_init A a b h₀ Z₀ x |
| 333 | have hS_open : IsOpen (U ×ˢ Set.Ioo a b : Set (F × ℝ)) := hU.prod isOpen_Ioo |
| 334 | refine IsOpen.continuousOn_iff hS_open |>.mpr ?_ |
| 335 | rintro ⟨x₀, t₀⟩ hp |
| 336 | obtain ⟨hx₀U, ht₀⟩ := hp |
| 337 | rw [Metric.continuousAt_iff] |
| 338 | intro ε hε |
| 339 | set α : ℝ := (a + min t₀ h₀) / 2 with hα_def |
| 340 | set β : ℝ := (b + max t₀ h₀) / 2 with hβ_def |
| 341 | have hα_lt_min : α < min t₀ h₀ := by |
| 342 | rw [hα_def] |
| 343 | have := lt_min ht₀.1 h₀_mem.1 |
| 344 | linarith |
| 345 | have hα_lt_a : a < α := by |
| 346 | rw [hα_def] |
| 347 | have := lt_min ht₀.1 h₀_mem.1 |
| 348 | linarith |
| 349 | have hmax_lt_β : max t₀ h₀ < β := by |
| 350 | rw [hβ_def] |
| 351 | have := max_lt ht₀.2 h₀_mem.2 |
| 352 | linarith |
| 353 | have hβ_lt_b : β < b := by |
| 354 | rw [hβ_def] |
| 355 | have := max_lt ht₀.2 h₀_mem.2 |
| 356 | linarith |
| 357 | have hα_le_t₀ : α ≤ t₀ := le_of_lt (lt_of_lt_of_le hα_lt_min (min_le_left _ _)) |
| 358 | have hα_le_h₀ : α ≤ h₀ := le_of_lt (lt_of_lt_of_le hα_lt_min (min_le_right _ _)) |
| 359 | have ht₀_le_β : t₀ ≤ β := le_of_lt (lt_of_le_of_lt (le_max_left _ _) hmax_lt_β) |
| 360 | have hh₀_le_β : h₀ ≤ β := le_of_lt (lt_of_le_of_lt (le_max_right _ _) hmax_lt_β) |
| 361 | have hα_le_β : α ≤ β := le_trans hα_le_h₀ hh₀_le_β |
| 362 | have hIcc_sub_Ioo : Icc α β ⊆ Ioo a b := fun s hs => |
| 363 | ⟨lt_of_lt_of_le hα_lt_a hs.1, lt_of_le_of_lt hs.2 hβ_lt_b⟩ |
| 364 | have ht₀_mem_Icc : t₀ ∈ Icc α β := ⟨hα_le_t₀, ht₀_le_β⟩ |
| 365 | have hh₀_mem_Icc : h₀ ∈ Icc α β := ⟨hα_le_h₀, hh₀_le_β⟩ |
| 366 | have hIcc_compact : IsCompact (Icc α β) := isCompact_Icc |
| 367 | obtain ⟨M, hM_nn, hM_x₀_bd⟩ : |
| 368 | ∃ M : ℝ, 0 ≤ M ∧ ∀ s ∈ Icc α β, ‖A x₀ s‖ ≤ M := by |
| 369 | have hAx₀_cont : ContinuousOn (A x₀) (Icc α β) := by |
| 370 | have hAx₀_uncurry : ContinuousOn (A x₀) (Ioo a b) := |
| 371 | ContinuousOn.uncurry_left x₀ hx₀U hA_cont |
| 372 | exact hAx₀_uncurry.mono (fun s hs => hIcc_sub_Ioo hs) |
| 373 | have hnorm_Ax₀ : ContinuousOn (fun s => ‖A x₀ s‖) (Icc α β) := |
| 374 | continuous_norm.comp_continuousOn hAx₀_cont |
| 375 | have hne : (Icc α β).Nonempty := ⟨h₀, hh₀_mem_Icc⟩ |
| 376 | rcases hIcc_compact.exists_isMaxOn hne hnorm_Ax₀ with ⟨τ, _, hτ_max⟩ |
| 377 | exact ⟨‖A x₀ τ‖, norm_nonneg _, fun s hs => hτ_max hs⟩ |
| 378 | have hS_open' : IsOpen (U ×ˢ Set.Ioo a b : Set (F × ℝ)) := hS_open |
| 379 | have h_open_set : IsOpen |
| 380 | {q : F × ℝ | q.1 ∈ U ∧ q.2 ∈ Ioo a b ∧ ‖A q.1 q.2‖ < M + 1} := by |
| 381 | set normA : F × ℝ → ℝ := fun p => ‖A p.1 p.2‖ |
| 382 | have hnormA_cont : ContinuousOn normA (U ×ˢ Set.Ioo a b) := |
| 383 | continuous_norm.comp_continuousOn hA_cont |
| 384 | have hpre_open : IsOpen ((U ×ˢ Set.Ioo a b) ∩ normA ⁻¹' Set.Iio (M + 1)) := |
| 385 | hnormA_cont.isOpen_inter_preimage hS_open' isOpen_Iio |
| 386 | have h_eq : {q : F × ℝ | q.1 ∈ U ∧ q.2 ∈ Ioo a b ∧ ‖A q.1 q.2‖ < M + 1} = |
| 387 | (U ×ˢ Set.Ioo a b) ∩ normA ⁻¹' Set.Iio (M + 1) := by |
| 388 | ext q |
| 389 | constructor |
| 390 | · rintro ⟨h1, h2, h3⟩; exact ⟨⟨h1, h2⟩, h3⟩ |
| 391 | · rintro ⟨⟨h1, h2⟩, h3⟩; exact ⟨h1, h2, h3⟩ |
| 392 | rw [h_eq] |
| 393 | exact hpre_open |
| 394 | have h_slice_in_open : ({x₀} : Set F) ×ˢ Icc α β ⊆ |
| 395 | {q : F × ℝ | q.1 ∈ U ∧ q.2 ∈ Ioo a b ∧ ‖A q.1 q.2‖ < M + 1} := by |
| 396 | intro q hq |
| 397 | obtain ⟨hq1, hq2⟩ := hq |
| 398 | rw [Set.mem_singleton_iff] at hq1 |
| 399 | subst hq1 |
| 400 | refine ⟨hx₀U, hIcc_sub_Ioo hq2, ?_⟩ |
| 401 | exact lt_of_le_of_lt (hM_x₀_bd q.2 hq2) (by linarith) |
| 402 | obtain ⟨W₀, V, hW₀_open, _hV_open, hx₀_W₀, hIcc_V, hWV_sub⟩ := |
| 403 | generalized_tube_lemma isCompact_singleton hIcc_compact h_open_set h_slice_in_open |
| 404 | have hx₀_W₀' : x₀ ∈ W₀ := hx₀_W₀ (Set.mem_singleton x₀) |
| 405 | set Wopen : Set F := W₀ ∩ U with hWopen_def |
| 406 | have hWopen_open : IsOpen Wopen := hW₀_open.inter hU |
| 407 | have hx₀_Wopen : x₀ ∈ Wopen := ⟨hx₀_W₀', hx₀U⟩ |
| 408 | have hWopen_sub_U : Wopen ⊆ U := fun x hx => hx.2 |
| 409 | have hMbd_W : ∀ x ∈ Wopen, ∀ s ∈ Icc α β, ‖A x s‖ ≤ M + 1 := by |
| 410 | intro x hx s hs |
| 411 | have hx_W₀ : x ∈ W₀ := hx.1 |
| 412 | have hs_V : s ∈ V := hIcc_V hs |
| 413 | have hxs_sub : (x, s) ∈ W₀ ×ˢ V := ⟨hx_W₀, hs_V⟩ |
| 414 | have := hWV_sub hxs_sub |
| 415 | exact le_of_lt this.2.2 |
| 416 | set K : ℝ := M + 1 with hK_def |
| 417 | have hK_nn : 0 ≤ K := by rw [hK_def]; linarith |
| 418 | have hZ_apriori : ∀ x ∈ Wopen, ∀ t ∈ Icc α β, |
| 419 | ‖Z x t‖ ≤ ‖Z₀ x‖ * Real.exp (K * (β - α)) := by |
| 420 | intro x hx t ht |
| 421 | have hZxh₀_eq : Z x h₀ = Z₀ x := hZ_init x |
| 422 | have hZx_deriv_all : ∀ s ∈ Ioo a b, HasDerivAt (Z x) (A x s (Z x s)) s := |
| 423 | hZ_deriv x (hWopen_sub_U hx) |
| 424 | have habs := linearODE_apriori_bound (A := A x) (a := a) (b := b) (α := α) (β := β) |
| 425 | (c := h₀) (M := K) hα_le_β hα_lt_a hβ_lt_b hh₀_mem_Icc hK_nn |
| 426 | (fun s hs => hMbd_W x hx s hs) hZx_deriv_all t ht |
| 427 | rw [hZxh₀_eq] at habs |
| 428 | exact habs |
| 429 | set T : ℝ := β - α with hT_def |
| 430 | have hT_nn : 0 ≤ T := by rw [hT_def]; linarith |
| 431 | have hgb_eq_zero : gronwallBound 0 K 0 T = 0 := by simp [gronwallBound_ε0_δ0] |
| 432 | have hK_pos : 0 < K := by rw [hK_def]; linarith |
| 433 | have hK_ne : K ≠ 0 := ne_of_gt hK_pos |
| 434 | have hgb_cont : Continuous (fun p : ℝ × ℝ => gronwallBound p.1 K p.2 T) := by |
| 435 | simp only [gronwallBound_of_K_ne_0 hK_ne] |
| 436 | fun_prop |
| 437 | have hgb_tendsto : Tendsto (fun p : ℝ × ℝ => gronwallBound p.1 K p.2 T) |
| 438 | (𝓝 (0, 0)) (𝓝 0) := by |
| 439 | have := hgb_cont.continuousAt (x := (0, 0)) |
| 440 | rw [ContinuousAt, hgb_eq_zero] at this |
| 441 | exact this |
| 442 | rw [Metric.tendsto_nhds] at hgb_tendsto |
| 443 | obtain ⟨ρ, hρ_pos, hρ_bd⟩ := Metric.mem_nhds_iff.mp (hgb_tendsto (ε / 2) (by linarith)) |
| 444 | set δ_target : ℝ := ρ / 2 with hδ_target_def |
| 445 | set η_target : ℝ := ρ / 2 with hη_target_def |
| 446 | have hδ_target_pos : 0 < δ_target := by rw [hδ_target_def]; linarith |
| 447 | have hη_target_pos : 0 < η_target := by rw [hη_target_def]; linarith |
| 448 | have hbd_gb : ∀ δ η : ℝ, 0 ≤ δ → 0 ≤ η → δ < δ_target → η < η_target → |
| 449 | gronwallBound δ K η T < ε / 2 := by |
| 450 | intro δ η hδ_nn hη_nn hδ_lt hη_lt |
| 451 | have h_pair_mem : (δ, η) ∈ Metric.ball ((0 : ℝ), (0 : ℝ)) ρ := by |
| 452 | rw [Metric.mem_ball, Prod.dist_eq] |
| 453 | have h1 : dist δ 0 < ρ := by |
| 454 | rw [Real.dist_0_eq_abs, abs_of_nonneg hδ_nn] |
| 455 | exact lt_of_lt_of_le hδ_lt (by rw [hδ_target_def]; linarith) |
| 456 | have h2 : dist η 0 < ρ := by |
| 457 | rw [Real.dist_0_eq_abs, abs_of_nonneg hη_nn] |
| 458 | exact lt_of_lt_of_le hη_lt (by rw [hη_target_def]; linarith) |
| 459 | exact max_lt h1 h2 |
| 460 | have hd := hρ_bd h_pair_mem |
| 461 | simp only [Set.mem_ofPred_eq] at hd |
| 462 | rw [Real.dist_0_eq_abs] at hd |
| 463 | exact lt_of_le_of_lt (le_abs_self _) hd |
| 464 | set R' : ℝ := (‖Z₀ x₀‖ + 1) * Real.exp (K * T) with hR'_def |
| 465 | have hR'_pos : 0 < R' := by |
| 466 | rw [hR'_def] |
| 467 | apply mul_pos |
| 468 | · linarith [norm_nonneg (Z₀ x₀)] |
| 469 | · exact Real.exp_pos _ |
| 470 | set η_op : ℝ := η_target / (R' + 1) with hη_op_def |
| 471 | have hη_op_pos : 0 < η_op := div_pos hη_target_pos (by linarith) |
| 472 | set g : F × ℝ → ℝ := fun p => ‖A p.1 p.2 - A x₀ p.2‖ |
| 473 | have hg_cont : ContinuousOn g (U ×ˢ Set.Ioo a b) := by |
| 474 | have h_swap : ContinuousOn (fun p : F × ℝ => A x₀ p.2) (U ×ˢ Set.Ioo a b) := by |
| 475 | have h_A_x₀_cont : ContinuousOn (A x₀) (Ioo a b) := |
| 476 | ContinuousOn.uncurry_left x₀ hx₀U hA_cont |
| 477 | exact h_A_x₀_cont.comp continuousOn_snd (fun _ hp => hp.2) |
| 478 | have : ContinuousOn (fun p : F × ℝ => A p.1 p.2 - A x₀ p.2) (U ×ˢ Set.Ioo a b) := |
| 479 | hA_cont.sub h_swap |
| 480 | exact continuous_norm.comp_continuousOn this |
| 481 | have hg_x₀ : ∀ s, g (x₀, s) = 0 := fun s => by |
| 482 | change ‖A x₀ s - A x₀ s‖ = 0 |
| 483 | rw [sub_self, norm_zero] |
| 484 | have h_gopen : IsOpen |
| 485 | {p : F × ℝ | p.1 ∈ U ∧ p.2 ∈ Ioo a b ∧ g p < η_op} := by |
| 486 | have hpre_open : IsOpen ((U ×ˢ Set.Ioo a b) ∩ g ⁻¹' Set.Iio η_op) := |
| 487 | hg_cont.isOpen_inter_preimage hS_open' isOpen_Iio |
| 488 | have h_eq : {p : F × ℝ | p.1 ∈ U ∧ p.2 ∈ Ioo a b ∧ g p < η_op} = |
| 489 | (U ×ˢ Set.Ioo a b) ∩ g ⁻¹' Set.Iio η_op := by |
| 490 | ext p; constructor |
| 491 | · rintro ⟨h1, h2, h3⟩; exact ⟨⟨h1, h2⟩, h3⟩ |
| 492 | · rintro ⟨⟨h1, h2⟩, h3⟩; exact ⟨h1, h2, h3⟩ |
| 493 | rw [h_eq] |
| 494 | exact hpre_open |
| 495 | have h_slice_in_gopen : ({x₀} : Set F) ×ˢ Icc α β ⊆ |
| 496 | {p : F × ℝ | p.1 ∈ U ∧ p.2 ∈ Ioo a b ∧ g p < η_op} := by |
| 497 | intro p hp |
| 498 | obtain ⟨hp1, hp2⟩ := hp |
| 499 | rw [Set.mem_singleton_iff] at hp1; subst hp1 |
| 500 | refine ⟨hx₀U, hIcc_sub_Ioo hp2, ?_⟩ |
| 501 | rw [hg_x₀]; exact hη_op_pos |
| 502 | obtain ⟨W₁, V₁, hW₁_open, _hV₁_open, hx₀_W₁, hIccα_V₁, hW₁V₁_sub⟩ := |
| 503 | generalized_tube_lemma isCompact_singleton hIcc_compact h_gopen h_slice_in_gopen |
| 504 | have hx₀_W₁' : x₀ ∈ W₁ := hx₀_W₁ (Set.mem_singleton x₀) |
| 505 | have hZ₀_cont_at : ContinuousAt Z₀ x₀ := (hZ₀_cont x₀ hx₀U).continuousAt (hU.mem_nhds hx₀U) |
| 506 | have hZ₀_diff_eps : ∀ᶠ x in 𝓝 x₀, ‖Z₀ x - Z₀ x₀‖ < δ_target := by |
| 507 | have h_tendsto_diff : Tendsto (fun x => Z₀ x - Z₀ x₀) (𝓝 x₀) (𝓝 0) := by |
| 508 | have h_tendsto : Tendsto Z₀ (𝓝 x₀) (𝓝 (Z₀ x₀)) := hZ₀_cont_at |
| 509 | have := h_tendsto.sub (tendsto_const_nhds (x := Z₀ x₀)) |
| 510 | simpa using this |
| 511 | rw [Metric.tendsto_nhds] at h_tendsto_diff |
| 512 | have := h_tendsto_diff δ_target hδ_target_pos |
| 513 | filter_upwards [this] with x hx |
| 514 | have h_eq : dist (Z₀ x - Z₀ x₀) 0 = ‖Z₀ x - Z₀ x₀‖ := by |
| 515 | rw [dist_zero_right] |
| 516 | rwa [h_eq] at hx |
| 517 | have hZ₀_norm_eps : ∀ᶠ x in 𝓝 x₀, ‖Z₀ x‖ < ‖Z₀ x₀‖ + 1 := by |
| 518 | have h_norm_cont : ContinuousAt (fun x => ‖Z₀ x‖) x₀ := |
| 519 | continuous_norm.continuousAt.comp hZ₀_cont_at |
| 520 | have h_one_pos : ‖Z₀ x₀‖ < ‖Z₀ x₀‖ + 1 := by linarith |
| 521 | have h_open : IsOpen {y : ℝ | y < ‖Z₀ x₀‖ + 1} := isOpen_Iio |
| 522 | have hmem : ‖Z₀ x₀‖ ∈ {y : ℝ | y < ‖Z₀ x₀‖ + 1} := h_one_pos |
| 523 | exact h_norm_cont.preimage_mem_nhds (h_open.mem_nhds hmem) |
| 524 | obtain ⟨W_diff, hZ₀_diff_in, hW_diff_open, hx₀_W_diff⟩ := _root_.mem_nhds_iff.mp hZ₀_diff_eps |
| 525 | obtain ⟨W_norm, hZ₀_norm_in, hW_norm_open, hx₀_W_norm⟩ := _root_.mem_nhds_iff.mp hZ₀_norm_eps |
| 526 | set Wparam : Set F := Wopen ∩ W₁ ∩ W_diff ∩ W_norm with hWparam_def |
| 527 | have hWparam_open : IsOpen Wparam := |
| 528 | ((hWopen_open.inter hW₁_open).inter hW_diff_open).inter hW_norm_open |
| 529 | have hx₀_Wparam : x₀ ∈ Wparam := |
| 530 | ⟨⟨⟨hx₀_Wopen, hx₀_W₁'⟩, hx₀_W_diff⟩, hx₀_W_norm⟩ |
| 531 | have hWparam_sub_Wopen : Wparam ⊆ Wopen := fun x hx => hx.1.1.1 |
| 532 | have hWparam_sub_U : Wparam ⊆ U := fun x hx => hWopen_sub_U (hWparam_sub_Wopen hx) |
| 533 | have hWparam_diff_lt : ∀ x ∈ Wparam, ‖Z₀ x - Z₀ x₀‖ < δ_target := |
| 534 | fun x hx => hZ₀_diff_in hx.1.2 |
| 535 | have hWparam_norm_lt : ∀ x ∈ Wparam, ‖Z₀ x‖ < ‖Z₀ x₀‖ + 1 := |
| 536 | fun x hx => hZ₀_norm_in hx.2 |
| 537 | have hWparam_g_lt : ∀ x ∈ Wparam, ∀ s ∈ Icc α β, ‖A x s - A x₀ s‖ < η_op := by |
| 538 | intro x hx s hs |
| 539 | have hx_W₁ : x ∈ W₁ := hx.1.1.2 |
| 540 | have hs_V₁ : s ∈ V₁ := hIccα_V₁ hs |
| 541 | have hxs_sub : (x, s) ∈ W₁ ×ˢ V₁ := ⟨hx_W₁, hs_V₁⟩ |
| 542 | exact (hW₁V₁_sub hxs_sub).2.2 |
| 543 | have hbd_diff : ∀ x ∈ Wparam, ∀ t ∈ Icc α β, |
| 544 | ‖Z x t - Z x₀ t‖ ≤ gronwallBound ‖Z₀ x - Z₀ x₀‖ K η_target |t - h₀| := by |
| 545 | intro x hx t ht |
| 546 | have hxU : x ∈ U := hWparam_sub_U hx |
| 547 | have h_Zxs_bd : ∀ s ∈ Icc α β, ‖Z x s‖ ≤ R' := by |
| 548 | intro s hs |
| 549 | have hZx_apr := hZ_apriori x (hWparam_sub_Wopen hx) s hs |
| 550 | have hZ₀x_lt : ‖Z₀ x‖ < ‖Z₀ x₀‖ + 1 := hWparam_norm_lt x hx |
| 551 | have hexp_pos : 0 < Real.exp (K * T) := Real.exp_pos _ |
| 552 | have h_bound : ‖Z₀ x‖ * Real.exp (K * T) ≤ (‖Z₀ x₀‖ + 1) * Real.exp (K * T) := |
| 553 | mul_le_mul_of_nonneg_right hZ₀x_lt.le hexp_pos.le |
| 554 | exact le_trans hZx_apr h_bound |
| 555 | have hAx_bd : ∀ s ∈ Icc α β, ‖A x s‖ ≤ K := |
| 556 | fun s hs => hMbd_W x (hWparam_sub_Wopen hx) s hs |
| 557 | have hAx₀_bd : ∀ s ∈ Icc α β, ‖A x₀ s‖ ≤ K := |
| 558 | fun s hs => le_trans (hM_x₀_bd s hs) (by linarith) |
| 559 | have hZx_cont : ContinuousOn (Z x) (Icc α β) := by |
| 560 | intro s hs; exact (hZ_cont_t x hxU s (hIcc_sub_Ioo hs)).mono (fun u hu => hIcc_sub_Ioo hu) |
| 561 | have hZx₀_cont : ContinuousOn (Z x₀) (Icc α β) := by |
| 562 | intro s hs; exact (hZ_cont_t x₀ hx₀U s (hIcc_sub_Ioo hs)).mono (fun u hu => hIcc_sub_Ioo hu) |
| 563 | have hZx_deriv_Icc : ∀ s ∈ Icc α β, HasDerivAt (Z x) (A x s (Z x s)) s := |
| 564 | fun s hs => hZ_deriv x hxU s (hIcc_sub_Ioo hs) |
| 565 | have hZx₀_deriv_Icc : ∀ s ∈ Icc α β, HasDerivAt (Z x₀) (A x₀ s (Z x₀ s)) s := |
| 566 | fun s hs => hZ_deriv x₀ hx₀U s (hIcc_sub_Ioo hs) |
| 567 | have hdiff_bd_full : ∀ s ∈ Icc α β, ‖(A x s - A x₀ s) (Z x s)‖ ≤ η_target := by |
| 568 | intro s hs |
| 569 | have h1 : ‖(A x s - A x₀ s) (Z x s)‖ ≤ ‖A x s - A x₀ s‖ * ‖Z x s‖ := |
| 570 | (A x s - A x₀ s).le_opNorm _ |
| 571 | have h2 : ‖A x s - A x₀ s‖ * ‖Z x s‖ ≤ η_op * R' := by |
| 572 | have hop_lt : ‖A x s - A x₀ s‖ < η_op := hWparam_g_lt x hx s hs |
| 573 | have hZ_lt : ‖Z x s‖ ≤ R' := h_Zxs_bd s hs |
| 574 | have h_nn_Z : 0 ≤ ‖Z x s‖ := norm_nonneg _ |
| 575 | have h_op_nn : 0 ≤ ‖A x s - A x₀ s‖ := norm_nonneg _ |
| 576 | have h_η_op_nn : 0 ≤ η_op := le_of_lt hη_op_pos |
| 577 | have h_R'_nn : 0 ≤ R' := le_of_lt hR'_pos |
| 578 | calc ‖A x s - A x₀ s‖ * ‖Z x s‖ |
| 579 | ≤ η_op * ‖Z x s‖ := mul_le_mul_of_nonneg_right hop_lt.le h_nn_Z |
| 580 | _ ≤ η_op * R' := mul_le_mul_of_nonneg_left hZ_lt h_η_op_nn |
| 581 | have h3 : η_op * R' ≤ η_target := by |
| 582 | rw [hη_op_def] |
| 583 | rw [div_mul_eq_mul_div, mul_comm] |
| 584 | rw [div_le_iff₀ (by linarith)] |
| 585 | have hR'_nn : 0 ≤ R' := le_of_lt hR'_pos |
| 586 | have h_η_t_nn : 0 ≤ η_target := le_of_lt hη_target_pos |
| 587 | have h_le : R' ≤ R' + 1 := by linarith |
| 588 | calc R' * η_target ≤ (R' + 1) * η_target := |
| 589 | mul_le_mul_of_nonneg_right h_le h_η_t_nn |
| 590 | _ = η_target * (R' + 1) := by ring |
| 591 | linarith |
| 592 | rcases le_total h₀ t with hht | hth |
| 593 | · have hh₀_le_t : h₀ ≤ t := hht |
| 594 | have hZ₁_cont_ht : ContinuousOn (Z x₀) (Icc h₀ β) := by |
| 595 | intro s hs |
| 596 | exact (hZx₀_cont s ⟨le_trans hα_le_h₀ hs.1, hs.2⟩).mono |
| 597 | (fun u hu => ⟨le_trans hα_le_h₀ hu.1, hu.2⟩) |
| 598 | have hZ₂_cont_ht : ContinuousOn (Z x) (Icc h₀ β) := by |
| 599 | intro s hs |
| 600 | exact (hZx_cont s ⟨le_trans hα_le_h₀ hs.1, hs.2⟩).mono |
| 601 | (fun u hu => ⟨le_trans hα_le_h₀ hu.1, hu.2⟩) |
| 602 | have hZ₁_deriv_ht : ∀ s ∈ Icc h₀ β, HasDerivAt (Z x₀) (A x₀ s (Z x₀ s)) s := |
| 603 | fun s hs => hZx₀_deriv_Icc s ⟨le_trans hα_le_h₀ hs.1, hs.2⟩ |
| 604 | have hZ₂_deriv_ht : ∀ s ∈ Icc h₀ β, HasDerivAt (Z x) (A x s (Z x s)) s := |
| 605 | fun s hs => hZx_deriv_Icc s ⟨le_trans hα_le_h₀ hs.1, hs.2⟩ |
| 606 | have hAx₀_bd_ht : ∀ s ∈ Icc h₀ β, ‖A x₀ s‖ ≤ K := |
| 607 | fun s hs => hAx₀_bd s ⟨le_trans hα_le_h₀ hs.1, hs.2⟩ |
| 608 | have hdiff_bd_ht : ∀ s ∈ Icc h₀ β, ‖(A x s - A x₀ s) (Z x s)‖ ≤ η_target := |
| 609 | fun s hs => hdiff_bd_full s ⟨le_trans hα_le_h₀ hs.1, hs.2⟩ |
| 610 | have hres := linearODE_gronwall_forward (A₁ := A x₀) (A₂ := A x) (Z₁ := Z x₀) (Z₂ := Z x) |
| 611 | hK_nn hZ₁_cont_ht hZ₂_cont_ht hZ₁_deriv_ht hZ₂_deriv_ht |
| 612 | hAx₀_bd_ht hdiff_bd_ht t ⟨hh₀_le_t, ht.2⟩ |
| 613 | have h_init_eq : ‖Z x₀ h₀ - Z x h₀‖ = ‖Z₀ x - Z₀ x₀‖ := by |
| 614 | rw [hZ_init x, hZ_init x₀] |
| 615 | rw [← norm_neg]; congr 1; abel |
| 616 | rw [h_init_eq] at hres |
| 617 | have h_lhs_eq : ‖Z x t - Z x₀ t‖ = ‖Z x₀ t - Z x t‖ := by |
| 618 | rw [← norm_neg]; congr 1; abel |
| 619 | rw [h_lhs_eq] |
| 620 | have h_abs : |t - h₀| = t - h₀ := abs_of_nonneg (by linarith) |
| 621 | rw [h_abs] |
| 622 | exact hres |
| 623 | · have ht_le_h₀ : t ≤ h₀ := hth |
| 624 | have hZ₁_cont_th : ContinuousOn (Z x₀) (Icc α h₀) := by |
| 625 | intro s hs |
| 626 | exact (hZx₀_cont s ⟨hs.1, le_trans hs.2 hh₀_le_β⟩).mono |
| 627 | (fun u hu => ⟨hu.1, le_trans hu.2 hh₀_le_β⟩) |
| 628 | have hZ₂_cont_th : ContinuousOn (Z x) (Icc α h₀) := by |
| 629 | intro s hs |
| 630 | exact (hZx_cont s ⟨hs.1, le_trans hs.2 hh₀_le_β⟩).mono |
| 631 | (fun u hu => ⟨hu.1, le_trans hu.2 hh₀_le_β⟩) |
| 632 | have hZ₁_deriv_th : ∀ s ∈ Icc α h₀, HasDerivAt (Z x₀) (A x₀ s (Z x₀ s)) s := |
| 633 | fun s hs => hZx₀_deriv_Icc s ⟨hs.1, le_trans hs.2 hh₀_le_β⟩ |
| 634 | have hZ₂_deriv_th : ∀ s ∈ Icc α h₀, HasDerivAt (Z x) (A x s (Z x s)) s := |
| 635 | fun s hs => hZx_deriv_Icc s ⟨hs.1, le_trans hs.2 hh₀_le_β⟩ |
| 636 | have hAx₀_bd_th : ∀ s ∈ Icc α h₀, ‖A x₀ s‖ ≤ K := |
| 637 | fun s hs => hAx₀_bd s ⟨hs.1, le_trans hs.2 hh₀_le_β⟩ |
| 638 | have hdiff_bd_th : ∀ s ∈ Icc α h₀, ‖(A x s - A x₀ s) (Z x s)‖ ≤ η_target := |
| 639 | fun s hs => hdiff_bd_full s ⟨hs.1, le_trans hs.2 hh₀_le_β⟩ |
| 640 | have hres := linearODE_gronwall_backward (A₁ := A x₀) (A₂ := A x) (Z₁ := Z x₀) (Z₂ := Z x) |
| 641 | hα_le_h₀ hK_nn hZ₁_cont_th hZ₂_cont_th hZ₁_deriv_th hZ₂_deriv_th |
| 642 | hAx₀_bd_th hdiff_bd_th t ⟨ht.1, ht_le_h₀⟩ |
| 643 | have h_init_eq : ‖Z x₀ h₀ - Z x h₀‖ = ‖Z₀ x - Z₀ x₀‖ := by |
| 644 | rw [hZ_init x, hZ_init x₀] |
| 645 | rw [← norm_neg]; congr 1; abel |
| 646 | rw [h_init_eq] at hres |
| 647 | have h_lhs_eq : ‖Z x t - Z x₀ t‖ = ‖Z x₀ t - Z x t‖ := by |
| 648 | rw [← norm_neg]; congr 1; abel |
| 649 | rw [h_lhs_eq] |
| 650 | have h_abs : |t - h₀| = h₀ - t := by |
| 651 | rw [abs_of_nonpos (by linarith)]; ring |
| 652 | rw [h_abs] |
| 653 | exact hres |
| 654 | have hZx₀_cont_Ioo : ContinuousOn (Z x₀) (Ioo a b) := hZ_cont_t x₀ hx₀U |
| 655 | have hZx₀_cont_at : ContinuousAt (Z x₀) t₀ := |
| 656 | (hZx₀_cont_Ioo t₀ ht₀).continuousAt (isOpen_Ioo.mem_nhds ht₀) |
| 657 | have hZx₀_tendsto : Tendsto (Z x₀) (𝓝 t₀) (𝓝 (Z x₀ t₀)) := hZx₀_cont_at |
| 658 | rw [Metric.tendsto_nhds] at hZx₀_tendsto |
| 659 | obtain ⟨δ_t, hδ_t_pos, hδ_t_bd⟩ := |
| 660 | Metric.mem_nhds_iff.mp (hZx₀_tendsto (ε / 2) (by linarith)) |
| 661 | obtain ⟨ρ_param, hρ_param_pos, hρ_param_sub⟩ := |
| 662 | Metric.isOpen_iff.mp hWparam_open x₀ hx₀_Wparam |
| 663 | set δ_time : ℝ := min δ_t (min (β - t₀) (t₀ - α)) with hδ_time_def |
| 664 | have hδ_time_pos : 0 < δ_time := by |
| 665 | rw [hδ_time_def] |
| 666 | refine lt_min hδ_t_pos (lt_min ?_ ?_) |
| 667 | · linarith [lt_of_le_of_lt (le_max_left _ _) hmax_lt_β] |
| 668 | · linarith [lt_of_lt_of_le hα_lt_min (min_le_left _ _)] |
| 669 | set δ_final : ℝ := min ρ_param δ_time with hδ_final_def |
| 670 | have hδ_final_pos : 0 < δ_final := |
| 671 | lt_min hρ_param_pos hδ_time_pos |
| 672 | use δ_final |
| 673 | refine ⟨hδ_final_pos, ?_⟩ |
| 674 | intro p hp |
| 675 | obtain ⟨x, t⟩ := p |
| 676 | rw [Prod.dist_eq] at hp |
| 677 | have hdx : dist x x₀ < δ_final := lt_of_le_of_lt (le_max_left _ _) hp |
| 678 | have hdt : dist t t₀ < δ_final := lt_of_le_of_lt (le_max_right _ _) hp |
| 679 | have hx_param : x ∈ Wparam := hρ_param_sub |
| 680 | (Metric.mem_ball.mpr (lt_of_lt_of_le hdx (min_le_left _ _))) |
| 681 | have hdt_t : dist t t₀ < δ_t := |
| 682 | lt_of_lt_of_le hdt (le_trans (min_le_right _ _) (min_le_left _ _)) |
| 683 | have hdt_β : dist t t₀ < β - t₀ := |
| 684 | lt_of_lt_of_le hdt (le_trans (min_le_right _ _) (le_trans (min_le_right _ _) (min_le_left _ _))) |
| 685 | have hdt_α : dist t t₀ < t₀ - α := |
| 686 | lt_of_lt_of_le hdt (le_trans (min_le_right _ _) |
| 687 | (le_trans (min_le_right _ _) (min_le_right _ _))) |
| 688 | have ht_Icc : t ∈ Icc α β := by |
| 689 | rw [Real.dist_eq] at hdt_β hdt_α |
| 690 | refine ⟨?_, ?_⟩ |
| 691 | · have := abs_lt.mp hdt_α |
| 692 | linarith [this.1] |
| 693 | · have := abs_lt.mp hdt_β |
| 694 | linarith [this.2] |
| 695 | have h_triangle : ‖Z x t - Z x₀ t₀‖ ≤ ‖Z x t - Z x₀ t‖ + ‖Z x₀ t - Z x₀ t₀‖ := by |
| 696 | have h_eq : Z x t - Z x₀ t₀ = (Z x t - Z x₀ t) + (Z x₀ t - Z x₀ t₀) := by abel |
| 697 | rw [h_eq] |
| 698 | exact norm_add_le _ _ |
| 699 | have h_t_piece : ‖Z x₀ t - Z x₀ t₀‖ < ε / 2 := by |
| 700 | have hd := hδ_t_bd (Metric.mem_ball.mpr hdt_t) |
| 701 | simp only [Set.mem_ofPred_eq] at hd |
| 702 | rw [dist_eq_norm] at hd |
| 703 | exact hd |
| 704 | have hbd := hbd_diff x hx_param t ht_Icc |
| 705 | have h_init_bd : ‖Z₀ x - Z₀ x₀‖ < δ_target := hWparam_diff_lt x hx_param |
| 706 | have h_t_h0_le_T : |t - h₀| ≤ T := by |
| 707 | rw [hT_def] |
| 708 | rcases le_total h₀ t with hht | hth |
| 709 | · rw [abs_of_nonneg (by linarith)]; linarith [ht_Icc.2, hh₀_mem_Icc.1] |
| 710 | · rw [abs_of_nonpos (by linarith)]; linarith [ht_Icc.1, hh₀_mem_Icc.2] |
| 711 | have h_t_h0_nn : 0 ≤ |t - h₀| := abs_nonneg _ |
| 712 | have h_init_nn : 0 ≤ ‖Z₀ x - Z₀ x₀‖ := norm_nonneg _ |
| 713 | have h_eta_nn : 0 ≤ η_target := le_of_lt hη_target_pos |
| 714 | have h_gb_mono := gronwallBound_mono h_init_nn h_eta_nn hK_nn h_t_h0_le_T |
| 715 | have hbd' : ‖Z x t - Z x₀ t‖ ≤ gronwallBound ‖Z₀ x - Z₀ x₀‖ K η_target T := |
| 716 | le_trans hbd h_gb_mono |
| 717 | have h_param_piece : ‖Z x t - Z x₀ t‖ < ε / 2 := by |
| 718 | have h_gb_lt : gronwallBound ‖Z₀ x - Z₀ x₀‖ K η_target T < ε / 2 := by |
| 719 | have h_gb_mono_eps : gronwallBound ‖Z₀ x - Z₀ x₀‖ K η_target T ≤ |
| 720 | gronwallBound δ_target K η_target T := by |
| 721 | simp only [gronwallBound_of_K_ne_0 hK_ne] |
| 722 | have h_exp_pos : 0 < Real.exp (K * T) := Real.exp_pos _ |
| 723 | have h_init_le : ‖Z₀ x - Z₀ x₀‖ ≤ δ_target := le_of_lt h_init_bd |
| 724 | have h_mul_le : ‖Z₀ x - Z₀ x₀‖ * Real.exp (K * T) ≤ δ_target * Real.exp (K * T) := |
| 725 | mul_le_mul_of_nonneg_right h_init_le h_exp_pos.le |
| 726 | linarith |
| 727 | have h_inner_lt : gronwallBound δ_target K η_target T < ε / 2 := by |
| 728 | have h_pair_in_ball : (δ_target, η_target) ∈ Metric.ball ((0 : ℝ), (0 : ℝ)) ρ := by |
| 729 | rw [Metric.mem_ball, Prod.dist_eq] |
| 730 | have h1 : dist δ_target 0 < ρ := by |
| 731 | rw [Real.dist_0_eq_abs, abs_of_nonneg (le_of_lt hδ_target_pos)] |
| 732 | rw [hδ_target_def]; linarith |
| 733 | have h2 : dist η_target 0 < ρ := by |
| 734 | rw [Real.dist_0_eq_abs, abs_of_nonneg (le_of_lt hη_target_pos)] |
| 735 | rw [hη_target_def]; linarith |
| 736 | exact max_lt h1 h2 |
| 737 | have hd := hρ_bd h_pair_in_ball |
| 738 | simp only [Set.mem_ofPred_eq] at hd |
| 739 | rw [Real.dist_0_eq_abs] at hd |
| 740 | exact lt_of_le_of_lt (le_abs_self _) hd |
| 741 | exact lt_of_le_of_lt h_gb_mono_eps h_inner_lt |
| 742 | exact lt_of_le_of_lt hbd' h_gb_lt |
| 743 | have h_dist_eq : dist (Z x t) (Z x₀ t₀) = ‖Z x t - Z x₀ t₀‖ := dist_eq_norm _ _ |
| 744 | change dist (Z x t) (Z x₀ t₀) < ε |
| 745 | rw [h_dist_eq] |
| 746 | calc ‖Z x t - Z x₀ t₀‖ |
| 747 | ≤ ‖Z x t - Z x₀ t‖ + ‖Z x₀ t - Z x₀ t₀‖ := h_triangle |
| 748 | _ < ε / 2 + ε / 2 := add_lt_add h_param_piece h_t_piece |
| 749 | _ = ε := by ring |
| 750 | |
| 751 | end JointContinuity |
| 752 | |
| 753 | end Poincare.ODE.LocalFlow |
| 754 | |
| 755 | end |