Download data/lean/OAI/Probability/RandomSAT/Binomial.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.38 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/RandomSAT/Binomial.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/RandomSAT/Binomial.lean
-
curl -L -o Binomial.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/RandomSAT/Binomial.lean
7.38 kB
| import OAI.Probability.RandomSAT.ClauseProcess | |
| namespace OAI | |
| /-! | |
| Finite Bernoulli-count expectations and integrated telescoping estimates. | |
| -/ | |
| namespace FixedClauseThreshold | |
| open Finset | |
| noncomputable section | |
| attribute [local instance] Classical.propDecidable | |
| def binomialMean (p : β) : β β (β β β) β β | |
| | 0, f => f 0 | |
| | m + 1, f => (1 - p) * binomialMean p m f + | |
| p * binomialMean p m (fun d => f (d + 1)) | |
| theorem binomialMean_congr {p : β} {m : β} {f g : β β β} | |
| (h : β d β€ m, f d = g d) : binomialMean p m f = binomialMean p m g := by | |
| induction m generalizing f g with | |
| | zero => exact h 0 (by omega) | |
| | succ m ih => | |
| simp only [binomialMean] | |
| rw [ih (fun d hd => h d (by omega)), ih (fun d hd => h (d + 1) (by omega))] | |
| theorem binomialMean_const (p c : β) (m : β) : binomialMean p m (fun _ => c) = c := by | |
| induction m with | |
| | zero => rfl | |
| | succ m ih => simp only [binomialMean, ih]; ring | |
| theorem binomialMean_add (p : β) (m : β) (f g : β β β) : | |
| binomialMean p m (fun d => f d + g d) = binomialMean p m f + binomialMean p m g := by | |
| induction m generalizing f g with | |
| | zero => rfl | |
| | succ m ih => simp only [binomialMean, ih]; ring | |
| theorem binomialMean_sub (p : β) (m : β) (f g : β β β) : | |
| binomialMean p m (fun d => f d - g d) = binomialMean p m f - binomialMean p m g := by | |
| induction m generalizing f g with | |
| | zero => rfl | |
| | succ m ih => simp only [binomialMean, ih]; ring | |
| theorem binomialMean_mul_const (p c : β) (m : β) (f : β β β) : | |
| binomialMean p m (fun d => f d * c) = binomialMean p m f * c := by | |
| induction m generalizing f with | |
| | zero => rfl | |
| | succ m ih => simp only [binomialMean, ih]; ring | |
| theorem binomialMean_const_mul (p c : β) (m : β) (f : β β β) : | |
| binomialMean p m (fun d => c * f d) = c * binomialMean p m f := by | |
| simpa only [mul_comm] using binomialMean_mul_const p c m f | |
| theorem binomialMean_sum {ΞΉ : Type*} (p : β) (m : β) (s : Finset ΞΉ) (f : ΞΉ β β β β) : | |
| binomialMean p m (fun d => β i β s, f i d) = β i β s, binomialMean p m (f i) := by | |
| induction s using Finset.induction_on with | |
| | empty => simp [binomialMean_const] | |
| | @insert i s hi ih => | |
| simp only [Finset.sum_insert hi, binomialMean_add, ih] | |
| theorem binomialMean_mono {p : β} {m : β} (hp0 : 0 β€ p) (hp1 : p β€ 1) | |
| {f g : β β β} (h : β d β€ m, f d β€ g d) : binomialMean p m f β€ binomialMean p m g := by | |
| induction m generalizing f g with | |
| | zero => exact h 0 (by omega) | |
| | succ m ih => | |
| exact add_le_add | |
| (mul_le_mul_of_nonneg_left (ih (fun d hd => h d (by omega))) (sub_nonneg.mpr hp1)) | |
| (mul_le_mul_of_nonneg_left (ih (fun d hd => h (d + 1) (by omega))) hp0) | |
| theorem binomialMean_nonneg {p : β} {m : β} (hp0 : 0 β€ p) (hp1 : p β€ 1) | |
| {f : β β β} (h : β d β€ m, 0 β€ f d) : 0 β€ binomialMean p m f := by | |
| simpa only [binomialMean_const] using binomialMean_mono hp0 hp1 h | |
| theorem binomialMean_id (p : β) (m : β) : | |
| binomialMean p m (fun d => (d : β)) = (m : β) * p := by | |
| induction m with | |
| | zero => simp [binomialMean] | |
| | succ m ih => | |
| simp only [binomialMean, Nat.cast_add, Nat.cast_one, binomialMean_add, | |
| binomialMean_const, ih] | |
| ring | |
| theorem binomialMean_monotone_trials {p : β} (hp0 : 0 β€ p) (hp1 : p β€ 1) | |
| {f : β β β} (hf : Monotone f) : Monotone (fun m => binomialMean p m f) := by | |
| apply monotone_nat_of_le_succ | |
| intro m | |
| have h := binomialMean_mono (m := m) hp0 hp1 (f := f) (g := fun d => f (d + 1)) | |
| (fun d _ => hf (by omega)) | |
| change _ β€ (1 - p) * _ + p * _ | |
| nlinarith | |
| theorem uniformMean_binomialMean {Ξ± : Type*} [Fintype Ξ±] | |
| (p : β) (m : β) (f : β β Ξ± β β) : | |
| uniformMean (fun a => binomialMean p m (fun d => f d a)) = | |
| binomialMean p m (fun d => uniformMean (f d)) := by | |
| induction m generalizing f with | |
| | zero => rfl | |
| | succ m ih => | |
| simp only [binomialMean, uniformMean_add, uniformMean_const_mul, ih] | |
| theorem sum_shift_difference_le (P : β β β) (hP0 : β j, 0 β€ P j) | |
| (hP1 : β j, P j β€ 1) (l b : β) : | |
| β j β Finset.range l, (P j - P (j + b)) β€ (b : β) := by | |
| have h1 := Finset.sum_range_add P l b | |
| have h2 := Finset.sum_range_add P b l | |
| have hid : (β j β Finset.range l, (P j - P (j + b))) = | |
| β j β Finset.range b, (P j - P (j + l)) := by | |
| rw [Finset.sum_sub_distrib, Finset.sum_sub_distrib] | |
| have hc : l + b = b + l := Nat.add_comm _ _ | |
| simp only [Nat.add_comm l] at h1 | |
| simp only [Nat.add_comm b] at h2 | |
| rw [hc] at h2 | |
| linarith | |
| rw [hid] | |
| calc | |
| _ β€ β _j β Finset.range b, (1 : β) := by | |
| apply Finset.sum_le_sum | |
| intro j _ | |
| linarith [hP0 (j + l), hP1 j] | |
| _ = b := by simp | |
| theorem sum_two_shift_difference_le (P : β β β) (hP0 : β j, 0 β€ P j) | |
| (hP1 : β j, P j β€ 1) (l a b : β) : | |
| β j β Finset.range l, (P (j - a) - P (j + b)) β€ (a : β) + b := by | |
| have h1 := sum_shift_difference_le (fun j => P (j - a)) | |
| (fun j => hP0 _) (fun j => hP1 _) l a | |
| simp only [Nat.add_sub_cancel] at h1 | |
| have h2 := sum_shift_difference_le P hP0 hP1 l b | |
| have he : (β j β Finset.range l, (P (j - a) - P (j + b))) = | |
| (β j β Finset.range l, (P (j - a) - P j)) + | |
| β j β Finset.range l, (P j - P (j + b)) := by | |
| rw [β Finset.sum_add_distrib] | |
| apply Finset.sum_congr rfl | |
| intro j _ | |
| ring | |
| rw [he] | |
| linarith | |
| def replacementDifference (P : β β β) (g j d : β) : β := | |
| P (j - d) - P (j + (g - 1) * d) | |
| theorem replacementDifference_mono {P : β β β} (hP : Antitone P) (g j : β) : | |
| Monotone (replacementDifference P g j) := by | |
| intro d e hde | |
| apply sub_le_sub | |
| Β· exact hP (Nat.sub_le_sub_left hde j) | |
| Β· exact hP (Nat.add_le_add_left (Nat.mul_le_mul_left _ hde) j) | |
| theorem replacementDifference_sum_le {P : β β β} | |
| (hP0 : β j, 0 β€ P j) (hP1 : β j, P j β€ 1) {g : β} (hg : 1 β€ g) (l d : β) : | |
| β j β Finset.range l, replacementDifference P g j d β€ (g : β) * d := by | |
| have h := sum_two_shift_difference_le P hP0 hP1 l d ((g - 1) * d) | |
| have he : (d : β) + ((g - 1) * d : β) = (g : β) * d := by | |
| rw [Nat.cast_mul, Nat.cast_sub hg] | |
| push_cast | |
| ring | |
| simpa only [replacementDifference, he] using h | |
| theorem binomial_replacement_sum_le {p : β} (hp0 : 0 β€ p) (hp1 : p β€ 1) | |
| {P : β β β} (hP : Antitone P) (hP0 : β j, 0 β€ P j) (hP1 : β j, P j β€ 1) | |
| {g : β} (hg : 1 β€ g) (M : β) : | |
| β j β Finset.range (M + 1), binomialMean p j (replacementDifference P g j) β€ | |
| (g : β) * (M : β) * p := by | |
| calc | |
| _ β€ β j β Finset.range (M + 1), binomialMean p M (replacementDifference P g j) := by | |
| apply Finset.sum_le_sum | |
| intro j hj | |
| have hjM : j β€ M := by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hj | |
| exact binomialMean_monotone_trials hp0 hp1 (replacementDifference_mono hP g j) hjM | |
| _ = binomialMean p M (fun d => β j β Finset.range (M + 1), | |
| replacementDifference P g j d) := (binomialMean_sum _ _ _ _).symm | |
| _ β€ binomialMean p M (fun d => (g : β) * d) := | |
| binomialMean_mono hp0 hp1 (fun d _ => replacementDifference_sum_le hP0 hP1 hg _ d) | |
| _ = _ := by rw [binomialMean_const_mul, binomialMean_id]; ring | |
| end | |
| end FixedClauseThreshold | |
| end OAI | |