Download lean/OAI/Combinatorics/IndependentSets/Expansion/PoweringDecoding.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 6.33 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Expansion/PoweringDecoding.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/IndependentSets/Expansion/PoweringDecoding.lean
-
curl -L -o PoweringDecoding.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Expansion/PoweringDecoding.lean
6.33 kB
Lean 4 · 20
declarations statementsfull
noncomputable def mass (opinion : Ω → A) (a : A) : ℝ := by body · 2 lines
classical
exact Finset.univ.expect (fun ω => if opinion ω = a then 1 else 0)theorem mass_sum (opinion : Ω → A) : (∑ a, mass opinion a) = 1 := by proof · 12 lines
classical
calc
(∑ a, mass opinion a) =
(Finset.univ : Finset Ω).expect
(fun ω => ∑ a : A, if opinion ω = a then (1 : ℝ) else 0) :=
(Finset.expect_sum_comm (Finset.univ : Finset Ω) (Finset.univ : Finset A)
(fun ω a => if opinion ω = a then (1 : ℝ) else 0)).symm
_ = (Finset.univ : Finset Ω).expect (fun _ => (1 : ℝ)) := by
apply Finset.expect_congr rfl
intro ω _
simp
_ = 1 := Finset.expect_const Finset.univ_nonempty 1theorem exists_mode (opinion : Ω → A) :
∃ a : A, ∀ b : A, mass opinion b ≤ mass opinion a := by proof · 3 lines
obtain ⟨a, _, ha⟩ := Finset.exists_max_image (Finset.univ : Finset A)
(mass opinion) Finset.univ_nonempty
exact ⟨a, fun b => ha b (Finset.mem_univ b)⟩noncomputable def mode (opinion : Ω → A) : A := Classical.choose (exists_mode opinion) theorem mode_max (opinion : Ω → A) (b : A) :
mass opinion b ≤ mass opinion (mode opinion) := proof · 1 line
Classical.choose_spec (exists_mode opinion) btheorem mode_mass_lower (opinion : Ω → A) :
1 / (Fintype.card A : ℝ) ≤ mass opinion (mode opinion) := by proof · 8 lines
have hk : 0 < (Fintype.card A : ℝ) := Nat.cast_pos.mpr Fintype.card_pos
have hsum : (1 : ℝ) ≤ mass opinion (mode opinion) * (Fintype.card A : ℝ) := by
calc
(1 : ℝ) = ∑ a : A, mass opinion a := (mass_sum opinion).symm
_ ≤ ∑ _a : A, mass opinion (mode opinion) :=
Finset.sum_le_sum (fun a _ => mode_max opinion a)
_ = mass opinion (mode opinion) * (Fintype.card A : ℝ) := by simp [mul_comm]
exact (div_le_iff₀ hk).2 hsumtheorem exists_letter_mass_lower (opinion : Ω → A) :
∃ a : A, 1 / (Fintype.card A : ℝ) ≤ mass opinion a := proof · 1 line
⟨mode opinion, mode_mass_lower opinion⟩
def bit (p : Prop) : ℝ := by body · 2 lines
classical
exact if p then 1 else 0def hits {I Ω : Type*} [Fintype I] (E : I → Ω → Prop) (ω : Ω) : ℝ := body · 1 line
∑ i, bit (E i ω)def mean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := Finset.univ.expect f theorem bit_nonneg (p : Prop) : 0 ≤ bit p := by proof · 2 lines
classical
by_cases hp : p <;> simp [bit, hp]theorem bit_sq (p : Prop) : bit p ^ 2 = bit p := by proof · 2 lines
classical
by_cases hp : p <;> simp [bit, hp]theorem bit_mul (p q : Prop) : bit p * bit q = bit (p ∧ q) := by proof · 2 lines
classical
by_cases hp : p <;> by_cases hq : q <;> simp [bit, hp, hq]theorem bit_mono {p q : Prop} (hpq : p → q) : bit p ≤ bit q := by proof · 6 lines
classical
by_cases hp : p
· simp [bit, hp, hpq hp]
· have hz : bit p = 0 := by simp [bit, hp]
rw [hz]
exact bit_nonneg qtheorem hits_nonneg {I Ω : Type*} [Fintype I] (E : I → Ω → Prop) (ω : Ω) :
0 ≤ hits E ω := Finset.sum_nonneg (fun i _ => bit_nonneg (E i ω)) theorem mean_nonneg {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (hf : ∀ ω, 0 ≤ f ω) :
0 ≤ mean f := Finset.expect_nonneg (fun ω _ => hf ω) theorem mean_hits {I Ω : Type*} [Fintype I] [Fintype Ω] (E : I → Ω → Prop) :
mean (hits E) = ∑ i, mean (fun ω => bit (E i ω)) := by proof · 1 line
exact Finset.expect_sum_comm _ _ _theorem second_moment_eq {I Ω : Type*} [Fintype I] [Fintype Ω]
(E : I → Ω → Prop) :
mean (fun ω => hits E ω ^ 2) =
∑ i, ∑ j, mean (fun ω => bit (E i ω ∧ E j ω)) := by proof · 3 lines
simp only [hits, pow_two, Finset.sum_mul, Finset.mul_sum, bit_mul,
mean, Finset.expect_sum_comm]
exact Finset.sum_commtheorem mean_witness_sq_le {I Ω : Type*} [Fintype I] [Fintype Ω]
(E W : I → Ω → Prop) (reject : Ω → Prop)
(hWE : ∀ i ω, W i ω → E i ω)
(hWR : ∀ i ω, W i ω → reject ω) :
mean (hits W) ^ 2 ≤
mean (fun ω => bit (reject ω)) * mean (fun ω => hits E ω ^ 2) := by proof · 25 lines
classical
have hNH (ω : Ω) : hits W ω ≤ hits E ω :=
Finset.sum_le_sum (fun i _ => bit_mono (hWE i ω))
have hzero (ω : Ω) (hr : ¬ reject ω) : hits W ω = 0 := by
apply Finset.sum_eq_zero
intro i _
have hw : ¬ W i ω := fun h => hr (hWR i ω h)
simp [bit, hw]
have hsupport (ω : Ω) : bit (reject ω) * hits W ω = hits W ω := by
by_cases hr : reject ω
· simp [bit, hr]
· rw [hzero ω hr]
simp
have hCS := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ
(fun ω => bit (reject ω)) (hits W)
have hsquares : mean (fun ω => hits W ω ^ 2) ≤ mean (fun ω => hits E ω ^ 2) := by
apply Finset.expect_le_expect
intro ω _
simpa only [pow_two] using
(mul_le_mul (hNH ω) (hNH ω) (hits_nonneg W ω) (hits_nonneg E ω))
calc
_ ≤ mean (fun ω => bit (reject ω)) * mean (fun ω => hits W ω ^ 2) := by
simpa only [mean, hsupport, bit_sq] using hCS
_ ≤ _ := mul_le_mul_of_nonneg_left hsquares
(mean_nonneg _ (fun ω => bit_nonneg (reject ω)))theorem rejection_lower_bound {I Ω : Type*} [Fintype I] [Fintype Ω]
(E W : I → Ω → Prop) (reject : Ω → Prop)
(hWE : ∀ i ω, W i ω → E i ω)
(hWR : ∀ i ω, W i ω → reject ω)
(a b : ℝ) (ha : 0 < a) (hb : 0 < b)
(hfirst : a ≤ mean (hits W))
(hsecond : mean (fun ω => hits E ω ^ 2) ≤ b) :
a ^ 2 / b ≤ mean (fun ω => bit (reject ω)) := by proof · 8 lines
have hN : 0 ≤ mean (hits W) := mean_nonneg _ (hits_nonneg W)
have hρ : 0 ≤ mean (fun ω => bit (reject ω)) :=
mean_nonneg _ (fun ω => bit_nonneg (reject ω))
have haSq : a ^ 2 ≤ mean (hits W) ^ 2 := by
simpa only [pow_two] using mul_le_mul hfirst hfirst ha.le hN
have hCS := mean_witness_sq_le E W reject hWE hWR
apply (div_le_iff₀ hb).2
exact haSq.trans (hCS.trans (mul_le_mul_of_nonneg_left hsecond hρ))Outline
- def
mass11 - theorem
mass_sum16 - theorem
exists_mode31 - def
mode37 - theorem
mode_max40 - theorem
mode_mass_lower44 - theorem
exists_letter_mass_lower55 - def
bit66 - def
hits70 - def
mean73 - theorem
bit_nonneg75 - theorem
bit_sq79 - theorem
bit_mul83 - theorem
bit_mono87 - theorem
hits_nonneg95 - theorem
mean_nonneg98 - theorem
mean_hits101 - theorem
second_moment_eq105 - theorem
mean_witness_sq_le113 - theorem
rejection_lower_bound145