import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.LinearAlgebra.Matrix.NonsingularInverse /-! # Smooth matrix inversion on a nonsingular parameter set The finite determinant and adjugate formulas preserve within-smoothness. This gives the parameter regularity of the actual cylinder connection in Morgan-Tian Proposition 12.7, pp. 298-299; see the closed-time intrinsic-jet derivation. -/ set_option autoImplicit false open Set open scoped ContDiff BigOperators variable {๐•œ E ฮน : Type*} [NontriviallyNormedField ๐•œ] [NormedAddCommGroup E] [NormedSpace ๐•œ E] [Fintype ฮน] [DecidableEq ฮน] {n : โ„•โˆžฯ‰} {S : Set E} {A : E โ†’ Matrix ฮน ฮน ๐•œ} /-- Entrywise within-smoothness passes to the finite determinant (Proposition 12.7, pp. 298-299, parameter regularity). -/ theorem ContDiffOn.matrix_det (hA : โˆ€ a b, ContDiffOn ๐•œ n (fun x => A x a b) S) : ContDiffOn ๐•œ n (fun x => (A x).det) S := by classical have heq : (fun x => (A x).det) = fun x => โˆ‘ ฯƒ : Equiv.Perm ฮน, (Equiv.Perm.sign ฯƒ : ๐•œ) * โˆ i, A x (ฯƒ i) i := by funext x simp [Matrix.det_apply, Units.smul_def] rw [heq] exact ContDiffOn.sum fun ฯƒ _ => contDiffOn_const.mul (contDiffOn_prod fun i _ => hA (ฯƒ i) i) /-- The actual matrix inverse is entrywise smooth wherever the determinant does not vanish (Proposition 12.7, pp. 298-299). -/ theorem ContDiffOn.matrix_inv (hA : โˆ€ a b, ContDiffOn ๐•œ n (fun x => A x a b) S) (hdet : โˆ€ x โˆˆ S, (A x).det โ‰  0) (a b : ฮน) : ContDiffOn ๐•œ n (fun x => (A x)โปยน a b) S := by classical simp only [Matrix.inv_def, Matrix.smul_apply, smul_eq_mul, Ring.inverse_eq_inv', Matrix.adjugate_apply] apply ((ContDiffOn.matrix_det hA).inv hdet).mul apply ContDiffOn.matrix_det intro i j by_cases hi : i = b ยท subst i simpa only [Matrix.updateRow_self] using (contDiffOn_const (c := (Pi.single a (1 : ๐•œ) : ฮน โ†’ ๐•œ) j) : ContDiffOn ๐•œ n (fun _ : E => (Pi.single a (1 : ๐•œ) : ฮน โ†’ ๐•œ) j) S) ยท simpa only [Matrix.updateRow_ne hi] using hA i j