Download lean/OAI/Computability/VertexCover/Encoding/FormulaEncoding.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.85 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/VertexCover/Encoding/FormulaEncoding.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Computability/VertexCover/Encoding/FormulaEncoding.lean
-
curl -L -o FormulaEncoding.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/VertexCover/Encoding/FormulaEncoding.lean
3.85 kB
| import Mathlib | |
| import OAI.Computability.VertexCover.Encoding.Serialization | |
| namespace OAI | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| section | |
| namespace UniqueGames.Foundations.Complexity | |
| open Target | |
| def parseLiteral («variables» : Nat) : List Nat → Option (Literal «variables» × List Nat) | |
| | index :: sign :: rest => | |
| if bounded : index < «variables» then | |
| if sign = 0 then some (⟨⟨index, bounded⟩, false⟩, rest) | |
| else if sign = 1 then some (⟨⟨index, bounded⟩, true⟩, rest) | |
| else none | |
| else none | |
| | _ => none | |
| @[simp] theorem parseLiteral_encoded {n : Nat} (literal : Literal n) (rest : List Nat) : | |
| parseLiteral n (literalWords literal ++ rest) = some (literal, rest) := by | |
| cases literal with | |
| | mk index positive => | |
| cases positive <;> simp [literalWords, parseLiteral, index.isLt] | |
| def parseClause («variables» : Nat) (words : List Nat) : Option (Clause «variables» × List Nat) := do | |
| let (a, words) ← parseLiteral «variables» words | |
| let (b, words) ← parseLiteral «variables» words | |
| let («c», words) ← parseLiteral «variables» words | |
| return (⟨#[a, b, «c»], rfl⟩, words) | |
| theorem clause_three_entries {n : Nat} (clause : Clause n) : | |
| (⟨#[clause[0], clause[1], clause[2]], rfl⟩ : Clause n) = clause := by | |
| apply Vector.ext | |
| intro i hi | |
| have cases_i : i = 0 ∨ i = 1 ∨ i = 2 := by omega | |
| rcases cases_i with rfl | rfl | rfl <;> rfl | |
| @[simp] theorem parseClause_encoded {n : Nat} (clause : Clause n) (rest : List Nat) : | |
| parseClause n (clauseWords clause ++ rest) = some (clause, rest) := by | |
| simp [clauseWords, List.append_assoc, parseClause, parseLiteral_encoded, | |
| clause_three_entries] | |
| def parseClauses («variables» : Nat) : Nat → List Nat → Option (List (Clause «variables») × List Nat) | |
| | 0, words => some ([], words) | |
| | count + 1, words => do | |
| let (clause, words) ← parseClause «variables» words | |
| let (clauses, words) ← parseClauses «variables» count words | |
| return (clause :: clauses, words) | |
| @[simp] theorem parseClauses_encoded {n : Nat} (clauses : List (Clause n)) (rest : List Nat) : | |
| parseClauses n clauses.length (clauses.flatMap clauseWords ++ rest) = some (clauses, rest) := by | |
| induction clauses with | |
| | nil => rfl | |
| | cons clause clauses ih => | |
| simp [List.append_assoc, parseClauses, parseClause_encoded, ih] | |
| def decodeFormulaWords : List Nat → Option Formula | |
| | «variables» :: count :: words => do | |
| let (clauses, trailing) ← parseClauses «variables» count words | |
| if trailing = [] then some ⟨«variables», clauses⟩ else none | |
| | _ => none | |
| @[simp] theorem decodeFormulaWords_encoded (formula : Formula) : | |
| decodeFormulaWords (formulaWords formula) = some formula := by | |
| cases formula with | |
| | mk «variables» clauses => | |
| have parsed := parseClauses_encoded clauses [] | |
| simp only [List.append_nil] at parsed | |
| simp [decodeFormulaWords, formulaWords, parsed] | |
| def decodeFormulaBits (bits : List Bool) : Option Formula := | |
| decodeWords bits >>= decodeFormulaWords | |
| @[simp] theorem decodeFormulaBits_encoded (formula : Formula) : | |
| decodeFormulaBits (formulaBits formula) = some formula := by | |
| simp [decodeFormulaBits, formulaBits] | |
| theorem formulaBits_injective {first second : Formula} | |
| (same : formulaBits first = formulaBits second) : first = second := by | |
| have parsed := congrArg decodeFormulaBits same | |
| simpa only [decodeFormulaBits_encoded, Option.some.injEq] using parsed | |
| end UniqueGames.Foundations.Complexity | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end OAI | |