import PoincareLib.Analysis.Calculus.ImplicitFunction.RegularScalar import Mathlib.Geometry.Manifold.ContMDiff.Atlas import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace import Mathlib.Geometry.Manifold.MFDeriv.Basic set_option backward.isDefEq.respectTransparency false open Poincare.Analysis Set Function open scoped Topology ContDiff Manifold /-! Adapted from AxelWorkspace, `MorganTianLib/Foundations/ManifoldSuperlevelCharts.lean`, revision `f1cdb30cabdc8781d2d3dec86d3d99ab1820f30e`. See `references/analysis/axel-workspace/regular-domain-reuse.md`. -/ namespace Poincare.Manifold variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {M : Type*} [TopologicalSpace M] [ChartedSpace E M] [IsManifold π“˜(ℝ, E) ∞ M] /-- Smooth local coordinates adapted to a scalar function at a regular point. -/ theorem exists_manifold_superlevel_chart {f : M β†’ ℝ} (hf : ContMDiff π“˜(ℝ, E) π“˜(ℝ, ℝ) ∞ f) (a : M) (hreg : Surjective (mfderiv π“˜(ℝ, E) π“˜(ℝ, ℝ) f a)) : let L : E β†’L[ℝ] ℝ := mfderiv π“˜(ℝ, E) π“˜(ℝ, ℝ) f a βˆƒ e : OpenPartialHomeomorph M (ℝ Γ— L.ker), a ∈ e.source ∧ e a = (f a, 0) ∧ ContMDiffOn π“˜(ℝ, E) π“˜(ℝ, ℝ Γ— L.ker) ∞ e e.source ∧ ContMDiffOn π“˜(ℝ, ℝ Γ— L.ker) π“˜(ℝ, E) ∞ e.symm e.target ∧ (βˆ€ x ∈ e.source, (e x).1 = f x) ∧ βˆ€ c : ℝ, e '' (e.source ∩ {x | c ≀ f x}) = e.target ∩ {y | c ≀ y.1} := by dsimp only let Ο† := chartAt E a let g : E β†’ ℝ := f ∘ Ο†.symm have hg : ContDiffOn ℝ ∞ g Ο†.target := (hf.comp_contMDiffOn (contMDiffOn_chart_symm (I := π“˜(ℝ, E)))).contDiffOn have hder : mfderiv π“˜(ℝ, E) π“˜(ℝ, ℝ) f a = fderiv ℝ g (Ο† a) := by rw [(hf.mdifferentiable (by simp) a).mfderiv] simp [writtenInExtChartAt, extChartAt, g, Ο†, fderivWithin_univ, chartAt_self_eq] rw [hder] at hreg ⊒ obtain ⟨e0, ha0, heV, he0a, he0, he0inv, he0f, he0level⟩ := exists_smooth_superlevel_chart Ο†.open_target hg (Ο†.map_source (mem_chart_source E a)) hreg let e := Ο†.trans e0 have hea : a ∈ e.source := ⟨mem_chart_source E a, ha0⟩ have hefirst : βˆ€ x ∈ e.source, (e x).1 = f x := by intro x hx change (e0 (Ο† x)).1 = f x rw [he0f (Ο† x) (show Ο† x ∈ e0.source from hx.2)] change f (Ο†.symm (Ο† x)) = f x rw [Ο†.left_inv hx.1] refine ⟨e, hea, ?_, ?_, ?_, hefirst, ?_⟩ Β· change e0 (Ο† a) = (f a, 0) simpa [g, Ο†] using he0a Β· exact he0.contMDiffOn.comp ((contMDiffOn_chart (I := π“˜(ℝ, E))).mono (fun x hx => hx.1)) (fun x hx => hx.2) Β· exact (contMDiffOn_chart_symm (I := π“˜(ℝ, E))).comp (he0inv.contMDiffOn.mono (fun y hy => hy.1)) (fun y hy => hy.2) Β· intro c ext y constructor Β· rintro ⟨x, ⟨hx, hcx⟩, rfl⟩ exact ⟨e.map_source hx, by simpa [hefirst x hx] using hcx⟩ Β· rintro ⟨hy, hcy⟩ refine ⟨e.symm y, ⟨e.map_target hy, ?_⟩, e.right_inv hy⟩ change c ≀ f (e.symm y) rw [← hefirst _ (e.map_target hy), e.right_inv hy] exact hcy /-- The frontier of a regular superlevel is precisely its defining level set. -/ theorem frontier_superlevel_eq_regular_level {f : M β†’ ℝ} (hf : ContMDiff π“˜(ℝ, E) π“˜(ℝ, ℝ) ∞ f) (c : ℝ) (hc : βˆ€ x, f x = c β†’ Surjective (mfderiv π“˜(ℝ, E) π“˜(ℝ, ℝ) f x)) : frontier {x | c ≀ f x} = {x | f x = c} := by apply Subset.antisymm Β· intro x hx exact (frontier_le_subset_eq continuous_const hf.continuous hx).symm Β· intro x hx obtain ⟨e, hxe, hea, he, hei, hef, helevel⟩ := exists_manifold_superlevel_chart hf x (hc x hx) have himg := OpenPartialHomeomorph.IsImage.of_image_eq (helevel c) apply (himg.frontier.apply_mem_iff hxe).mp let L : E β†’L[ℝ] ℝ := mfderiv π“˜(ℝ, E) π“˜(ℝ, ℝ) f x have hhalf : {y : ℝ Γ— L.ker | c ≀ y.1} = Ici c Γ—Λ’ univ := by ext y simp rw [hhalf, frontier_prod_univ_eq, frontier_Ici] exact ⟨by simpa [hea] using hx, mem_univ _⟩ end Poincare.Manifold