import OAI.Combinatorics.HalvingLines.Partition namespace OAI open Filter Topology namespace PlanarHalving.TimeWindows open Set open scoped unitInterval Classical abbrev Window := Σ d : ℕ, Fin (2^d) noncomputable def carrier (J : Window) : Set I := UniformPartition.cell (2^J.1) J.2 lemma measurable_carrier (J : Window) : MeasurableSet (carrier J) := UniformPartition.cell_measurable _ _ noncomputable def time (R : ℕ) [NeZero R] (b : Fin R) : I := ⟨((b : ℝ)+1/2)/(R : ℝ),by have hR : (0 : ℝ) t b t c t c time R b ∈ carrier J).card := by have he : (Finset.univ.filter fun b : Fin R => time R b ∈ carrier J) = (Finset.univ.filter fun b : Fin R => b.val < stop R J) \ (Finset.univ.filter fun b : Fin R => b.val < start R J) := by ext b simp only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_sdiff,not_lt, mem_carrier_iff,and_comm] rw [he,Finset.card_sdiff_of_subset] · have hcard (c : ℕ) (hc : c ≤ R) : (Finset.univ.filter fun b : Fin R => b.val x i ∈ U).card : ℝ) := by classical have h := integral_weightedAtoms w x (U.indicator (fun _ => (1 : ℝ))) rw [integral_indicator_const 1 hU] at h simpa only [smul_eq_mul,mul_one,measureReal_def,← FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure, ENNReal.coe_toReal,Set.indicator_apply,Finset.sum_boole] using h end PlanarHalving.Limits namespace PlanarHalving.Batches open MeasureTheory Set Limits open scoped NNReal ENNReal Classical variable {n R k a : ℕ} {P : Fin n → Point} noncomputable def System.vertexMeasure (S : @System n R k a P) {X : Type*} [MeasurableSpace X] (z : Fin n → X) : FiniteMeasure X := weightedAtoms (n : ℝ≥0)⁻¹ (fun v : ↥S.vertices => z v.val) noncomputable def System.endpointMeasure (S : @System n R k a P) {X : Type*} [MeasurableSpace X] (z : Fin n → X) (E : ℝ≥0) : FiniteMeasure X := weightedAtoms E⁻¹ (fun e : ↥S.edges => z e.val.1) lemma System.vertexMeasure_apply (S : @System n R k a P) {X : Type*} [MeasurableSpace X] [MeasurableSingletonClass X] (z : Fin n → X) {U : Set X} (hU : MeasurableSet U) : (S.vertexMeasure z U : ℝ) = ((S.vertices.filter fun v => z v ∈ U).card : ℝ)/(n : ℝ) := by classical rw [System.vertexMeasure,weightedAtoms_apply_finset _ _ hU] have he : (Finset.univ.filter fun v : ↥S.vertices => z v.val ∈ U).card = (S.vertices.filter fun v => z v ∈ U).card := by apply Finset.card_bij (fun v _ => v.val) · intro v hv exact Finset.mem_filter.mpr ⟨v.property,(Finset.mem_filter.mp hv).2⟩ · intro v _ w _ h; exact Subtype.ext h · intro v hv exact ⟨⟨v,(Finset.mem_filter.mp hv).1⟩,by simpa using (Finset.mem_filter.mp hv).2,rfl⟩ rw [he] simp only [NNReal.coe_inv,NNReal.coe_natCast,div_eq_inv_mul] lemma System.endpointMeasure_apply (S : @System n R k a P) {X : Type*} [MeasurableSpace X] [MeasurableSingletonClass X] (z : Fin n → X) (E : ℝ≥0) {U : Set X} (hU : MeasurableSet U) : (S.endpointMeasure z E U : ℝ) = ((S.edges.filter fun e => z e.1 ∈ U).card : ℝ)/(E : ℝ) := by classical rw [System.endpointMeasure,weightedAtoms_apply_finset _ _ hU] have he : (Finset.univ.filter fun e : ↥S.edges => z e.val.1 ∈ U).card = (S.edges.filter fun e => z e.1 ∈ U).card := by apply Finset.card_bij (fun e _ => e.val) · intro e he exact Finset.mem_filter.mpr ⟨e.property,(Finset.mem_filter.mp he).2⟩ · intro e _ f _ h; exact Subtype.ext h · intro e he exact ⟨⟨e,(Finset.mem_filter.mp he).1⟩,by simpa using (Finset.mem_filter.mp he).2,rfl⟩ rw [he] simp only [NNReal.coe_inv,div_eq_inv_mul] theorem System.atomic_cubed_bound (S : @System n R k a P) [NeZero n] [NeZero a] (hP : Generic P) {X : Type*} [MeasurableSpace X] [MeasurableSingletonClass X] (z : Fin n → X) {E : ℝ≥0} (hE : 0 < E) {U : Set X} (hU : MeasurableSet U) : (S.endpointMeasure z E U : ℝ)^3 ≤ (4608 * (a : ℝ)^2 * n^4 / (E : ℝ)^3) * ((S.vertices.card : ℝ)/(n : ℝ))^3 * (S.vertexMeasure z U : ℝ) + 13824 * (S.vertices.card : ℝ)^3 / (E : ℝ)^3 := by classical let F := S.vertices.filter fun v => z v ∈ U have hF : F ⊆ S.vertices := Finset.filter_subset _ _ have hc := S.localized_crossing hP F hF have he : S.edges.filter (fun e => e.1 ∈ F) = S.edges.filter (fun e => z e.1 ∈ U) := by ext e simp only [Finset.mem_filter,F] exact ⟨fun h => ⟨h.1,h.2.2⟩,fun h => ⟨h.1,(S.edge_ends h.1).1,h.2⟩⟩ rw [he] at hc rw [S.endpointMeasure_apply z E hU,S.vertexMeasure_apply z hU] have hn : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne n) have hER : 0 < (E : ℝ) := hE have hc' := div_le_div_of_nonneg_right hc (le_of_lt (pow_pos hER 3)) convert hc' using 1 all_goals try dsimp only [F] try field_simp [hn,ne_of_gt hER] try ring try rfl end PlanarHalving.Batches namespace PlanarHalving.TimeWindows open Set Filter open scoped unitInterval Topology lemma cut_time_error (R : ℕ) [NeZero R] (x : I) : |(cut (time R) x : ℝ)-(R : ℝ)*(x : ℝ)| ≤ 1 := by have hR : (0 : ℝ) (length (R n) J : ℝ)/(R n : ℝ)) atTop (𝓝 (1/(2^J.1 : ℕ) : ℝ)) := by apply tendsto_iff_dist_tendsto_zero.mpr apply squeeze_zero (fun _ => dist_nonneg) (fun n => by simpa only [Real.dist_eq] using length_error (R n) J) have hn : Tendsto (fun n => (R n : ℝ)) atTop atTop := tendsto_natCast_atTop_atTop.comp hR simpa only [div_eq_mul_inv,Function.comp_def,mul_zero] using (tendsto_inv_atTop_zero.comp hn).const_mul 2 lemma eventually_length_pos (R : ℕ → ℕ) [∀ n, NeZero (R n)] (hR : Tendsto R atTop atTop) (J : Window) : ∀ᶠ n in atTop, 0 hS.ordConnected.out ha hb ⟨hx.1.le,hx.2.le⟩ exact (isOpen_Ioo.subset_interior_iff.mpr hs) ⟨hqa,hqb⟩ lemma ae_subsingleton (μ : Measure ℝ) [NullSingletonClass μ] (K : Set ℝ) (hK : Bornology.IsBounded K) (D : ℝ → Set ℝ) (hc : ∀ t ∈ K, Convex ℝ (D t)) (hd : ∀ s ∈ K, ∀ t ∈ K, s ht.1)) intro s hs t ht hst apply le_antisymm _ zero_le by_contra h have hp : 0<μ (Ioo s t) := lt_of_not_ge h exact Set.disjoint_left.mp (hd s hs.1 t ht.1 hst hp) (interior_subset hs.2) (interior_subset ht.2) apply measure_mono_null (t := ⋃ q : ℚ, S q) · intro t ht obtain ⟨q,hq⟩ := interval_has_rat_interior (hc t ht.1) ht.2 exact mem_iUnion.mpr ⟨q,ht.1,hq⟩ · exact measure_iUnion_null hz theorem exists_three_singletons (μ : Measure ℝ) [NullSingletonClass μ] (K : Set ℝ) (hK : Bornology.IsBounded K) (hpos : 0<μ K) (D : ℝ → Set ℝ) (hne : ∀ t ∈ K, (D t).Nonempty) (hc : ∀ t ∈ K, Convex ℝ (D t)) (hd : ∀ s ∈ K, ∀ t ∈ K, s (S.trace e.property).batch=b).card=a^2 := by classical have he : (Finset.univ.filter fun e : ↥S.edges => (S.trace e.property).batch=b).card = ((S.loss b).product (S.gain b)).card := by apply Finset.card_bij (fun e _ => e.val) · intro e he have hh := (Finset.mem_filter.mp he).2 exact Finset.mem_product.mpr (hh ▸ ⟨(S.trace e.property).loss,(S.trace e.property).gain⟩) · intro e _ f _ h; exact Subtype.ext h · intro e he have hm : e∈S.edges := (S.mem_edges e).mpr ⟨b,Finset.mem_product.mp he⟩ refine ⟨⟨e,hm⟩,Finset.mem_filter.mpr ⟨Finset.mem_univ _,?_⟩,rfl⟩ exact S.batch_unique ⟨(S.trace hm).loss,(S.trace hm).gain⟩ (Finset.mem_product.mp he) rw [he] calc _ = (S.loss b).card * (S.gain b).card := Finset.card_product _ _ _ = a^2 := by rw [S.card_loss,S.card_gain,pow_two] end PlanarHalving.Batches end OAI