import PoincareLib.Geometry.RicciFlow.ReducedGeometry.LGeometry.Variation.Coordinates.PullbackRegularity import PoincareLib.Geometry.RicciFlow.ReducedGeometry.LGeometry.Variation.Second.SecondVariationCoefficients import PoincareLib.Geometry.RicciFlow.ReducedGeometry.LGeometry.Jacobi.JacobiInitialValue /-! Adapted from Mapher `PoincareMT/Proofs/M08/IndexMetricPair.lean` at `f927d9e1f0810042766d3b5f64d3f4da02ee93cc`. -/ set_option autoImplicit false set_option backward.isDefEq.respectTransparency false noncomputable section open Set Filter Topology open scoped Manifold ContDiff Bundle universe u namespace PoincareMT.LGeometry variable {n : β„•} {M : Type u} [TopologicalSpace M] [ChartedSpace (EuclideanSpace ℝ (Fin n)) M] [IsManifold (𝓑 n) ∞ M] local instance indexMetricPairDualGroup : NormedAddCommGroup (EuclideanSpace ℝ (Fin n) β†’L[ℝ] ℝ) := ContinuousLinearMap.toNormedAddCommGroup local instance indexMetricPairDualSpace : NormedSpace ℝ (EuclideanSpace ℝ (Fin n) β†’L[ℝ] ℝ) := ContinuousLinearMap.toNormedSpace local instance indexMetricPairBilinGroup : NormedAddCommGroup (EuclideanSpace ℝ (Fin n) β†’L[ℝ] EuclideanSpace ℝ (Fin n) β†’L[ℝ] ℝ) := ContinuousLinearMap.toNormedAddCommGroup local instance indexMetricPairBilinSpace : NormedSpace ℝ (EuclideanSpace ℝ (Fin n) β†’L[ℝ] EuclideanSpace ℝ (Fin n) β†’L[ℝ] ℝ) := ContinuousLinearMap.toNormedSpace set_option maxHeartbeats 1200000 in theorem chartMovingMetric_pair_hasDerivAt {J : Set ℝ} (F : RicciFlow n M J) (hM04 : RicciFlowCurvatureTheory.{u}) (T : ℝ) {a b : ℝ} (hab : a < b) (htime : βˆ€ r ∈ Icc a b, T - r ^ 2 ∈ J) (x : M) (Ξ± : ℝ β†’ M) {s : ℝ} (hs : s ∈ Ioo a b) (hx : Ξ± s ∈ (chartAt (EuclideanSpace ℝ (Fin n)) x).source) (hΞ± : MDifferentiableAt (π“˜(ℝ, ℝ)) (𝓑 n) Ξ± s) (c d : ℝ β†’ EuclideanSpace ℝ (Fin n)) (dc dd : EuclideanSpace ℝ (Fin n)) (hc : HasDerivAt c dc s) (hd : HasDerivAt d dd s) : HasDerivAt (fun r ↦ chartActionMetric F T x (r, extChartAt (𝓑 n) x (Ξ± r)) (c r) (d r)) (let z := (s, extChartAt (𝓑 n) x (Ξ± s)) let v := deriv ((extChartAt (𝓑 n) x) ∘ Ξ±) s let Ξ“ := closedChartConnection F T x (Icc a b) z chartActionMetric F T x z (dc + Ξ“ v (c s)) (d s) + chartActionMetric F T x z (c s) (dd + Ξ“ v (d s)) + 4 * s * (F.connection (T - s ^ 2)).ricci (Ξ± s) (chartFrame x (c s) (Ξ± s)) (chartFrame x (d s) (Ξ± s))) s := by let C := Icc a b let U := (extChartAt (𝓑 n) x).target let G := chartActionMetric F T x let q := (extChartAt (𝓑 n) x) ∘ Ξ± let v := deriv q s let Ξ“ := closedChartConnection F T x C (s, q s) have hsC : s ∈ C := Ioo_subset_Icc_self hs have hsN : C ∈ 𝓝 s := Icc_mem_nhds hs.1 hs.2 have hqmem : q s ∈ U := (extChartAt (𝓑 n) x).map_source (by simpa only [extChartAt_source] using hx) have hU : IsOpen U := isOpen_extChartAt_target (I := 𝓑 n) x have hG : ContDiffOn ℝ ∞ G (C Γ—Λ’ U) := chartActionMetric_closed_contDiffOn F T x htime have hGd : DifferentiableAt ℝ G (s, q s) := ((hG (s, q s) ⟨hsC, hqmem⟩).contDiffAt (prod_mem_nhds hsN (hU.mem_nhds hqmem))).differentiableAt (by simp) have hqd : DifferentiableAt ℝ q s := (((contMDiffAt_extChartAt' (I := 𝓑 n) (n := ∞) hx).mdifferentiableAt (by simp)).comp s hΞ±).differentiableAt have hgraph : HasDerivAt (fun r : ℝ ↦ (r, q r)) (1, v) s := (hasDerivAt_id s).prodMk hqd.hasDerivAt have hGc : HasDerivAt (fun r : ℝ ↦ G (r, q r)) (fderiv ℝ G (s, q s) (1, v)) s := by simpa only [Function.comp_def] using (hGd.hasFDerivAt.comp_hasDerivAt (l := G) (l' := fderiv ℝ G (s, q s)) s hgraph) have hcompat := closedChartConnection_spatial_compatibility F T htime hx hsC v (c s) (d s) change fderiv ℝ (fun y ↦ G (s, y)) (q s) v (c s) (d s) = G (s, q s) (Ξ“ v (c s)) (d s) + G (s, q s) (c s) (Ξ“ v (d s)) at hcompat rw [(hasFDerivAt_spatialWithin hU G hG hsC hqmem).fderiv, spatialWithinFDeriv_eq_spatialFDeriv hU G hsN hqmem] at hcompat change fderiv ℝ G (s, q s) (0, v) (c s) (d s) = G (s, q s) (Ξ“ v (c s)) (d s) + G (s, q s) (c s) (Ξ“ v (d s)) at hcompat have hcompat' : fderiv ℝ G (s, q s) (1, v) (c s) (d s) = G (s, q s) (Ξ“ v (c s)) (d s) + G (s, q s) (c s) (Ξ“ v (d s)) + fderiv ℝ G (s, q s) (1, 0) (c s) (d s) := by rw [show ((1 : ℝ), v) = (1, (0 : EuclideanSpace ℝ (Fin n))) + (0, v) by simp, map_add, add_apply, add_apply, hcompat] ring have h := chart_pair_moving_covariant_hasDerivAt (fun r ↦ G (r, q r)) Ξ“ (fderiv ℝ G (s, q s) (1, 0)) (fderiv ℝ G (s, q s) (1, v)) hGc hc hd hcompat' have htimepair : fderiv ℝ G (s, q s) (1, 0) (c s) (d s) = 4 * s * (F.connection (T - s ^ 2)).ricci (Ξ± s) (chartFrame x (c s) (Ξ± s)) (chartFrame x (d s) (Ξ± s)) := chartActionMetric_time_pair_interior F hM04 T (uniqueDiffOn_Icc hab) htime hx hsC hsN (c s) (d s) rw [htimepair] at h exact h set_option maxHeartbeats 1600000 in theorem pullback_metric_pair_hasDerivAt {J : Set ℝ} (F : RicciFlow n M J) (hM04 : RicciFlowCurvatureTheory.{u}) (T : ℝ) {a b : ℝ} (hab : a < b) (htime : βˆ€ r ∈ Icc a b, T - r ^ 2 ∈ J) {U : Set ℝ} (hU : IsOpen U) (hCU : Icc a b βŠ† U) (Ξ± : ℝ β†’ M) (hΞ± : ContMDiffOn (π“˜(ℝ, ℝ)) (𝓑 n) ∞ Ξ± U) (Y Z : βˆ€ r, TangentSpace (𝓑 n) (Ξ± r)) (EY : ParametricAlongCurveExtensionOn (Icc a b) Ξ± Y) (EZ : ParametricAlongCurveExtensionOn (Icc a b) Ξ± Z) {s : ℝ} (hs : s ∈ Ioo a b) : HasDerivAt (fun r ↦ (F.metric (T - r ^ 2)).inner (Ξ± r) (Y r) (Z r)) ((F.metric (T - s ^ 2)).inner (Ξ± s) (pullbackCovariantDerivative F (fun r ↦ T - r ^ 2) Ξ± Y (Icc a b) EY s) (Z s) + (F.metric (T - s ^ 2)).inner (Ξ± s) (Y s) (pullbackCovariantDerivative F (fun r ↦ T - r ^ 2) Ξ± Z (Icc a b) EZ s) + 4 * s * (F.connection (T - s ^ 2)).ricci (Ξ± s) (Y s) (Z s)) s := by let x := Ξ± s let c := parametricExtension_chartCoordinates EY x let d := parametricExtension_chartCoordinates EZ x have hx : Ξ± s ∈ (chartAt (EuclideanSpace ℝ (Fin n)) x).source := mem_chart_source _ _ have hsC : s ∈ Icc a b := Ioo_subset_Icc_self hs obtain ⟨N, hN, hsN, hNU, hsrc, hc, hY⟩ := exists_parametricExtension_chartCoordinates hU hCU Ξ± hΞ± Y EY hsC hx obtain ⟨O, hO, hsO, hOU, hsrcO, hd, hZ⟩ := exists_parametricExtension_chartCoordinates hU hCU Ξ± hΞ± Z EZ hsC hx have hΞ±s := ((hΞ± s (hCU hsC)).contMDiffAt (hU.mem_nhds (hCU hsC))).mdifferentiableAt (by simp) have hdc : HasDerivAt c (deriv c s) s := (((hc s hsN).contDiffAt (hN.mem_nhds hsN)).differentiableAt (by simp)).hasDerivAt have hdd : HasDerivAt d (deriv d s) s := (((hd s hsO).contDiffAt (hO.mem_nhds hsO)).differentiableAt (by simp)).hasDerivAt have hpair := chartMovingMetric_pair_hasDerivAt F hM04 T hab htime x Ξ± hs hx hΞ±s c d (deriv c s) (deriv d s) hdc hdd have hDY := pullbackCovariantDerivative_chart_extension F T hab htime hN x Ξ± (hΞ±.mono hNU) Y EY hsrc hc hY ⟨hsC, hsN⟩ have hDZ := pullbackCovariantDerivative_chart_extension F T hab htime hO x Ξ± (hΞ±.mono hOU) Z EZ hsrcO hd hZ ⟨hsC, hsO⟩ have hnear : βˆ€αΆ  r in 𝓝 s, r ∈ Icc a b ∩ N ∩ O := inter_mem (inter_mem (Icc_mem_nhds hs.1 hs.2) (hN.mem_nhds hsN)) (hO.mem_nhds hsO) have heq : (fun r ↦ (F.metric (T - r ^ 2)).inner (Ξ± r) (Y r) (Z r)) =αΆ [𝓝 s] (fun r ↦ chartActionMetric F T x (r, extChartAt (𝓑 n) x (Ξ± r)) (c r) (d r)) := by filter_upwards [hnear] with r hr rw [chartActionMetric_apply F T (hsrc hr.1.2), hY r hr.1, hZ r ⟨hr.1.1, hr.2⟩] have hvalue : (let z := (s, extChartAt (𝓑 n) x (Ξ± s)) let v := deriv ((extChartAt (𝓑 n) x) ∘ Ξ±) s let Ξ“ := closedChartConnection F T x (Icc a b) z chartActionMetric F T x z (deriv c s + Ξ“ v (c s)) (d s) + chartActionMetric F T x z (c s) (deriv d s + Ξ“ v (d s)) + 4 * s * (F.connection (T - s ^ 2)).ricci (Ξ± s) (chartFrame x (c s) (Ξ± s)) (chartFrame x (d s) (Ξ± s))) = (F.metric (T - s ^ 2)).inner (Ξ± s) (pullbackCovariantDerivative F (fun r ↦ T - r ^ 2) Ξ± Y (Icc a b) EY s) (Z s) + (F.metric (T - s ^ 2)).inner (Ξ± s) (Y s) (pullbackCovariantDerivative F (fun r ↦ T - r ^ 2) Ξ± Z (Icc a b) EZ s) + 4 * s * (F.connection (T - s ^ 2)).ricci (Ξ± s) (Y s) (Z s) := by dsimp only rw [chartActionMetric_apply F T hx, chartActionMetric_apply F T hx, hY s ⟨hsC, hsN⟩, hZ s ⟨hsC, hsO⟩, hDY, hDZ] rfl rw [hvalue] at hpair exact hpair.congr_of_eventuallyEq heq theorem extension_metric_pair_contDiffOn {J C : Set ℝ} (F : RicciFlow n M J) (T : ℝ) (htime : βˆ€ r ∈ C, T - r ^ 2 ∈ J) (Ξ± : ℝ β†’ M) (hΞ± : ContMDiffOn (π“˜(ℝ, ℝ)) (𝓑 n) ∞ Ξ± C) (Y Z : βˆ€ r, TangentSpace (𝓑 n) (Ξ± r)) (EY : ParametricAlongCurveExtensionOn C Ξ± Y) (EZ : ParametricAlongCurveExtensionOn C Ξ± Z) : ContDiffOn ℝ ∞ (fun r ↦ (F.metric (T - r ^ 2)).inner (Ξ± r) (Y r) (Z r)) C := by exact (movingMetric_pair_contMDiffOn F (fun r ↦ T - r ^ 2) Ξ± Y Z (contDiff_const.sub (contDiff_id.pow 2)).contMDiff.contMDiffOn hΞ± (parametricExtension_along_contMDiffOn EY hΞ±) (parametricExtension_along_contMDiffOn EZ hΞ±) htime).contDiffOn end PoincareMT.LGeometry