import Mathlib import OAI.Analysis.BiholderTransport.Contact.HopfSupports namespace OAI noncomputable section open Set Filter Manifold Bundle Metric open scoped Topology ContDiff NNReal namespace WeakMTWTransport variable {n : β„•} {M : Type*} [MetricSpace M] [CompactSpace M] [Nonempty M] [ChartedSpace (Model n) M] [IsManifold π“˜(ℝ,Model n) ∞ M] [RiemannianBundle (fun x : M => TangentSpace π“˜(ℝ,Model n) x)] [IsContMDiffRiemannianBundle π“˜(ℝ,Model n) ∞ (Model n) (fun x : M => TangentSpace π“˜(ℝ,Model n) x)] [IsRiemannianManifold π“˜(ℝ,Model n) M] omit [CompactSpace M] [Nonempty M] in lemma cost_divided_triangle_two_times (x y z : M) {s t : ℝ} (hs : 0 TangentSpace π“˜(ℝ,Model n) x)] [IsContMDiffRiemannianBundle π“˜(ℝ,Model n) ∞ (Model n) (fun x : M => TangentSpace π“˜(ℝ,Model n) x)] [IsRiemannianManifold π“˜(ℝ,Model n) M] in lemma mdifferentiableAt_of_chart_differentiable {f : M β†’ ℝ} {x : M} (hd : DifferentiableAt ℝ (fun y => f ((extChartAt π“˜(ℝ,Model n) x).symm y)) (extChartAt π“˜(ℝ,Model n) x x)) : MDifferentiableAt π“˜(ℝ,Model n) π“˜(ℝ,ℝ) f x := by have H := hd.hasFDerivAt.hasMFDerivAt.comp x (mdifferentiableAt_extChartAt (I := π“˜(ℝ,Model n)) (show x∈(chartAt (Model n) x).source from mem_chart_source _ _)).hasMFDerivAt apply (H.congr_of_eventuallyEq ?_).mdifferentiableAt filter_upwards [extChartAt_source_mem_nhds (I := π“˜(ℝ,Model n)) x] with y hy simp only [Function.comp_apply,(extChartAt π“˜(ℝ,Model n) x).left_inv hy] lemma WeakMTW.mdifferentiable_hopfLax (hmtw : WeakMTW (n := n) (M := M)) {u v : M β†’ ℝ} (hu : Continuous u) (hv : Continuous v) (hdual : IsCostDualPair u v) {t : ℝ} (ht : 0 u x+cost x a/(t-Ξ΅)+cost a y/Ξ΅ have hG : HasMFDerivAt π“˜(ℝ,Model n) π“˜(ℝ,ℝ) G z.1 (innerSL ℝ z.2) := by have H := (hasMFDerivAt_const (I := π“˜(ℝ,Model n)) (I' := π“˜(ℝ,ℝ)) (u x+cost x a/(t-Ξ΅)) z.1).add (hshort.const_smul Ρ⁻¹) have heD : 0+Ρ⁻¹ β€’ innerSL ℝ (Ξ΅ β€’ (sprayFlow t (⟨x,p⟩ : TangentBundle π“˜(ℝ,Model n) M)).2) = innerSL ℝ z.2 := by ext v simp only [zero_add,_root_.smul_apply,smul_eq_mul,innerSL_apply_apply, real_inner_smul_left] dsimp [z,w] field_simp replace H := H.congr_mfderiv heD have heG : G = ((fun _ => u x+cost x a/(t-Ξ΅)) + Ρ⁻¹ β€’ fun y => dist (sprayFlow (t-Ξ΅) (⟨x,p⟩ : TangentBundle π“˜(ℝ,Model n) M)).1 y^2/2) := by funext y dsimp [G,cost,a,w] ring rw [heG] exact H have hmin : dist x z.1=t*β€–pβ€– := by dsimp [z,w] rw [←riemannianExp_smul,minimizingVectors_smul hp ht.le ht1,norm_smul, Real.norm_eq_abs,abs_of_pos ht] have hleft : dist x a=(t-Ξ΅)*β€–pβ€– := sprayFlow_minimizing_prefix w (sub_pos.mpr hΞ΅t).le (by linarith) hmin have hright : dist a z.1=Ξ΅*β€–pβ€– := by have H := sprayFlow_minimizing_subinterval w (sub_pos.mpr hΞ΅t).le (by linarith) hmin simpa only [sub_sub_cancel] using H have hcontact : hopfLax t u z.1=G z.1 := by rw [heq] dsimp [G,cost] rw [hmin,hleft,hright] field_simp ring have hle : βˆ€ y, hopfLax t u y≀G y := by intro y have H := cost_divided_triangle_two_times x a y (sub_pos.mpr hΞ΅t) hΞ΅ rw [sub_add_cancel] at H exact (hopfLax_le hu t y x).trans (by dsimp [G]; linarith) exact hd.hasMFDerivAt.congr_mfderiv ((upper_contact_mfderiv hd hG.mdifferentiableAt (Filter.Eventually.of_forall hle) hcontact).trans hG.mfderiv) def riemannianGradient (f : M β†’ ℝ) (x : M) : TangentSpace π“˜(ℝ,Model n) x := by letI : FiniteDimensional ℝ (TangentSpace π“˜(ℝ,Model n) x) := inferInstanceAs (FiniteDimensional ℝ (Model n)) exact (InnerProductSpace.toDual ℝ (TangentSpace π“˜(ℝ,Model n) x)).symm (mfderiv π“˜(ℝ,Model n) π“˜(ℝ,ℝ) f x) omit [CompactSpace M] [Nonempty M] [IsContMDiffRiemannianBundle π“˜(ℝ,Model n) ∞ (Model n) (fun x : M => TangentSpace π“˜(ℝ,Model n) x)] [IsRiemannianManifold π“˜(ℝ,Model n) M] in lemma riemannianGradient_eq_of_derivative {f : M β†’ ℝ} {x : M} {v : TangentSpace π“˜(ℝ,Model n) x} (h : HasMFDerivAt π“˜(ℝ,Model n) π“˜(ℝ,ℝ) f x (innerSL ℝ v)) : riemannianGradient (n := n) f x=v := by let : FiniteDimensional ℝ (TangentSpace π“˜(ℝ,Model n) x) := inferInstanceAs (FiniteDimensional ℝ (Model n)) rw [riemannianGradient,h.mfderiv] exact (InnerProductSpace.toDual ℝ (TangentSpace π“˜(ℝ,Model n) x)).symm_apply_apply v lemma WeakMTW.hopfLax_backward_flow (hmtw : WeakMTW (n := n) (M := M)) {v : M β†’ ℝ} (hv : Continuous v) {t : ℝ} (ht : 0