import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Analysis.Calculus.FDeriv.OfCompLeft /-! # Smoothness of an inverse within a set The inverse derivative formula bootstraps a continuous right inverse to smoothness on its actual domain, which may have boundary. This is the relative inverse step for Morgan-Tian Proposition 6.28, p. 117; see tasks/M14/derivations/2026-09-21-relative-inverse.md. -/ set_option autoImplicit false open Set Filter open scoped ContDiff Topology namespace PoincareMT.M14 variable {π•œ : Type*} [NontriviallyNormedField π•œ] {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] [CompleteSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace π•œ F] /-- A continuous right inverse of a smooth map with invertible within derivative is smooth on its domain, including boundary points. No unique-differentiation assumption on the inverse domain is needed. Relative inverse step for Proposition 6.28, p. 117; see the derivation 2026-09-21-relative-inverse.md. -/ theorem contDiffOn_inverse_of_leftInverse {f : E β†’ F} {g : F β†’ E} {S : Set E} {T : Set F} (hS : UniqueDiffOn π•œ S) (hf : ContDiffOn π•œ ∞ f S) (hg : ContinuousOn g T) (hmap : MapsTo g T S) (hfg : βˆ€ y ∈ T, f (g y) = y) (hinv : βˆ€ z ∈ S, (fderivWithin π•œ f S z).IsInvertible) : ContDiffOn π•œ ∞ g T := by let D : F β†’ F β†’L[π•œ] E := fun y => ContinuousLinearMap.inverse (fderivWithin π•œ f S (g y)) have hD (y : F) (hy : y ∈ T) : HasFDerivWithinAt g (D y) T y := by obtain ⟨e, he⟩ := hinv (g y) (hmap hy) have hfe : HasFDerivWithinAt f (e : E β†’L[π•œ] F) S (g y) := by rw [he] exact (hf.differentiableOn (by simp) _ (hmap hy)).hasFDerivWithinAt have hd := HasFDerivWithinAt.of_local_left_inverse ((hg y hy).tendsto_nhdsWithin hmap) hfe hy (eventually_nhdsWithin_of_forall hfg) simpa only [D, ← he, ContinuousLinearMap.inverse_equiv] using hd rw [contDiffOn_infty] intro k induction k with | zero => exact contDiffOn_zero.mpr hg | succ k ih => have hf' : ContDiffOn π•œ k (fderivWithin π•œ f S) S := hf.fderivWithin hS (by exact_mod_cast (le_top : (k + 1 : β„•βˆž) ≀ ⊀)) have hDs : ContDiffOn π•œ k D T := by intro y hy exact (hinv (g y) (hmap hy)).contDiffAt_map_inverse.comp_contDiffWithinAt y ((hf' (g y) (hmap hy)).comp y (ih y hy) hmap) rw [Nat.cast_succ] apply (contDiffOn_succ_iff_hasFDerivWithinAt (by simp)).mpr intro y hy refine ⟨T, ?_, by simp, D, hD, hDs⟩ simpa only [insert_eq_of_mem hy] using (self_mem_nhdsWithin : T ∈ 𝓝[T] y) end PoincareMT.M14