import Mathlib.Analysis.Calculus.ImplicitContDiff import Mathlib.Geometry.Manifold.Instances.Real import Mathlib.Geometry.Manifold.MFDeriv.NormedSpace import Mathlib.Geometry.Manifold.Algebra.LieGroup import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # Smooth hitting times for uniformly decreasing trajectories Strict decrease gives uniqueness and a quantitative time bound. The intermediate value theorem constructs the roots, and local implicit functions identify the selected roots smoothly on a common open domain. -/ noncomputable section set_option autoImplicit false set_option backward.isDefEq.respectTransparency false open Set Filter open scoped Manifold ContDiff Bundle Topology namespace Poincare.Manifold private theorem contMDiffAt_unique_time_root {n : β„•} {M : Type*} [TopologicalSpace M] [ChartedSpace (EuclideanSpace ℝ (Fin n)) M] [IsManifold (𝓑 n) ∞ M] {F : ℝ Γ— M β†’ ℝ} {Οƒ : M β†’ ℝ} {I : Set ℝ} {V : Set M} (hI : IsOpen I) (hV : IsOpen V) (hF : ContMDiffOn (π“˜(ℝ, ℝ).prod (𝓑 n)) π“˜(ℝ, ℝ) ∞ F (I Γ—Λ’ V)) (hroot : βˆ€ y ∈ V, Οƒ y ∈ I ∧ F (Οƒ y, y) = 0) (hinj : βˆ€ y ∈ V, InjOn (fun s => F (s, y)) I) {y : M} (hy : y ∈ V) {v : ℝ} (hv : v β‰  0) (hder : HasDerivAt (fun s => F (s, y)) v (Οƒ y)) : ContMDiffAt (𝓑 n) π“˜(ℝ, ℝ) ∞ Οƒ y := by let e := extChartAt (𝓑 n) y have he := (contMDiffWithinAt_extChartAt_symm_target (n := ∞) y (mem_extChartAt_target y)).contMDiffAt (extChartAt_target_mem_nhds' (I := 𝓑 n) (mem_extChartAt_target y)) let G : EuclideanSpace ℝ (Fin n) Γ— ℝ β†’ ℝ := fun q => F (q.2, e.symm q.1) let qβ‚€ : EuclideanSpace ℝ (Fin n) Γ— ℝ := (e y, Οƒ y) have hG : ContDiffAt ℝ ∞ G qβ‚€ := by have he' : ContMDiffAt π“˜(ℝ, EuclideanSpace ℝ (Fin n) Γ— ℝ) (𝓑 n) ∞ (fun q => e.symm q.1) qβ‚€ := he.comp qβ‚€ contDiffAt_fst.contMDiffAt have hpair : ContMDiffAt π“˜(ℝ, EuclideanSpace ℝ (Fin n) Γ— ℝ) (π“˜(ℝ, ℝ).prod (𝓑 n)) ∞ (fun q => (q.2, e.symm q.1)) qβ‚€ := contDiffAt_snd.contMDiffAt.prodMk he' have hF' := hF.contMDiffAt ((hI.prod hV).mem_nhds (show (Οƒ y, y) ∈ I Γ—Λ’ V from ⟨(hroot y hy).1, hy⟩)) have hsame : (qβ‚€.2, e.symm qβ‚€.1) = (Οƒ y, y) := by simp only [qβ‚€, e.left_inv (mem_extChartAt_source y)] rw [← hsame] at hF' exact (hF'.comp qβ‚€ hpair).contDiffAt have hGder : HasDerivAt (fun s => G (qβ‚€.1, s)) v (Οƒ y) := by simpa only [G, qβ‚€, e.left_inv (mem_extChartAt_source y)] using hder have hpart : (fderiv ℝ G qβ‚€).comp (ContinuousLinearMap.inr ℝ (EuclideanSpace ℝ (Fin n)) ℝ) = v β€’ (ContinuousLinearMap.id ℝ ℝ) := by have hd := (hG.differentiableAt (by simp)).hasFDerivAt have hcomp := hd.comp (Οƒ y) ((hasFDerivAt_const qβ‚€.1 (Οƒ y)).prodMk (hasFDerivAt_id (Οƒ y))) have heq := hcomp.unique hGder.hasFDerivAt apply ContinuousLinearMap.ext intro z have hz := congrArg (fun L : ℝ β†’L[ℝ] ℝ => L z) heq change fderiv ℝ G qβ‚€ (0, z) = z * v at hz change fderiv ℝ G qβ‚€ (0, z) = v * z simpa only [mul_comm] using hz have hinv : ((fderiv ℝ G qβ‚€).comp (ContinuousLinearMap.inr ℝ (EuclideanSpace ℝ (Fin n)) ℝ)).IsInvertible := by rw [hpart] refine ⟨(LinearEquiv.smulOfNeZero ℝ ℝ v hv).toContinuousLinearEquiv, ?_⟩ apply ContinuousLinearMap.ext intro z rfl let ψ := hG.implicitFunction (by simp) hinv have hψ : ContDiffAt ℝ ∞ ψ (e y) := hG.contDiffAt_implicitFunction (by simp) hinv have hψzero : ψ (e y) = Οƒ y := hG.implicitFunction_apply_self (by simp) hinv have hψeq : βˆ€αΆ  z in 𝓝 (e y), G (z, ψ z) = G qβ‚€ := hG.eventually_apply_implicitFunction (by simp) hinv have hψI : βˆ€αΆ  z in 𝓝 (e y), ψ z ∈ I := by apply hψ.continuousAt.preimage_mem_nhds rw [hψzero] exact hI.mem_nhds (hroot y hy).1 have hechart : ContMDiffAt (𝓑 n) (𝓑 n) ∞ e y := contMDiffAt_extChartAt have hcomp : ContMDiffAt (𝓑 n) π“˜(ℝ, ℝ) ∞ (fun z => ψ (e z)) y := hψ.contMDiffAt.comp y hechart apply hcomp.congr_of_eventuallyEq filter_upwards [hechart.continuousAt hψeq, hechart.continuousAt hψI, hV.mem_nhds hy, extChartAt_source_mem_nhds' (I := 𝓑 n) (mem_extChartAt_source y)] with z heq hIz hz hchartz apply (hinj z hz) (hroot z hz).1 hIz change F (Οƒ z, z) = F (ψ (e z), z) rw [(hroot z hz).2] have hback : e.symm (e z) = z := e.left_inv hchartz change 0 = F (ψ (e z), z) conv_rhs => arg 1; arg 2; rw [← hback] change 0 = G (e z, ψ (e z)) rw [heq] simpa only [G, qβ‚€, e.left_inv (mem_extChartAt_source y)] using (hroot y hy).2.symm end Poincare.Manifold namespace Poincare.Manifold private theorem time_control_of_derivative_le_neg {F : ℝ β†’ ℝ} {F' : ℝ β†’ ℝ} {a b c s : ℝ} (ha : a < 0) (hb : 0 < b) (hc : 0 < c) (hs : s ∈ Ioo a b) (hF : βˆ€ t ∈ Ioo a b, HasDerivAt F (F' t) t) (hd : βˆ€ t ∈ Ioo a b, F' t ≀ -c) : |s| ≀ |F 0 - F s| / c ∧ (0 ≀ s ↔ F s ≀ F 0) := by have hz : (0 : ℝ) ∈ Ioo a b := ⟨ha, hb⟩ have hcont : ContinuousOn F (Ioo a b) := fun t ht => (hF t ht).continuousAt.continuousWithinAt have hdiff : DifferentiableOn ℝ F (interior (Ioo a b)) := by simpa only [interior_Ioo] using (show DifferentiableOn ℝ F (Ioo a b) from fun t ht => (hF t ht).differentiableAt.differentiableWithinAt) have hder : βˆ€ t ∈ interior (Ioo a b), deriv F t ≀ -c := by simpa only [interior_Ioo] using (show βˆ€ t ∈ Ioo a b, deriv F t ≀ -c from fun t ht => by rw [(hF t ht).deriv]; exact hd t ht) by_cases hpos : 0 ≀ s Β· have hle := (convex_Ioo a b).image_sub_le_mul_sub_of_deriv_le hcont hdiff hder 0 hz s hs hpos have hval : F s ≀ F 0 := by nlinarith refine ⟨?_, iff_of_true hpos hval⟩ rw [abs_of_nonneg hpos, abs_of_nonneg (sub_nonneg.mpr hval)] exact (le_div_iffβ‚€ hc).mpr (by nlinarith) Β· have hneg : s < 0 := lt_of_not_ge hpos have hle := (convex_Ioo a b).image_sub_le_mul_sub_of_deriv_le hcont hdiff hder s hs 0 hz hneg.le have hval : F 0 < F s := by nlinarith refine ⟨?_, iff_of_false hpos (not_le.mpr hval)⟩ rw [abs_of_neg hneg, abs_of_neg (sub_neg.mpr hval)] exact (le_div_iffβ‚€ hc).mpr (by nlinarith) end Poincare.Manifold namespace Poincare.Manifold private theorem image_sub_le_of_derivative_le {F F' : ℝ β†’ ℝ} {a b c u v : ℝ} (hF : βˆ€ s ∈ Ioo a b, HasDerivAt F (F' s) s) (hd : βˆ€ s ∈ Ioo a b, F' s ≀ -c) (hu : u ∈ Ioo a b) (hv : v ∈ Ioo a b) (huv : u ≀ v) : F v - F u ≀ -c * (v - u) := (convex_Ioo a b).image_sub_le_mul_sub_of_deriv_le (fun s hs => (hF s hs).continuousAt.continuousWithinAt) (fun s hs => (hF s (interior_subset hs)).differentiableAt.differentiableWithinAt) (fun s hs => by rw [(hF s (interior_subset hs)).deriv]; exact hd s (interior_subset hs)) u hu v hv huv private theorem strictAntiOn_of_derivative_le_neg {F F' : ℝ β†’ ℝ} {a b c : ℝ} (hc : 0 < c) (hF : βˆ€ s ∈ Ioo a b, HasDerivAt F (F' s) s) (hd : βˆ€ s ∈ Ioo a b, F' s ≀ -c) : StrictAntiOn F (Ioo a b) := by intro u hu v hv huv have hle := image_sub_le_of_derivative_le hF hd hu hv huv.le have hneg : -c * (v - u) < 0 := mul_neg_of_neg_of_pos (by linarith) (sub_pos.mpr huv) linarith end Poincare.Manifold namespace Poincare.Manifold theorem exists_smooth_hitting_time_of_derivative_le_neg {n : β„•} {M : Type*} [TopologicalSpace M] [ChartedSpace (EuclideanSpace ℝ (Fin n)) M] [IsManifold (𝓑 n) ∞ M] {F : ℝ Γ— M β†’ ℝ} {F' : ℝ Γ— M β†’ ℝ} {W : Set M} (hW : IsOpen W) {T Ξ΄ c : ℝ} (hT : 0 ≀ T) (hΞ΄ : 0 < Ξ΄) (hc : 0 < c) (hF : ContMDiffOn (π“˜(ℝ, ℝ).prod (𝓑 n)) π“˜(ℝ, ℝ) ∞ F (Ioo (-Ξ΄) (T + Ξ΄) Γ—Λ’ W)) (hder : βˆ€ y ∈ W, βˆ€ s ∈ Ioo (-Ξ΄) (T + Ξ΄), HasDerivAt (fun u => F (u, y)) (F' (s, y)) s) (hbound : βˆ€ y ∈ W, βˆ€ s ∈ Ioo (-Ξ΄) (T + Ξ΄), F' (s, y) ≀ -c) (t : ℝ) : βˆƒ (V : Set M) (Οƒ : M β†’ ℝ), IsOpen V ∧ V βŠ† W ∧ {y | y ∈ W ∧ t ≀ F (0, y) ∧ F (0, y) ≀ t + c * T} βŠ† V ∧ ContMDiffOn (𝓑 n) π“˜(ℝ, ℝ) ∞ Οƒ V ∧ (βˆ€ y ∈ V, Οƒ y ∈ Ioo (-Ξ΄) (T + Ξ΄) ∧ F (Οƒ y, y) = t ∧ |Οƒ y| ≀ |F (0, y) - t| / c ∧ (0 ≀ Οƒ y ↔ t ≀ F (0, y)) ∧ (F (0, y) = t β†’ Οƒ y = 0)) ∧ βˆ€ y ∈ V, t ≀ F (0, y) β†’ F (0, y) ≀ t + c * T β†’ Οƒ y ∈ Icc 0 T := by classical let a := -Ξ΄ / 2 let b := T + Ξ΄ / 2 have ha : a ∈ Ioo (-Ξ΄) (T + Ξ΄) := by constructor <;> dsimp [a] <;> linarith have hb : b ∈ Ioo (-Ξ΄) (T + Ξ΄) := by constructor <;> dsimp [b] <;> linarith have hab : a ≀ b := by dsimp [a,b]; linarith have hzero : (0 : ℝ) ∈ Ioo (-Ξ΄) (T + Ξ΄) := by constructor <;> linarith have hIcc : Icc a b βŠ† Ioo (-Ξ΄) (T + Ξ΄) := fun _ hu => ⟨ha.1.trans_le hu.1, hu.2.trans_lt hb.2⟩ have hFtime (s : ℝ) (hs : s ∈ Ioo (-Ξ΄) (T + Ξ΄)) : ContinuousOn (fun y => F (s, y)) W := by intro y hy exact ((hF.contMDiffAt ((isOpen_Ioo.prod hW).mem_nhds ⟨hs, hy⟩)).comp y (contMDiffAt_const.prodMk contMDiffAt_id)).continuousAt.continuousWithinAt let V := W ∩ {y | t < F (a, y)} ∩ {y | F (b, y) < t} have hVo : IsOpen V := by have haopen := (hFtime a ha).isOpen_inter_preimage hW (isOpen_Ioi (a := t)) have hbopen := (hFtime b hb).isOpen_inter_preimage hW (isOpen_Iio (a := t)) convert haopen.inter hbopen using 1 ext y simp only [V, mem_inter_iff, mem_ofPred_eq, mem_preimage, mem_Ioi, mem_Iio] tauto have hVW : V βŠ† W := fun _ hy => hy.1.1 have hK : {y | y ∈ W ∧ t ≀ F (0, y) ∧ F (0, y) ≀ t + c * T} βŠ† V := by intro y hy have hleft := Poincare.Manifold.image_sub_le_of_derivative_le (hder y hy.1) (hbound y hy.1) ha hzero (by dsimp [a]; linarith) have hright := Poincare.Manifold.image_sub_le_of_derivative_le (hder y hy.1) (hbound y hy.1) hzero hb (by dsimp [b]; linarith) refine ⟨⟨hy.1, ?_⟩, ?_⟩ Β· change t < F (a,y) have hpos : 0 < c * (0-a) := mul_pos hc (by dsimp[a]; linarith) nlinarith [hy.2.1] Β· change F (b,y) < t have hpos : 0 < c * (b-T) := mul_pos hc (by dsimp[b]; linarith) nlinarith [hy.2.2] have hex (y : M) : βˆƒ s : ℝ, y ∈ V β†’ s ∈ Ioo (-Ξ΄) (T + Ξ΄) ∧ F (s, y) = t := by by_cases hy : y ∈ V Β· obtain ⟨s, hs, heq⟩ := intermediate_value_Icc' hab (show ContinuousOn (fun s => F (s,y)) (Icc a b) from fun s hs => (hder y (hVW hy) s (hIcc hs)).continuousAt.continuousWithinAt) ⟨hy.2.le, hy.1.2.le⟩ exact ⟨s, fun _ => ⟨hIcc hs, heq⟩⟩ Β· exact ⟨0, fun h => (hy h).elim⟩ choose Οƒ hΟƒroot using hex have hanti (y : M) (hy : y ∈ W) : StrictAntiOn (fun s => F (s,y)) (Ioo (-Ξ΄) (T + Ξ΄)) := Poincare.Manifold.strictAntiOn_of_derivative_le_neg hc (hder y hy) (hbound y hy) have hΟƒsmooth : ContMDiffOn (𝓑 n) π“˜(ℝ, ℝ) ∞ Οƒ V := by intro y hy apply (contMDiffAt_unique_time_root isOpen_Ioo hVo ((hF.mono (prod_mono_right hVW)).sub contMDiffOn_const) (F := fun q => F q - t) (v := F' (Οƒ y,y)) ?_ ?_ hy ?_ ?_).contMDiffWithinAt Β· intro z hz exact ⟨(hΟƒroot z hz).1, sub_eq_zero.mpr (hΟƒroot z hz).2⟩ Β· intro z hz s hs u hu heq apply (hanti z (hVW hz)).injOn hs hu exact sub_left_injective heq Β· exact (lt_of_le_of_lt (hbound y (hVW hy) _ (hΟƒroot y hy).1) (by linarith : -c < 0)).ne Β· exact (hder y (hVW hy) _ (hΟƒroot y hy).1).sub_const t have hcontrol (y : M) (hy : y ∈ V) : |Οƒ y| ≀ |F (0,y)-t| / c ∧ (0 ≀ Οƒ y ↔ t ≀ F (0,y)) := by have hd := Poincare.Manifold.time_control_of_derivative_le_neg (by linarith : -Ξ΄ < 0) (by linarith : 0 < T+Ξ΄) hc (hΟƒroot y hy).1 (hder y (hVW hy)) (hbound y (hVW hy)) simpa only [(hΟƒroot y hy).2] using hd refine ⟨V, Οƒ, hVo, hVW, hK, hΟƒsmooth, ?_, ?_⟩ Β· intro y hy refine ⟨(hΟƒroot y hy).1, (hΟƒroot y hy).2, (hcontrol y hy).1, (hcontrol y hy).2, ?_⟩ intro heq apply abs_eq_zero.mp apply le_antisymm _ (abs_nonneg _) simpa only [heq, sub_self, abs_zero, zero_div] using (hcontrol y hy).1 Β· intro y hy hlow hupp have hs0 := (hcontrol y hy).2.mpr hlow refine ⟨hs0, ?_⟩ have hle : Οƒ y ≀ (F (0,y)-t)/c := by simpa only [abs_of_nonneg hs0, abs_of_nonneg (sub_nonneg.mpr hlow)] using (hcontrol y hy).1 exact hle.trans ((div_le_iffβ‚€ hc).mpr (by linarith)) end Poincare.Manifold