import PoincareLib.Geometry.CurveShortening.Comparison.Compatibility.SourceNames import PoincareLib.Geometry.CurveShortening.Ramp.Approximation.Sampled.PolygonLength import PoincareLib.Geometry.CurveShortening.Comparison.PolygonApproximation.Polygon.CellBoundaryNull /-! # Quantitative distance to a sampled polygon A loop with speed at most `S` stays within `2 * S * cellLength` of any minimizing polygon through its sampled vertices. Each term in the triangle inequality is bounded by the original cell arc. Periodicity extends the estimate from the fundamental interval to every real angular parameter. Morgan--Tian context: Section 19.4, Definition 19.18 and Claims 19.19-19.22, printed pp. 450-453. -/ set_option autoImplicit false set_option backward.isDefEq.respectTransparency false open Set MeasureTheory Bundle open scoped Manifold ContDiff Topology ENNReal intervalIntegral universe u namespace PoincareMT variable {n : β„•} {M : Type u} [TopologicalSpace M] [ChartedSpace (EuclideanSpace ℝ (Fin n)) M] [IsManifold (𝓑 n) ∞ M] /-- Bound the endpoint distance of a C1 subarc by its speed bound times parameter length. Source: Auxiliary step for MT Definition 19.18 and Claims 19.19/19.22, pp. 450-453; project construction in `proof-work/tasks/M64/reports/2026-09-23-static-polygon.md`. -/ theorem m64_c1_subarc_edist_le_speed (g : RiemannianMetric n M) {gamma : ℝ β†’ M} (hgamma : ContMDiff π“˜(ℝ, ℝ) (𝓑 n) 1 gamma) {S s t : ℝ} (hs : 0 ≀ s) (hst : s ≀ t) (ht : t ≀ curvePeriod) (hbound : βˆ€ x ∈ Icc (0 : ℝ) curvePeriod, g.tangentNorm (gamma x) (curveVelocity gamma x) ≀ S) : g.edist (gamma s) (gamma t) ≀ ENNReal.ofReal (S * (t - s)) := by have hd := g.edist_le_pathELength_of_mem_Icc hgamma.contMDiffOn (show t ∈ Icc s t from ⟨hst, le_rfl⟩) rw [M04.pathELength_eq_ofReal_integral_pathSpeed g hgamma hst] at hd apply hd.trans (ENNReal.ofReal_le_ofReal ?_) have hi := intervalIntegral.integral_mono_on (ΞΌ := volume) hst ((M04.continuous_pathSpeed g hgamma).intervalIntegrable s t) (continuous_const.intervalIntegrable s t) (fun x hx => hbound x ⟨hs.trans hx.1, hx.2.trans ht⟩) simpa only [M04.pathSpeed, curveVelocity, intervalIntegral.integral_const, smul_eq_mul, mul_comm] using hi /-- The endpoint distance of an initial part of a minimizing side is at most its full length. Source: Auxiliary step for MT Definition 19.18 and Claims 19.19/19.22, pp. 450-453; project construction in `proof-work/tasks/M64/reports/2026-09-23-static-polygon.md`. -/ theorem m64_minimizing_side_prefix_edist_le {g : RiemannianMetric n M} {D : LeviCivitaData g} {ell s : ℝ} {p q : M} (side : M63MinimizingGeodesicSide g D ell p q) (hs : s ∈ Icc (0 : ℝ) ell) : g.edist p (side.map s) ≀ g.edist p q := by have hside : ContMDiffOn π“˜(ℝ, ℝ) (𝓑 n) 1 side.map (Icc (0 : ℝ) ell) := (side.smooth.of_le (m := 1) (by norm_num)).mono side.interval_subset have hd := g.edist_le_pathELength_of_mem_Icc hside hs simpa only [side.start, side.minimizing] using hd /-- On a closed cell the source loop and sampled polygon are within twice the source arc-length bound. Source: Auxiliary step for MT Definition 19.18 and Claims 19.19/19.22, pp. 450-453; project construction in `proof-work/tasks/M64/reports/2026-09-23-static-polygon.md`. -/ theorem m64_sampled_polygon_cell_edist_le {g : RiemannianMetric n M} {D : LeviCivitaData g} {N : β„•} (hN : 0 < N) (polygon : M63GeodesicPolygon g D N) {gamma : ℝ β†’ M} (hgamma : ContMDiff π“˜(ℝ, ℝ) (𝓑 n) 1 gamma) (hperiodic : Function.Periodic gamma curvePeriod) (hvertices : βˆ€ j : Fin N, polygon.vertices j = gamma (m63CellLeft N j)) {S : ℝ} (hS : 0 ≀ S) (hbound : βˆ€ x ∈ Icc (0 : ℝ) curvePeriod, g.tangentNorm (gamma x) (curveVelocity gamma x) ≀ S) (j : Fin N) {s : ℝ} (hs : s ∈ Icc (0 : ℝ) (m63CellLength N)) : g.edist (gamma (m63CellLeft N j + s)) (polygon.map (m63CellLeft N j + s)) ≀ ENNReal.ofReal (2 * S * m63CellLength N) := by let : Bundle.RiemannianBundle (TangentSpace (𝓑 n) : M β†’ Type _) := ⟨g.toRiemannianMetric⟩ have hell : 0 < m63CellLength N := m63CellLength_pos hN have hleft : 0 ≀ m63CellLeft N j := mul_nonneg (Nat.cast_nonneg _) hell.le have hj : (j.val : ℝ) + 1 ≀ N := by exact_mod_cast Nat.succ_le_of_lt j.isLt have hright : m63CellLeft N j + m63CellLength N ≀ curvePeriod := by calc _ = ((j.val : ℝ) + 1) * m63CellLength N := by dsimp only [m63CellLeft] ring _ ≀ (N : ℝ) * m63CellLength N := mul_le_mul_of_nonneg_right hj hell.le _ = curvePeriod := m63_count_mul_cellLength hN have hadj : g.edist (polygon.vertices j) (polygon.vertices (finRotate N j)) ≀ ENNReal.ofReal (S * m63CellLength N) := by rw [hvertices j, hvertices (finRotate N j), m63PeriodicLoop_cell_finish hperiodic hN j] simpa only [add_sub_cancel_left] using m64_c1_subarc_edist_le_speed g hgamma hleft (le_add_of_nonneg_right hell.le) hright hbound have hside : g.edist (polygon.vertices j) ((polygon.side j).map s) ≀ ENNReal.ofReal (S * m63CellLength N) := (m64_minimizing_side_prefix_edist_le (polygon.side j) hs).trans hadj have horiginal : g.edist (polygon.vertices j) (gamma (m63CellLeft N j + s)) ≀ ENNReal.ofReal (S * m63CellLength N) := by rw [hvertices j] have h := m64_c1_subarc_edist_le_speed g hgamma hleft (le_add_of_nonneg_right hs.1) (by linarith [hs.2]) hbound apply h.trans (ENNReal.ofReal_le_ofReal ?_) rw [add_sub_cancel_left] exact mul_le_mul_of_nonneg_left hs.2 hS rw [polygon.cell_agreement j s hs] have htri : g.edist (gamma (m63CellLeft N j + s)) ((polygon.side j).map s) ≀ g.edist (gamma (m63CellLeft N j + s)) (polygon.vertices j) + g.edist (polygon.vertices j) ((polygon.side j).map s) := Manifold.riemannianEDist_triangle have hrev : g.edist (gamma (m63CellLeft N j + s)) (polygon.vertices j) = g.edist (polygon.vertices j) (gamma (m63CellLeft N j + s)) := Manifold.riemannianEDist_comm rw [hrev] at htri apply (htri.trans (add_le_add horiginal hside)).trans_eq rw [← ENNReal.ofReal_add (mul_nonneg hS hell.le) (mul_nonneg hS hell.le)] congr 1 ring /-- Periodicity extends the quantitative sampled-polygon distance bound to every real angle. Source: Auxiliary step for MT Definition 19.18 and Claims 19.19/19.22, pp. 450-453; project construction in `proof-work/tasks/M64/reports/2026-09-23-static-polygon.md`. -/ theorem m64_sampled_polygon_edist_le {g : RiemannianMetric n M} {D : LeviCivitaData g} {N : β„•} (hN : 0 < N) (polygon : M63GeodesicPolygon g D N) {gamma : ℝ β†’ M} (hgamma : ContMDiff π“˜(ℝ, ℝ) (𝓑 n) 1 gamma) (hperiodic : Function.Periodic gamma curvePeriod) (hvertices : βˆ€ j : Fin N, polygon.vertices j = gamma (m63CellLeft N j)) {S : ℝ} (hS : 0 ≀ S) (hbound : βˆ€ x ∈ Icc (0 : ℝ) curvePeriod, g.tangentNorm (gamma x) (curveVelocity gamma x) ≀ S) : βˆ€ x : ℝ, g.edist (gamma x) (polygon.map x) ≀ ENNReal.ofReal (2 * S * m63CellLength N) := by have hon {x : ℝ} (hx : x ∈ Icc (0 : ℝ) curvePeriod) : g.edist (gamma x) (polygon.map x) ≀ ENNReal.ofReal (2 * S * m63CellLength N) := by obtain ⟨j, hj⟩ := m64_polygon_cells_cover hN (annulusPoint x 0) (show annulusPoint x 0 ∈ m64AnnulusDomain from ⟨hx.1, hx.2, le_rfl, zero_le_one⟩) change m63CellLeft N j ≀ x ∧ x ≀ m63CellLeft N j + m63CellLength N ∧ 0 ≀ (0 : ℝ) ∧ (0 : ℝ) ≀ 1 at hj have hs : x - m63CellLeft N j ∈ Icc (0 : ℝ) (m63CellLength N) := by constructor <;> linarith [hj.1, hj.2.1] have hh := m64_sampled_polygon_cell_edist_le hN polygon hgamma hperiodic hvertices hS hbound j hs rw [show m63CellLeft N j + (x - m63CellLeft N j) = x by ring] at hh exact hh intro x let k : β„€ := Int.floor (x / curvePeriod) let y : ℝ := x - (k : ℝ) * curvePeriod have hy : y ∈ Icc (0 : ℝ) curvePeriod := by have h0 := (le_div_iffβ‚€ Real.two_pi_pos).mp (Int.floor_le (x / curvePeriod)) have h1 := (div_lt_iffβ‚€ Real.two_pi_pos).mp (Int.lt_floor_add_one (x / curvePeriod)) dsimp only [y, k] dsimp only [curvePeriod] at h0 h1 ⊒ constructor <;> linarith only [h0, h1] have hx : x = y + (k : ℝ) * curvePeriod := by dsimp only [y]; ring rw [hx, hperiodic.int_mul k y, polygon.periodic.int_mul k y] exact hon hy end PoincareMT