import Mathlib namespace OAI namespace LargeIndependentSets structure Literal where name : ℕ positive : Bool deriving DecidableEq structure Formula where clauses : List (List Literal) width : ∀ C ∈ clauses, C.length ≤ 3 def Formula.Satisfiable (φ : Formula) : Prop := ∃ assignment : ℕ → Bool, ∀ C ∈ φ.clauses, ∃ l ∈ C, assignment l.name = l.positive /-- Binary framing: `true,b` for a payload bit and `false` as terminator. -/ def frame : List Bool → List Bool | [] => [false] | b :: bs => true :: b :: frame bs def nameBits (n : ℕ) : List Bool := frame n.bits def literalBits (l : Literal) : List Bool := l.positive :: nameBits l.name def clauseBits (C : List Literal) : List Bool := nameBits C.length ++ C.flatMap literalBits def formulaBits (φ : Formula) : List Bool := nameBits φ.clauses.length ++ φ.clauses.flatMap clauseBits /-- A nonempty, finite, simple, undirected, unweighted graph. -/ structure Graph where vertices : ℕ nonempty : 0 < vertices adj : Fin vertices → Fin vertices → Bool symm : ∀ u v, adj u v = adj v u loopless : ∀ u, adj u u = false def Graph.Independent (G : Graph) (S : Finset (Fin G.vertices)) : Prop := ∀ u ∈ S, ∀ v ∈ S, u ≠ v → G.adj u v = false instance (G : Graph) (S : Finset (Fin G.vertices)) : Decidable (G.Independent S) := inferInstanceAs (Decidable (∀ u ∈ S, ∀ v ∈ S, u ≠ v → G.adj u v = false)) def Graph.independenceNumber (G : Graph) : ℕ := ((Finset.univ : Finset (Fin G.vertices)).powerset.filter G.Independent).sup Finset.card def Graph.ThreeColorable (G : Graph) : Prop := ∃ color : Fin G.vertices → Fin 3, ∀ u v, G.adj u v = true → color u ≠ color v /-- Full explicit adjacency matrix, row-major, with binary vertex count. -/ def graphBits (G : Graph) : List Bool := nameBits G.vertices ++ (List.finRange G.vertices).flatMap (fun u => (List.finRange G.vertices).map (G.adj u)) open scoped Classical noncomputable section /-- Polynomial-time graph reduction with a real independence-ratio threshold. -/ structure RealGraphReduction (δ : ℝ) where reduce : List Bool → Graph computation : Turing.TM2ComputableInPolyTime (id : List Bool → List Bool) graphBits reduce finiteAlphabets : ∀ k : computation.tm.K, Finite (computation.tm.Γ k) outputBound : Polynomial ℕ outputSize : ∀ b, (graphBits (reduce b)).length ≤ outputBound.eval b.length completeness : ∀ φ : Formula, φ.Satisfiable → (reduce (formulaBits φ)).ThreeColorable soundness : ∀ φ : Formula, ¬φ.Satisfiable → ((reduce (formulaBits φ)).independenceNumber : ℝ) < δ * (reduce (formulaBits φ)).vertices end end LargeIndependentSets end OAI