Download lean/OAI/Computability/VertexCover/Fourier/SourceGame.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 12.6 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/VertexCover/Fourier/SourceGame.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Computability/VertexCover/Fourier/SourceGame.lean
-
curl -L -o SourceGame.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/VertexCover/Fourier/SourceGame.lean
12.6 kB
Lean 4 · 23
declarations statementsfull
theorem event_nonempty (F : Formula) (hne : F.clauses ≠ []) :
Nonempty (RandomEvent F) := proof · 1 line
⟨(⟨0, List.length_pos_iff.mpr hne⟩, .first)⟩def eventLaw (F : Formula) (hne : F.clauses ≠ []) :
FiniteDistribution (RandomEvent F) := by body · 2 lines
let : Nonempty (RandomEvent F) := event_nonempty F hne
exact FiniteDistribution.uniform _def visibleQuestion (F : Formula) (e : RandomEvent F) :
Fin F.«variables» × Fin F.clauses.length := body · 1 line
(nameAt (clauseAt F e.1) e.2, e.1)def baseGame (F : Formula) (hne : F.clauses ≠ []) :
Game (Fin F.«variables») (Fin F.clauses.length) Bool ClauseAnswer where body · 2 lines
questions := (eventLaw F hne).pushforward (visibleQuestion F)
accepts := baseAccepts F@[simp] theorem baseGame_accepts (F : Formula) (hne : F.clauses ≠ [])
(v : Fin F.«variables») («c» : Fin F.clauses.length) (i : Bool) (j : ClauseAnswer) :
(baseGame F hne).accepts v «c» i j = baseAccepts F v «c» i j := rfl theorem eventLaw_probability (F : Formula) (hne : F.clauses ≠ [])
(P : RandomEvent F → Bool) :
(eventLaw F hne).probability P =
(∑ e : RandomEvent F, if P e then (1 : ℝ) else 0) /
(3 * F.clauses.length : ℕ) := by proof · 7 lines
classical
simp only [eventLaw, FiniteDistribution.uniform, FiniteDistribution.probability]
simp_rw [div_eq_mul_inv]
rw [Finset.sum_mul]
apply Finset.sum_congr rfl
intro e _
cases P e <;> simp [RandomEvent, Fintype.card_prod, Nat.mul_comm]theorem sum_slots (H : Slot → ℝ) :
(∑ s : Slot, H s) = H .first + H .second + H .third := by proof · 7 lines
have hu : (Finset.univ : Finset Slot) = {.first, .second, .third} := by
ext s
cases s <;> simp
rw [hu]
simp only [Finset.sum_insert, Finset.mem_insert, Finset.mem_singleton,
reduceCtorEq, or_self, not_false_eq_true, Finset.sum_singleton]
ringtheorem sum_slot_accepts (F : Formula) (alice : AliceStrategy F)
(bob : BobStrategy F) («c» : Fin F.clauses.length) :
(∑ s : Slot, if accepts F alice bob («c»,s) then (1 : ℝ) else 0) =
(acceptedSlots (clauseAt F «c») (alice «c»)
(honestAnswer (clauseAt F «c») bob) : ℕ) := by proof · 8 lines
rw [sum_slots]
by_cases hs : localSatisfies (clauseAt F «c») (alice «c») = true
· by_cases h₁ : (alice «c»).first = bob (clauseAt F «c»)[0].variableIndex <;>
by_cases h₂ : (alice «c»).second = bob (clauseAt F «c»)[1].variableIndex <;>
by_cases h₃ : (alice «c»).third = bob (clauseAt F «c»)[2].variableIndex <;>
norm_num [accepts, hs, acceptedSlots, matchingSlots, honestAnswer, answerAt, nameAt,
h₁, h₂, h₃]
· simp [accepts, acceptedSlots, hs]theorem failureCount_eq_sum_map (F : Formula) (bob : BobStrategy F)
(cs : List (Fin F.clauses.length)) :
failureCount F bob cs =
(cs.map (fun «c» => clauseFailure (clauseAt F «c») bob)).sum := by proof · 3 lines
induction cs with
| nil => rfl
| cons «c» cs ih => simp only [failureCount, List.map_cons, List.sum_cons, ih]theorem failureCount_allIndices (F : Formula) (bob : BobStrategy F) :
failureCount F bob (allIndices F) =
∑ «c» : Fin F.clauses.length, clauseFailure (clauseAt F «c») bob := by proof · 3 lines
rw [failureCount_eq_sum_map]
unfold allIndices
rw [← List.sum_toFinset _ (List.nodup_finRange _), List.toFinset_finRange]theorem verifier_probability_plus_failure (F : Formula) (hne : F.clauses ≠ [])
(alice : AliceStrategy F) (bob : BobStrategy F) :
(eventLaw F hne).probability (accepts F alice bob) +
(failureCount F bob (allIndices F) : ℝ) / (3 * F.clauses.length : ℕ) ≤ 1 := by proof · 16 lines
have hm : (0 : ℝ) < (3 * F.clauses.length : ℕ) := by
exact_mod_cast Nat.mul_pos (by decide : 0 < 3) (List.length_pos_iff.mpr hne)
have hlocal («c» : Fin F.clauses.length) :
(∑ s : Slot, if accepts F alice bob («c»,s) then (1 : ℝ) else 0) +
(clauseFailure (clauseAt F «c») bob : ℝ) ≤ 3 := by
rw [sum_slot_accepts]
exact_mod_cast local_rejection_bound (clauseAt F «c») (alice «c») bob
have hsum := Finset.sum_le_sum (fun «c» (_ : «c» ∈ (Finset.univ : Finset _)) => hlocal «c»)
simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ,
Fintype.card_fin, nsmul_eq_mul] at hsum
rw [eventLaw_probability, failureCount_allIndices]
push_cast
push_cast at hm
rw [Fintype.sum_prod_type, ← add_div]
apply (div_le_one hm).mpr
simpa only [Nat.cast_mul, Nat.cast_ofNat, mul_comm] using hsumtheorem base_success_le_verifier (F : Formula) (hne : F.clauses ≠ [])
(strategy : Strategy (Fin F.«variables») (Fin F.clauses.length) Bool ClauseAnswer) :
(baseGame F hne).success strategy ≤
(eventLaw F hne).probability (accepts F strategy.2 strategy.1) := by proof · 5 lines
unfold Game.success baseGame
rw [FiniteDistribution.probability_pushforward]
apply FiniteDistribution.probability_mono
intro e he
exact baseAccepts_implies_sampled F e.1 e.2 _ _ hetheorem base_value_le_of_clause_gap (F : Formula) (hne : F.clauses ≠ [])
(δ : ℝ) (hgap : ∀ bob : BobStrategy F,
δ * F.clauses.length ≤ (failureCount F bob (allIndices F) : ℝ)) :
(baseGame F hne).value ≤ 1 - δ / 3 := by proof · 15 lines
apply (Game.value_le_iff _ _).mpr
intro strategy
have hbase := base_success_le_verifier F hne strategy
have hprob := verifier_probability_plus_failure F hne strategy.2 strategy.1
have hm : (0 : ℝ) < F.clauses.length :=
Nat.cast_pos.mpr (List.length_pos_iff.mpr hne)
have hg : δ / 3 ≤ (failureCount F strategy.1 (allIndices F) : ℝ) /
(3 * F.clauses.length : ℕ) := by
have hden : (0 : ℝ) < (3 * F.clauses.length : ℕ) := by
exact_mod_cast Nat.mul_pos (by decide : 0 < 3) (List.length_pos_iff.mpr hne)
apply (le_div_iff₀ hden).mpr
calc
δ / 3 * (3 * F.clauses.length : ℕ) = δ * F.clauses.length := by push_cast; ring
_ ≤ _ := hgap strategy.1
linariththeorem pushforward_comp {X Y Z : Type*} [Fintype X] [Fintype Y] [Fintype Z]
(μ : FiniteDistribution X) (f : X → Y) (g : Y → Z) :
(μ.pushforward f).pushforward g = μ.pushforward (g ∘ f) := by proof · 11 lines
classical
apply FiniteDistribution.eq_of_weight_eq
intro z
simp only [FiniteDistribution.pushforward]
calc
_ = ∑ y : Y, ∑ x : X, if f x = y then
(if g y = z then μ.weight x else 0) else 0 := by
apply Finset.sum_congr rfl
intro y _
by_cases h : g y = z <;> simp [h]
_ = _ := by rw [Finset.sum_comm]; simptheorem expectation_pushforward {X Y : Type*} [Fintype X] [Fintype Y]
(μ : FiniteDistribution X) (f : X → Y) (H : Y → ℝ) :
(μ.pushforward f).expectation H = μ.expectation (H ∘ f) := by proof · 7 lines
classical
simp only [FiniteDistribution.expectation, FiniteDistribution.pushforward,
Finset.sum_mul]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro x _
simp [ite_mul]def repeatedVisible (F : Formula) (u : ℕ) (events : Fin u → RandomEvent F) :
VariableContext F u × ClauseContext F u := body · 2 lines
(fun t => nameAt (clauseAt F (events t).1) (events t).2,
fun t => (events t).1)theorem repeated_questions (F : Formula) (hne : F.clauses ≠ []) (u : ℕ) :
((baseGame F hne).repetition u).questions =
((eventLaw F hne).iid u).pushforward (repeatedVisible F u) := by proof · 5 lines
change (((eventLaw F hne).pushforward (visibleQuestion F)).iid u).transport
(Game.tupleQuestionEquiv u) = _
rw [FiniteDistribution.iid_pushforward, ← FiniteDistribution.pushforward_equiv,
pushforward_comp]
rfltheorem repeated_expectation (F : Formula) (hne : F.clauses ≠ []) (u : ℕ)
(H : VariableContext F u × ClauseContext F u → ℝ) :
((baseGame F hne).repetition u).questions.expectation H =
𝔼 events : Fin u → RandomEvent F, H (repeatedVisible F u events) := by proof · 6 lines
let : Nonempty (RandomEvent F) := event_nonempty F hne
rw [repeated_questions, expectation_pushforward]
change ((FiniteDistribution.uniform (RandomEvent F)).iid u).expectation _ = _
rw [FiniteDistribution.iid_uniform, FiniteDistribution.expectation_uniform,
Fintype.expect_eq_sum_div_card]
rfltheorem repeated_expectation_split (F : Formula) (hne : F.clauses ≠ []) (u : ℕ)
(H : VariableContext F u × ClauseContext F u → ℝ) :
((baseGame F hne).repetition u).questions.expectation H =
𝔼 «c» : ClauseContext F u, 𝔼 s : SlotContext u,
H (sampledVariables F «c» s, «c») := by proof · 8 lines
rw [repeated_expectation]
calc
_ = 𝔼 p : ClauseContext F u × SlotContext u,
H (sampledVariables F p.1 p.2, p.1) :=
Fintype.expect_equiv
(Game.tupleQuestionEquiv (Q₁ := Fin F.clauses.length) (Q₂ := Slot) u)
_ _ (fun _ => rfl)
_ = _ := SourceTape.expect_prod _def sourceProjectionGame (F : Formula) (hne : F.clauses ≠ []) (u : ℕ) :
Game (VariableContext F u) (ClauseContext F u) (I u) (J u) := body · 2 lines
projectionGame ((baseGame F hne).repetition u).questions
(fun v «c» => pi F «c» v) (validJ F)theorem projection_value_le_repetition (F : Formula) (hne : F.clauses ≠ [])
(u : ℕ) :
(sourceProjectionGame F hne u).value ≤ ((baseGame F hne).repetition u).value := by proof · 15 lines
apply (Game.value_le_iff _ _).mpr
intro strategy
have h : (sourceProjectionGame F hne u).success strategy ≤
((baseGame F hne).repetition u).success strategy := by
apply FiniteDistribution.probability_mono
intro q hq
have hlegal : pi F q.2 q.1 (strategy.2 q.2) = strategy.1 q.1 ∧
validJ F q.2 (strategy.2 q.2) = true := by
simpa only [Game.wins, sourceProjectionGame, projectionGame,
decide_eq_true_eq] using hq
apply (Game.repetition_accepts_iff _ _ _ _ _ _).mpr
intro t
exact projection_implies_coordinate_accepts F q.2 q.1
(strategy.1 q.1) (strategy.2 q.2) hlegal.2 hlegal.1 t
exact h.trans (Game.success_le_value _ strategy)theorem source_acceptance_le (F : Formula) (hne : F.clauses ≠ []) (u : ℕ)
(ε δ : ℝ) (i₀ : VariableContext F u → I u)
(tableA : ∀ v, HalfCube (i₀ v) → Bool)
(right : ∀ «c» : ClauseContext F u, ConditionedOracle (validJ F «c»))
(hε : 0 < ε) (hε' : ε ≤ 1 / 2) (hδ : 0 ≤ δ)
(hvalue : ((baseGame F hne).repetition u).value ≤ 4 * ε * δ ^ 2) :
(𝔼 events : Fin u → RandomEvent F,
questionAcceptance ε (fun v «c» => pi F «c» v)
(fun v => foldedAnswer (i₀ v) (tableA v)) (fun «c» => (right «c»).answer)
(repeatedVisible F u events)) ≤ (1 + δ) / 2 := by proof · 4 lines
rw [← repeated_expectation F hne u]
exact conditionedOracle_acceptance_bound _ ε δ _ (validJ F) i₀ tableA
(fun _ => default) right hε hε' hδ
((projection_value_le_repetition F hne u).trans hvalue)theorem source_acceptance_le_split (F : Formula) (hne : F.clauses ≠ []) (u : ℕ)
(ε δ : ℝ) (i₀ : VariableContext F u → I u)
(tableA : ∀ v, HalfCube (i₀ v) → Bool)
(right : ∀ «c» : ClauseContext F u, ConditionedOracle (validJ F «c»))
(hε : 0 < ε) (hε' : ε ≤ 1 / 2) (hδ : 0 ≤ δ)
(hvalue : ((baseGame F hne).repetition u).value ≤ 4 * ε * δ ^ 2) :
(𝔼 «c» : ClauseContext F u, 𝔼 s : SlotContext u,
testAcceptance ε (pi F «c» (sampledVariables F «c» s))
(foldedAnswer (i₀ (sampledVariables F «c» s)) (tableA (sampledVariables F «c» s)))
(right «c»).answer) ≤ (1 + δ) / 2 := by proof · 6 lines
have h := conditionedOracle_acceptance_bound
((baseGame F hne).repetition u).questions ε δ (fun v «c» => pi F «c» v)
(validJ F) i₀ tableA (fun _ => default) right hε hε' hδ
((projection_value_le_repetition F hne u).trans hvalue)
rw [repeated_expectation_split] at h
exact hOutline
- theorem
event_nonempty47 - def
eventLaw51 - def
visibleQuestion56 - def
baseGame60 - theorem
baseGame_accepts65 - theorem
eventLaw_probability69 - theorem
sum_slots82 - theorem
sum_slot_accepts92 - theorem
failureCount_eq_sum_map106 - theorem
failureCount_allIndices114 - theorem
verifier_probability_plus_failure121 - theorem
base_success_le_verifier142 - theorem
base_value_le_of_clause_gap152 - theorem
pushforward_comp172 - theorem
expectation_pushforward187 - def
repeatedVisible198 - theorem
repeated_questions203 - theorem
repeated_expectation212 - theorem
repeated_expectation_split223 - def
sourceProjectionGame237 - theorem
projection_value_le_repetition242 - theorem
source_acceptance_le261 - theorem
source_acceptance_le_split276