import OAI.Combinatorics.HalvingLines.ActivityRetention namespace OAI open Filter Topology namespace PlanarHalving.RankLimits open Set Filter MeasureTheory Metric Batches TimeWindows Zoom open scoped Topology unitInterval noncomputable def commonDirection : Fin 3 → Point := ![(1,0),(1,1),(0,1)] lemma commonDirection_independent (i j : Fin 3) (h : i≠j) : detPair (commonDirection i) (commonDirection j)≠0 := by fin_cases i <;> fin_cases j <;> norm_num [commonDirection,detPair] at * lemma common_frame (F : ℕ → Configuration) {K : Window} (q : CommonChoice K) (h12 : ∀ n, (F n).timeSlope (q.time 0)<(F n).timeSlope (q.time 1)) (h23 : ∀ n, (F n).timeSlope (q.time 1)<(F n).timeSlope (q.time 2)) : ∃ E : ℕ → Point ≃L[ℝ] Point, (∀ n i, detPair ((E n).symm (1,(F n).timeSlope (q.time i))) (commonDirection i)=0) ∧ ∀ n, ∃ a b l u : ℝ, 0 slope_frame (h12 n) (h23 n) refine ⟨E,?_,?_⟩ · intro n i have h1' : (E n).symm (1,(F n).timeSlope (q.time 0))=(a n)⁻¹ • (1,0) := by apply (E n).injective rw [(E n).apply_symm_apply,map_smul,h1,smul_smul,inv_mul_cancel₀ (ha n).ne',one_smul] have h2' : (E n).symm (1,(F n).timeSlope (q.time 2))=(b n)⁻¹ • (0,1) := by apply (E n).injective rw [(E n).apply_symm_apply,map_smul,h2,smul_smul,inv_mul_cancel₀ (hb n).ne',one_smul] have h3' : (E n).symm (1,(F n).timeSlope (q.time 1))=(1,1) := by rw [←h3,(E n).symm_apply_apply] fin_cases i · change detPair ((E n).symm (1,(F n).timeSlope (q.time 0))) (1,0)=0 rw [h1']; simp [detPair] · change detPair ((E n).symm (1,(F n).timeSlope (q.time 1))) (1,1)=0 rw [h3']; simp [detPair] · change detPair ((E n).symm (1,(F n).timeSlope (q.time 2))) (0,1)=0 rw [h2']; simp [detPair] · intro n refine ⟨a n,b n,_,_,ha n,hb n,(h12 n).trans (h23 n),h1 n,h2 n,?_⟩ intro i constructor · exact ((F n).timeSlope_before (J:=q.val.2.2) q.property.2.2.2.1.le).trans (((F n).system.timeWindow q.val.2.2).increasing.monotone (Fin.zero_le i)) · apply (((F n).system.timeWindow q.val.2.2).increasing.monotone (Fin.le_last i)).trans exact (F n).timeSlope_after (J:=q.val.2.2) (q.property.2.2.2.2.trans (q.property.2.1.trans (lower_lt_upper q.val.2.1))).le noncomputable def commonChart (F : Configuration) {A B : Window} (hAB : Before A B) (hA : 0 (F n).R) atTop atTop) (hM : Tendsto (fun n => (F n).a*(F n).n) atTop atTop) {C : ℝ} (hC : 0≤C) (hcoeff : ∀ n, 4608*((F n).a:ℝ)^2*(F n).n^4 / (((F n).R:ℝ)*(F n).a^2)^3≤C) (herror : Tendsto (fun n => 13824*((F n).n:ℝ)^3 / (((F n).R:ℝ)*(F n).a^2)^3) atTop (𝓝 0)) (hshort : Tendsto (fun n => ((F n).n:ℝ)/((F n).R*(F n).a)) atTop (𝓝 0)) {K A B : Window} (hAB : Before A B) (hKA : Before K A) (hKB : Before K B) (hA : ∀ n, 0 (F q.1).extendedRank true A B i.val q.2) (atTop ×ˢ 𝓝 p) (𝓝 (G i p))) (hGaed : ∀ i, ∀ᵐ p ∂(volume : Measure Point), DifferentiableAt ℝ (fun x => (G i x:ℝ)) p) (hid : ∀ i z, z∈(L.points:Measure Labels).support → ContinuousAt (G i) (pairCoordinates true A B z) → z i.val=G i (pairCoordinates true A B z)) (ν : Measure Labels) (he : ν≪(L.edge:Measure Labels)) (hp : ν≪(L.points:Measure Labels)) (hproj : ν.map (pairCoordinates true A B)≪volume) (q : CommonChoice K) (hpos : ∀ᵐ z ∂ν, L.conditional z (carrier K)≠0 ∧ z∈commonSet L q) (E : ℕ → Point ≃L[ℝ] Point) (hE : ∀ n i, detPair ((E n).symm (1,(F n).timeSlope (q.time i))) (commonDirection i)=0) : ∀ᵐ z ∂ν, pairCoordinates true A B z∈Ioo (0:ℝ) 1 ×ˢ Ioo (-1:ℝ) 0 ∧ ∃ C₀ : ℝ, 0] (0:ℝ), ∀ᶠ n in atTop, RadialCompare (commonChart (F n) hAB (hA n) (hB n) (E n)).symm (pairCoordinates true A B z) r C₀ T := by have hreg := h.rank_regular_ae ν hp hproj G hGaed hid have hind := he.ae_le (h.rank_independent_ae (A:=A) (B:=B) emb hR hM hC hcoeff herror hshort G) have hna := he.ae_le (h.conditional_nullSingleton emb hR hC hcoeff herror) filter_upwards [hreg,hind,hna,hpos,pairCoordinates_interior_ae hproj] with z hz hi hn hpos hzp let := hn refine ⟨hzp,?_⟩ have h := pointwise_radial F hR hAB hKA hKB hA hB G hjoint hGaed hzp (fun i => (hz i).1) (L.conditional z) hpos.1 (fun J hJ => by obtain ⟨i,j,hi,hj,_,hij⟩ := hi hz J hJ exact ⟨i,j,hi,hj,hij⟩) q.time q.time_mem (q.positive_gaps (L.conditional z) hpos.2.1 hpos.2.2.1) (fun n => (E n).symm) commonDirection commonDirection_independent hE exact h end PlanarHalving.RankLimits namespace PlanarHalving.RankLimits open Set Filter MeasureTheory Metric Batches TimeWindows Zoom Spatial Enhancement Boundary open scoped Topology unitInterval lemma normalized_commonChart (F : Configuration) {A B : Window} (hAB : Before A B) (hA : 0 f q.1 q.2) (atTop ×ˢ 𝓝 (p:Point)) (𝓝 (l p))) : ∀ z∈(μ:Measure (X×Cube)).support, ∀ hz : z.1∈G, z.2=encode (l ⟨π z.1,mem_image_of_mem π hz⟩) := by intro z hz hG apply support_spatial_graph hμ π hπ (f∘τ) (Filter.Eventually.of_forall (fun n => hid (τ n))) G l _ hz hG intro p exact (hjoint p).comp (hτ.tendsto_atTop.prodMap tendsto_id) lemma Converges.spatial_impossible {F : ℕ → Configuration} {L : Data} (hF : Converges F L) (hR : Tendsto (fun n => (F n).R) atTop atTop) (emb : ∀ n, (F n).SweepEmbedding) {C : ℝ} (hC : 0≤C) (hcoeff : ∀ n, 4608*((F n).a:ℝ)^2*(F n).n^4 / (((F n).R:ℝ)*(F n).a^2)^3≤C) (herror : Tendsto (fun n => 13824*((F n).n:ℝ)^3 / (((F n).R:ℝ)*(F n).a^2)^3) atTop (𝓝 0)) (J : Window) {A B : Window} (hAB : Before A B) (hA : ∀ n, 0] (0:ℝ), ∀ᶠ n in atTop, RadialCompare (commonChart (F n) hAB (hA n) (hB n) (E n)).symm (pairCoordinates true A B z) r C₀ Q) : False := by let π := pairCoordinates true A B let f := fun n => commonChart (F n) hAB (hA n) (hB n) (E n) obtain ⟨G,hG,hGT,hGp,m,hdensity,p₀,U,hU,φ,l,c,hc,hφ,hl,hjoint,hsep⟩ := positive_spatial_witness (L.points:Measure Labels) (L.edgeWindow J:Measure Labels) T hT hTp π (continuous_pairCoordinates true A B).measurable hac f (fun n => commonChart_source _ _ _ _ _) (fun n => commonChart_target _ _ _ _ _) hrad let o := fun n => ((F n).rankChart hAB (hA n) (hB n)).symm p₀ let ψ := fun n => physical (E n) (o n) (U n)⁻¹ obtain ⟨ρ,M,hρ,hM,hprojection⟩ := Enhancement.subsequence (hF.subseq hφ) (fun n => ψ (φ n)) have hgraph : ∀ z∈(M .point:Measure Space).support, ∀ hz : z.1∈G, z.2=encode (l ⟨π z.1,mem_image_of_mem π hz⟩) := support_graph_subseq (μs:=fun n => Enhancement.points (F (φ n)) (ψ (φ n))) hρ (hM .point) π (continuous_pairCoordinates true A B) (fun n => (normalizeChart (f (φ n)) p₀ (U (φ n)) (hU (φ n)).ne').symm) (fun n => normalized_points_graph (F (φ n)) hAB (hA _) (hB _) (E _) p₀ (hU _).ne') G l hjoint have hmap : (M .point:Measure Space).map Prod.fst=(L.points:Measure Labels) := by rw [← FiniteMeasure.toMeasure_map] exact congrArg FiniteMeasure.toMeasure (hprojection .point) obtain ⟨hH,hbounded,D,hD,hdisk⟩ := support_lift_disk (M .point:Measure Space) G hG π (continuous_pairCoordinates true A B).measurable l hc (by rwa [hmap]) hgraph hl hsep have hz := enhanced_boundary_zero ((hF.subseq hφ).subseq hρ) ((hR.comp hφ.tendsto_atTop).comp hρ.tendsto_atTop) (fun n => emb (φ (ρ n))) hC (fun n => hcoeff (φ (ρ n))) ((herror.comp hφ.tendsto_atTop).comp hρ.tendsto_atTop) J (fun n => E (φ (ρ n))) (fun n => o (φ (ρ n))) (fun n => (U (φ (ρ n)))⁻¹) (fun n => inv_pos.mpr (hU _)) (fun n => hframe (φ (ρ n))) hM hprojection G hG (fun z hz => ⟨hbounded z hz,by rw [hgraph z hz.2 hz.1,decode_encode]⟩) hD hdisk have hz' : L.edgeWindow J G=0 := NNReal.coe_injective hz apply hGp rw [← FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hz',ENNReal.coe_zero] end PlanarHalving.RankLimits namespace PlanarHalving.RankLimits open Set Filter MeasureTheory Metric Batches TimeWindows Zoom Spatial Enhancement Boundary open scoped Topology unitInterval lemma common_finite_eventually (F : ℕ → Configuration) (hR : Tendsto (fun n => (F n).R) atTop atTop) (A B : Window) {K : Window} (q : CommonChoice K) : ∀ᶠ n in atTop, 0 f z.1 z.2) (atTop ×ˢ 𝓝 p) (𝓝 y)) (N : ℕ) : Tendsto (fun z : ℕ × X => f (z.1+N) z.2) (atTop ×ˢ 𝓝 p) (𝓝 y) := h.comp ((tendsto_add_atTop_nat N).prodMap tendsto_id) lemma Converges.analytic_ready {F : ℕ → Configuration} {L : Data} (hF : Converges F L) (hR : Tendsto (fun n => (F n).R) atTop atTop) {K A B : Window} (hAB : Before A B) (hKA : Before K A) (hKB : Before K B) (q : CommonChoice K) : ∃ (φ : ℕ → ℕ) (G : Subwindows K → Point → I), StrictMono φ ∧ (∀ n, 0 (G i x:ℝ)) p) ∧ (∀ i z, z∈(L.points:Measure Labels).support → ContinuousAt (G i) (pairCoordinates true A B z) → z i.val=G i (pairCoordinates true A B z)) ∧ ∀ i p, ContinuousAt (G i) p → Tendsto (fun z : ℕ × Point => (F (φ z.1)).extendedRank true A B i.val z.2) (atTop ×ˢ 𝓝 p) (𝓝 (G i p)) := by have hC (i : Subwindows K) : Before i.val A ∧ Before i.val B := ⟨(endpoints_of_subset i.property).2.trans hKA,(endpoints_of_subset i.property).2.trans hKB⟩ obtain ⟨φ,G,hφ,_,hGaed,hid,hjoint⟩ := hF.rank_analytic hR true hAB (fun i : Subwindows K => i.val) (fun i => hC i) have hR' : Tendsto (fun n => (F (φ n)).R) atTop atTop := hR.comp hφ.tendsto_atTop have he := common_finite_eventually (F∘φ) hR' A B q obtain ⟨N,hN⟩ := eventually_atTop.mp he refine ⟨fun n => φ (n+N),G,(fun _ _ h => hφ (Nat.add_lt_add_right h N)), (fun n => hN (n+N) (Nat.le_add_left N n)),hGaed,hid,?_⟩ intro i p hp exact joint_shift (fun n => (F (φ n)).extendedRank true A B i.val) (hjoint i p hp) N end PlanarHalving.RankLimits namespace PlanarHalving.RankLimits open Set Filter MeasureTheory Metric Batches TimeWindows Zoom Spatial Enhancement Boundary open scoped Topology unitInterval lemma Converges.impossible {F : ℕ → Configuration} {L : Data} (hF : Converges F L) (emb : ∀ n, (F n).SweepEmbedding) (hR : Tendsto (fun n => (F n).R) atTop atTop) (hM : Tendsto (fun n => (F n).a*(F n).n) atTop atTop) {C : ℝ} (hC : 0≤C) (hcoeff : ∀ n, 4608*((F n).a:ℝ)^2*(F n).n^4 / (((F n).R:ℝ)*(F n).a^2)^3≤C) (herror : Tendsto (fun n => 13824*((F n).n:ℝ)^3 / (((F n).R:ℝ)*(F n).a^2)^3) atTop (𝓝 0)) (hshort : Tendsto (fun n => ((F n).n:ℝ)/((F n).R*(F n).a)) atTop (𝓝 0)) : False := by obtain ⟨K,H,A,B,T,hKH,hAH,hBH,hAB,hT,hTp,hpos,hcross,hpts⟩ := hF.positive_part emb hR hC hcoeff herror hshort obtain ⟨q,V,hV,hVT,hcommon,hVp,hVle⟩ := hF.common_positive hR K (hF.conditional_nullSingleton emb hR hC hcoeff herror) hT hTp (fun z hz => (hpos z hz).1) let ν := (L.edgeWindow q.val.2.2:Measure Labels).restrict V have he : ν≪(L.edge:Measure Labels) := Measure.absolutelyContinuous_of_le (hVle.trans Measure.restrict_le_self) have hp : ν≪(L.points:Measure Labels) := (Measure.absolutelyContinuous_of_le hVle).trans hpts have hproj : ν.map (pairCoordinates true A B)≪volume := (((Measure.absolutelyContinuous_of_le hVle).trans hcross).map (continuous_pairCoordinates true A B).measurable).trans (hF.crossing_signed_projection hR hM true hAB) have hgood : ∀ᵐ z ∂ν, L.conditional z (carrier K)≠0 ∧ z∈commonSet L q := by filter_upwards [ae_restrict_mem hV] with z hz exact ⟨(hpos z (hVT hz)).1,hcommon z hz⟩ have hKA : Before K A := hKH.2.1.le.trans (endpoints_of_subset hAH).1 have hKB : Before K B := hKH.2.1.le.trans (endpoints_of_subset hBH).1 obtain ⟨φ,G,hφ,hfinite,hGaed,hid,hjoint⟩ := hF.analytic_ready hR hAB hKA hKB q have hF' : Converges (F∘φ) L := hF.subseq hφ have hR' : Tendsto (fun n => (F (φ n)).R) atTop atTop := hR.comp hφ.tendsto_atTop obtain ⟨E,hE,hframe⟩ := common_frame (F∘φ) q (fun n => (hfinite n).2.2.1) (fun n => (hfinite n).2.2.2) exact hF'.spatial_impossible hR' (fun n => emb (φ n)) hC (fun n => hcoeff (φ n)) (herror.comp hφ.tendsto_atTop) q.val.2.2 hAB (fun n => (hfinite n).1) (fun n => (hfinite n).2.1) E hframe V hV hVp hproj (hF'.radial_ae (fun n => emb (φ n)) hR' (hM.comp hφ.tendsto_atTop) hC (fun n => hcoeff (φ n)) (herror.comp hφ.tendsto_atTop) (hshort.comp hφ.tendsto_atTop) hAB hKA hKB (fun n => (hfinite n).1) (fun n => (hfinite n).2.1) G hjoint hGaed hid ν he hp hproj q hgood E hE) end PlanarHalving.RankLimits namespace PlanarHalving.RankLimits open Filter open scoped Topology lemma normalized_sequence_impossible (F : ℕ → Configuration) (emb : ∀ n, (F n).SweepEmbedding) {c : ℝ} (hc : 0 ((F n).n:ℝ)/(F n).a) atTop atTop) : False := by obtain ⟨φ,L,hφ,hF⟩ := subsequence F have hnear' : ∀ n, c*((F (φ n)).n:ℝ)^4≤((F (φ n)).R:ℝ)^3*((F (φ n)).a:ℝ)^4 := fun n => hnear (φ n) have hq' := hq.comp hφ.tendsto_atTop have hs := normalization_sizes_atTop hc hnear' hq' exact hF.impossible (fun n => emb (φ n)) hs.2.2 hs.2.1 (by positivity : 0≤4608/c) (fun n => (F (φ n)).normalization_coefficient hc (hnear' n)) (sparse_error_tendsto_zero hc hnear' hq') (short_ratio_tendsto_zero hc hnear' hq') theorem uniform_batch_saving {c : ℝ} (hc : 0 ((F m).n:ℝ)/(F m).a) atTop atTop := by apply tendsto_atTop_mono hq exact tendsto_atTop_add_const_right _ 1 tendsto_natCast_atTop_atTop exact normalized_sequence_impossible F (fun n => (he n).some) hc hn hlim end PlanarHalving.RankLimits namespace PlanarHalving.Sweep open Set RankLimits noncomputable def greedyConfiguration {n k : ℕ} {P : Fin n → Point} (hP : Generic P) (hk : k≤n) (a : ℕ) (ha : 0 rfl lemma distance_saving {c : ℝ} (hc : 0 ∃ hk' : k+c≤n, c≤(states P hP hk').distance p.1 p.2) let B := C\A have hA : A⊆C := Finset.filter_subset _ _ have hB : B⊆C := Finset.sdiff_subset have hbound (D : Finset _) (hD : D⊆C) (r : ℕ) (hd : ∀ p∈D, ∃ hr : r≤n, c≤(states P hP hr).distance p.1 p.2) : (D.card : ℝ)^3*(c : ℝ)^4≤16*δ*(n : ℝ)^4 := by by_cases hne : D.Nonempty · obtain ⟨p,hp⟩ := hne obtain ⟨hr,_⟩ := hd p hp apply hdist P hP hr hc (hq.trans (div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast hc) (by exact_mod_cast (show c≤b by dsimp [c];omega)))) D · exact fun p hp q hq hpq => hC p (hD hp) q (hD hq) hpq · exact fun p hp => horder p (hD hp) · intro p hp obtain ⟨hr',hh⟩ := hd p hp exact hh · simp only [Finset.not_nonempty_iff_eq_empty.mp hne,Finset.card_empty,Nat.cast_zero,zero_pow (by omega : (3:ℕ)≠0),zero_mul] positivity have hAb := hbound A hA (k+c) (fun p hp => (Finset.mem_filter.mp hp).2) have hBb := hbound B hB (k-c) (fun p hp => by have hpC := hB hp have hh := states_intervalActivity_distance P hP hk (horder p hpC) ((show 4*c≤b from Nat.mul_div_le b 4).trans (hactivity p hpC)) rcases hh with hh | ⟨hr,_,hh⟩ · exact False.elim ((Finset.mem_sdiff.mp hp).2 (Finset.mem_filter.mpr ⟨hpC,hh⟩)) · exact ⟨hr,hh⟩) have hcard : (C.card : ℝ)=(A.card : ℝ)+(B.card : ℝ) := by exact_mod_cast (by simpa only [B,Nat.add_comm] using (Finset.card_sdiff_add_card_eq_card hA).symm : C.card=A.card+B.card) have hsum := mul_le_mul_of_nonneg_right (cube_add_le (show (0:ℝ)≤A.card by positivity) (show (0:ℝ)≤B.card by positivity)) (show (0:ℝ)≤(c : ℝ)^4 by positivity) rw [← hcard] at hsum have hcub : (C.card : ℝ)^3*(c : ℝ)^4≤128*δ*(n : ℝ)^4 := by nlinarith [hAb,hBb] calc _ ≤ (C.card : ℝ)^3*(8*(c : ℝ))^4 := by gcongr _ = 4096*((C.card : ℝ)^3*(c : ℝ)^4) := by ring _ ≤ 4096*(128*δ*(n : ℝ)^4) := mul_le_mul_of_nonneg_left hcub (by norm_num) _ ≤ _ := by nlinarith [mul_nonneg hδ.le (sq_nonneg ((n : ℝ)^2))] · have hd := hdist P hP hk (by omega : 0<1) (by simpa using hq.trans (div_le_self (by positivity) (by exact_mod_cast hb))) C hC horder (fun p hp => S.intervalActivity_pos_distance (horder p hp) (lt_of_lt_of_le hb (hactivity p hp))) norm_num at hd have hbLe : (b : ℝ)≤3 := by exact_mod_cast (by omega : b≤3) calc _ ≤ (C.card : ℝ)^3*3^4 := by gcongr _ ≤ 16*δ*(n : ℝ)^4*3^4 := mul_le_mul_of_nonneg_right hd (by norm_num) _ ≤ _ := by nlinarith [mul_nonneg hδ.le (sq_nonneg ((n : ℝ)^2))] end PlanarHalving.Sweep end OAI