Download data/lean/OAI/Combinatorics/IndependentSets/Repetition/Rectangle.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.48 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/IndependentSets/Repetition/Rectangle.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/IndependentSets/Repetition/Rectangle.lean
-
curl -L -o Rectangle.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/IndependentSets/Repetition/Rectangle.lean
9.48 kB
| import Mathlib | |
| import OAI.Combinatorics.IndependentSets.Repetition.Basic | |
| import OAI.Combinatorics.IndependentSets.Repetition.TraceLaw | |
| namespace OAI | |
| noncomputable section | |
| namespace IndependentSetsGames.Foundations.CorrelatedSampling | |
| section | |
| variable {Ξ± : Type*} [Fintype Ξ±] | |
| private theorem sum_div_const {ΞΉ : Type*} [Fintype ΞΉ] (f : ΞΉ β β) (c : β) : | |
| (β i, f i) / c = β i, f i / c := by | |
| simp only [div_eq_mul_inv, Finset.sum_mul] | |
| abbrev RectangleSeed (thresholds : List β) (Ξ± : Type*) := | |
| Ξ± Γ Fin (thresholdPartition thresholds).length | |
| def rectangleWeight (thresholds : List β) (seed : RectangleSeed thresholds Ξ±) : β := | |
| ((thresholdPartition thresholds)[seed.2].hi - (thresholdPartition thresholds)[seed.2].lo) / | |
| (Fintype.card Ξ± : β) | |
| def rectangleAccept (thresholds : List β) (density : Ξ± β β) | |
| (seed : RectangleSeed thresholds Ξ±) : Bool := | |
| decide ((thresholdPartition thresholds)[seed.2].lo < density seed.1) | |
| theorem rectangleWeight_nonnegative (thresholds : List β) (seed : RectangleSeed thresholds Ξ±) : | |
| 0 β€ rectangleWeight thresholds seed := | |
| div_nonneg (sub_nonneg.mpr ((thresholdPartition thresholds)[seed.2].valid)) (by positivity) | |
| theorem rectangleWeight_normalized [Nonempty Ξ±] (thresholds : List β) : | |
| β seed : RectangleSeed thresholds Ξ±, rectangleWeight thresholds seed = 1 := by | |
| rw [Fintype.sum_prod_type] | |
| have hrow (a : Ξ±) : (β i, rectangleWeight thresholds (a, i)) = | |
| 1 / (Fintype.card Ξ± : β) := by | |
| unfold rectangleWeight | |
| rw [β sum_div_const, sum_interval_get (fun I => I.hi - I.lo), partition_total_mass] | |
| simp_rw [hrow] | |
| have hc : (Fintype.card Ξ± : β) β 0 := by exact_mod_cast Fintype.card_ne_zero | |
| simp [hc] | |
| def rectangleDistribution [Nonempty Ξ±] (thresholds : List β) : | |
| Games.FiniteDistribution (RectangleSeed thresholds Ξ±) where | |
| weight := rectangleWeight thresholds | |
| nonnegative := rectangleWeight_nonnegative thresholds | |
| normalized := rectangleWeight_normalized thresholds | |
| theorem rectangle_row_mass (thresholds : List β) (density : Ξ± β β) (a : Ξ±) | |
| (hm : density a β thresholds) (h0 : 0 β€ density a) (h1 : density a β€ 1) : | |
| (β i, if rectangleAccept thresholds density (a, i) then | |
| rectangleWeight thresholds (a, i) else 0) = density a / (Fintype.card Ξ± : β) := by | |
| calc | |
| _ = (β i : Fin (thresholdPartition thresholds).length, | |
| if (thresholdPartition thresholds)[i].lo < density a then | |
| (thresholdPartition thresholds)[i].hi - (thresholdPartition thresholds)[i].lo else 0) / | |
| (Fintype.card Ξ± : β) := by | |
| rw [sum_div_const] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| simp [rectangleAccept, rectangleWeight, ite_div] | |
| _ = density a / (Fintype.card Ξ± : β) := by | |
| rw [sum_interval_get (fun I => if I.lo < density a then I.hi - I.lo else 0), | |
| partition_acceptance_mass thresholds (density a) hm h0 h1] | |
| theorem rectangle_acceptance_mass (thresholds : List β) (density : Ξ± β β) | |
| (hm : β a, density a β thresholds) (h0 : β a, 0 β€ density a) | |
| (h1 : β a, density a β€ 1) : | |
| eventMass (rectangleWeight thresholds) (rectangleAccept thresholds density) = | |
| (β a, density a) / (Fintype.card Ξ± : β) := by | |
| unfold eventMass | |
| rw [Fintype.sum_prod_type] | |
| simp_rw [rectangle_row_mass thresholds density _ (hm _) (h0 _) (h1 _)] | |
| rw [sum_div_const] | |
| theorem rectangle_label_mass [DecidableEq Ξ±] (thresholds : List β) (density : Ξ± β β) (a : Ξ±) | |
| (hm : β x, density x β thresholds) (h0 : β x, 0 β€ density x) | |
| (h1 : β x, density x β€ 1) : | |
| eventMass (rectangleWeight thresholds) | |
| (fun seed => rectangleAccept thresholds density seed && decide (seed.1 = a)) = | |
| density a / (Fintype.card Ξ± : β) := by | |
| unfold eventMass | |
| rw [Fintype.sum_prod_type] | |
| calc | |
| _ = β x : Ξ±, if x = a then density x / (Fintype.card Ξ± : β) else 0 := by | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| by_cases hx : x = a | |
| Β· simpa [hx] using rectangle_row_mass thresholds density x (hm x) (h0 x) (h1 x) | |
| Β· simp [hx] | |
| _ = density a / (Fintype.card Ξ± : β) := by simp | |
| omit [Fintype Ξ±] in theorem rectangle_and (thresholds : List β) (p q : Ξ± β β) : | |
| (fun seed => rectangleAccept thresholds p seed && rectangleAccept thresholds q seed) = | |
| rectangleAccept thresholds (fun a => min (p a) (q a)) := by | |
| funext seed | |
| simp [rectangleAccept] | |
| omit [Fintype Ξ±] in theorem rectangle_or (thresholds : List β) (p q : Ξ± β β) : | |
| (fun seed => rectangleAccept thresholds p seed || rectangleAccept thresholds q seed) = | |
| rectangleAccept thresholds (fun a => max (p a) (q a)) := by | |
| funext seed | |
| simp [rectangleAccept] | |
| theorem min_mem_thresholds (thresholds : List β) {x y : β} (hx : x β thresholds) | |
| (hy : y β thresholds) : min x y β thresholds := by | |
| by_cases h : x β€ y <;> simp [min_def, h, hx, hy] | |
| theorem max_mem_thresholds (thresholds : List β) {x y : β} (hx : x β thresholds) | |
| (hy : y β thresholds) : max x y β thresholds := by | |
| by_cases h : x β€ y <;> simp [max_def, h, hx, hy] | |
| theorem rectangle_union_mass (thresholds : List β) (p q : Ξ± β β) | |
| (hpm : β a, p a β thresholds) (hqm : β a, q a β thresholds) | |
| (hp0 : β a, 0 β€ p a) (_hq0 : β a, 0 β€ q a) | |
| (hp1 : β a, p a β€ 1) (hq1 : β a, q a β€ 1) : | |
| eventMass (rectangleWeight thresholds) | |
| (fun seed => rectangleAccept thresholds p seed || rectangleAccept thresholds q seed) = | |
| unionMass p q / (Fintype.card Ξ± : β) := by | |
| rw [rectangle_or] | |
| exact rectangle_acceptance_mass thresholds _ | |
| (fun a => max_mem_thresholds thresholds (hpm a) (hqm a)) | |
| (fun a => (hp0 a).trans (le_max_left _ _)) (fun a => max_le (hp1 a) (hq1 a)) | |
| theorem rectangle_common_label_mass [DecidableEq Ξ±] (thresholds : List β) | |
| (p q : Ξ± β β) (a : Ξ±) | |
| (hpm : β x, p x β thresholds) (hqm : β x, q x β thresholds) | |
| (hp0 : β x, 0 β€ p x) (hq0 : β x, 0 β€ q x) | |
| (hp1 : β x, p x β€ 1) (_hq1 : β x, q x β€ 1) : | |
| eventMass (rectangleWeight thresholds) | |
| (fun seed => (rectangleAccept thresholds p seed && rectangleAccept thresholds q seed) && | |
| decide (seed.1 = a)) = min (p a) (q a) / (Fintype.card Ξ± : β) := by | |
| have hand := congrFun (rectangle_and thresholds p q) | |
| simp_rw [hand] | |
| exact rectangle_label_mass thresholds _ a | |
| (fun x => min_mem_thresholds thresholds (hpm x) (hqm x)) | |
| (fun x => le_min (hp0 x) (hq0 x)) (fun x => (min_le_left _ _).trans (hp1 x)) | |
| end | |
| variable {Ο Ξ± : Type*} [Fintype Ο] [DecidableEq Ο] [DecidableEq Ξ±] | |
| def localSample (accept : Ο β Bool) (decode : Ο β Ξ±) (fallback : Ξ±) | |
| (proposals : List Ο) : Ξ± := | |
| ((firstAccepted accept proposals).map decode).getD fallback | |
| def localDiagonal (left right : Ο β Bool) (decode : Ο β Ξ±) (fallback a : Ξ±) | |
| (proposals : List Ο) : β := | |
| if localSample left decode fallback proposals = a β§ | |
| localSample right decode fallback proposals = a then 1 else 0 | |
| def goodLabel (left right : Ο β Bool) (decode : Ο β Ξ±) (a : Ξ±) (s : Ο) : Bool := | |
| (left s && right s) && decide (decode s = a) | |
| omit [Fintype Ο] [DecidableEq Ο] in | |
| theorem common_first_label_lower (left right : Ο β Bool) (decode : Ο β Ξ±) | |
| (fallback a : Ξ±) (proposals : List Ο) : | |
| goodFirstIndicator (fun s => left s || right s) (goodLabel left right decode a) proposals β€ | |
| localDiagonal left right decode fallback a proposals := by | |
| cases hfirst : firstAccepted (fun s => left s || right s) proposals with | |
| | none => | |
| simp only [goodFirstIndicator, hfirst] | |
| unfold localDiagonal | |
| split_ifs <;> norm_num | |
| | some s => | |
| by_cases hc : goodLabel left right decode a s = true | |
| Β· have hparts : (left s = true β§ right s = true) β§ decode s = a := by | |
| simpa [goodLabel] using hc | |
| have h := first_union_common left right proposals s hfirst hparts.1.1 hparts.1.2 | |
| simp [goodFirstIndicator, hfirst, hc, localDiagonal, localSample, h.1, h.2, hparts.2] | |
| Β· have hn : 0 β€ localDiagonal left right decode fallback a proposals := by | |
| unfold localDiagonal | |
| split_ifs <;> norm_num | |
| simpa [goodFirstIndicator, hfirst, hc] using hn | |
| omit [DecidableEq Ο] in theorem union_goodLabel_mass | |
| (w : Ο β β) (left right : Ο β Bool) (decode : Ο β Ξ±) (a : Ξ±) : | |
| eventMass w (fun s => (left s || right s) && goodLabel left right decode a s) = | |
| eventMass w (goodLabel left right decode a) := by | |
| unfold eventMass | |
| apply Finset.sum_congr rfl | |
| intro s _ | |
| cases hl : left s <;> cases hr : right s <;> simp [goodLabel, hl, hr] | |
| theorem finite_label_diagonal_bound (w : Ο β β) (left right : Ο β Bool) | |
| (decode : Ο β Ξ±) (fallback a : Ξ±) (hw : β s, 0 β€ w s) | |
| (hw_sum : β s, w s = 1) (hu : 0 < eventMass w (fun s => left s || right s)) (n : Nat) : | |
| eventMass w (goodLabel left right decode a) / eventMass w (fun s => left s || right s) * | |
| (1 - eventMass w (fun s => !(left s || right s)) ^ n) β€ | |
| traceAverage w n (localDiagonal left right decode fallback a) := by | |
| have h := traceAverage_mono w hw n _ _ (common_first_label_lower left right decode fallback a) | |
| rw [goodFirstIndicator_law w _ _ hw_sum n, | |
| goodFirstMass_exact w _ _ hw_sum (ne_of_gt hu) n, | |
| union_goodLabel_mass] at h | |
| exact h | |
| end IndependentSetsGames.Foundations.CorrelatedSampling | |
| end | |
| end OAI | |