Download lean/OAI/Computability/VertexCover/Fourier/SourceContexts.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/VertexCover/Fourier/SourceContexts.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Computability/VertexCover/Fourier/SourceContexts.lean
-
curl -L -o SourceContexts.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/VertexCover/Fourier/SourceContexts.lean
10.5 kB
Lean 4 · 42
declarations statementsfull
def clauseAnswerEquiv : ClauseAnswer ≃ Bool × Bool × Bool where body · 4 lines
toFun a := (a.first, a.second, a.third)
invFun a := ⟨a.1, a.2.1, a.2.2⟩
left_inv a := by cases a; rfl
right_inv a := by rcases a with ⟨a, b, «c»⟩; rfldef clauseAnswerFinEquiv : ClauseAnswer ≃ Fin 8 := body · 4 lines
clauseAnswerEquiv.trans
((Equiv.prodCongr finTwoEquiv.symm
(Equiv.prodCongr finTwoEquiv.symm finTwoEquiv.symm)).trans
((Equiv.prodCongr (Equiv.refl (Fin 2)) finProdFinEquiv).trans finProdFinEquiv))instance clauseAnswerFintype : Fintype ClauseAnswer := body · 1 line
Fintype.ofEquiv (Bool × Bool × Bool) clauseAnswerEquiv.symminstance clauseAnswerInhabited : Inhabited ClauseAnswer := ⟨⟨false, false, false⟩⟩ instance slotFintype : Fintype Slot where body · 2 lines
elems := {.first, .second, .third}
complete s := by cases s <;> simpinstance slotInhabited : Inhabited Slot := ⟨.first⟩ @[simp] theorem card_clauseAnswer : Fintype.card ClauseAnswer = 8 := by proof · 2 lines
rw [Fintype.card_congr clauseAnswerFinEquiv]
rfl@[simp] theorem card_slot : Fintype.card Slot = 3 := by decide abbrev I (u : ℕ) := Fin u → Bool abbrev J (u : ℕ) := Fin u → ClauseAnswer abbrev ClauseContext (F : Formula) (u : ℕ) := Fin u → Fin F.clauses.length abbrev VariableContext (F : Formula) (u : ℕ) := Fin u → Fin F.«variables» abbrev SlotContext (u : ℕ) := Fin u → Slot @[simp] theorem card_I (u : ℕ) : Fintype.card (I u) = 2 ^ u := by simp [I] @[simp] theorem card_J (u : ℕ) : Fintype.card (J u) = 8 ^ u := by simp [J] @[simp] theorem card_ClauseContext (F : Formula) (u : ℕ) :
Fintype.card (ClauseContext F u) = F.clauses.length ^ u := by simp [ClauseContext] @[simp] theorem card_VariableContext (F : Formula) (u : ℕ) :
Fintype.card (VariableContext F u) = F.«variables» ^ u := by simp [VariableContext] @[simp] theorem card_SlotContext (u : ℕ) :
Fintype.card (SlotContext u) = 3 ^ u := by simp [SlotContext] def localConsistent {n : ℕ} (clause : Clause n) (answer : ClauseAnswer) : Bool := body · 2 lines
decide (∀ s s' : Slot, nameAt clause s = nameAt clause s' →
answerAt answer s = answerAt answer s')@[simp] theorem localConsistent_eq_true_iff {n : ℕ}
(clause : Clause n) (answer : ClauseAnswer) :
localConsistent clause answer = true ↔
∀ s s' : Slot, nameAt clause s = nameAt clause s' →
answerAt answer s = answerAt answer s' := by proof · 1 line
simp [localConsistent]
def validJ (F : Formula) {u : ℕ} («c» : ClauseContext F u) (j : J u) : Bool := body · 3 lines
decide ((∀ t, localSatisfies (clauseAt F («c» t)) (j t) = true) ∧
∀ t t' s s', nameAt (clauseAt F («c» t)) s = nameAt (clauseAt F («c» t')) s' →
answerAt (j t) s = answerAt (j t') s')@[simp] theorem validJ_eq_true_iff (F : Formula) {u : ℕ}
(«c» : ClauseContext F u) (j : J u) :
validJ F «c» j = true ↔
(∀ t, localSatisfies (clauseAt F («c» t)) (j t) = true) ∧
∀ t t' s s', nameAt (clauseAt F («c» t)) s = nameAt (clauseAt F («c» t')) s' →
answerAt (j t) s = answerAt (j t') s' := by proof · 1 line
simp [validJ]
theorem validJ_satisfies (F : Formula) {u : ℕ} («c» : ClauseContext F u)
(j : J u) (hj : validJ F «c» j = true) (t : Fin u) :
localSatisfies (clauseAt F («c» t)) (j t) = true := proof · 1 line
((validJ_eq_true_iff F «c» j).mp hj).1 ttheorem validJ_consistent (F : Formula) {u : ℕ} («c» : ClauseContext F u)
(j : J u) (hj : validJ F «c» j = true) (t : Fin u) (s : Slot)
(t' : Fin u) (s' : Slot)
(hname : nameAt (clauseAt F («c» t)) s = nameAt (clauseAt F («c» t')) s') :
answerAt (j t) s = answerAt (j t') s' := proof · 1 line
((validJ_eq_true_iff F «c» j).mp hj).2 t t' s s' hnametheorem validJ_localConsistent (F : Formula) {u : ℕ} («c» : ClauseContext F u)
(j : J u) (hj : validJ F «c» j = true) (t : Fin u) :
localConsistent (clauseAt F («c» t)) (j t) = true := by proof · 3 lines
apply (localConsistent_eq_true_iff _ _).mpr
intro s s' hs
exact validJ_consistent F «c» j hj t s t s' hsdef canonicalSlot {n : ℕ} (clause : Clause n) (v : Fin n) : Slot := body · 2 lines
if nameAt clause .first = v then .first
else if nameAt clause .second = v then .second else .thirdtheorem canonicalSlot_name {n : ℕ} (clause : Clause n) (v : Fin n)
(hv : ∃ s, nameAt clause s = v) : nameAt clause (canonicalSlot clause v) = v := by proof · 9 lines
by_cases hfirst : nameAt clause .first = v
· simp [canonicalSlot, hfirst]
by_cases hsecond : nameAt clause .second = v
· simp [canonicalSlot, hfirst, hsecond]
obtain ⟨s, hs⟩ := hv
cases s with
| first => exact False.elim (hfirst hs)
| second => exact False.elim (hsecond hs)
| third => simpa [canonicalSlot, hfirst, hsecond] using hsdef pi (F : Formula) {u : ℕ} («c» : ClauseContext F u) (v : VariableContext F u)
(j : J u) : I u := body · 1 line
fun t => answerAt (j t) (canonicalSlot (clauseAt F («c» t)) (v t))def sampledVariables (F : Formula) {u : ℕ} («c» : ClauseContext F u)
(s : SlotContext u) : VariableContext F u := body · 1 line
fun t => nameAt (clauseAt F («c» t)) (s t)theorem sampledVariables_supported (F : Formula) {u : ℕ}
(«c» : ClauseContext F u) (s : SlotContext u) :
∀ t, ∃ slot, nameAt (clauseAt F («c» t)) slot = sampledVariables F «c» s t := proof · 1 line
fun t => ⟨s t, rfl⟩theorem sampled_eq_pi (F : Formula) {u : ℕ} («c» : ClauseContext F u)
(v : VariableContext F u) (j : J u) (hj : validJ F «c» j = true)
(t : Fin u) (s : Slot) (hs : nameAt (clauseAt F («c» t)) s = v t) :
answerAt (j t) s = pi F «c» v j t := by proof · 3 lines
exact validJ_consistent F «c» j hj t s t
(canonicalSlot (clauseAt F («c» t)) (v t))
(hs.trans (canonicalSlot_name _ _ ⟨s, hs⟩).symm)theorem sampled_answers_eq_of_visible_eq (F : Formula) {u : ℕ}
(«c» : ClauseContext F u) (s s' : SlotContext u) (j : J u)
(hj : validJ F «c» j = true)
(hvisible : sampledVariables F «c» s = sampledVariables F «c» s') :
(fun t => answerAt (j t) (s t)) = fun t => answerAt (j t) (s' t) := by proof · 2 lines
funext t
exact validJ_consistent F «c» j hj t (s t) t (s' t) (congrFun hvisible t)def honestJ (F : Formula) {u : ℕ} («c» : ClauseContext F u)
(assignment : Fin F.«variables» → Bool) : J u := body · 1 line
fun t => honestAnswer (clauseAt F («c» t)) assignmentdef honestI (F : Formula) {u : ℕ} (v : VariableContext F u)
(assignment : Fin F.«variables» → Bool) : I u := body · 1 line
fun t => assignment (v t)theorem honestJ_valid (F : Formula) {u : ℕ} («c» : ClauseContext F u)
(assignment : Fin F.«variables» → Bool)
(hs : ∀ clause ∈ F.clauses, clause.eval assignment = true) :
validJ F «c» (honestJ F «c» assignment) = true := by proof · 7 lines
apply (validJ_eq_true_iff F «c» _).mpr
constructor
· intro t
exact (honest_satisfies _ assignment).trans (hs _ (List.getElem_mem _))
· intro t t' s s' hname
simp only [honestJ, honest_answerAt]
exact congrArg assignment hnametheorem pi_honest (F : Formula) {u : ℕ} («c» : ClauseContext F u)
(v : VariableContext F u) (assignment : Fin F.«variables» → Bool)
(hsupport : ∀ t, ∃ s, nameAt (clauseAt F («c» t)) s = v t) :
pi F «c» v (honestJ F «c» assignment) = honestI F v assignment := by proof · 3 lines
funext t
exact (honest_answerAt _ assignment _).trans
(congrArg assignment (canonicalSlot_name _ _ (hsupport t)))theorem pi_honest_sampled (F : Formula) {u : ℕ} («c» : ClauseContext F u)
(s : SlotContext u) (assignment : Fin F.«variables» → Bool) :
pi F «c» (sampledVariables F «c» s) (honestJ F «c» assignment) =
honestI F (sampledVariables F «c» s) assignment := proof · 1 line
pi_honest F «c» _ assignment (sampledVariables_supported F «c» s)def baseAccepts (F : Formula) (v : Fin F.«variables») («c» : Fin F.clauses.length)
(i : Bool) (j : ClauseAnswer) : Bool := body · 3 lines
decide (localSatisfies (clauseAt F «c») j = true ∧
localConsistent (clauseAt F «c») j = true ∧
answerAt j (canonicalSlot (clauseAt F «c») v) = i)@[simp] theorem baseAccepts_eq_true_iff (F : Formula) (v : Fin F.«variables»)
(«c» : Fin F.clauses.length) (i : Bool) (j : ClauseAnswer) :
baseAccepts F v «c» i j = true ↔
localSatisfies (clauseAt F «c») j = true ∧
localConsistent (clauseAt F «c») j = true ∧
answerAt j (canonicalSlot (clauseAt F «c») v) = i := by proof · 1 line
simp [baseAccepts]
theorem projection_implies_coordinate_accepts (F : Formula) {u : ℕ}
(«c» : ClauseContext F u) (v : VariableContext F u) (i : I u) (j : J u)
(hj : validJ F «c» j = true) (hpi : pi F «c» v j = i) (t : Fin u) :
baseAccepts F (v t) («c» t) (i t) (j t) = true := by proof · 2 lines
exact (baseAccepts_eq_true_iff F _ _ _ _).mpr
⟨validJ_satisfies F «c» j hj t, validJ_localConsistent F «c» j hj t, congrFun hpi t⟩theorem baseAccepts_implies_sampled (F : Formula) («c» : Fin F.clauses.length)
(s : Slot) (i : Bool) (j : ClauseAnswer)
(h : baseAccepts F (nameAt (clauseAt F «c») s) «c» i j = true) :
(localSatisfies (clauseAt F «c») j && decide (answerAt j s = i)) = true := by proof · 5 lines
obtain ⟨hsat, hcons, heq⟩ := (baseAccepts_eq_true_iff F _ _ _ _).mp h
have hname := canonicalSlot_name (clauseAt F «c») (nameAt (clauseAt F «c») s) ⟨s, rfl⟩
have hans := (localConsistent_eq_true_iff _ _).mp hcons s
(canonicalSlot (clauseAt F «c») (nameAt (clauseAt F «c») s)) hname.symm
simp [hsat, hans.trans heq]theorem projection_implies_sampled_accepts (F : Formula) {u : ℕ}
(«c» : ClauseContext F u) (s : SlotContext u) (i : I u) (j : J u)
(hj : validJ F «c» j = true) (hpi : pi F «c» (sampledVariables F «c» s) j = i) :
∀ t, (localSatisfies (clauseAt F («c» t)) (j t) &&
decide (answerAt (j t) (s t) = i t)) = true := by proof · 3 lines
intro t
exact baseAccepts_implies_sampled F («c» t) (s t) (i t) (j t)
(projection_implies_coordinate_accepts F «c» _ i j hj hpi t)Outline
- def
clauseAnswerEquiv36 - def
clauseAnswerFinEquiv42 - instance
clauseAnswerFintype48 - instance
clauseAnswerInhabited51 - instance
slotFintype53 - instance
slotInhabited57 - theorem
card_clauseAnswer59 - theorem
card_slot63 - abbrev
I65 - abbrev
J66 - abbrev
ClauseContext67 - abbrev
VariableContext68 - abbrev
SlotContext69 - theorem
card_I71 - theorem
card_J72 - theorem
card_ClauseContext73 - theorem
card_VariableContext75 - theorem
card_SlotContext77 - def
localConsistent80 - theorem
localConsistent_eq_true_iff84 - def
validJ91 - theorem
validJ_eq_true_iff96 - theorem
validJ_satisfies104 - theorem
validJ_consistent109 - theorem
validJ_localConsistent116 - def
canonicalSlot123 - theorem
canonicalSlot_name127 - def
pi139 - def
sampledVariables143 - theorem
sampledVariables_supported147 - theorem
sampled_eq_pi152 - theorem
sampled_answers_eq_of_visible_eq160 - def
honestJ168 - def
honestI172 - theorem
honestJ_valid176 - theorem
pi_honest188 - theorem
pi_honest_sampled196 - def
baseAccepts202 - theorem
baseAccepts_eq_true_iff208 - theorem
projection_implies_coordinate_accepts216 - theorem
baseAccepts_implies_sampled223 - theorem
projection_implies_sampled_accepts233