import PoincareLib.Geometry.RicciFlow.ReducedGeometry.ReducedLength.Variation.Fields.SquareTimeFields import Mathlib.Analysis.Calculus.Deriv.Comp /-! # The metric derivative in the regularized equation The term `4s Ric` is the ordinary derivative of the square-time metric. The chain rule applies also at zero because the signed neighborhood maps into the given flow interval. -/ set_option autoImplicit false open scoped Manifold ContDiff Bundle Topology open Filter universe u namespace PoincareMT.ReducedLength variable {n : โ„•} {M : Type u} [TopologicalSpace M] [ChartedSpace (EuclideanSpace โ„ (Fin n)) M] [IsManifold (๐“ก n) โˆž M] set_option backward.isDefEq.respectTransparency false in theorem squareTime_metric_hasDerivAt {J : Set โ„} (F : RicciFlow n M J) (T b : โ„) (hb : 0 < b) (hwindow : Set.Icc (T - b) T โІ J) (s : โ„) (hs : s โˆˆ Set.Ioo (-Real.sqrt b) (Real.sqrt b)) (x : M) (u v : TangentSpace (๐“ก n) x) : HasDerivAt (fun r โ†ฆ (F.metric (T - r ^ 2)).inner x u v) (4 * s * (F.connection (T - s ^ 2)).ricci x u v) s := by have hclock : HasDerivAt (fun r : โ„ โ†ฆ T - r ^ 2) (-2 * s) s := by simpa only [id_eq, Nat.reduceSub, Nat.cast_ofNat, pow_one, mul_one, neg_mul] using (hasDerivAt_pow 2 s).const_sub T have hnear : โˆ€แถ  r in ๐“ s, T - r ^ 2 โˆˆ J := by filter_upwards [Ioo_mem_nhds hs.1 hs.2] with r hr exact hwindow (squareTime_mem_window T hb hr) have h := (F.equation (T - s ^ 2) (hwindow (squareTime_mem_window T hb hs)) x u v).comp_hasDerivAt s hclock hnear convert! h using 1 <;> first | rfl | ring end PoincareMT.ReducedLength