introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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