Download data/lean/OAI/Computability/PerfectCompleteness/Model.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.12 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Model.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/PerfectCompleteness/Model.lean
-
curl -L -o Model.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Model.lean
5.12 kB
| import Mathlib | |
| import OAI.Computability.UniqueGames.Model | |
| namespace OAI | |
| namespace PerfectCompleteness.BinaryFormula | |
| 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 | |
| structure Formula where | |
| clauses : List Clause | |
| def Formula.Satisfiable (F : Formula) : Prop := | |
| β assignment : Nat β Bool, β clause β F.clauses, clause.eval assignment = true | |
| end PerfectCompleteness.BinaryFormula | |
| namespace PerfectCompleteness.BinaryEncoding | |
| open PerfectCompleteness.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 | |
| 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) | |
| 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 PerfectCompleteness.BinaryEncoding | |
| namespace PerfectCompleteness.BinaryLanguage | |
| def language (input : List Bool) : Prop := | |
| β formula, BinaryEncoding.decodeFormula input = some formula β§ formula.Satisfiable | |
| end PerfectCompleteness.BinaryLanguage | |
| namespace PerfectCompleteness | |
| structure ProjectionTable (q : Nat) where | |
| images : Vector (Fin q) (2 * q) | |
| exactlyTwo : β b : Fin q, | |
| ((List.finRange (2 * q)).filter (fun a => decide (images[a] = b))).length = 2 | |
| structure Edge (leftVertices rightVertices q : Nat) where | |
| left : Fin leftVertices | |
| right : Fin rightVertices | |
| projection : ProjectionTable q | |
| structure Instance (q : Nat) where | |
| leftVertices : Nat | |
| rightVertices : Nat | |
| edges : List (Edge leftVertices rightVertices q) | |
| nonempty : edges β [] | |
| abbrev Labeling {q : Nat} (G : Instance q) := | |
| (Fin G.leftVertices β Fin (2 * q)) Γ (Fin G.rightVertices β Fin q) | |
| def Edge.satisfied {l r q : Nat} (e : Edge l r q) | |
| (a : Fin l β Fin (2 * q)) (b : Fin r β Fin q) : Bool := | |
| decide (e.projection.images[a e.left] = b e.right) | |
| def countSatisfied {l r q : Nat} (a : Fin l β Fin (2 * q)) | |
| (b : Fin r β Fin q) : List (Edge l r q) β Nat | |
| | [] => 0 | |
| | e :: es => (if e.satisfied a b then 1 else 0) + countSatisfied a b es | |
| end PerfectCompleteness | |
| namespace PerfectCompleteness.Instance | |
| def maxSatisfied {q : Nat} (G : Instance q) : Nat := | |
| Finset.univ.sup (fun s : Labeling G => countSatisfied s.1 s.2 G.edges) | |
| noncomputable def value {q : Nat} (G : Instance q) : β := | |
| (G.maxSatisfied : β) / G.edges.length | |
| end PerfectCompleteness.Instance | |
| namespace PerfectCompleteness.Encoding | |
| open UniqueGamesTheorem.Foundations.Complexity | |
| def tableWords {q : Nat} (table : ProjectionTable q) : List Nat := | |
| table.images.toList.map Fin.val | |
| def edgeWords {l r q : Nat} (edge : Edge l r q) : List Nat := | |
| [edge.left.val, edge.right.val] ++ tableWords edge.projection | |
| def gameWords {q : Nat} (game : Instance q) : List Nat := | |
| [game.leftVertices, game.rightVertices, q, game.edges.length] ++ | |
| game.edges.flatMap edgeWords | |
| def gameBits {q : Nat} (game : Instance q) : List Bool := | |
| encodeWords (gameWords game) | |
| end PerfectCompleteness.Encoding | |
| namespace PerfectCompleteness | |
| open Turing UniqueGamesTheorem.Foundations.Complexity | |
| structure BinaryGapReduction (Ξ΄ : β) where | |
| alphabet : Nat | |
| alphabet_ge_two : 2 β€ alphabet | |
| construct : List Bool β Instance alphabet | |
| computation : TM2ComputableInPolyTime (id : List Bool β List Bool) | |
| Encoding.gameBits construct | |
| finiteAlphabet : MachineFiniteAlphabet.FiniteAlphabet computation.tm | |
| completeness : β input, BinaryLanguage.language input β (construct input).value = 1 | |
| soundness : β input, Β¬BinaryLanguage.language input β (construct input).value β€ (Ξ΄ : β) | |
| end PerfectCompleteness | |
| end OAI | |