Download lean/ComparatorChallenges/UniqueGamesTheorem.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 8.78 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/ComparatorChallenges/UniqueGamesTheorem.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/ComparatorChallenges/UniqueGamesTheorem.lean
-
curl -L -o UniqueGamesTheorem.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/ComparatorChallenges/UniqueGamesTheorem.lean
8.78 kB
| import Mathlib | |
| namespace OAI | |
| namespace UniqueGamesTheorem.Foundations.Target | |
| /-- Finite forward and inverse tables make totality and invertibility explicit. | |
| An eventual external encoding only needs to serialize the forward table. -/ | |
| structure PermutationTable (alphabet : Nat) where | |
| images : Vector (Fin alphabet) alphabet | |
| inverseImages : Vector (Fin alphabet) alphabet | |
| leftInverse : ∀ label : Fin alphabet, inverseImages[images[label]] = label | |
| rightInverse : ∀ label : Fin alphabet, images[inverseImages[label]] = label | |
| structure Constraint (vertices alphabet : Nat) where | |
| source : Fin vertices | |
| target : Fin vertices | |
| permutation : PermutationTable alphabet | |
| def Constraint.satisfied {n q : Nat} (constraint : Constraint n q) | |
| (labeling : Fin n → Fin q) : Bool := | |
| decide (constraint.permutation.images[labeling constraint.source] = labeling constraint.target) | |
| /-- Constraint occurrences are list entries, so repeated parallel edges retain | |
| their multiplicity. No weights are hidden in this representation. -/ | |
| structure Instance (alphabet : Nat) where | |
| vertices : Nat | |
| constraints : List (Constraint vertices alphabet) | |
| nonempty : constraints ≠ [] | |
| def countSatisfied {n q : Nat} (labeling : Fin n → Fin q) : | |
| List (Constraint n q) → Nat | |
| | [] => 0 | |
| | constraint :: rest => | |
| (if constraint.satisfied labeling then 1 else 0) + countSatisfied labeling rest | |
| end UniqueGamesTheorem.Foundations.Target | |
| namespace UniqueGamesTheorem.BinaryFormula | |
| open UniqueGamesTheorem.Foundations | |
| structure Literal where | |
| name : Nat | |
| positive : Bool | |
| deriving DecidableEq | |
| def Literal.eval (literal : Literal) (assignment : Nat → Bool) : Bool := | |
| if literal.positive then assignment literal.name else !(assignment literal.name) | |
| abbrev Clause := Vector Literal 3 | |
| def Clause.eval (clause : Clause) (assignment : Nat → Bool) : Bool := | |
| (clause[0].eval assignment || clause[1].eval assignment) || clause[2].eval assignment | |
| /-- An ordinary conjunction of three-slot clauses with sparse variable names. | |
| Repeated names and repeated literals are permitted in every clause. -/ | |
| structure Formula where | |
| clauses : List Clause | |
| def Formula.Satisfiable (F : Formula) : Prop := | |
| ∃ assignment : Nat → Bool, ∀ clause ∈ F.clauses, clause.eval assignment = true | |
| end UniqueGamesTheorem.BinaryFormula | |
| namespace UniqueGamesTheorem.BinaryEncoding | |
| open BinaryFormula | |
| def bitsValue : List Bool → Nat | |
| | [] => 0 | |
| | b :: bits => Nat.bit b (bitsValue bits) | |
| def parseFrame : List Bool → Option (List Bool × List Bool) | |
| | false :: rest => some ([], rest) | |
| | true :: b :: rest => do | |
| let (bits, trailing) ← parseFrame rest | |
| return (b :: bits, trailing) | |
| | _ => none | |
| /-- Equality with the canonical digits rejects alternate padded encodings. -/ | |
| def parseName (input : List Bool) : Option (Nat × List Bool) := do | |
| let (digits, rest) ← parseFrame input | |
| let name := bitsValue digits | |
| if digits = name.bits then some (name, rest) else none | |
| def parseLiteral : List Bool → Option (Literal × List Bool) | |
| | sign :: input => do | |
| let (name, rest) ← parseName input | |
| return (⟨name, sign⟩, rest) | |
| | [] => none | |
| def parseClause (input : List Bool) : Option (Clause × List Bool) := do | |
| let (a, input) ← parseLiteral input | |
| let (b, input) ← parseLiteral input | |
| let (c, rest) ← parseLiteral input | |
| return (#v[a, b, c], rest) | |
| /-- Fuel bounds the number of clause iterations, not the size of any name. -/ | |
| def parseClauses : Nat → List Bool → Option (List Clause × List Bool) | |
| | 0, _ => none | |
| | _ + 1, false :: rest => some ([], rest) | |
| | fuel + 1, true :: input => do | |
| let (clause, input) ← parseClause input | |
| let (clauses, rest) ← parseClauses fuel input | |
| return (clause :: clauses, rest) | |
| | _ + 1, [] => none | |
| def decodeFormula (input : List Bool) : Option Formula := do | |
| let (clauses, rest) ← parseClauses (input.length + 1) input | |
| if rest = [] then some ⟨clauses⟩ else none | |
| end UniqueGamesTheorem.BinaryEncoding | |
| namespace UniqueGamesTheorem.BinaryLanguage | |
| open UniqueGamesTheorem.Foundations | |
| def language (input : List Bool) : Prop := | |
| ∃ formula, BinaryEncoding.decodeFormula input = some formula ∧ formula.Satisfiable | |
| end UniqueGamesTheorem.BinaryLanguage | |
| namespace UniqueGamesTheorem.Integration.BinaryLinear | |
| abbrev F2 := ZMod 2 | |
| abbrev Vector (n : Nat) := Fin n → F2 | |
| end UniqueGamesTheorem.Integration.BinaryLinear | |
| namespace UniqueGamesTheorem.Integration.TranslationTarget | |
| open UniqueGamesTheorem.Foundations | |
| open Target | |
| def IsTranslationInstance {q s : Nat} (coordinates : Fin q ≃ BinaryLinear.Vector s) | |
| (g : Instance q) : Prop := | |
| ∀ constraint ∈ g.constraints, ∃ shift : BinaryLinear.Vector s, | |
| ∀ label : Fin q, | |
| coordinates (constraint.permutation.images[label]) = coordinates label + shift | |
| end UniqueGamesTheorem.Integration.TranslationTarget | |
| namespace UniqueGamesTheorem.Foundations.Complexity | |
| def encodeWord (n : Nat) : List Bool := List.replicate n true ++ [false] | |
| def encodeWords : List Nat → List Bool | |
| | [] => [] | |
| | n :: ns => encodeWord n ++ encodeWords ns | |
| end UniqueGamesTheorem.Foundations.Complexity | |
| namespace UniqueGamesTheorem.Foundations.Complexity | |
| open Target | |
| def tableWords {q : Nat} (table : PermutationTable q) : List Nat := | |
| table.images.toList.map Fin.val | |
| def constraintWords {n q : Nat} (constraint : Constraint n q) : List Nat := | |
| [constraint.source.val, constraint.target.val] ++ tableWords constraint.permutation | |
| def gameWords {q : Nat} (game : Instance q) : List Nat := | |
| [game.vertices, q, game.constraints.length] ++ game.constraints.flatMap constraintWords | |
| def gameBits {q : Nat} (game : Instance q) : List Bool := encodeWords (gameWords game) | |
| end UniqueGamesTheorem.Foundations.Complexity | |
| namespace UniqueGamesTheorem.Foundations.Complexity.MachineFiniteAlphabet | |
| open Turing | |
| /-- Every physical tape has a finite alphabet. Together with `M.kFin`, this | |
| also makes the disjoint union of all physical tape alphabets finite. -/ | |
| def FiniteAlphabet (M : FinTM2) : Prop := ∀ k, Finite (M.Γ k) | |
| end UniqueGamesTheorem.Foundations.Complexity.MachineFiniteAlphabet | |
| namespace UniqueGamesTheorem.Explicit.MachineOutputContract | |
| open UniqueGamesTheorem.Foundations | |
| open Target | |
| open scoped BigOperators | |
| /-- A canonical orientation from the false side to the true side. Injectivity | |
| is on occurrence indices, so two distinct list entries cannot be parallel even | |
| when their constraint tables are different. -/ | |
| structure SimpleBipartite {q : Nat} (game : Instance q) where | |
| side : Fin game.vertices → Bool | |
| sourceSide : ∀ i : Fin game.constraints.length, | |
| side game.constraints[i].source = false | |
| targetSide : ∀ i : Fin game.constraints.length, | |
| side game.constraints[i].target = true | |
| endpoints_injective : Function.Injective (fun i : Fin game.constraints.length => | |
| (game.constraints[i].source, game.constraints[i].target)) | |
| /-- Every parameter, coordinate identification, program, and polynomial is | |
| fixed before the input quantifier. The identity input encoding measures runtime | |
| in the original raw bit length, including sparse binary variable names. -/ | |
| structure BinaryGapReduction (ε δ : ℝ) where | |
| alphabet : Nat | |
| alphabetAtLeastTwo : 2 ≤ alphabet | |
| dimension : Nat | |
| dimensionPositive : 1 ≤ dimension | |
| coordinates : Fin alphabet ≃ Integration.BinaryLinear.Vector dimension | |
| construct : List Bool → Instance alphabet | |
| simpleBipartite : ∀ input, SimpleBipartite (construct input) | |
| translations : ∀ input, | |
| Integration.TranslationTarget.IsTranslationInstance coordinates (construct input) | |
| computation : Turing.TM2ComputableInPolyTime (id : List Bool → List Bool) | |
| Complexity.gameBits construct | |
| finiteAlphabet : Complexity.MachineFiniteAlphabet.FiniteAlphabet computation.tm | |
| completeness : ∀ input, BinaryLanguage.language input → | |
| ∃ labeling, 1 - ε ≤ | |
| (countSatisfied labeling (construct input).constraints : ℝ) / | |
| (construct input).constraints.length | |
| soundness : ∀ input, ¬BinaryLanguage.language input → | |
| ∀ labeling, (countSatisfied labeling (construct input).constraints : ℝ) / | |
| (construct input).constraints.length ≤ δ | |
| end UniqueGamesTheorem.Explicit.MachineOutputContract | |
| namespace UniqueGamesTheorem | |
| /-- For every fixed pair of errors in `(0, 1/2)`, binary 3SAT reduces in | |
| polynomial time to translation Unique Games with completeness at least `1 - ε` | |
| and soundness at most `δ`. The alphabet and machine depend only on the errors. -/ | |
| theorem theorem11 (ε δ : ℝ) | |
| (hε : 0 < ε) (hεhalf : ε < 1 / 2) | |
| (hδ : 0 < δ) (hδhalf : δ < 1 / 2) : | |
| Nonempty (Explicit.MachineOutputContract.BinaryGapReduction ε δ) := by | |
| sorry | |
| end UniqueGamesTheorem | |
| end OAI | |