Buckets:
| import Mathlib | |
| import OAI.Combinatorics.SharpRamsey.Selection.FreshAccrual | |
| namespace OAI | |
| section | |
| namespace SharpLogRamsey.FreshExecution | |
| open Finset BinaryTree TreeDecoder PublicTables | |
| open scoped Classical BigOperators | |
| noncomputable section | |
| variable {I A B C : Type*} [DecidableEq I] {α : I→Type*} | |
| def leftPath (target : I) : BinaryTree I→Finset I | |
| | .nil=>∅ | |
| | .node i l r=>if i=target then ∅ else | |
| if target∈labels l then insert i (leftPath target l) else leftPath target r | |
| lemma leftPath_subset (target : I) (t : BinaryTree I) : leftPath target t⊆labels t := by | |
| induction t with | |
| | nil=>exact empty_subset _ | |
| | node i l r hl hr=> | |
| rw [leftPath,labels_node] | |
| split_ifs with hi hj | |
| · exact empty_subset _ | |
| · exact insert_subset_insert i (hl.trans subset_union_left) | |
| · exact hr.trans (subset_union_right.trans (subset_insert _ _)) | |
| lemma leftPath_card (target : I) (t : BinaryTree I) : | |
| (leftPath target t).card≤t.height := by | |
| induction t with | |
| | nil=>rfl | |
| | node i l r hl hr=> | |
| rw [leftPath] | |
| split_ifs | |
| · exact Nat.zero_le _ | |
| · exact (card_insert_le _ _).trans (by simp only [height]; omega) | |
| · simp only [height]; omega | |
| def firstLoss (choose : ∀ i,α i→Domains A B→Option C) | |
| (mask : ∀ i,α i→CapReader A B C) (Y : Finset A) | |
| (i : I) (U : Domains A B) (x : α i) : ℝ := | |
| match choose i x U with | |
| | none=>0 | |
| | some c=>((Y\(mask i x U c).1).card:ℝ) | |
| omit [DecidableEq I] in | |
| lemma firstLoss_nonneg (choose : ∀ i,α i→Domains A B→Option C) | |
| (mask : ∀ i,α i→CapReader A B C) (Y : Finset A) | |
| (i : I) (U : Domains A B) (x : α i) : 0≤firstLoss choose mask Y i U x := by | |
| unfold firstLoss | |
| cases choose i x U <;> positivity | |
| lemma sdiff_inter_card (Y U M : Finset A) : | |
| ((Y\(U∩M)).card:ℝ)≤((Y\U).card:ℝ)+(Y\M).card := by | |
| have he : Y\(U∩M)=(Y\U)∪(Y\M) := by ext x; simp; tauto | |
| rw [he] | |
| exact_mod_cast card_union_le (Y\U) (Y\M) | |
| theorem reached_first_loss (choose : ∀ i,α i→Domains A B→Option C) | |
| (read mask : ∀ i,α i→CapReader A B C) | |
| (hread : ∀ i x U c,(read i x U c).1=U.1∩(mask i x U c).1) | |
| (z : ∀ i,α i) (target : I) (Y : Finset A) | |
| (t : BinaryTree I) (U V : Domains A B) (ht : Separated t) | |
| (hmem : target∈labels t) (hv : arrive choose read z target t U=some V) : | |
| ((Y\V.1).card:ℝ)≤((Y\U.1).card:ℝ)+ | |
| ∑ j∈leftPath target t,produced choose read j (firstLoss choose mask Y j) t U z := by | |
| induction t generalizing U V with | |
| | nil=>simp [labels_nil] at hmem | |
| | node i l r hl hr=> | |
| rcases ht with ⟨htl,htr,hli,hri,hd⟩ | |
| by_cases hi : i=target | |
| · rw [arrive,ite_eq_left hi] at hv | |
| have hUV : U=V := Option.some.inj hv | |
| rw [leftPath,ite_eq_left hi,hUV,sum_empty,add_zero] | |
| · by_cases hL : target∈labels l | |
| · have hR : target∉labels r := disjoint_left.mp hd hL | |
| rw [arrive,ite_eq_right hi] at hv | |
| cases hc : choose i (z i) U with | |
| | none=>simp only [hc] at hv; contradiction | |
| | some c=> | |
| rw [hc] at hv | |
| dsimp only at hv | |
| rw [arrive_absent choose read z target r _ hR] at hv | |
| have hv' : arrive choose read z target l ((read i (z i) U c).1,U.2)=some V := by | |
| cases hh : arrive choose read z target l ((read i (z i) U c).1,U.2) with | |
| | none=>simp [hh] at hv | |
| | some W=>rw [hh] at hv; exact hv | |
| have hchild:=hl _ _ htl hL hv' | |
| rw [leftPath,ite_eq_right hi,ite_eq_left hL] | |
| have hnot : i∉leftPath target l := fun hj=>hli (leftPath_subset target l hj) | |
| rw [sum_insert hnot,produced_root] | |
| have he : (∑ j∈leftPath target l,produced choose read j (firstLoss choose mask Y j) | |
| (.node i l r) U z)= | |
| ∑ j∈leftPath target l,produced choose read j (firstLoss choose mask Y j) | |
| l ((read i (z i) U c).1,U.2) z := by | |
| apply sum_congr rfl | |
| intro j hj | |
| exact produced_left choose read z i j _ l r U (leftPath_subset target l hj) hli hd c hc | |
| rw [he] | |
| have hs:=sdiff_inter_card Y U.1 (mask i (z i) U c).1 | |
| have hs' : ((Y\(read i (z i) U c).1).card:ℝ)≤ | |
| ((Y\U.1).card:ℝ)+(Y\(mask i (z i) U c).1).card := by | |
| rw [hread] | |
| exact hs | |
| simp only [firstLoss,hc] | |
| linarith | |
| · have hR : target∈labels r := by | |
| rw [labels_node,mem_insert,mem_union] at hmem | |
| rcases hmem with he|he|he | |
| · exact False.elim (hi he.symm) | |
| · exact False.elim (hL he) | |
| · exact he | |
| rw [arrive,ite_eq_right hi] at hv | |
| cases hc : choose i (z i) U with | |
| | none=>simp only [hc] at hv; contradiction | |
| | some c=> | |
| rw [hc] at hv | |
| dsimp only at hv | |
| rw [arrive_absent choose read z target l _ hL] at hv | |
| have hv' : arrive choose read z target r (U.1,(read i (z i) U c).2)=some V := hv | |
| have hchild:=hr _ _ htr hR hv' | |
| rw [leftPath,ite_eq_right hi,ite_eq_right hL] | |
| have he : (∑ j∈leftPath target r,produced choose read j (firstLoss choose mask Y j) | |
| (.node i l r) U z)= | |
| ∑ j∈leftPath target r,produced choose read j (firstLoss choose mask Y j) | |
| r (U.1,(read i (z i) U c).2) z := by | |
| apply sum_congr rfl | |
| intro j hj | |
| exact produced_right choose read z i j _ l r U (leftPath_subset target r hj) hri hd c hc | |
| rw [he] | |
| exact hchild | |
| variable [Fintype I] [∀ i,Fintype (α i)] | |
| theorem expected_first_path_loss (p : ∀ i,Law (α i)) (dummy : ∀ i,α i) | |
| (choose : ∀ i,α i→Domains A B→Option C) | |
| (read mask : ∀ i,α i→CapReader A B C) (Y : Finset A) | |
| (target : I) (t : BinaryTree I) (U : Domains A B) | |
| (δ : ℝ) (hδ : 0≤δ) | |
| (hlocal : ∀ i∈leftPath target t,∀ V, | |
| (∑ x,(p i).mass x*firstLoss choose mask Y i V x)≤δ) : | |
| (∑ z,(piLaw p).mass z*(∑ j∈leftPath target t, | |
| produced choose read j (firstLoss choose mask Y j) t U z))≤(t.height:ℝ)*δ := by | |
| simp_rw [mul_sum] | |
| rw [sum_comm] | |
| calc | |
| _ ≤ ∑ j∈leftPath target t,δ := by | |
| apply sum_le_sum | |
| intro j hj | |
| exact produced_bound p choose read j (dummy j) (firstLoss choose mask Y j) t U δ hδ (hlocal j hj) | |
| _ = ((leftPath target t).card:ℝ)*δ := by simp only [sum_const,nsmul_eq_mul] | |
| _ ≤ _ := mul_le_mul_of_nonneg_right (by exact_mod_cast leftPath_card target t) hδ | |
| def firstTrim (choose : ∀ i,α i→Domains A B→Option C) | |
| (read : ∀ i,α i→CapReader A B C) (Y : Finset A) | |
| (target : I) (t : BinaryTree I) (U : Domains A B) (z : ∀ i,α i) : Prop := | |
| ∃ V,arrive choose read z target t U=some V ∧ | |
| ((Y∩V.1).card:ℝ)<(9/10:ℝ)*Y.card | |
| omit [Fintype I] [∀ i,Fintype (α i)] in | |
| lemma produced_nonneg (choose : ∀ i,α i→Domains A B→Option C) | |
| (read : ∀ i,α i→CapReader A B C) (target : I) | |
| (f : Domains A B→α target→ℝ) (hf : ∀ V x,0≤f V x) | |
| (t : BinaryTree I) (U : Domains A B) (z : ∀ i,α i) : | |
| 0≤produced choose read target f t U z := by | |
| unfold produced | |
| cases arrive choose read z target t U with | |
| | none=>exact le_rfl | |
| | some V=>exact hf V (z target) | |
| omit [Fintype I] [∀ i,Fintype (α i)] in | |
| theorem reached_first_trim_charge (choose : ∀ i,α i→Domains A B→Option C) | |
| (read mask : ∀ i,α i→CapReader A B C) | |
| (hread : ∀ i x U c,(read i x U c).1=U.1∩(mask i x U c).1) | |
| (z : ∀ i,α i) (target : I) (Y : Finset A) (hY : Y.Nonempty) | |
| (t : BinaryTree I) (U : Domains A B) (ht : Separated t) | |
| (hmem : target∈labels t) (hYU : Y⊆U.1) : | |
| (if firstTrim choose read Y target t U z then (1:ℝ) else 0)≤ | |
| (10/(Y.card:ℝ))*∑ j∈leftPath target t, | |
| produced choose read j (firstLoss choose mask Y j) t U z := by | |
| have hy : 0<(Y.card:ℝ) := by exact_mod_cast card_pos.mpr hY | |
| split_ifs with htrim | |
| · obtain ⟨V,hv,hsmall⟩:=htrim | |
| have hl:=reached_first_loss choose read mask hread z target Y t U V ht hmem hv | |
| rw [sdiff_eq_empty_iff_subset.mpr hYU,card_empty,Nat.cast_zero,zero_add] at hl | |
| have hc : ((Y\V.1).card:ℝ)+((Y∩V.1).card:ℝ)=Y.card := by | |
| exact_mod_cast card_sdiff_add_card_inter Y V.1 | |
| rw [div_mul_eq_mul_div] | |
| apply (le_div_iff₀ hy).mpr | |
| nlinarith | |
| · apply mul_nonneg (div_nonneg (by norm_num) hy.le) | |
| apply sum_nonneg | |
| intro j _ | |
| exact produced_nonneg choose read j _ (firstLoss_nonneg choose mask Y j) t U z | |
| theorem expected_first_trim (p : ∀ i,Law (α i)) (dummy : ∀ i,α i) | |
| (choose : ∀ i,α i→Domains A B→Option C) | |
| (read mask : ∀ i,α i→CapReader A B C) | |
| (hread : ∀ i x U c,(read i x U c).1=U.1∩(mask i x U c).1) | |
| (target : I) (Y : Finset A) (hY : Y.Nonempty) | |
| (t : BinaryTree I) (U : Domains A B) (ht : Separated t) | |
| (hmem : target∈labels t) (hYU : Y⊆U.1) | |
| (δ : ℝ) (hδ : 0≤δ) | |
| (hlocal : ∀ i∈leftPath target t,∀ V, | |
| (∑ x,(p i).mass x*firstLoss choose mask Y i V x)≤δ) : | |
| (∑ z,(piLaw p).mass z*(if firstTrim choose read Y target t U z then (1:ℝ) else 0))≤ | |
| (10/(Y.card:ℝ))*t.height*δ := by | |
| have hy : 0≤10/(Y.card:ℝ) := div_nonneg (by norm_num) (Nat.cast_nonneg _) | |
| calc | |
| _ ≤ ∑ z,(piLaw p).mass z*((10/(Y.card:ℝ))*∑ j∈leftPath target t, | |
| produced choose read j (firstLoss choose mask Y j) t U z) := by | |
| apply sum_le_sum | |
| intro z _ | |
| exact mul_le_mul_of_nonneg_left | |
| (reached_first_trim_charge choose read mask hread z target Y hY t U ht hmem hYU) | |
| ((piLaw p).nonneg z) | |
| _ = (10/(Y.card:ℝ))*(∑ z,(piLaw p).mass z*∑ j∈leftPath target t, | |
| produced choose read j (firstLoss choose mask Y j) t U z) := by | |
| rw [mul_sum] | |
| apply sum_congr rfl | |
| intro z _ | |
| ring | |
| _ ≤ (10/(Y.card:ℝ))*((t.height:ℝ)*δ) := | |
| mul_le_mul_of_nonneg_left | |
| (expected_first_path_loss p dummy choose read mask Y target t U δ hδ hlocal) hy | |
| _ = _ := by ring | |
| end | |
| end SharpLogRamsey.FreshExecution | |
| end | |
| end OAI | |
Xet Storage Details
- Size:
- 10.1 kB
- Xet hash:
- 487aba948b4715897c2a94f3eb006956b04e5fbb4c90fab577624e500daefad4
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.