Download data/lean/OAI/Combinatorics/GraphThreshold/BernoulliUnion.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.26 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/GraphThreshold/BernoulliUnion.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/GraphThreshold/BernoulliUnion.lean
-
curl -L -o BernoulliUnion.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/GraphThreshold/BernoulliUnion.lean
6.26 kB
| import OAI.Combinatorics.GraphThreshold.BernoulliCoupling | |
| import OAI.Combinatorics.GraphThreshold.AdaptiveTrials | |
| import OAI.Combinatorics.GraphThreshold.GraphProbability | |
| namespace OAI | |
| open scoped BigOperators | |
| noncomputable section | |
| attribute [local instance] Classical.propDecidable | |
| namespace LeanBlast.SecondKahnKalai | |
| variable {X : Type*} [Fintype X] [DecidableEq X] | |
| theorem bernoulli_union_product (p q : β) (f : X β Bool β β) : | |
| bernoulliExpectation p (fun U => bernoulliExpectation q | |
| (fun V => β x, f x (decide (x β U βͺ V)))) = | |
| β x, ((p + q - p * q) * f x true + (1 - (p + q - p * q)) * f x false) := by | |
| have hi (U : Finset X) : | |
| bernoulliExpectation q (fun V => β x, f x (decide (x β U βͺ V))) = | |
| β x, (q * f x true + (1 - q) * f x (decide (x β U))) := by | |
| have hfun : (fun V : Finset X => β x, f x (decide (x β U βͺ V))) = | |
| (fun V => β x, f x (decide (x β U) || decide (x β V))) := by | |
| funext V | |
| apply Finset.prod_congr rfl | |
| intro x _ | |
| by_cases hu : x β U <;> by_cases hv : x β V <;> simp [Finset.mem_union, hu, hv] | |
| rw [hfun] | |
| simpa using | |
| bernoulliExpectation_product q (fun x b => f x (decide (x β U) || b)) | |
| calc | |
| _ = bernoulliExpectation p (fun U => | |
| β x, (q * f x true + (1 - q) * f x (decide (x β U)))) := | |
| bernoulliExpectation_congr p hi | |
| _ = _ := by | |
| rw [bernoulliExpectation_product p (fun x b => q * f x true + (1 - q) * f x b)] | |
| apply Finset.prod_congr rfl | |
| intro x _ | |
| ring | |
| theorem bernoulli_union_mass (p q : β) (Y : Finset X) : | |
| bernoulliExpectation p (fun U => bernoulliExpectation q | |
| (fun V => if U βͺ V = Y then 1 else 0)) = bernoulliWeight (p + q - p * q) Y := by | |
| let f : X β Bool β β := fun x b => if (b = true β x β Y) then 1 else 0 | |
| have hi (U V : Finset X) : | |
| (if U βͺ V = Y then (1 : β) else 0) = β x, f x (decide (x β U βͺ V)) := by | |
| simpa [f] using finset_eq_indicator_product (U βͺ V) Y | |
| calc | |
| _ = bernoulliExpectation p (fun U => bernoulliExpectation q | |
| (fun V => β x, f x (decide (x β U βͺ V)))) := | |
| bernoulliExpectation_congr p fun U => bernoulliExpectation_congr q (hi U) | |
| _ = _ := by | |
| rw [bernoulli_union_product] | |
| apply Finset.prod_congr rfl | |
| intro x _ | |
| by_cases hy : x β Y <;> simp [f, hy] | |
| /-- The union of two independent Bernoulli subsets has the stated Bernoulli law. -/ | |
| theorem bernoulliExpectation_union (p q : β) (F : Finset X β β) : | |
| bernoulliExpectation p (fun U => bernoulliExpectation q (fun V => F (U βͺ V))) = | |
| bernoulliExpectation (p + q - p * q) F := by | |
| calc | |
| _ = bernoulliExpectation p (fun U => β Y : Finset X, | |
| bernoulliExpectation q (fun V => if U βͺ V = Y then 1 else 0) * F Y) := | |
| bernoulliExpectation_congr p fun U => | |
| bernoulliExpectation_pushforward q (fun V => U βͺ V) F | |
| _ = β Y : Finset X, bernoulliExpectation p (fun U => | |
| bernoulliExpectation q (fun V => if U βͺ V = Y then 1 else 0) * F Y) := | |
| bernoulliExpectation_sum p _ | |
| _ = β Y : Finset X, bernoulliWeight (p + q - p * q) Y * F Y := by | |
| apply Finset.sum_congr rfl | |
| intro Y _ | |
| have hfactor : bernoulliExpectation p (fun U => | |
| bernoulliExpectation q (fun V => if U βͺ V = Y then 1 else 0) * F Y) = | |
| bernoulliExpectation p (fun U => | |
| bernoulliExpectation q (fun V => if U βͺ V = Y then 1 else 0)) * F Y := by | |
| simp only [bernoulliExpectation, Finset.sum_mul, mul_assoc] | |
| rw [hfactor, bernoulli_union_mass] | |
| _ = _ := rfl | |
| omit [Fintype X] in | |
| theorem biUnion_fin_cons {n : β} (A : Finset X) (draws : Fin n β Finset X) : | |
| Finset.univ.biUnion (Fin.cases A draws) = A βͺ Finset.univ.biUnion draws := by | |
| ext x | |
| simp only [Finset.mem_biUnion, Finset.mem_univ, true_and, Finset.mem_union] | |
| constructor | |
| Β· rintro β¨i, hiβ© | |
| revert hi | |
| refine Fin.cases ?_ (fun j => ?_) i | |
| Β· intro hi | |
| exact Or.inl hi | |
| Β· intro hi | |
| exact Or.inr β¨j, hiβ© | |
| Β· rintro (hx | β¨j, hjβ©) | |
| Β· exact β¨0, hxβ© | |
| Β· exact β¨j.succ, hjβ© | |
| /-- Exact law of the union of a finite history of independent draws. -/ | |
| theorem iid_bernoulli_union_expectation (p : β) (hp0 : 0 β€ p) (hp1 : p β€ 1) | |
| (n : β) (F : Finset X β β) : | |
| ((bernoulliLaw p hp0 hp1).iid n).expectation (fun draws => F (Finset.univ.biUnion draws)) = | |
| bernoulliExpectation (1 - (1 - p) ^ n) F := by | |
| induction n generalizing F with | |
| | zero => simp | |
| | succ n ih => | |
| rw [FiniteLaw.iid_expectation_succ] | |
| simp_rw [biUnion_fin_cons] | |
| have hi (A : Finset X) := ih (fun W => F (A βͺ W)) | |
| have hrewrite : (fun A => ((bernoulliLaw p hp0 hp1).iid n).expectation | |
| (fun draws => F (A βͺ Finset.univ.biUnion draws))) = | |
| (fun A => bernoulliExpectation (1 - (1 - p) ^ n) (fun W => F (A βͺ W))) := by | |
| funext A | |
| exact hi A | |
| rw [hrewrite, bernoulliLaw_expectation, bernoulliExpectation_union] | |
| congr 1 | |
| rw [pow_succ] | |
| ring | |
| theorem iid_bernoulli_union_probability (p : β) (hp0 : 0 β€ p) (hp1 : p β€ 1) | |
| (n : β) (P : Finset X β Prop) : | |
| ((bernoulliLaw p hp0 hp1).iid n).prob (fun draws => P (Finset.univ.biUnion draws)) = | |
| bernoulliProbability (1 - (1 - p) ^ n) P := by | |
| rw [FiniteLaw.prob_eq_expectation, bernoulliProbability_eq_expectation] | |
| exact iid_bernoulli_union_expectation p hp0 hp1 n (fun W => if P W then 1 else 0) | |
| theorem bernoulli_union_parameter_mem {p : β} (hp0 : 0 β€ p) (hp1 : p β€ 1) (n : β) : | |
| 0 β€ 1 - (1 - p) ^ n β§ 1 - (1 - p) ^ n β€ 1 := by | |
| have hpow0 : 0 β€ (1 - p) ^ n := pow_nonneg (sub_nonneg.mpr hp1) _ | |
| have hpow1 : (1 - p) ^ n β€ 1 := pow_le_oneβ (sub_nonneg.mpr hp1) (by linarith) | |
| constructor <;> linarith | |
| theorem bernoulli_union_parameter_le {p : β} (hp0 : 0 β€ p) (hp1 : p β€ 1) (n : β) : | |
| 1 - (1 - p) ^ n β€ (n : β) * p := by | |
| induction n with | |
| | zero => simp | |
| | succ n ih => | |
| have hpow1 : (1 - p) ^ n β€ 1 := pow_le_oneβ (sub_nonneg.mpr hp1) (by linarith) | |
| have hmul := mul_le_mul_of_nonneg_left hpow1 hp0 | |
| rw [pow_succ, Nat.cast_succ] | |
| nlinarith | |
| end LeanBlast.SecondKahnKalai | |
| end | |
| end OAI | |