import Mathlib import OAI.Analysis.BiholderTransport.Geodesics.NoCorner import OAI.Analysis.BiholderTransport.Geodesics.IntegratedGauss namespace OAI noncomputable section open Set MeasureTheory Manifold Bundle open scoped ContDiff Manifold ENNReal NNReal Topology open Set Filter open scoped Topology NNReal open Set Filter open scoped Topology open Set Manifold MeasureTheory Bundle open scoped ENNReal ContDiff Topology open Set open scoped Topology open Set Filter Manifold Bundle ContinuousLinearMap open scoped Topology ContDiff Manifold Bundle open Set Filter ContinuousLinearMap InnerProductSpace open scoped Topology ContDiff open Set Filter ContinuousLinearMap open scoped Topology ContDiff open Set Filter ContinuousLinearMap open scoped Topology ContDiff open Set Filter ContinuousLinearMap open scoped Topology ContDiff open scoped NNReal open Set Filter ContinuousLinearMap open scoped Topology ContDiff open Set Filter ContinuousLinearMap open scoped Topology open MeasureTheory open scoped ContDiff ENNReal open Set Filter Manifold Bundle ContinuousLinearMap MeasureTheory open scoped Topology ContDiff Manifold Bundle ENNReal open Set Filter Manifold MeasureTheory Bundle open scoped ENNReal ContDiff Topology Manifold open Set Filter Manifold Bundle ContinuousLinearMap open scoped Topology ContDiff Manifold Bundle open Set Filter Manifold Bundle open scoped Topology ContDiff Manifold Bundle open Set Filter Manifold Bundle open scoped Topology ContDiff Manifold Bundle open Set Filter Bundle open scoped Topology Bundle open scoped Topology open Function Manifold Set open Manifold Bundle open scoped Manifold Bundle open Set open Set Filter open scoped Topology ContDiff namespace WeakMTWTransport section variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] {M : Type*} [MetricSpace M] [CompactSpace M] [ChartedSpace E M] [IsManifold π“˜(ℝ,E) ∞ M] [RiemannianBundle (fun x : M => TangentSpace π“˜(ℝ,E) x)] [IsContMDiffRiemannianBundle π“˜(ℝ,E) ∞ E (fun x : M => TangentSpace π“˜(ℝ,E) x)] [IsRiemannianManifold π“˜(ℝ,E) M] lemma exists_local_spray_cost_gradient (a : M) : βˆƒ Ξ΄ : ℝ, 0 < Ξ΄ ∧ βˆ€ z : TangentBundle π“˜(ℝ,E) M, βˆ€ t : ℝ, 0 < t β†’ z.1 ∈ Metric.ball a Ξ΄ β†’ (sprayFlow t z).1 ∈ Metric.ball a Ξ΄ β†’ dist z.1 (sprayFlow t z).1 = t*β€–z.2β€– β†’ HasMFDerivAt π“˜(ℝ,E) π“˜(ℝ,ℝ) (fun y => dist z.1 y^2/2) (sprayFlow t z).1 (innerSL ℝ (t β€’ (sprayFlow t z).2)) := by obtain ⟨δ,hΞ΄,H⟩ := exists_local_cost_gradient (E := E) a refine ⟨δ,hΞ΄,?_⟩ intro z t ht hz hy hmin obtain ⟨⟨b,w⟩,hb,hn,_,hD⟩ := H z.1 hz (sprayFlow t z).1 hy dsimp only at hb subst b have hw := sprayFlow_minimizer_gradient z ht hmin w hn hD rwa [hw] at hD omit [IsRiemannianManifold π“˜(ℝ,E) M] in lemma sprayFlow_reverse (z : TangentBundle π“˜(ℝ,E) M) (t : ℝ) : sprayFlow t (tangentScale (-1) (sprayFlow t z)) = tangentScale (-1) z := by rw [sprayFlow_scale,neg_one_mul,←sprayFlow_add,neg_add_cancel,sprayFlow_zero] lemma exists_local_spray_cost_start_gradient (a : M) : βˆƒ Ξ΄ : ℝ, 0 < Ξ΄ ∧ βˆ€ z : TangentBundle π“˜(ℝ,E) M, βˆ€ t : ℝ, 0 < t β†’ z.1 ∈ Metric.ball a Ξ΄ β†’ (sprayFlow t z).1 ∈ Metric.ball a Ξ΄ β†’ dist z.1 (sprayFlow t z).1 = t*β€–z.2β€– β†’ HasMFDerivAt π“˜(ℝ,E) π“˜(ℝ,ℝ) (fun y => dist y (sprayFlow t z).1^2/2) z.1 (innerSL ℝ ((-t) β€’ z.2)) := by obtain ⟨δ,hΞ΄,H⟩ := exists_local_spray_cost_gradient (E := E) a refine ⟨δ,hΞ΄,?_⟩ intro z t ht hz hy hmin let w := tangentScale (-1) (sprayFlow t z) have hw : sprayFlow t w = tangentScale (-1) z := sprayFlow_reverse z t have hb : (sprayFlow t w).1 ∈ Metric.ball a Ξ΄ := by rw [hw]; exact hz have hm : dist w.1 (sprayFlow t w).1 = t*β€–w.2β€– := by rw [hw] change dist (sprayFlow t z).1 z.1 = t*β€–(-1:ℝ) β€’ (sprayFlow t z).2β€– rw [neg_one_smul,norm_neg,sprayFlow_speed,dist_comm,hmin] have hd := H w t ht hy hb hm rw [hw] at hd change HasMFDerivAt π“˜(ℝ,E) π“˜(ℝ,ℝ) (fun y => dist (sprayFlow t z).1 y^2/2) z.1 (innerSL ℝ (t β€’ ((-1:ℝ) β€’ z.2))) at hd rw [smul_smul,mul_neg_one] at hd have hf : (fun y => dist y (sprayFlow t z).1^2/2) = (fun y => dist (sprayFlow t z).1 y^2/2) := by funext y; rw [dist_comm] rw [hf] exact hd end variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] {M : Type*} [MetricSpace M] [CompactSpace M] [ChartedSpace E M] [IsManifold π“˜(ℝ,E) ∞ M] [RiemannianBundle (fun x : M => TangentSpace π“˜(ℝ,E) x)] [IsContMDiffRiemannianBundle π“˜(ℝ,E) ∞ E (fun x : M => TangentSpace π“˜(ℝ,E) x)] [IsRiemannianManifold π“˜(ℝ,E) M] omit [FiniteDimensional ℝ E] [CompactSpace M] [IsContMDiffRiemannianBundle π“˜(ℝ,E) ∞ E (fun x : M => TangentSpace π“˜(ℝ,E) x)] [IsRiemannianManifold π“˜(ℝ,E) M] in lemma contMDiff_fiber_embedding (x : M) : ContMDiff π“˜(ℝ,TangentSpace π“˜(ℝ,E) x) (π“˜(ℝ,E).prod π“˜(ℝ,E)) ∞ (fun v : TangentSpace π“˜(ℝ,E) x => (⟨x,v⟩ : TangentBundle π“˜(ℝ,E) M)) := by intro v rw [Bundle.contMDiffAt_totalSpace] refine ⟨contMDiffAt_const,?_⟩ let e := trivializationAt E (fun y : M => TangentSpace π“˜(ℝ,E) y) x let L : TangentSpace π“˜(ℝ,E) x β†’L[ℝ] E := e.continuousLinearMapAt ℝ x have heq : (fun w : TangentSpace π“˜(ℝ,E) x => (e (⟨x,w⟩ : TangentBundle π“˜(ℝ,E) M)).2) = L := by funext w exact (e.continuousLinearMapAt_apply_of_mem ℝ (mem_baseSet_trivializationAt E _ x) _).symm change ContMDiffAt π“˜(ℝ,TangentSpace π“˜(ℝ,E) x) π“˜(ℝ,E) ∞ (fun w => (e ⟨x,w⟩).2) v rw [heq] exact L.contDiff.contDiffAt.contMDiffAt omit [IsRiemannianManifold π“˜(ℝ,E) M] in lemma contMDiff_spray_fiber (x : M) (t : ℝ) : ContMDiff π“˜(ℝ,TangentSpace π“˜(ℝ,E) x) (π“˜(ℝ,E).prod π“˜(ℝ,E)) ∞ (fun v : TangentSpace π“˜(ℝ,E) x => sprayFlow t (⟨x,v⟩ : TangentBundle π“˜(ℝ,E) M)) := contMDiff_sprayFlow.comp (contMDiff_const.prodMk (contMDiff_fiber_embedding x)) omit [IsRiemannianManifold π“˜(ℝ,E) M] in lemma spray_action_line_stationary (x : M) (p w : TangentSpace π“˜(ℝ,E) x) (L Ξ΅ : ℝ) (hΞ΅ : Ξ΅ β‰  0) (y : M) (hD : HasMFDerivAt π“˜(ℝ,E) π“˜(ℝ,ℝ) (fun b => dist b y^2/2) (sprayFlow L (⟨x,p⟩ : TangentBundle π“˜(ℝ,E) M)).1 (innerSL ℝ ((-Ξ΅) β€’ (sprayFlow L (⟨x,p⟩ : TangentBundle π“˜(ℝ,E) M)).2))) : HasDerivAt (fun s : ℝ => L*β€–p+s β€’ wβ€–^2/2 + (dist (sprayFlow L (⟨x,p+s β€’ w⟩ : TangentBundle π“˜(ℝ,E) M)).1 y^2/2)/Ξ΅) 0 0 := by let Ξ½ : ℝ β†’ TangentBundle π“˜(ℝ,E) M := fun s => sprayFlow L ⟨x,p+s β€’ w⟩ let ψ : ℝ β†’ M := fun s => (Ξ½ s).1 have hψ : ContMDiff π“˜(ℝ,ℝ) π“˜(ℝ,E) ∞ ψ := (Bundle.contMDiff_proj (fun b : M => TangentSpace π“˜(ℝ,E) b)).comp (contMDiff_sprayFlow.comp (contMDiff_const.prodMk (contMDiff_fiber_line x p w))) have hΞ½0 : Ξ½ 0 = sprayFlow L (⟨x,p⟩ : TangentBundle π“˜(ℝ,E) M) := by simp [Ξ½] have hDβ‚€ : HasMFDerivAt π“˜(ℝ,E) π“˜(ℝ,ℝ) (fun b => dist b y^2/2) (Ξ½ 0).1 (innerSL ℝ ((-Ξ΅) β€’ (Ξ½ 0).2)) := by rw [hΞ½0]; exact hD have hDc := hDβ‚€.comp 0 (hψ.mdifferentiable (by simp) 0).hasMFDerivAt let J := mfderiv π“˜(ℝ,ℝ) π“˜(ℝ,E) ψ 0 (1:ℝ) have hd : HasDerivAt (fun s => dist (ψ s) y^2/2) ((-Ξ΅) * inner ℝ (Ξ½ 0).2 J) 0 := by have hf : HasFDerivAt (fun s => dist (ψ s) y^2/2) ((innerSL ℝ ((-Ξ΅) β€’ (Ξ½ 0).2)).comp (mfderiv π“˜(ℝ,ℝ) π“˜(ℝ,E) ψ 0)) 0 := by convert! hDc.hasFDerivAt using 1 convert! hf.hasDerivAt using 1 change (-Ξ΅) * inner ℝ (Ξ½ 0).2 J = inner ℝ ((-Ξ΅) β€’ (Ξ½ 0).2) J rw [real_inner_smul_left] have hg : inner ℝ (Ξ½ 0).2 J = L*inner ℝ p w := by have he : HasDerivAt (fun s : ℝ => β€–p+s β€’ wβ€–^2) (2*inner ℝ p w) 0 := by convert! ((hasDerivAt_const (0:ℝ) p).add ((hasDerivAt_id (0:ℝ)).smul_const w)).norm_sq using 1 simp have H := spray_variation_pairing_affine (Ξ½ := fun s => (⟨x,p+s β€’ w⟩ : TangentBundle π“˜(ℝ,E) M)) (contMDiff_fiber_line x p w) he L convert! H using 1 simp have hn := ((hasDerivAt_const (0:ℝ) p).add ((hasDerivAt_id (0:ℝ)).smul_const w)).norm_sq have he : HasDerivAt (fun s : ℝ => L*β€–p+s β€’ wβ€–^2/2) (L*inner ℝ p w) 0 := by convert! (hn.const_mul L).div_const 2 using 1 simp ring have H := he.add (hd.div_const Ξ΅) apply H.congr_deriv rw [hg] field_simp ring end WeakMTWTransport end end OAI