Recognition languages, explicit time bounds and chart encodings
Definitionrsg_paper_complexityComputational vocabulary for the recognition problems, extending the published module rsg_recognition_core (graph words, the RSG and -SAT languages, polynomial time, and many-one reductions).
- Languages. VIG and EIG recognition are the sets of graph words whose graph is a vertex (resp. edge) involutive graph.
- Promise hardness. A language is -hard on a class of words when every language reduces to by a polynomial-time many-one reduction all of whose outputs lie in .
- Explicit time. A machine runs within on when it halts with the encoded output after at most steps. A language is decided within (on a class ) when one machine decides it correctly and within steps on every word (of ).
- Formula size. For a -CNF formula , is the number of distinct variables plus the number of clauses; a word that encodes no formula is assigned its length. -SAT is decidable in time when for some constant it is decided within
steps. 5. Chart encodings. A chart on is written as and in unary followed by the coordinates of each vertex; a list of permutations as its length in unary followed by the permutation matrices; a chart instance as the framed graph word followed by the chart.
Formalization Note The factor accounts for reading the input, since variable indices are unbounded in the binary formula encoding.
import Definitions.Def_rsg_paper_structure
import Mathlib.Analysis.SpecialFunctions.Pow.Real
set_option autoImplicit false
namespace RSGPaper
open RSGRecognition
/-! ### Languages of the paper -/
/-- Encodings (unary order, row-major adjacency matrix) of vertex involutive graphs. -/
def vigLanguage (w : Word) : Prop :=
∃ (n : ℕ) (G : SimpleGraph (Fin n)) (adj : DecidableRel G.Adj),
w = graphWord G adj ∧ IsVIG G
/-- Encodings of edge involutive graphs. -/
def eigLanguage (w : Word) : Prop :=
∃ (n : ℕ) (G : SimpleGraph (Fin n)) (adj : DecidableRel G.Adj),
w = graphWord G adj ∧ IsEIG G
/-- NP-hardness on a promise class `P`: every NP language reduces to `M` by a polynomial-time
many-one reduction whose every output satisfies `P`. -/
def NPHardOn (P : Word → Prop) (M : Language) : Prop :=
∀ L : Language, InNP L → ∃ reduce : Word → Word,
PolyTime wordEncoding.encode reduce ∧ (∀ w, P (reduce w)) ∧ ∀ w, L w ↔ M (reduce w)
/-! ### Explicit time bounds -/
/-- The bundled multi-stack machine `M` (input and output alphabets identified with `Bool`),
started on the word `w`, halts with the encoding `out (f w)` of the value `f w` after at most
`T` steps. -/
def RunsWithin {β : Type} (out : β → Word) (M : Turing.TM2ComputableAux Bool Bool)
(f : Word → β) (w : Word) (T : ℝ) : Prop :=
∃ m : ℕ, (m : ℝ) ≤ T ∧
Nonempty (Turing.TM2OutputsInTime M.tm (w.map M.inputAlphabet.invFun)
(some ((out (f w)).map M.outputAlphabet.invFun)) m)
/-- `L` is decided on the inputs satisfying `P` by one deterministic finite multi-stack machine
that halts on each such input `w` within `T w` steps. -/
def DecidesOnWithin (P : Word → Prop) (L : Language) (T : Word → ℝ) : Prop :=
∃ (M : Turing.TM2ComputableAux Bool Bool) (dec : Word → Bool),
∀ w, P w → (dec w = true ↔ L w) ∧ RunsWithin Computability.encodeBool M dec w (T w)
/-- `L` is decided on all words within `T w` steps. -/
def DecidesWithin (L : Language) (T : Word → ℝ) : Prop :=
DecidesOnWithin (fun _ => True) L T
/-! ### The size of a 3-CNF formula -/
/-- The variables occurring in a formula, without repetition. -/
def formulaVars (φ : Formula) : List ℕ :=
(φ.flatMap fun c => (List.ofFn c).map Prod.fst).dedup
/-- `s` = number of distinct variables plus number of clauses. -/
def formulaSize (φ : Formula) : ℕ := (formulaVars φ).length + φ.length
open Classical in
/-- The size of an input word: `s` of the formula it encodes, and the word length for words
that encode no formula. -/
noncomputable def threeSATSize (w : Word) : ℕ :=
if h : ∃ φ : Formula, w = formulaWord φ then formulaSize h.choose else w.length
/-- The time bound `2^{C·(s+1)^{e}} · (|w|+1)^C` for an exponent `e`. -/
noncomputable def satTimeBound (C : ℕ) (e : ℝ) (w : Word) : ℝ :=
(2 : ℝ) ^ ((C : ℝ) * ((threeSATSize w : ℝ) + 1) ^ e) * ((w.length : ℝ) + 1) ^ C
/-- 3-SAT is decidable in deterministic time `2^{O(s^{e})} · poly(|w|)`. -/
def ThreeSATInTimeExp (e : ℝ) : Prop :=
∃ C : ℕ, DecidesWithin threeSAT (satTimeBound C e)
/-! ### Chart and generator encodings -/
/-- The bits of a binary vector. -/
def bitsOf {m : ℕ} (x : Fin m → ZMod 2) : Word :=
List.ofFn fun i => decide (x i = 1)
/-- A chart on `Fin n`: `d` and `r` in unary, then the chart coordinates
(position bits, then label bits) of the vertices `0, …, n-1` in order. -/
def chartWord {n : ℕ} (ch : BinaryChart (Fin n)) : Word :=
List.replicate ch.d true ++ [false] ++ List.replicate ch.r true ++ [false] ++
(List.ofFn fun i : Fin n => bitsOf (ch.coord i).1 ++ bitsOf (ch.coord i).2).flatten
/-- A list of permutations of `Fin n`: the number of permutations in unary, then each
permutation matrix in row-major order (entry `(i, j)` is `true` iff `g i = j`). -/
def permsWord {n : ℕ} (gs : List (Equiv.Perm (Fin n))) : Word :=
List.replicate gs.length true ++ [false] ++
(gs.map fun g => (List.ofFn fun i : Fin n => List.ofFn fun j : Fin n =>
decide (g i = j)).flatten).flatten
/-- An instance of recognition in a supplied chart: the framed graph word, then the chart. -/
def chartInstanceWord {n : ℕ} (G : SimpleGraph (Fin n)) (adj : DecidableRel G.Adj)
(ch : BinaryChart (Fin n)) : Word :=
frame (graphWord G adj) ++ chartWord ch
end RSGPaper
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Background notions used throughout (from the imported modules). A word is a finite list of bits (booleans), written with true and false; is its length and is ones. A language is a predicate on words.
- .
- For a simple graph on (with some decision procedure for adjacency; the result does not depend on which), followed by the adjacency bits in row-major order, bit being iff .
- Polynomial time for a function from words to values with an output encoding means: there exists a (Mathlib) deterministic finite multi-stack Turing machine computing , reading the input word bit by bit and writing the encoded output, within a polynomial number of steps in the input length. For -valued functions the output encoding is the standard encoding of a boolean; for word-valued functions it is the word itself.
- means: there exist a polynomial with natural-number coefficients and a polynomial-time : words Bool such that for every , iff some certificate with has .
IsVIG: every vertex has an automorphism of with , , and for every neighbour of .IsEIG: every edge has an automorphism with , , , .- A 3-CNF formula is a finite list of clauses, each clause an ordered triple of literals, each literal a pair of a variable number and a required value . is satisfiable iff some assignment makes, in every clause, at least one literal satisfy . The word concatenates, clause by clause and literal by literal, the bit followed by , where is the little-endian binary expansion of (empty for ). holds iff for some satisfiable . The empty formula is encoded by the empty word and is satisfiable.
- A binary chart on is a pair with a bijection .
vigLanguage. is in the language iff there are and a simple graph on with and satisfying IsVIG. Edge cases: (word ) is in the language vacuously; every -vertex graph is excluded (no nonidentity permutation exists).
eigLanguage. Same, with IsEIG in place of IsVIG. Every edgeless graph (including ) is in the language vacuously.
NPHardOn. For a promise predicate on words and a language : for every language there is a polynomial-time function from words to words such that holds for every word , and for every .
RunsWithin. For an output encoding , a bundled finite multi-stack machine (a machine together with bijections identifying its input and output stack alphabets with ), a function , a word and a real bound : there is a natural number such that , started on (translated into its input alphabet), halts with output (translated into its output alphabet) within steps, in the sense of Mathlib's TM2OutputsInTime. If this is impossible.
DecidesOnWithin. For a predicate on words, a language and : words : there exist one machine and one function : words Bool such that for every word with : , and on input outputs the boolean encoding of within steps (as in RunsWithin). Nothing is required on words outside .
DecidesWithin. DecidesOnWithin with true for all words: a single machine correctly decides on every word within steps.
formulaVars. The list of variable numbers occurring in any literal of , with duplicates removed.
formulaSize. , where clauses are counted as list entries (repeated clauses count repeatedly).
threeSATSize. For a word : if there exists a formula with , then for one such formula selected by the axiom of choice (unspecified if several formulas encode ); otherwise . The empty word gets .
satTimeBound. For , and a word , with ,
a real number (real powers and , natural power in the second factor).
ThreeSATInTimeExp. For a real exponent (no sign or size restriction): there exists such that DecidesWithin holds for with bound , i.e. one machine decides, on every word (including words that encode no formula, whose is then ), whether encodes a satisfiable formula, within steps. For the first factor is at most .
bitsOf. For , the word with bit equal to iff .
chartWord. For a chart on , the word
listing, for each vertex in order, its position bits then its label bits. The number itself is not written.
permsWord. For a list of permutations of , the word followed, for each in order, by its permutation matrix in row-major order (bit is iff ). The number is not written.
chartInstanceWord. For a graph on and a chart on the same vertex set, the word , i.e. with , followed by the chart word. No relation between and the chart is required.