import PoincareLib.Geometry.CurveShortening.Evolution.Flow import PoincareLib.Geometry.RicciFlow.CurveShortening.Connection.FrameForms import Mathlib.Geometry.Manifold.MFDeriv.NormedSpace import Mathlib.Analysis.Calculus.Deriv.Comp /-! # Metric compatibility along a parameterized curve The frozen local-frame pullback derivative obeys the metric product rule, including for stationary or self-intersecting curves. This is the spatial calculus used in Morgan--Tian Lemma 19.6, pp. 441-442, and the 2015 correction, Lemma 0.1, p. 3. The frame bridge is derived in `references/ricci-flow/mapher/curve-evolution/derivations/2026-09-19-pullback-metric.md`. -/ set_option autoImplicit false set_option maxSynthPendingDepth 3 open scoped Manifold ContDiff Bundle Topology open Filter universe u namespace PoincareMT.M62 open PoincareMT.ReducedLengthMinimum.Variation.Geometry variable {n : β„•} {M : Type u} [TopologicalSpace M] [ChartedSpace (EuclideanSpace ℝ (Fin n)) M] [IsManifold (𝓑 n) ∞ M] set_option backward.isDefEq.respectTransparency false in /-- Metric compatibility for the actual frozen-frame pullback derivative. Morgan--Tian Lemma 19.6, pp. 441-442; correction Lemma 0.1, p. 3. -/ theorem hasDerivAt_metric_pairing {g : RiemannianMetric n M} (D : LeviCivitaData g) {Ξ³ : ℝ β†’ M} {Y Z : (s : ℝ) β†’ TangentSpace (𝓑 n) (Ξ³ s)} {x : ℝ} (hΞ³ : MDifferentiableAt (π“˜(ℝ, ℝ)) (𝓑 n) Ξ³ x) (hY : MDifferentiableAt (π“˜(ℝ, ℝ)) ((𝓑 n).prod (𝓑 n)) (fun s ↦ (⟨γ s, Y s⟩ : TangentBundle (𝓑 n) M)) x) (hZ : MDifferentiableAt (π“˜(ℝ, ℝ)) ((𝓑 n).prod (𝓑 n)) (fun s ↦ (⟨γ s, Z s⟩ : TangentBundle (𝓑 n) M)) x) : HasDerivAt (fun s ↦ g.inner (Ξ³ s) (Y s) (Z s)) (g.inner (Ξ³ x) (rampHorizontalCovariantDerivative D Ξ³ Y x) (Z x) + g.inner (Ξ³ x) (Y x) (rampHorizontalCovariantDerivative D Ξ³ Z x)) x := by let : Bundle.RiemannianBundle (TangentSpace (𝓑 n) : M β†’ Type _) := ⟨g.toRiemannianMetric⟩ let p := Ξ³ x let e := trivializationAt (EuclideanSpace ℝ (Fin n)) (TangentSpace (𝓑 n)) p have hp : p ∈ e.baseSet := FiberBundle.mem_baseSet_trivializationAt' p let y : ℝ β†’ EuclideanSpace ℝ (Fin n) := fun s ↦ (e ⟨γ s, Y s⟩).2 let z : ℝ β†’ EuclideanSpace ℝ (Fin n) := fun s ↦ (e ⟨γ s, Z s⟩).2 let v : ℝ β†’ TangentSpace (𝓑 n) p := fun s ↦ e.symmL ℝ p (y s) let w : ℝ β†’ TangentSpace (𝓑 n) p := fun s ↦ e.symmL ℝ p (z s) have hy : DifferentiableAt ℝ y x := by rw [mdifferentiableAt_totalSpace] at hY exact hY.2.differentiableAt have hz : DifferentiableAt ℝ z x := by rw [mdifferentiableAt_totalSpace] at hZ exact hZ.2.differentiableAt have hv : HasDerivAt v (e.symmL ℝ p (deriv y x)) x := (e.symmL ℝ p).hasFDerivAt.comp_hasDerivAt x hy.hasDerivAt have hw : HasDerivAt w (e.symmL ℝ p (deriv z x)) x := (e.symmL ℝ p).hasFDerivAt.comp_hasDerivAt x hz.hasDerivAt have hvx : v x = Y x := by change e.symmL ℝ p (e ⟨p, Y x⟩).2 = Y x rw [← e.continuousLinearMapAt_apply_of_mem ℝ hp] exact e.symmL_continuousLinearMapAt hp _ have hwx : w x = Z x := by change e.symmL ℝ p (e ⟨p, Z x⟩).2 = Z x rw [← e.continuousLinearMapAt_apply_of_mem ℝ hp] exact e.symmL_continuousLinearMapAt hp _ let G := frameMetricForm g p have hG : MDifferentiableAt (𝓑 n) (π“˜(ℝ, TangentSpace (𝓑 n) p β†’L[ℝ] TangentSpace (𝓑 n) p β†’L[ℝ] ℝ)) G p := ((frameMetricForm_smooth g p).contMDiffAt (e.open_baseSet.mem_nhds hp)).mdifferentiableAt (by simp) have hGcurve : HasDerivAt (fun s ↦ G (Ξ³ s)) (mvfderiv (𝓑 n) G p (curveVelocity Ξ³ x)) x := by exact (hG.hasMFDerivAt.comp x hΞ³.hasMFDerivAt).hasFDerivAt.hasDerivAt have hpair := (hGcurve.clm_apply hv).clm_apply hw have heval (a b : TangentSpace (𝓑 n) p) : mvfderiv (𝓑 n) G p (curveVelocity Ξ³ x) a b = g.inner p (frozenConnectionEndomorphism D p (curveVelocity Ξ³ x) a) b + g.inner p a (frozenConnectionEndomorphism D p (curveVelocity Ξ³ x) b) := by let L := (ContinuousLinearMap.apply ℝ ℝ b).comp (ContinuousLinearMap.apply ℝ (TangentSpace (𝓑 n) p β†’L[ℝ] ℝ) a) have h := L.hasMFDerivAt.comp p hG.hasMFDerivAt have hvalue : mvfderiv (𝓑 n) (fun q ↦ G q a b) p (curveVelocity Ξ³ x) = mvfderiv (𝓑 n) G p (curveVelocity Ξ³ x) a b := by exact congrArg (fun A : TangentSpace (𝓑 n) p β†’L[ℝ] ℝ ↦ A (curveVelocity Ξ³ x)) h.mfderiv rw [← hvalue] exact frameMetricForm_derivative D p (curveVelocity Ξ³ x) a b have hnear : βˆ€αΆ  s in 𝓝 x, Ξ³ s ∈ e.baseSet := hΞ³.continuousAt (e.open_baseSet.mem_nhds hp) have hrep (s : ℝ) (hs : Ξ³ s ∈ e.baseSet) (A : (r : ℝ) β†’ TangentSpace (𝓑 n) (Ξ³ r)) : extensionMap p (Ξ³ s) (e.symmL ℝ p (e ⟨γ s, A s⟩).2) = A s := by change e.symmL ℝ (Ξ³ s) (e.continuousLinearMapAt ℝ p (e.symmL ℝ p (e ⟨γ s, A s⟩).2)) = A s rw [e.continuousLinearMapAt_symmL hp, ← e.continuousLinearMapAt_apply_of_mem ℝ hs] exact e.symmL_continuousLinearMapAt hs _ have heq : (fun s ↦ g.inner (Ξ³ s) (Y s) (Z s)) =αΆ [𝓝 x] (fun s ↦ G (Ξ³ s) (v s) (w s)) := by filter_upwards [hnear] with s hs dsimp only [G, frameMetricForm_apply, v, w, y, z] rw [hrep s hs Y, hrep s hs Z] apply (hpair.congr_of_eventuallyEq heq).congr_deriv simp only [hvx, hwx, add_apply, heval, G, p, frameMetricForm_self, rampHorizontalCovariantDerivative, frozenConnectionEndomorphism_apply, map_add] ring end PoincareMT.M62