import PoincareLib.Analysis.Calculus.Sard.Basic import Mathlib.Geometry.Manifold.Instances.Real /-! # Scalar regular values on smooth manifolds A null set of critical values has dense complement. These lemmas select regular values from that complement; scalar Sard supplies nullity separately. -/ open MeasureTheory Set Function open scoped ContDiff Manifold Topology noncomputable section namespace Poincare.Manifold open Poincare.Analysis variable {E : Type*} [NormedAddCommGroup E] [NormedSpace โ„ E] [FiniteDimensional โ„ E] {M : Type*} [TopologicalSpace M] [ChartedSpace E M] [IsManifold ๐“˜(โ„, E) โˆž M] [T2Space M] [SecondCountableTopology M] /-- A null critical-value image gives a dense set of regular scalar values on the smooth manifold. -/ theorem dense_regular_values_of_manifold_critical_image_null {f : M โ†’ โ„} (hf : ContMDiff ๐“˜(โ„, E) ๐“˜(โ„, โ„) โˆž f) (hcrit : volume (f '' {x | ยฌ Function.Surjective (mfderiv ๐“˜(โ„, E) ๐“˜(โ„, โ„) f x)}) = 0) : Dense {c : โ„ | โˆ€ x, f x = c โ†’ Function.Surjective (mfderiv ๐“˜(โ„, E) ๐“˜(โ„, โ„) f x)} := by let C : Set โ„ := f '' {x | ยฌ Function.Surjective (mfderiv ๐“˜(โ„, E) ๐“˜(โ„, โ„) f x)} have hC : Dense Cแถœ := dense_compl_of_measure_zero_image volume hcrit have hregular : {c : โ„ | โˆ€ x, f x = c โ†’ Function.Surjective (mfderiv ๐“˜(โ„, E) ๐“˜(โ„, โ„) f x)} = Cแถœ := by ext c constructor ยท intro hc โŸจx, hx, hfxโŸฉ exact hx (hc x hfx) ยท intro hc x hfx by_contra hns exact hc โŸจx, hns, hfxโŸฉ rw [hregular] exact hC /-- Every nonempty open interval contains a regular value once the scalar critical-value image is null. -/ theorem exists_regular_value_in_interval_of_manifold_critical_image_null {f : M โ†’ โ„} (hf : ContMDiff ๐“˜(โ„, E) ๐“˜(โ„, โ„) โˆž f) (hcrit : volume (f '' {x | ยฌ Function.Surjective (mfderiv ๐“˜(โ„, E) ๐“˜(โ„, โ„) f x)}) = 0) {I : Set โ„} (hI : IsOpen I) (hIn : I.Nonempty) : โˆƒ c โˆˆ I, โˆ€ x, f x = c โ†’ Function.Surjective (mfderiv ๐“˜(โ„, E) ๐“˜(โ„, โ„) f x) := by rcases (dense_iff_inter_open.mp (dense_regular_values_of_manifold_critical_image_null hf hcrit) I hI hIn) with โŸจc, hcI, hcโŸฉ exact โŸจc, hcI, hcโŸฉ /-- The positive cutoff interval used by the compact regular-domain consumer has a regular scalar level under the same nullity hypothesis. -/ theorem exists_regular_value_unit_interval_of_manifold_critical_image_null {f : M โ†’ โ„} (hf : ContMDiff ๐“˜(โ„, E) ๐“˜(โ„, โ„) โˆž f) (hcrit : volume (f '' {x | ยฌ Function.Surjective (mfderiv ๐“˜(โ„, E) ๐“˜(โ„, โ„) f x)}) = 0) : โˆƒ c โˆˆ Set.Ioo (0 : โ„) 1, โˆ€ x, f x = c โ†’ Function.Surjective (mfderiv ๐“˜(โ„, E) ๐“˜(โ„, โ„) f x) := by exact exists_regular_value_in_interval_of_manifold_critical_image_null hf hcrit isOpen_Ioo โŸจ(1 / 2 : โ„), by norm_num, by norm_numโŸฉ end Poincare.Manifold