import Mathlib import OAI.Analysis.BiholderTransport.LinearAlgebra.FirstMatrixLimit import OAI.Analysis.BiholderTransport.Coordinates.CoordinateMatrices import OAI.Analysis.BiholderTransport.Coordinates.ChartActiveLimit namespace OAI noncomputable section open Set Filter Manifold Bundle open scoped Topology ContDiff 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] structure ChartFixedPrefixLimit (a : M) (v G : M β†’ ℝ) (t : ℝ) (q : β„• β†’ subgradientGraph (n := n) (cTransform v)) (qβ‚€ : subgradientGraph (n := n) (cTransform v)) where Οƒ : β„• β†’ β„• strictMono : StrictMono Οƒ pj : β„• β†’ Fin (Module.finrank ℝ (Model n)+1) β†’ Model n w : β„• β†’ Fin (Module.finrank ℝ (Model n)+1) β†’ ℝ pjβ‚€ : Fin (Module.finrank ℝ (Model n)+1) β†’ Model n wβ‚€ : Fin (Module.finrank ℝ (Model n)+1) β†’ ℝ H : Model n β†’L[ℝ] Model n β†’L[ℝ] ℝ L : Model n β†’L[ℝ] Model n β†’L[ℝ] ℝ activeLimit : βˆ€ i,chartFiberInverse a (graphBaseCoordinate a qβ‚€.1) (pjβ‚€ i)∈ activeLogs v ((extChartAt π“˜(ℝ,Model n) a).symm (graphBaseCoordinate a qβ‚€.1)) nonnegLimit : βˆ€ i,0≀wβ‚€ i totalLimit : βˆ‘ i,wβ‚€ i=1 baryLimit : βˆ‘ i,wβ‚€ i β€’ pjβ‚€ i=graphVelocityCoordinate a qβ‚€.1 pjLimit : Tendsto pj atTop (𝓝 pjβ‚€) wLimit : Tendsto w atTop (𝓝 wβ‚€) HLimit : Tendsto (fun k=>coordinateCenterMatrix a t G (graphBaseCoordinate a (q (Οƒ k)).1) (graphVelocityCoordinate a (q (Οƒ k)).1)) atTop (𝓝 H) LLimit : Tendsto (fun k=>coordinatePoleMatrix a t v (graphBaseCoordinate a (q (Οƒ k)).1) (graphVelocityCoordinate a (q (Οƒ k)).1)) atTop (𝓝 L) positive : βˆ€ d:Model n,0≀L d d symmetric : βˆ€ d e:Model n,L d e=L e d kernel : βˆ€ i,βˆ€ d:Model n,L (pjβ‚€ i-graphVelocityCoordinate a qβ‚€.1) d=0 upper : βˆ€ d:Model n,H d d≀L d d samples : βˆ€αΆ  k in atTop, let b := graphBaseCoordinate a (q (Οƒ k)).1 let p := graphVelocityCoordinate a (q (Οƒ k)).1 let A := chartFiberInverse a b (βˆ€ i,0≀w k i) ∧ (βˆ‘ i,w k i=1) ∧ (βˆ‘ i,w k i β€’ pj k i=p) ∧ (βˆ€ i,A (pj k i)∈activeLogs v ((extChartAt π“˜(ℝ,Model n) a).symm b)) ∧ (βˆ€ i,0v (movingNormal a (b,pj k i+r))+β€–A (pj k i+r)β€–^2/2) 0 (w k i β€’ coordinatePoleMatrix a t v b p)) lemma WeakMTW.first_fixed_prefix_limit_in_chart (hmtw : WeakMTW (n := n) (M := M)) {v G : M β†’ ℝ} (hv : Continuous v) {t : ℝ} (ht : 0graphProjection (cTransform v) t (q k)) atTop (𝓝 (graphProjection (cTransform v) t qβ‚€))) {a c d : M} (ha0 : qβ‚€.1.1∈(extChartAt π“˜(ℝ,Model n) a).source) (hc : graphProjection (cTransform v) t qβ‚€βˆˆ(extChartAt π“˜(ℝ,Model n) c).source) (hd : qβ‚€.1.1∈(extChartAt π“˜(ℝ,Model n) d).source) : let Ο‡ := extChartAt π“˜(ℝ,Model n) c let F := fun z:Model n=>hopfLax t (cTransform v) (Ο‡.symm z) let C := fun z:Model n=>G (Ο‡.symm z) let z := fun k=>Ο‡ (graphProjection (cTransform v) t (q k)) let zβ‚€ := Ο‡ (graphProjection (cTransform v) t qβ‚€) βˆ€ Af Ac : Model n β†’L[ℝ] Model n β†’L[ℝ] ℝ, ContinuousAt (fderiv ℝ F) zβ‚€ β†’ ContinuousAt (fderiv ℝ C) zβ‚€ β†’ (βˆ€αΆ  z in 𝓝 zβ‚€,DifferentiableAt ℝ F z ∧ DifferentiableAt ℝ C z) β†’ Tendsto (fun k=>fderiv ℝ (fderiv ℝ F) (z k)) atTop (𝓝 Af) β†’ Tendsto (fun k=>fderiv ℝ (fderiv ℝ C) (z k)) atTop (𝓝 Ac) β†’ Tendsto (fun k=>fderiv ℝ F (z k)+fderiv ℝ C (z k)) atTop (𝓝 0) β†’ (βˆ€ r:Model n,Af r r+Ac r r≀0) β†’ (βˆ€αΆ  k in atTop,DifferentiableAt ℝ (fderiv ℝ F) (z k) ∧ DifferentiableAt ℝ (fderiv ℝ C) (z k) ∧ DifferentiableAt ℝ (fun w:Model n=>extChartAt π“˜(ℝ,Model n) d (hopfPole (n := n) t (cTransform v) (Ο‡.symm w))) (z k)) β†’ Nonempty (ChartFixedPrefixLimit a v G t q qβ‚€) := by dsimp only intro Af Ac hF hC hnear hAf hAc herr hquad hsample let Ο‡ := extChartAt π“˜(ℝ,Model n) c let F := fun z:Model n=>hopfLax t (cTransform v) (Ο‡.symm z) let C := fun z:Model n=>G (Ο‡.symm z) let z := fun k=>Ο‡ (graphProjection (cTransform v) t (q k)) let zβ‚€ := Ο‡ (graphProjection (cTransform v) t qβ‚€) have hzCoord : Tendsto z atTop (𝓝 zβ‚€) := ((continuousOn_extChartAt _).continuousAt ((isOpen_extChartAt_source _).mem_nhds hc)).tendsto.comp hz have hjF := hF.tendsto.comp hzCoord have hjC := hC.tendsto.comp hzCoord have hgrad : fderiv ℝ F zβ‚€+fderiv ℝ C zβ‚€=0 := tendsto_nhds_unique (hjF.add hjC) herr obtain ⟨K,hK,hKs,pj,w,pjβ‚€,wβ‚€,Οƒ,hΟƒ,hs,hpj,hw,ha,hn,h1,hbar⟩ := hmtw.active_barycentric_tail_limit_in_chart hv ht ht1 q qβ‚€ hz ha0 let b := fun k=>graphBaseCoordinate a (q (Οƒ k)).1 let p := fun k=>graphVelocityCoordinate a (q (Οƒ k)).1 let bβ‚€ := graphBaseCoordinate a qβ‚€.1 let pβ‚€ := graphVelocityCoordinate a qβ‚€.1 have hq := hmtw.graph_points_tendsto hv ht ht1 (hz.comp hΟƒ.tendsto_atTop) have hbase := (FiberBundle.continuous_proj (Model n) (TangentSpace π“˜(ℝ,Model n))).tendsto qβ‚€.1 |>.comp hq have hbsource : βˆ€αΆ  k in atTop,(q (Οƒ k)).1.1∈(extChartAt π“˜(ℝ,Model n) a).source := hbase.eventually ((isOpen_extChartAt_source _).mem_nhds ha0) have hdsource : βˆ€αΆ  k in atTop,(q (Οƒ k)).1.1∈(extChartAt π“˜(ℝ,Model n) d).source := hbase.eventually ((isOpen_extChartAt_source _).mem_nhds hd) have hzsource : βˆ€αΆ  k in atTop,graphProjection (cTransform v) t (q (Οƒ k))βˆˆΟ‡.source := (hz.comp hΟƒ.tendsto_atTop).eventually ((isOpen_extChartAt_source _).mem_nhds hc) obtain ⟨hb,hp⟩ := hmtw.graph_coordinate_limit_in_chart hv ht ht1 (hz.comp hΟƒ.tendsto_atTop) ha0 have hbβ‚€ : bβ‚€βˆˆ(extChartAt π“˜(ℝ,Model n) a).target := (extChartAt π“˜(ℝ,Model n) a).map_source ha0 have hpβ‚€ : t β€’ chartFiberInverse a bβ‚€ pβ‚€βˆˆ injectivityDomain ((extChartAt π“˜(ℝ,Model n) a).symm bβ‚€) := by exact hmtw.graphCoordinate_prefix_regular hv ht ht1 qβ‚€ ha0 have heβ‚€ : movingPrefix a t bβ‚€ pβ‚€=graphProjection (cTransform v) t qβ‚€ := by exact movingPrefix_graph_coordinates ha0 t (q := qβ‚€.1) have hg := movingPrefixChart_contDiffAt hbβ‚€ (heβ‚€ β–Έ hc) have henergy := movingPrefixEnergy_contDiffAt hbβ‚€ hpβ‚€ have he : βˆ€αΆ  k in atTop,movingPrefix a t (b k) (p k)= graphProjection (cTransform v) t (q (Οƒ k)) := hbsource.mono (fun k hk=>movingPrefix_graph_coordinates hk t) have hzEq : βˆ€αΆ  k in atTop,movingPrefixChart a c t (b k) (p k)=z (Οƒ k) := he.mono (fun k hk=>congrArg Ο‡ hk) have hM : βˆ€αΆ  k in atTop, (βˆ€ r:Model n,0≀coordinatePoleMatrix a t v (b k) (p k) r r) ∧ (βˆ€ r s:Model n,coordinatePoleMatrix a t v (b k) (p k) r s= coordinatePoleMatrix a t v (b k) (p k) s r) ∧ (βˆ€ i,βˆ€ r:Model n,coordinatePoleMatrix a t v (b k) (p k) (pj k i-p k) r=0) ∧ (βˆ€ i,chartFiberInverse a (b k) (pj k i)∈ activeLogs v ((extChartAt π“˜(ℝ,Model n) a).symm (b k))) ∧ (βˆ€ i,0v (movingNormal a (b k,pj k i+r))+ β€–chartFiberInverse a (b k) (pj k i+r)β€–^2/2) 0 (w k i β€’ coordinatePoleMatrix a t v (b k) (p k))) := by filter_upwards [hbsource,hdsource,hzsource,he,hzEq,hΟƒ.tendsto_atTop.eventually hsample] with k hbk hdk hzk hek hzEk hsk have hbtk := (extChartAt π“˜(ℝ,Model n) a).map_source hbk have hba : (extChartAt π“˜(ℝ,Model n) a).symm (b k)=(q (Οƒ k)).1.1 := (extChartAt π“˜(ℝ,Model n) a).left_inv hbk have hact : βˆ€ i,chartFiberInverse a (b k) (pj k i)∈ activeLogs v ((extChartAt π“˜(ℝ,Model n) a).symm (b k)) := fun i=>(mem_active_coordinates hKs ((hs k).1 i)).2.1 obtain ⟨hpos,hsym,hker,hjet⟩ := hmtw.coordinate_sample_pole_matrix hv ht ht1 hbtk (graphCoordinate_normalSubdifferential (q (Οƒ k)) hbk) (hek β–Έ hzk) (hba β–Έ hdk) (show DifferentiableAt ℝ _ (movingPrefixChart a c t (b k) (p k)) from hzEk β–Έ hsk.2.2) exact ⟨hpos,hsym,fun i=>hker (pj k i) (hact i),hact, fun i hi=>hjet _ (pj k) (w k) (hs k).2.1 (hs k).2.2.1 (hs k).2.2.2 hact i hi⟩ have hL_eq : βˆ€αΆ  k in atTop,coordinatePoleMatrix a t v (b k) (p k)= fderiv ℝ (fderiv ℝ (movingPrefixEnergy a t (b k))) (p k)- fderiv ℝ (fderiv ℝ (fun r=>F (movingPrefixChart a c t (b k) r))) (p k) := by filter_upwards [hbsource,hzsource,he] with k hbk hzk hek exact coordinatePoleMatrix_chart ((extChartAt π“˜(ℝ,Model n) a).map_source hbk) (hek β–Έ hzk) have hH_eq : βˆ€αΆ  k in atTop,coordinateCenterMatrix a t G (b k) (p k)= fderiv ℝ (fderiv ℝ (movingPrefixEnergy a t (b k))) (p k)+ fderiv ℝ (fderiv ℝ (fun r=>C (movingPrefixChart a c t (b k) r))) (p k) := by filter_upwards [hbsource,hzsource,he] with k hbk hzk hek exact coordinateCenterMatrix_chart ((extChartAt π“˜(ℝ,Model n) a).map_source hbk) (hek β–Έ hzk) have hDz : βˆ€αΆ  k in atTop, (βˆ€αΆ  y in 𝓝 (movingPrefixChart a c t (b k) (p k)),DifferentiableAt ℝ F y ∧ DifferentiableAt ℝ C y) ∧ DifferentiableAt ℝ (fderiv ℝ F) (movingPrefixChart a c t (b k) (p k)) ∧ DifferentiableAt ℝ (fderiv ℝ C) (movingPrefixChart a c t (b k) (p k)) := by filter_upwards [(hzCoord.comp hΟƒ.tendsto_atTop).eventually (eventually_eventually_nhds.mpr hnear), hΟƒ.tendsto_atTop.eventually hsample,hzEq] with k hnk hsk hek rw [hek] exact ⟨hnk,hsk.1,hsk.2.1⟩ have hpos : βˆ€αΆ  k in atTop,βˆ€ r:Model n, 0≀(fderiv ℝ (fderiv ℝ (movingPrefixEnergy a t (b k))) (p k)- fderiv ℝ (fderiv ℝ (fun r=>F (movingPrefixChart a c t (b k) r))) (p k)) r r := by filter_upwards [hM,hL_eq] with k hk he; rw [←he]; exact hk.1 have hker : βˆ€αΆ  k in atTop,βˆ€ i,βˆ€ r:Model n, (fderiv ℝ (fderiv ℝ (movingPrefixEnergy a t (b k))) (p k)- fderiv ℝ (fderiv ℝ (fun r=>F (movingPrefixChart a c t (b k) r))) (p k)) (pj k i-p k) r=0 := by filter_upwards [hM,hL_eq] with k hk he; rw [←he]; exact hk.2.2.1 obtain ⟨H,L,hH,hL,hpositive,hkernel,hupper⟩ := first_fixed_prefix_matrix_limit henergy hg hb hp (fun i=>tendsto_pi_nhds.mp hpj i) ((hjF.comp hΟƒ.tendsto_atTop).congr' (hzEq.mono (fun k hk=>congrArg (fderiv ℝ F) hk.symm))) ((hjC.comp hΟƒ.tendsto_atTop).congr' (hzEq.mono (fun k hk=>congrArg (fderiv ℝ C) hk.symm))) ((hAf.comp hΟƒ.tendsto_atTop).congr' (hzEq.mono (fun k hk=>congrArg (fderiv ℝ (fderiv ℝ F)) hk.symm))) ((hAc.comp hΟƒ.tendsto_atTop).congr' (hzEq.mono (fun k hk=>congrArg (fderiv ℝ (fderiv ℝ C)) hk.symm))) (hDz.mono (fun k hk=>⟨hk.1.mono (fun y hy=>hy.1),hk.2.1⟩)) (hDz.mono (fun k hk=>⟨hk.1.mono (fun y hy=>hy.2),hk.2.2⟩)) hgrad hquad hpos hker have hH' := hH.congr' (hH_eq.mono (fun k hk=>hk.symm)) have hL' := hL.congr' (hL_eq.mono (fun k hk=>hk.symm)) refine βŸ¨βŸ¨Οƒ,hΟƒ,pj,w,pjβ‚€,wβ‚€,H,L,(fun i=>(mem_active_coordinates hKs (ha i)).2.1),hn,h1,hbar,hpj,hw,hH',hL',hpositive, fun r s=>bilinear_limit_symm hL' (hM.mono (fun k hk=>hk.2.1)) r s,?_,hupper,?_⟩⟩ Β· exact hkernel Β· filter_upwards [hM] with k hk exact ⟨(hs k).2.1,(hs k).2.2.1,(hs k).2.2.2,hk.2.2.2.1,hk.2.2.2.2⟩ end WeakMTWTransport end end OAI