File size: 8,782 Bytes
cfa2fd2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | 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
|