import OAI.Geometry.IsometricImmersion.Metric import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Tactic.FinCases namespace OAI noncomputable section open scoped ContDiff BigOperators Matrix namespace SmoothLocal.Geometry variable {g : MetricField} {U : Set Coord} theorem metricDet_ne_zero (hg : SmoothPositiveOn g U) {p : Coord} (hp : p ∈ U) : (g p).det ≠ 0 := ((Matrix.isUnit_iff_isUnit_det _).mp (hg.2 p hp).isUnit).ne_zero theorem metricDet_contDiffOn (hg : SmoothPositiveOn g U) : ContDiffOn ℝ ∞ (fun p => (g p).det) U := by simpa only [Matrix.det_fin_two] using ((hg.1 0 0).mul (hg.1 1 1)).sub ((hg.1 0 1).mul (hg.1 1 0)) theorem metricAdjugate_contDiffOn (hg : SmoothPositiveOn g U) (i j : Fin 2) : ContDiffOn ℝ ∞ (fun p => (g p).adjugate i j) U := by fin_cases i <;> fin_cases j · simpa [Matrix.adjugate_fin_two] using hg.1 1 1 · simpa [Matrix.adjugate_fin_two] using (hg.1 0 1).neg · simpa [Matrix.adjugate_fin_two] using (hg.1 1 0).neg · simpa [Matrix.adjugate_fin_two] using hg.1 0 0 theorem inverseMetric_contDiffOn (hg : SmoothPositiveOn g U) (i j : Fin 2) : ContDiffOn ℝ ∞ (fun p => inverseMetric g p i j) U := by have hi : ContDiffOn ℝ ∞ (fun p => ((g p).det)⁻¹) U := (metricDet_contDiffOn hg).inv (fun p hp => metricDet_ne_zero hg hp) have ha := metricAdjugate_contDiffOn hg i j simpa [inverseMetric, Matrix.inv_def, Ring.inverse_eq_inv, smul_eq_mul] using hi.mul ha theorem christoffel_contDiffOn (hg : SmoothPositiveOn g U) (hU : IsOpen U) (k i j : Fin 2) : ContDiffOn ℝ ∞ (christoffel g k i j) U := by have hs : ContDiffOn ℝ ∞ (fun p => ∑ l, inverseMetric g p k l * (coordPartial i (fun q => g q j l) p + coordPartial j (fun q => g q i l) p - coordPartial l (fun q => g q i j) p)) U := by apply ContDiffOn.sum intro l hl exact (inverseMetric_contDiffOn hg k l).mul (((partial_contDiffOn (hg.1 j l) hU i).add (partial_contDiffOn (hg.1 i l) hU j)).sub (partial_contDiffOn (hg.1 i j) hU l)) exact contDiffOn_const.mul hs theorem covHessian_contDiffOn (hg : SmoothPositiveOn g U) (hU : IsOpen U) {z : Coord → ℝ} (hz : ContDiffOn ℝ ∞ z U) (i j : Fin 2) : ContDiffOn ℝ ∞ (fun p => covHessian g z p i j) U := by have hs : ContDiffOn ℝ ∞ (fun p => ∑ k, christoffel g k i j p * coordPartial k z p) U := by apply ContDiffOn.sum intro k hk exact (christoffel_contDiffOn hg hU k i j).mul (partial_contDiffOn hz hU k) exact (partial_contDiffOn (partial_contDiffOn hz hU j) hU i).sub hs theorem covectorNormSq_contDiffOn (hg : SmoothPositiveOn g U) (hU : IsOpen U) {z : Coord → ℝ} (hz : ContDiffOn ℝ ∞ z U) : ContDiffOn ℝ ∞ (covectorNormSq g z) U := by apply ContDiffOn.sum intro i hi apply ContDiffOn.sum intro j hj exact ((inverseMetric_contDiffOn hg i j).mul (partial_contDiffOn hz hU i)).mul (partial_contDiffOn hz hU j) theorem riemann_contDiffOn (hg : SmoothPositiveOn g U) (hU : IsOpen U) (l k i j : Fin 2) : ContDiffOn ℝ ∞ (riemann g l k i j) U := by have hs : ContDiffOn ℝ ∞ (fun p => ∑ m, (christoffel g m j k p * christoffel g l i m p - christoffel g m i k p * christoffel g l j m p)) U := by apply ContDiffOn.sum intro m hm exact ((christoffel_contDiffOn hg hU m j k).mul (christoffel_contDiffOn hg hU l i m)).sub ((christoffel_contDiffOn hg hU m i k).mul (christoffel_contDiffOn hg hU l j m)) exact ((partial_contDiffOn (christoffel_contDiffOn hg hU l j k) hU i).sub (partial_contDiffOn (christoffel_contDiffOn hg hU l i k) hU j)).add hs theorem gaussianCurvature_contDiffOn (hg : SmoothPositiveOn g U) (hU : IsOpen U) : ContDiffOn ℝ ∞ (gaussianCurvature g) U := by have hn : ContDiffOn ℝ ∞ (fun p => ∑ l, g p 0 l * riemann g l 1 0 1 p) U := by apply ContDiffOn.sum intro l hl exact (hg.1 0 l).mul (riemann_contDiffOn hg hU l 1 0 1) exact hn.div (metricDet_contDiffOn hg) (fun p hp => metricDet_ne_zero hg hp) end SmoothLocal.Geometry end end OAI