import PoincareLib.Geometry.Manifold.Sublevel.Minimum import Mathlib.Geometry.Manifold.Algebra.LieGroup /-! # Critical points and extrema of compact regions -/ noncomputable section set_option autoImplicit false set_option backward.isDefEq.respectTransparency false open Set Filter open scoped Manifold ContDiff Topology namespace Poincare.Geometry.Manifold /-- A regular interior point lies strictly between any global minimum and maximum of the region. -/ theorem strict_bounds_on_interior_of_regular {n : Nat} {M : Type*} [TopologicalSpace M] [ChartedSpace (EuclideanSpace Real (Fin n)) M] [IsManifold (𝓑 n) ∞ M] {h : M -> Real} (hh : ContMDiff (𝓑 n) π“˜(Real, Real) ∞ h) {K : Set M} {p q : M} (hmin : IsMinOn h K p) (hmax : IsMaxOn h K q) (hreg : βˆ€ x ∈ K, mfderiv (𝓑 n) π“˜(Real, Real) h x β‰  0) : βˆ€ x ∈ interior K, h p < h x ∧ h x < h q := by intro x hx have hxK := interior_subset hx have hnhds := mem_interior_iff_mem_nhds.mp hx constructor Β· apply lt_of_le_of_ne (hmin hxK) intro heq have hxMin : IsMinOn h K x := by intro y hy; rw [← heq]; exact hmin hy exact hreg x hxK (mfderiv_eq_zero_of_isLocalMin hh (hxMin.isLocalMin hnhds)) Β· apply lt_of_le_of_ne (hmax hxK) intro heq have hxMax : IsMaxOn h K x := by intro y hy; rw [heq]; exact hmax hy have hn := mfderiv_eq_zero_of_isLocalMin hh.neg (hxMax.isLocalMax hnhds).neg change mfderiv (𝓑 n) π“˜(Real, Real) (-h) x = 0 at hn exact hreg x hxK (by simpa only [mfderiv_neg, neg_eq_zero] using hn) /-- A compact region without critical points attains both extrema on its frontier. -/ theorem exists_boundary_extrema_of_regular {n : Nat} {M : Type*} [TopologicalSpace M] [ChartedSpace (EuclideanSpace Real (Fin n)) M] [IsManifold (𝓑 n) ∞ M] {h : M -> Real} (hh : ContMDiff (𝓑 n) π“˜(Real, Real) ∞ h) {K : Set M} (hK : IsCompact K) (hne : K.Nonempty) (hreg : βˆ€ p ∈ K, mfderiv (𝓑 n) π“˜(Real, Real) h p β‰  0) : βˆƒ p ∈ frontier K, βˆƒ q ∈ frontier K, IsMinOn h K p ∧ IsMaxOn h K q := by obtain ⟨p, hp, hmin⟩ := hK.exists_isMinOn hne hh.continuous.continuousOn obtain ⟨q, hq, hmax⟩ := hK.exists_isMaxOn hne hh.continuous.continuousOn refine ⟨p, ⟨subset_closure hp, ?_⟩, q, ⟨subset_closure hq, ?_⟩, hmin, hmax⟩ Β· intro hpi exact hreg p hp (mfderiv_eq_zero_of_isLocalMin hh (hmin.isLocalMin (mem_interior_iff_mem_nhds.mp hpi))) Β· intro hqi have hn := mfderiv_eq_zero_of_isLocalMin hh.neg (hmax.isLocalMax (mem_interior_iff_mem_nhds.mp hqi)).neg change mfderiv (𝓑 n) π“˜(Real, Real) (-h) q = 0 at hn exact hreg q hq (by simpa only [mfderiv_neg, neg_eq_zero] using hn) /-- A smooth real function on a nontrivial compact boundaryless manifold has two distinct critical points, including when the function is constant. -/ theorem exists_two_distinct_critical_points {n : Nat} {M : Type*} [TopologicalSpace M] [ChartedSpace (EuclideanSpace Real (Fin n)) M] [IsManifold (𝓑 n) ∞ M] [CompactSpace M] [Nontrivial M] {h : M -> Real} (hh : ContMDiff (𝓑 n) π“˜(Real, Real) ∞ h) : βˆƒ p q : M, p β‰  q ∧ mfderiv (𝓑 n) π“˜(Real, Real) h p = 0 ∧ mfderiv (𝓑 n) π“˜(Real, Real) h q = 0 := by obtain ⟨p, _, hmin⟩ := isCompact_univ.exists_isMinOn univ_nonempty hh.continuous.continuousOn obtain ⟨q, _, hmax⟩ := isCompact_univ.exists_isMaxOn univ_nonempty hh.continuous.continuousOn have hp := mfderiv_eq_zero_of_isLocalMin hh (hmin.isLocalMin univ_mem) have hq : mfderiv (𝓑 n) π“˜(Real, Real) h q = 0 := by have hneg := mfderiv_eq_zero_of_isLocalMin hh.neg (hmax.isLocalMax univ_mem).neg change mfderiv (𝓑 n) π“˜(Real, Real) (-h) q = 0 at hneg simpa only [mfderiv_neg, neg_eq_zero] using hneg by_cases hpq : p = q Β· have hconstant : h = fun _ => h p := by funext x exact (hpq β–Έ hmax (mem_univ x)).antisymm (hmin (mem_univ x)) obtain ⟨x, y, hxy⟩ := exists_pair_ne M refine ⟨x, y, hxy, ?_, ?_⟩ <;> rw [hconstant] <;> exact mfderiv_const Β· exact ⟨p, q, hpq, hp, hq⟩ end Poincare.Geometry.Manifold