Download data/lean/OAI/Computability/UniqueGames/Model.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.29 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/UniqueGames/Model.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/UniqueGames/Model.lean
-
curl -L -o Model.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/UniqueGames/Model.lean
8.29 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 | |
| end OAI | |