2-SAT Is Decided in Time Linear in the Word Times the Number of Variables
Lax117284.TwoSatRunningTime · concepts/Lax117284/TwoSatRunningTime.lean · lax-117284
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Theorem
There is one word RAM program and one constant such that, at every word length , given the bits of a binary word with , the program halts within instructions, where is the number of distinct variables of the formula encodes (and if it encodes none), with output if is in 2-SAT and otherwise. Since a formula with clauses has at most variables and at most , the bound is at most and at most .
Concept map
Evidence
Each proof establishes this claim relative to its assumptions.
Lean source view on GitHub
| 1 | import Lax117284.TwoSatCNF |
| 2 | import Lax808846.RamComputes |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: 2-SAT Is Decided in Time Linear in the Word Times the Number of Variables |
| 7 | type: theorem |
| 8 | --- |
| 9 | There is one word RAM program and one constant such that, at every word length , given |
| 10 | the bits of a binary word with , the program halts within |
| 11 | instructions, where is the number of distinct variables of the formula |
| 12 | encodes (and if it encodes none), with output if is in 2-SAT and otherwise. |
| 13 | Since a formula with clauses has at most variables and at most , the bound is at |
| 14 | most and at most . |
| 15 | |
| 16 | # Formalization Notes |
| 17 | |
| 18 | The word RAM of `lax-808846` reads words of natural numbers; a binary word is handed to it as |
| 19 | its list of zeros and ones, one bit an entry, so that the length of the input is the length of |
| 20 | the binary word and the machine has no advantage from packing bits into its words. The admissible |
| 21 | inputs are the lists of zeros and ones, all of them: a list that is not the encoding of a formula |
| 22 | is answered `0`, as it is not in the language. The output is `1` or `0`; the machine writes it |
| 23 | as a single entry. |
| 24 | |
| 25 | The bound is proved, not merely asserted, from the program: reading and decoding the word is |
| 26 | linear in its length; the implication graph has nodes for the bound on the indices, |
| 27 | which is at most the length of the word because an index is written in unary, and at most two |
| 28 | edges per clause; each of the at most searches costs a number of instructions linear in the |
| 29 | size of the graph, and skipping a variable that does not occur costs a constant. The strongly |
| 30 | connected components of Aspvall, Plass and Tarjan would bring the second factor down to a |
| 31 | constant; that algorithm is not formalized here. |
| 32 | |
| 33 | The fitting hypothesis is the "word is wide enough" condition written as an |
| 34 | inequality: every value the program manipulates is a count of nodes, edges, bits or steps, all |
| 35 | of them below . The program is quantified before the word length, so it is one |
| 36 | algorithm at every word length, not a family. |
| 37 | -/ |
| 38 | |
| 39 | namespace Lax117284.TwoSatRunningTime |
| 40 | |
| 41 | open Lax429075.CNF Lax429075.Encoding Lax434930.PolynomialTime Lax117284.TwoSatCNF |
| 42 | open Lax808846.Ram Lax808846.RamComputes |
| 43 | |
| 44 | /-- A binary word as a list of zeros and ones, the form in which the word RAM reads it. -/ |
| 45 | def natBits (w : Word) : List ℕ := w.map fun b => if b then 1 else 0 |
| 46 | |
| 47 | /-- A list of numbers as a binary word: which entries are nonzero. -/ |
| 48 | def bitsOf (x : List ℕ) : Word := x.map fun n => decide (n ≠ 0) |
| 49 | |
| 50 | /-- The number of distinct variables of the formula a list of bits encodes, and `0` if it |
| 51 | encodes none. -/ |
| 52 | def wordVarCount (x : List ℕ) : ℕ := ((decodeCNF (bitsOf x)).map varCount).getD 0 |
| 53 | |
| 54 | open scoped Classical in |
| 55 | /-- **2-SAT is decided within `c · (|x| + 1) · (v + 1)` instructions**, `v` the number of |
| 56 | distinct variables, by one word RAM program at every word length that fits the word. -/ |
| 57 | axiom decides : ∃ (prog : Program) (c : ℕ), ∀ w : ℕ, |
| 58 | ComputesInTime w prog |
| 59 | {x | (∀ v ∈ x, v ≤ 1) ∧ c * (x.length + 1) ≤ 2 ^ w} |
| 60 | (fun x => if bitsOf x ∈ TwoSAT then [1] else [0]) |
| 61 | (fun x => c * (x.length + 1) * (wordVarCount x + 1)) |
| 62 | |
| 63 | end Lax117284.TwoSatRunningTime |
| 64 |
Formalization Notes
The word RAM of reads words of natural numbers; a binary word is handed to it as its list of zeros and ones, one bit an entry, so that the length of the input is the length of the binary word and the machine has no advantage from packing bits into its words. The admissible inputs are the lists of zeros and ones, all of them: a list that is not the encoding of a formula is answered , as it is not in the language. The output is or ; the machine writes it as a single entry.
The bound is proved, not merely asserted, from the program: reading and decoding the word is linear in its length; the implication graph has nodes for the bound on the indices, which is at most the length of the word because an index is written in unary, and at most two edges per clause; each of the at most searches costs a number of instructions linear in the size of the graph, and skipping a variable that does not occur costs a constant. The strongly connected components of Aspvall, Plass and Tarjan would bring the second factor down to a constant; that algorithm is not formalized here.
The fitting hypothesis is the "word is wide enough" condition written as an inequality: every value the program manipulates is a count of nodes, edges, bits or steps, all of them below . The program is quantified before the word length, so it is one algorithm at every word length, not a family.
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments