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