import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Geometry.Manifold.MFDeriv.Atlas import Mathlib.Geometry.Manifold.MFDeriv.NormedSpace /-! # Constancy from vanishing manifold derivatives -/ set_option autoImplicit false open Set ChartedSpace open scoped Manifold Topology namespace Poincare.Manifold variable {E : Type*} [NormedAddCommGroup E] [NormedSpace โ„ E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners โ„ E H} [I.Boundaryless] {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I 1 M] /-- A differentiable scalar function with vanishing derivative on a manifold without boundary is locally constant. -/ theorem isLocallyConstant_of_mvfderiv_eq_zero {f : M โ†’ โ„} (hf : MDifferentiable I ๐“˜(โ„, โ„) f) (hdf : โˆ€ x v, mvfderiv I f x v = 0) : IsLocallyConstant f := by intro s refine isOpen_iff_forall_mem_open.mpr fun x hx => ?_ let e := extChartAt I x have he : IsOpen e.target := isOpen_extChartAt_target x have he' : โˆ€ y โˆˆ e.target, MDifferentiableAt ๐“˜(โ„, E) I e.symm y := fun y hy => (mdifferentiableOn_extChartAt_symm y hy).mdifferentiableAt (he.mem_nhds hy) have hf' : DifferentiableOn โ„ (f โˆ˜ e.symm) e.target := by intro y hy exact ((hf (e.symm y)).comp y (he' y hy)).differentiableAt.differentiableWithinAt have hdf' : e.target.EqOn (fderiv โ„ (f โˆ˜ e.symm)) 0 := by intro y hy ext v rw [โ† mfderiv_eq_fderiv] change mvfderiv ๐“˜(โ„, E) (f โˆ˜ e.symm) y v = 0 exact (mvfderiv_comp_apply y (hf (e.symm y)) (he' y hy) v).trans (hdf _ _) have hu := he.isOpen_inter_preimage_of_fderiv_eq_zero hf' hdf' s refine โŸจe.source โˆฉ e โปยน' (e.target โˆฉ (f โˆ˜ e.symm) โปยน' s), ?_, isOpen_extChartAt_preimage' x hu, ?_โŸฉ ยท intro y hy simpa only [mem_preimage, Function.comp_apply, e.left_inv hy.1] using hy.2.2 ยท have hx' : x โˆˆ e.source := mem_extChartAt_source x refine โŸจhx', e.map_source hx', ?_โŸฉ simpa only [mem_preimage, Function.comp_apply, e.left_inv hx'] using hx /-- A differentiable scalar function with zero derivative takes equal values at all points of a preconnected manifold without boundary. -/ theorem eq_of_mvfderiv_eq_zero [PreconnectedSpace M] {f : M โ†’ โ„} (hf : MDifferentiable I ๐“˜(โ„, โ„) f) (hdf : โˆ€ x v, mvfderiv I f x v = 0) (x y : M) : f x = f y := (isLocallyConstant_of_mvfderiv_eq_zero hf hdf).apply_eq_of_preconnectedSpace x y /-- A differentiable scalar function with zero derivative is constant on a preconnected manifold without boundary. -/ theorem exists_eq_const_of_mvfderiv_eq_zero [PreconnectedSpace M] {f : M โ†’ โ„} (hf : MDifferentiable I ๐“˜(โ„, โ„) f) (hdf : โˆ€ x v, mvfderiv I f x v = 0) : โˆƒ c : โ„, โˆ€ x, f x = c := by obtain โŸจc, hcโŸฉ := (isLocallyConstant_of_mvfderiv_eq_zero hf hdf).exists_eq_const exact โŸจc, fun x => congrFun hc xโŸฉ end Poincare.Manifold