import PoincareLib.Geometry.CurveShortening.Comparison.IntrinsicComparison.Inward.RaySign import PoincareLib.Topology.Plane.Triangles.CapTransversality /-! # The actual fitted cap supplies positive endpoint chord directions Cap transversality gives nonzero physical cross products. The chord belongs to the closed Jordan region, so the proved inward-side criterion fixes their signs in the original loop orientation. Morgan--Tian context: Proposition 19.35, printed pp. 467-481. These project Jordan-region constructions supply the actual domains, boundary charts and finite faces used in its regional Gauss--Bonnet arguments. -/ noncomputable section set_option autoImplicit false set_option backward.isDefEq.respectTransparency false open Set Filter open scoped Topology ContDiff Matrix open Poincare.Topology.Plane.Curves Poincare.Topology.Plane.Triangles namespace PoincareMT private theorem transverse_inner_ne_zero {u w : AnnulusCoordinates} (hind : LinearIndependent ℝ (![u, w] : Fin 2 → AnnulusCoordinates)) : inner ℝ (quarterTurn u) w ≠ 0 := by let B := basisOfLinearIndependentOfCardEqFinrank hind (by simp) have horth : inner ℝ (quarterTurn u) u = 0 := by rw [real_inner_comm] exact inner_quarterTurn_self _ intro hw have hzero : (innerSL ℝ (quarterTurn u)).toLinearMap = 0 := by apply B.ext intro i fin_cases i <;> simp [B, coe_basisOfLinearIndependentOfCardEqFinrank, horth, hw] have hself : inner ℝ (quarterTurn u) (quarterTurn u) = 0 := congrArg (fun f : AnnulusCoordinates →ₗ[ℝ] ℝ => f (quarterTurn u)) hzero have hu : u = 0 := quarterTurn.injective (by simpa only [map_zero] using (inner_self_eq_zero.mp hself)) exact (hind.ne_zero (0 : Fin 2)) (by simpa using hu) /-- A fitted cap with the two original endpoint arcs supplies strictly inward chord directions at both ends. The signs are consequences of its actual placement and smooth cap transversality. Source: `proof-work/tasks/M64/reports/2026-09-24-signed-corner-chords.md`, Signed corner cap coordinates and external chord signs. -/ theorem m64Intrinsic_fitted_cap_chord_signs {gamma : ℝ → AnnulusCoordinates} (hg : ContDiff ℝ ∞ gamma) {T r : ℝ} (hend : gamma 0 = gamma T) (hinj : InjOn gamma (Ico 0 T)) (hregular : ∀ t ∈ Ioo (0 : ℝ) T, deriv gamma t ≠ 0) {U V : Set AnnulusCoordinates} (hU : IsOpen U) (hV : IsOpen V) (hdisj : Disjoint U V) (hfU : frontier U = gamma '' Icc 0 T) (hfV : frontier V = gamma '' Icc 0 T) (hray : ∀ t ∈ Ioo (0 : ℝ) T, ∀ᶠ z in 𝓝[>] (0 : ℝ), gamma t + z • quarterTurn (deriv gamma t) ∈ U) (hr : 0 < r) (hrT : r < T) (F : OpenPartialHomeomorph (ℝ × ℝ) AnnulusCoordinates) (hsource : {q : ℝ × ℝ | 0 ≤ q.1 ∧ 0 ≤ q.2 ∧ q.1 + q.2 ≤ r} ⊆ F.source) (hF : ContDiffOn ℝ ∞ F F.source) (hFi : ContDiffOn ℝ ∞ F.symm F.target) (hfirst : ∀ s ∈ Icc (0 : ℝ) r, F (s, 0) = gamma s) (hsecond : ∀ s ∈ Icc (0 : ℝ) r, F (0, s) = gamma (T - s)) (hchord : ∀ t : ℝ, F ((1 - t) * r, t * r) = (1 - t) • gamma r + t • gamma (T - r)) (hsub : F '' {q : ℝ × ℝ | 0 ≤ q.1 ∧ 0 ≤ q.2 ∧ q.1 + q.2 ≤ r} ⊆ closure U) : 0 < inner ℝ (quarterTurn (deriv gamma r)) (gamma (T - r) - gamma r) ∧ 0 < inner ℝ (quarterTurn (deriv gamma (T - r))) (gamma r - gamma (T - r)) := by have hrI : r ∈ Icc (0 : ℝ) r := ⟨hr.le, le_rfl⟩ have hchordF : ∀ t ∈ Icc (0 : ℝ) 1, F ((1 - t) * r, t * r) = (1 - t) • F (r, 0) + t • F (0, r) := by intro t _ rw [hfirst r hrI, hsecond r hrI] exact hchord t have hrev : ContDiff ℝ ∞ (fun s => gamma (T - s)) := hg.comp (contDiff_const.sub contDiff_id) obtain ⟨hleft, hright, _, _⟩ := cap_endpoint_transversality_of_axis_maps F hF hFi hr hsource hchordF ((hg.differentiable (by simp)) r) ((hrev.differentiable (by simp)) r) hfirst hsecond have hleftne := transverse_inner_ne_zero hleft have hrightne : inner ℝ (quarterTurn (deriv gamma (T - r))) (gamma r - gamma (T - r)) ≠ 0 := by have h := transverse_inner_ne_zero hright simpa only [deriv_comp_const_sub, map_neg, inner_neg_left, neg_ne_zero] using h have hleftRay : ∀ᶠ t in 𝓝[>] (0 : ℝ), gamma r + t • (gamma (T - r) - gamma r) ∈ closure U := by filter_upwards [Ioo_mem_nhdsGT (show (0 : ℝ) < 1 by norm_num)] with t ht apply hsub refine ⟨((1 - t) * r, t * r), ⟨mul_nonneg (sub_nonneg.mpr ht.2.le) hr.le, mul_nonneg ht.1.le hr.le, by dsimp; nlinarith⟩, ?_⟩ rw [hchord] module have hrightRay : ∀ᶠ t in 𝓝[>] (0 : ℝ), gamma (T - r) + t • (gamma r - gamma (T - r)) ∈ closure U := by filter_upwards [Ioo_mem_nhdsGT (show (0 : ℝ) < 1 by norm_num)] with t ht apply hsub refine ⟨((1 - (1 - t)) * r, (1 - t) * r), ⟨by nlinarith [mul_nonneg ht.1.le hr.le], mul_nonneg (sub_nonneg.mpr ht.2.le) hr.le, by dsimp; nlinarith⟩, ?_⟩ rw [hchord] module have hrT' : T - r ∈ Ioo (0 : ℝ) T := ⟨sub_pos.mpr hrT, sub_lt_self T hr⟩ exact ⟨m64Intrinsic_inward_ray_transverse_pos hg hend hinj ⟨hr, hrT⟩ (hregular r ⟨hr, hrT⟩) hU hV hdisj hfU hfV (hray r ⟨hr, hrT⟩) hleftne hleftRay, m64Intrinsic_inward_ray_transverse_pos hg hend hinj hrT' (hregular (T - r) hrT') hU hV hdisj hfU hfV (hray (T - r) hrT') hrightne hrightRay⟩ /-- Either axis of a signed-sector cap gives a strictly inward chord when that axis is the actual outgoing or reversed incoming loop arc. This also applies to the two external caps at a reflex corner. Source: `proof-work/tasks/M64/reports/2026-09-24-signed-corner-chords.md`, Signed corner cap coordinates and external chord signs. -/ theorem m64Intrinsic_cap_endpoint_chord_sign {gamma : ℝ → AnnulusCoordinates} (hg : ContDiff ℝ ∞ gamma) {T r : ℝ} (hend : gamma 0 = gamma T) (hinj : InjOn gamma (Ico 0 T)) (hregular : ∀ t ∈ Ioo (0 : ℝ) T, deriv gamma t ≠ 0) {U V : Set AnnulusCoordinates} (hU : IsOpen U) (hV : IsOpen V) (hdisj : Disjoint U V) (hfU : frontier U = gamma '' Icc 0 T) (hfV : frontier V = gamma '' Icc 0 T) (hray : ∀ t ∈ Ioo (0 : ℝ) T, ∀ᶠ z in 𝓝[>] (0 : ℝ), gamma t + z • quarterTurn (deriv gamma t) ∈ U) (hr : 0 < r) (hrT : r < T) (F : OpenPartialHomeomorph (ℝ × ℝ) AnnulusCoordinates) (hsource : {q : ℝ × ℝ | 0 ≤ q.1 ∧ 0 ≤ q.2 ∧ q.1 + q.2 ≤ r} ⊆ F.source) (hF : ContDiffOn ℝ ∞ F F.source) (hFi : ContDiffOn ℝ ∞ F.symm F.target) (hchord : ∀ t : ℝ, F ((1 - t) * r, t * r) = (1 - t) • F (r, 0) + t • F (0, r)) (hsub : F '' {q : ℝ × ℝ | 0 ≤ q.1 ∧ 0 ≤ q.2 ∧ q.1 + q.2 ≤ r} ⊆ closure U) (terminal vertical : Bool) (haxis : ∀ s ∈ Icc (0 : ℝ) r, F (if vertical then (0, s) else (s, 0)) = gamma (if terminal then T - s else s)) : 0 < inner ℝ (quarterTurn (deriv gamma (if terminal then T - r else r))) (if vertical then F (r, 0) - F (0, r) else F (0, r) - F (r, 0)) := by let b : ℝ → AnnulusCoordinates := fun s => F (if vertical then (0, s) else (s, 0)) let beta : ℝ → AnnulusCoordinates := fun s => gamma (if terminal then T - s else s) let p := if terminal then T - r else r let d := if vertical then F (r, 0) - F (0, r) else F (0, r) - F (r, 0) have hp : p ∈ Ioo (0 : ℝ) T := by cases terminal · exact ⟨hr, hrT⟩ · exact ⟨sub_pos.mpr hrT, sub_lt_self T hr⟩ have hrI : r ∈ Icc (0 : ℝ) r := ⟨hr.le, le_rfl⟩ have hbs : (if vertical then ((0 : ℝ), r) else (r, 0)) ∈ F.source := by apply hsource cases vertical <;> simp [hr.le] have hb : DifferentiableAt ℝ b r := by have hdF := (hF.contDiffAt (F.open_source.mem_nhds hbs)).differentiableAt (by simp) cases vertical · exact hdF.comp r (differentiableAt_id.prodMk (differentiableAt_const (0 : ℝ))) · exact hdF.comp r ((differentiableAt_const (0 : ℝ)).prodMk differentiableAt_id) have hbeta : ContDiff ℝ ∞ beta := by cases terminal · exact hg · exact hg.comp (contDiff_const.sub contDiff_id) have hderiv : deriv b r = deriv beta r := by rw [← hb.derivWithin (uniqueDiffOn_Icc hr r hrI), ← ((hbeta.differentiable (by simp)) r).derivWithin (uniqueDiffOn_Icc hr r hrI)] exact derivWithin_congr haxis (haxis r hrI) have hind : LinearIndependent ℝ (![deriv b r, d] : Fin 2 → AnnulusCoordinates) := by obtain ⟨hl, hr', _⟩ := cap_endpoint_transversality F hF hFi hr hsource (fun t _ => hchord t) cases vertical · exact hl · exact hr' have hnonzero : inner ℝ (quarterTurn (deriv gamma p)) d ≠ 0 := by have h := transverse_inner_ne_zero hind rw [hderiv] at h cases terminal · exact h · simpa only [beta, p, Bool.true_eq, ite_true, deriv_comp_const_sub, map_neg, inner_neg_left, neg_ne_zero] using h have hbase : (if vertical then F (0, r) else F (r, 0)) = gamma p := by cases vertical <;> exact haxis r hrI have hwray : ∀ᶠ t in 𝓝[>] (0 : ℝ), gamma p + t • d ∈ closure U := by filter_upwards [Ioo_mem_nhdsGT (show (0 : ℝ) < 1 by norm_num)] with t ht cases vertical · apply hsub refine ⟨((1 - t) * r, t * r), ⟨mul_nonneg (sub_nonneg.mpr ht.2.le) hr.le, mul_nonneg ht.1.le hr.le, by dsimp; nlinarith⟩, ?_⟩ rw [hchord, ← hbase] dsimp [d] module · apply hsub refine ⟨((1 - (1 - t)) * r, (1 - t) * r), ⟨by nlinarith [mul_nonneg ht.1.le hr.le], mul_nonneg (sub_nonneg.mpr ht.2.le) hr.le, by dsimp; nlinarith⟩, ?_⟩ rw [hchord, ← hbase] dsimp [d] module exact m64Intrinsic_inward_ray_transverse_pos hg hend hinj hp (hregular p hp) hU hV hdisj hfU hfV (hray p hp) hnonzero hwray end PoincareMT