math / data /lean /OAI /Computability /MaxCut /Model.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.44 kB
import Mathlib
namespace OAI
namespace MaxCutGames.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
/-- 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 MaxCutGames.BinaryFormula
namespace MaxCutGames.BinaryEncoding
open BinaryFormula
def bitsValue : List Bool β†’ Nat
| [] => 0
| b :: bits => Nat.bit b (bitsValue bits)
/-- Prefix-free framing on the two-symbol input alphabet. -/
def frame : List Bool β†’ List Bool
| [] => [false]
| b :: bits => true :: b :: frame 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 nameBits (name : Nat) : List Bool := frame name.bits
/-- 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 MaxCutGames.BinaryEncoding
namespace OptimalMaxCut
open scoped BigOperators
/-- The exact Goemans–Williamson ratio, as an infimum over -1 ≀ ρ < 1. -/
noncomputable def alphaGW : ℝ :=
sInf ((fun ρ : ℝ => 2 * Real.arccos ρ / (Real.pi * (1 - ρ))) ''
Set.Ico (-1 : ℝ) 1)
/-- The ordinary binary 3SAT language, including rejection of malformed words. -/
def binary3SAT (input : List Bool) : Prop :=
βˆƒ formula, MaxCutGames.BinaryEncoding.decodeFormula input = some formula ∧
formula.Satisfiable
/-- A finite simple unweighted graph with its full Boolean adjacency table. -/
structure Graph where
vertices : β„•
adj : Fin vertices β†’ Fin vertices β†’ Bool
symmetric : βˆ€ u v, adj u v = adj v u
loopless : βˆ€ u, adj u u = false
/-- Each unordered distinct edge crossing the cut is counted exactly once. -/
def Graph.cutSize (G : Graph) (cut : Fin G.vertices β†’ Bool) : β„• :=
βˆ‘ u : Fin G.vertices, βˆ‘ v : Fin G.vertices,
if u < v ∧ G.adj u v = true ∧ cut u β‰  cut v then 1 else 0
/-- The maximum over all Boolean cuts of the finite vertex set. -/
def Graph.maxCut (G : Graph) : β„• :=
(Finset.univ.image G.cutSize).sup id
/-- The positive integer scale Q is part of the output. It need not equal the
number of graph edges. -/
structure ScaledGraph where
graph : Graph
scale : β„•
scale_pos : 0 < scale
/-- Canonical delimited binary vertex count and scale, followed by the full
adjacency table in lexicographic order. -/
def ScaledGraph.bits (G : ScaledGraph) : List Bool :=
MaxCutGames.BinaryEncoding.nameBits G.graph.vertices ++
MaxCutGames.BinaryEncoding.nameBits G.scale ++
(List.finRange G.graph.vertices).flatMap (fun u =>
(List.finRange G.graph.vertices).map (fun v => G.graph.adj u v))
/-- The rational gap bounds and the finite machine are fixed before the input.
The bounds compare the maximum cut divided by the positive output scale. -/
structure GapReduction (Ξ± : ℝ) where
yesBound : β„š
noBound : β„š
yes_pos : 0 < yesBound
no_nonneg : 0 ≀ noBound
gap : (noBound : ℝ) < Ξ± * (yesBound : ℝ)
construct : List Bool β†’ ScaledGraph
computation : Turing.TM2ComputableInPolyTime (id : List Bool β†’ List Bool)
ScaledGraph.bits construct
finiteAlphabet : βˆ€ k, Finite (computation.tm.Ξ“ k)
completeness : βˆ€ input, binary3SAT input β†’
(yesBound : ℝ) ≀ ((construct input).graph.maxCut : ℝ) / (construct input).scale
soundness : βˆ€ input, Β¬ binary3SAT input β†’
((construct input).graph.maxCut : ℝ) / (construct input).scale ≀ (noBound : ℝ)
def MainStatement : Prop :=
βˆ€ Ξ± : ℝ, alphaGW < Ξ± β†’ Ξ± ≀ 1 β†’ Nonempty (GapReduction Ξ±)
end OptimalMaxCut
end OAI