Stack alphabet of the SAT verifier to A clause has at most as many tokens as code bits
InductiveStack alphabet of the SAT verifier#✓fully proved
The symbols of the token and table stacks are a name bit \(b\) for each boolean \(b\), a polarity marker for each polarity \(p\), a clause end marker, a value marker for each boolean \(b\), and a dead marker. Equality of symbols is decidable.
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
Used by 410
TM2 SAT verifier · Clause token length bound for the SAT verifier (moved alias) · Finiteness of the SAT verifier alphabet (moved alias) · Token length bound for the SAT verifier (moved alias) · Literal-marker test · Quiescent states of the 3-COLOR emitter · The 3-COLOR emitter machine · Unit symbol of a counter · Reading unary units · Stack alphabets of the 3-coloring emitter · Running a sequence of copy sites of the 3-COLOR emitter · The 3-COLOR emitter clears its OR-output counter · Name comparison in the 3-COLOR emitter · Encoding of an earlier occurrence on stack \(D\) · Moving \(U\) onto \(E\) · Copying a counter through \(W\) · Adding the vertex counter to the OR output · Walk tokens · Moving an earlier name from \(D\) to \(E\) · Moving an earlier literal vertex from \(D\) to \(U\) · Name of a variable · Moving the current name from \(T\) to \(A\) · Running a copy site of the 3-COLOR emitter · Skipping an earlier literal vertex · Stacks of a quiescent state · 3-COLOR emitter: moving the walk side back · One more token preserves the 3-COLOR emitter's size invariant · The 3-COLOR emitter processes one clause · The emitter state of a construction state · One step of the walk over earlier occurrences · The emitter on a list of clauses · Size invariant of the 3-coloring emitter · The emitter processes the remaining literals of a clause · The size invariant survives a new literal occurrence · Emitting one literal occurrence · Recording the current occurrence · Walking the earlier occurrences · Correctness and step bound of the 3-COLOR emitter · Edge-loop start of the 3-COLOR verifier · Load step of the 3-COLOR verifier · Moving one color code in the 3-COLOR verifier · The 3-COLOR verifier machine · Unary reader of the 3-COLOR verifier · One step of the 3-COLOR verifier · Statements of the 3-COLOR verifier · Interleaved updates of two stacks of the 3-COLOR verifier · One step of the joint walk of the 3-COLOR verifier · One step of the walk towards the farther endpoint · Restoring the color stack in the 3-COLOR verifier · The 3-COLOR verifier as a host component · Correctness and running time of the edge loop · Run of the load phase of the 3-COLOR verifier · The unary reader rejects an unterminated number · The unary reader on a terminated number · Correctness and time bound of the 3-coloring verifier machine · Moving one color code from the color stack · The color-moving block rejects on an empty color stack · Joint-walk step with both counters nonempty · Joint-walk step when the second endpoint counter runs out first · Joint-walk step when the first endpoint counter runs out first · Joint-walk step with both counters exhausted · Walk-on step with a unit on the counter · Walk-on step with the counter exhausted · The joint walk of the 3-COLOR verifier decides one edge · The walk towards the farther endpoint decides the edge · 3-COLOR is in NP · The 3-COLOR emitter · The SAT-to-3-COLOR reduction is polynomial-time · Run of the load phase · Load step of the CLIQUE verifier · Program of the clique verifier · The clique verifier's unary reader · Reading an unterminated unary number rejects · The clique verifier's unary reader succeeds · One row of the clique verifier's walk · All rows of the clique verifier's walk · The verifier machine for clique, independent set and vertex cover · One step of a clique-verifier program to a known label · Statements of the clique verifier · Walking the pairs of one row of the clique verifier · Walk step of the clique verifier · Rest of a walk step of the clique verifier · Polarity-first tokens of a literal · Tokens moved by the walk · Tokens of an item on the walked stack · Moving a walked name from \(D\) to \(E\) · Name bits of a variable in the CLIQUE emitter · CLIQUE emitter: reading a variable name · The CLIQUE emitter machine · Configuration stacks of the CLIQUE emitter · CLIQUE emitter: recognizing a standard state · Stack alphabets of the CLIQUE emitter · Clique emitter: moving the walk side back · Clique emitter: one clause · Clique emitter: comparing two names · Clique emitter: the instance prefix · Emitter run over a formula's clauses · Test for the input bit true · Test for the moved bit true · Emitter run over one literal occurrence · Emitter run over a clause's literals · CLIQUE emitter: putting the current occurrence on the walked stack · The CLIQUE emitter computes Karp's instance in cubic time · Counter unit symbol of the clique reduction machine · Stack alphabets of the clique reduction machine · Walk over the occurrence stack in the CLIQUE emitter · The CLIQUE emitter · CLIQUE ≤ INDEPENDENT-SET is polynomial-time · INDEPENDENT-SET ≤ VERTEX-COVER is polynomial-time · SAT ≤ CLIQUE is polynomial-time · The CLIQUE-to-INDEPENDENT-SET and INDEPENDENT-SET-to-VERTEX-COVER map as a host component · Moving the pair bits onto stack \(Y\) · Output phase of the KG-map machine · Output loop for the pair bits of the KG-map machine · The KG-map machine · Unterminated first unary number in the KG-map machine · Reading the first unary number in the KG-map machine · Unterminated second unary number in the KG-map machine · Reading the second unary number in the KG-map machine · Correctness and running time of the KG-map machine · Failed subtraction in the KG-map machine · Subtraction loop of the clique reduction machine · Number output of the clique reduction machine · The CLIQUE, INDEPENDENT-SET and VERTEX-COVER verifier as a host component · NP membership from the CLIQUE, INDEPENDENT-SET and VERTEX-COVER verifier · Raw-input SUBSET-SUM to PARTITION machine as a host component · SUBSET-SUM to PARTITION padding machine as a host component · Canonical PARTITION membership transducer as a host component · Padding machine embeds the summation machine · Membership transducer embeds the summation machine · SUBSET-SUM to PARTITION map is polynomial-time · Program of the raw-input SUBSET-SUM to PARTITION machine · Program of the SUBSET-SUM to PARTITION padding machine · Program of the canonical PARTITION membership transducer · Quadratic run of the raw-input SUBSET-SUM to PARTITION machine · Quadratic run of the padding machine on canonical instances · Raw-input PARTITION membership machine runs in quadratic time · Canonical PARTITION membership transducer runs in quadratic time · Summation-machine stack embedding in the padding machine · Summation-machine stack embedding in the membership transducer · Stack alphabets of the canonical PARTITION membership transducer · Test for the input bit true (SUBSET-SUM reduction machine) · Test for the value symbol true (SUBSET-SUM reduction machine) · Counter unit of the subset-sum emitter · Stack alphabets of the subset-sum emitter · Reading a pair bit or vertex mark · Edge-number phase (SUBSET-SUM reduction machine) · One halving step of the binary conversion (SUBSET-SUM reduction machine) · Testing a popped input bit · Testing a popped input bit · Testing a popped input bit · Subset-sum emitter: moving the pair bits · Subset-sum emitter: one row of the pair walk · The subset-sum emitter machine · Subset-sum emitter: unterminated unary prefix at rdK · Subset-sum emitter: reading the unary k · Subset-sum emitter: unterminated unary prefix at rdN · Subset-sum emitter: reading the unary n · Subset-sum emitter: one vertex number · Subset-sum emitter: moving unmarked vertices back to L · Run of the mark-return loop of the subset-sum emitter · Run of the pair-counting loop of the subset-sum emitter · Run of the vertex-number phase of the subset-sum emitter · Run of the subset-sum emitter's pair walk · Binary conversion (SUBSET-SUM reduction machine) · Run of the VERTEX-COVER to SUBSET-SUM machine · Statements of the SUBSET-SUM verifier · Run of the target-bit loop of the subset-sum emitter · Run of the target-output phase of the subset-sum emitter · The verifier rejects an unterminated chosen block · The verifier rejects a chosen block that ends in false · Adding a canonical chosen block · Adding one payload bit to the sum · Moving the new sum back · Comparing the sum with the target · Carry phase of the SUBSET-SUM verifier · Carry step of the SUBSET-SUM verifier · Moving the final sum for the comparison · Starting the next number · The SUBSET-SUM verifier program · Reading one pair of a block · Rejection by the SUBSET-SUM verifier within a step bound · Rejecting in one step · The verifier rejects an unterminated skipped block · Skipping a number block · Stack contents of the SUBSET-SUM verifier · The verifier rejects an unterminated target block · Reading the target block · The VERTEX-COVER to SUBSET-SUM machine as a host component · Identity embedding of the verifier stacks · The VERTEX-COVER to SUBSET-SUM reduction is polynomial-time · The summing loop of the SUBSET-SUM verifier · Binary addition program built on the SUBSET-SUM machine · The SUBSET-SUM verifier machine · Binary addition of framed numbers in quadratic time · The SUBSET-SUM verifier machine as a host component · SUBSET-SUM is in NP · SUBSET-SUM verifier computes the mask-selected sum · Embedded SUBSET-SUM summing component reaches the mapped label · Embedded run of the binary addition component · Unit symbol of an emitter counter · Stack alphabets of the HAMPATH emitter · HAMPATH emitter, phase A: moving the walk stack back onto the variable stack · HAMPATH emitter, phase A: copying a reversed name onto two stacks · HAMPATH emitter, phase A: searching the variable stack for a name · A symbol that reads as a name bit is that bit · Running a chain of copy sites in the HAMPATH emitter · Comparing a name with the top entry of the variable stack · Copying a counter in the HAMPATH emitter · Variable-stack symbols of the HAMPATH emitter · Quiescent states of the HAMPATH emitter · Name of a variable in the HAMPATH emitter · The HAMPATH emitter machine · Run of a HAMPATH copy site · Stacks of a quiescent emitter state · Variable stack of the HAMPATH emitter · HAMPATH emitter, phase A: one clause · HAMPATH emitter, phase A: the clauses of a formula · HAMPATH emitter, phase A: one literal · HAMPATH emitter, phase A: the literals of a clause · One clause of the detour walk · Front of a diamond · The emitter state before the diamonds · One literal of the detour walk · The literals of a clause in the detour walk · The row loop of a diamond in the HAMPATH emitter · The detour walk of a diamond in the HAMPATH emitter · Initial state of the HAMPATH emitter · Token symbols of the HAMPATH emitter · The tokens of a literal do not start with a clause end · Phase A of the HAMPATH emitter · Moving the tokens back in the HAMPATH emitter · End of a diamond · The detours of a diamond · One diamond · The diamonds · The row of a diamond in the HAMPATH emitter · The output phase of the HAMPATH emitter · Correctness and running time of the HAMPATH emitter · Step of the HAMPATH verifier's unary comparison loop · Emptiness test · The unary reader of the Hamiltonian path verifier · The unary mover of the Hamiltonian path verifier · Statements of the Hamiltonian-path verifier · Extending a reversed unary block · Run of the HAMPATH verifier's unary comparison loop · Run of a HAMPATH-verifier counter comparison · HAMPATH-verifier unary comparison with the counter restored · One step of the emptiness test · Moving a stack of bits · The Hamiltonian path verifier machine · The unary reader of the Hamiltonian path verifier rejects an unterminated number · The unary reader of the Hamiltonian path verifier reads a terminated number · The edge scan of the Hamiltonian path verifier · The unary mover of the Hamiltonian path verifier rejects an unterminated number · The unary mover of the Hamiltonian path verifier moves a terminated number · A single step of the Hamiltonian-path verifier · Interleaved stack updates in the Hamiltonian-path verifier · The edge-list check of the Hamiltonian-path verifier · The witness check of the Hamiltonian-path verifier · The HAMPATH emitter · HAMPATH is in NP · The HAMPATH verifier as a host component · Running the head-or-edge check · SAT ≤ HAMPATH is polynomial-time · Stack layout between vertex steps · Running the vertex loop · Stack layout during a vertex step · The repeat scan of the Hamiltonian path verifier · Correctness and running time of the Hamiltonian path verifier · One vertex step of the Hamiltonian-path verifier · The rest of a vertex step in the Hamiltonian-path verifier · The return phase ends on an empty side stack · The 3SAT filter's return phase moves the side stack back · One step of the 3SAT filter's return phase · A clause with more than three literals makes the capped 3SAT filter fail · The 3SAT filter walks one clause within the cap · The 3SAT emitter processes one clause · A long clause makes the capped 3SAT filter fail on a list of clauses · The 3SAT filter walks a list of clauses within the cap · The tokenize-then-emit machine as a host component · Name copy loop of the 3SAT emitter · Embedding the tokenizer's stacks into tokenize-then-emit · The SAT-to-3SAT emitter · Emitter · The 3SAT emitter processes a whole formula · Fresh-literal subroutine of the 3SAT emitter · The 3SAT emitter reads a literal marker · Initial stacks of the tokenize-then-emit machine · Literal-marker test of the 3SAT emitter · Emitter reductions out of SAT are polynomial-time · The SAT-to-3SAT reduction is polynomial-time · Token symbols of the 3SAT filter · One literal of the emitter · The capped filter fails on a clause with too many literals · The filter walks a clause's literals within the cap · The literals of a clause in the emitter · Conditional move between stacks · Copying a renamed name · The SAT-to-3SAT emitter machine · The clause-length filter program · Program of the tokenize-then-emit machine · The SAT-to-3SAT emitter writes the encoded translation in quadratic time · Correctness of the clause-length filter · Tokenize, then emit · Stack contents of the SAT-to-3SAT emitter · Filter stacks from two lists · Statements of the filter · Closing an output clause in the SAT-to-3SAT emitter · Label after a token · Initial stacks of the tokenizer · Stack alphabets of the SAT-to-3SAT emitter · Alphabets of the tokenize-then-emit machine · One step of the clause-length walk · Walking over name bits keeps the label · An empty token stack ends the walk · Walking over a literal advances the literal count · A capped walk fails on a literal past the third · One step of the clause-length walk on a token · Reading the mark of vertex \(j\) · The edge loop of a pass · The marking algorithm is polynomial-time · The counter unit of the PATH marking machine · The pass loop of the marking machine · The marking machine as a host component · The marking machine for PATH · The unary read instruction · Reading a cut-off unary number · Reading a unary number · Reading the mark of a vertex · Restoring the parked marks · Running time and output of the marking machine · Mark-setting step · Walking to a vertex and setting its mark · Effect of the mark-setting step · A walk step with an exhausted counter · Stack alphabets of the PATH marking machine · Validation phase of the PATH marking machine · Walking along the marks of the PATH marking machine · Walk step of the PATH marking machineDefinitionReading a symbol as a name bit#✓fully proved
A symbol of the token and table stacks that is the name bit \(b\) reads as the bit \(b\); every other symbol reads as no bit, and so ends a name block.
def Sym.bit? : Sym → Option Bool
| .bit b => some b
| _ => none
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
Uses 1 · Used by 135
DefinitionTokens of a literal#✓fully proved
For a literal \((n, p)\) with variable index \(n\) and polarity \(p\), the token list is one bit symbol for each bit of the canonical binary representation of \(n\) (least significant bit first, empty for \(n = 0\)), in order, followed by the polarity marker symbol for \(p\).
def litToks (l : ℕ × Bool) : List Sym := (encodeNat l.1).map .bit ++ [.lit l.2]
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
Uses 1 · Used by 22
TM2 SAT verifier · Correctness and step bound of the 3-COLOR emitter · The CLIQUE emitter computes Karp's instance in cubic time · HAMPATH emitter, phase A: one clause · HAMPATH emitter, phase A: one literal · HAMPATH emitter, phase A: the literals of a clause · One clause of the detour walk · One literal of the detour walk · The literals of a clause in the detour walk · The tokens of a literal do not start with a clause end · Phase A of the HAMPATH emitter · End of a diamond · One diamond · Correctness and running time of the HAMPATH emitter · The SAT-to-3SAT emitter writes the encoded translation in quadratic time · Correctness of the clause-length filterDefinitionTokens of a clause#✓fully proved
The tokens of a CNF clause are the tokens of its literals, in order, followed by the clause-end symbol.
def clauseToks (C : CNFClause) : List Sym := C.flatMap litToks ++ [.cl]
abbrev CNFClause := List (Nat × Bool)
CSLibExt/Logics/Propositional/CNF/Basic.lean:30
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
def litToks (l : ℕ × Bool) : List Sym := (encodeNat l.1).map .bit ++ [.lit l.2]
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:51
Uses 3 · Used by 23
TM2 SAT verifier · Clause token length bound for the SAT verifier (moved alias) · Correctness and step bound of the 3-COLOR emitter · The CLIQUE emitter computes Karp's instance in cubic time · HAMPATH emitter, phase A: one clause · HAMPATH emitter, phase A: the clauses of a formula · One clause of the detour walk · The detour walk of a diamond in the HAMPATH emitter · Phase A of the HAMPATH emitter · End of a diamond · The detours of a diamond · One diamond · Correctness and running time of the HAMPATH emitter · The SAT-to-3SAT emitter writes the encoded translation in quadratic time · Correctness of the clause-length filterDefinitionToken sequence of a CNF formula#✓fully proved
For a CNF formula \(\varphi\) with clauses
\(C_1, \dots, C_k\) (in order), the token sequence of \(\varphi\) is the concatenation of the token
sequences of \(C_1, \dots, C_k\). The token sequence of a clause is the concatenation of the token
sequences of its literals, in order, followed by a clause-end symbol; the token sequence of a
literal with variable index \(n \in \mathbb{N}\) and polarity \(p\) is the bits of the binary
encoding of \(n\) (Mathlib's encodeNat), each as a name-bit symbol, followed by a polarity
marker for \(p\).
The verifier's token stack holds this sequence in reverse order.
def toks (φ : CNF) : List Sym := φ.flatMap clauseToks
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
def clauseToks (C : CNFClause) : List Sym := C.flatMap litToks ++ [.cl]
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:54
Uses 4 · Used by 29
TM2 SAT verifier · Token length bound for the SAT verifier (moved alias) · Correctness and step bound of the 3-COLOR emitter · The 3-COLOR emitter · The CLIQUE emitter computes Karp's instance in cubic time · The CLIQUE emitter · HAMPATH emitter, phase A: the clauses of a formula · The emitter state before the diamonds · The detour walk of a diamond in the HAMPATH emitter · Initial state of the HAMPATH emitter · Phase A of the HAMPATH emitter · End of a diamond · The detours of a diamond · One diamond · The diamonds · Correctness and running time of the HAMPATH emitter · The HAMPATH emitter · The SAT-to-3SAT emitter · Emitter · The SAT-to-3SAT emitter writes the encoded translation in quadratic time · Correctness of the clause-length filter · Tokenize, then emitAbbreviationTable entries#✓fully proved
A table entry is a pair of a name, which is a list of bits, and an optional bit, its value; the value is absent for occurrences past the end of the witness.
Used by 21
TM2 SAT verifierDefinitionClosing marker of a table entry#✓fully proved
The marker closing a table entry whose value is the boolean \(b\) is the value symbol for \(b\); for an entry with no value it is the dead symbol.
def markOf : Option Bool → Sym
| some b => .val b
| none => .dead
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
Uses 1 · Used by 7
DefinitionSymbols of a table entry#✓fully proved
The symbols of a table entry with name \(q\) and value \(v\) are the bits of \(q\) as name-bit symbols, in order, followed by one closing marker: the value marker of \(b\) if \(v\) is a bit \(b\), and the dead marker if \(v\) is absent.
def entToks (e : Ent) : List Sym := e.1.map .bit ++ [markOf e.2]
abbrev Ent := List Bool × Option Bool
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:60
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
def markOf : Option Bool → Sym
| some b => .val b
| none => .dead
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:63
Uses 3 · Used by 10
TM2 SAT verifierDefinitionTable stack of an entry list#✓fully proved
Write each table entry as one bit symbol per bit of its name followed by its closing marker (the value symbol for its value, or the dead symbol if it has no value), and concatenate these in the order of the list. The table stack is the reverse of this sequence, with the head as the top of the stack, so the first entry lies at the bottom.
def tblStk (es : List Ent) : List Sym := (es.flatMap entToks).reverse
abbrev Ent := List Bool × Option Bool
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:60
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
def entToks (e : Ent) : List Sym := e.1.map .bit ++ [markOf e.2]
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:68
Uses 3 · Used by 18
TM2 SAT verifier · Tokenize, then emitDefinitionOccurrence table of a list of variables#✓fully proved
Given natural numbers \(n_0, \dots, n_{k-1}\) and a list \(w\) of bits, the occurrence table is the list of \(k\) table entries whose \(i\)-th entry has as name the binary code of \(n_i\) (Mathlib's encoding of natural numbers as bit lists) and as value the bit \(w_i\) if \(i\) is less than the length of \(w\), and no value otherwise.
def entsOf : List ℕ → List Bool → List Ent
| [], _ => []
| n :: ns, [] => (encodeNat n, none) :: entsOf ns []
| n :: ns, b :: bs => (encodeNat n, some b) :: entsOf ns bs
abbrev Ent := List Bool × Option Bool
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:60
Uses 1 · Used by 11
TM2 SAT verifierDefinitionOccurrence table of a formula and a witness#✓fully proved
Let \(\varphi\) be a CNF formula, \(w\) a list of booleans, and \(n_0, \dots, n_{k-1}\) the variable indices of the literals of \(\varphi\) in reading order, with repetitions. The occurrence table is the list of \(k\) entries whose \(i\)-th entry pairs the binary name of \(n_i\) (its canonical binary representation, least significant bit first, empty for \(0\)) with the value \(w_i\) if \(i\) is less than the length of \(w\), and with no value otherwise.
def ents (φ : CNF) (w : List Bool) : List Ent := entsOf (varsOf φ) w
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
abbrev Ent := List Bool × Option Bool
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:60
def entsOf : List ℕ → List Bool → List Ent
| [], _ => []
| n :: ns, [] => (encodeNat n, none) :: entsOf ns []
| n :: ns, b :: bs => (encodeNat n, some b) :: entsOf ns bs
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:74
def varsOf (φ : CNF) : List Nat := φ.flatMap fun C => C.map Prod.fst
CSLibExt/Computability/SatTimeM.lean:70
Uses 4 · Used by 10
TM2 SAT verifier · Answer of the SAT host with the three-literal filter · Tokenize, then emitDefinitionLive value of a name in a table#✓fully proved
Given a list of table entries, each pairing a name (a bit string) with either a boolean value or no value, and a bit string \(q\), the live value of \(q\) is the value of the first entry whose name is \(q\) and which carries a value, or false if there is no such entry.
def liveVal (es : List Ent) (q : List Bool) : Bool :=
(es.findSome? fun e => if e.1 = q then e.2 else none).getD false
abbrev Ent := List Bool × Option Bool
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:60
Uses 1 · Used by 11
DefinitionClause check against an occurrence table#✓fully proved
For a CNF formula \(\varphi\) and a list \(es\) of table entries, the clause check is true exactly when every clause of \(\varphi\) contains a literal \((x, p)\) whose live value equals its polarity \(p\). Here the live value of \(x\) is the value of the first entry of \(es\) that is named by the binary code of \(x\) and has a value, and false if there is no such entry.
def checkSpec (φ : CNF) (es : List Ent) : Bool :=
φ.all fun C => C.any fun l => liveVal es (encodeNat l.1) == l.2
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
abbrev Ent := List Bool × Option Bool
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:60
def liveVal (es : List Ent) (q : List Bool) : Bool :=
(es.findSome? fun e => if e.1 = q then e.2 else none).getD false
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:83
Uses 4 · Used by 7
DefinitionTokenizer of the SAT verifier#✓fully proved
Given bit strings \(x\) and \(w\), the tokenizer rejects (returns no result) if \(x\) does not decode to a CNF formula. If \(x\) decodes to a formula \(\varphi\), it returns the pair consisting of the token stack, the reverse of the tokens of \(\varphi\) in reading order, and the table stack of the occurrence table of \(\varphi\) and \(w\).
def tokenize (x w : List Bool) : Option (List Sym × List Sym) :=
(decodeCNF x).map fun φ => ((toks φ).reverse, tblStk (ents φ w))
inductive Sym
| bit (b : Bool) | lit (p : Bool) | cl | val (b : Bool) | dead
deriving DecidableEq
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:41
def decodeCNF (input : List Bool) : Option CNF := do
let (φ, rest) ← decodeCNFAux input
if rest.isEmpty then some φ else none
CSLibExt/Computability/CookLevin.lean:108
def toks (φ : CNF) : List Sym := φ.flatMap clauseToks
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:57
def tblStk (es : List Ent) : List Sym := (es.flatMap entToks).reverse
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:71
def ents (φ : CNF) (w : List Bool) : List Ent := entsOf (varsOf φ) w
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:80
TheoremThe binary code of natural numbers is injective#✓fully proved
For natural numbers \(m\) and \(n\), the binary codes of \(m\) and \(n\) (Mathlib's encoding of natural numbers as bit lists) are equal if and only if \(m = n\).
Used by 6
TheoremCanonical binary names#✓fully proved
For every list \(l\) of bits, encoding the natural number that \(l\) decodes to (Mathlib's binary code of natural numbers, least significant bit first) gives back \(l\) if and only if \(l\) is empty or its last bit is true.
TheoremTable lookup agrees with the verifier's variable lookup#✓fully proved
Let \(n = (n_0, \dots, n_{k-1})\) be a list of natural numbers, \(w\) a list of booleans and \(x\) a natural number. Write \([m]\) for the binary name of a natural number \(m\): its canonical binary representation, least significant bit first, empty for \(m = 0\). Form the table whose \(i\)-th entry, for \(i < k\), pairs \([n_i]\) with \(w_i\) if \(i\) is less than the length of \(w\), and with no value otherwise. Then the live value of \([x]\) in this table (the value of the first entry named \([x]\) that carries a value, or false if there is none) equals the return value of the verifier's lookup of \(x\) in the lists \(n\) and \(w\): the value \(w_i\) for the first \(i\) below both \(k\) and the length of \(w\) with \(n_i = x\), or false if there is none.
theorem liveVal_entsOf (ns : List ℕ) (w : List Bool) (x : ℕ) :
liveVal (entsOf ns w) (encodeNat x) = (lookupVar ns w x).ret
def liveVal (es : List Ent) (q : List Bool) : Bool :=
(es.findSome? fun e => if e.1 = q then e.2 else none).getD false
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:83
def entsOf : List ℕ → List Bool → List Ent
| [], _ => []
| n :: ns, [] => (encodeNat n, none) :: entsOf ns []
| n :: ns, b :: bs => (encodeNat n, some b) :: entsOf ns bs
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:74
def lookupVar : List Nat → List Bool → Nat → TimeM Nat Bool
| [], _, _ => pure false
| _, [], _ => pure false
| n :: ns, b :: bs, x =>
TimeM.tick 1 >>= fun _ =>
if x = n then pure b else lookupVar ns bs x
CSLibExt/Computability/SatTimeM.lean:75
Uses 5 · Used by 1
TheoremThe clause check on the occurrence table is the formula check#✓fully proved
For every CNF formula \(\varphi\) and every list \(w\) of bits, the clause check of \(\varphi\) against the occurrence table of \(\varphi\) and \(w\) equals the value returned (ignoring the time count) by the formula check of \(\varphi\) against \(w\) that uses the variable occurrences of \(\varphi\), in order, as its variable list.
theorem checkSpec_ents (φ : CNF) (w : List Bool) :
checkSpec φ (ents φ w) = (checkCNF (varsOf φ) w φ).ret
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
def checkSpec (φ : CNF) (es : List Ent) : Bool :=
φ.all fun C => C.any fun l => liveVal es (encodeNat l.1) == l.2
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:87
def ents (φ : CNF) (w : List Bool) : List Ent := entsOf (varsOf φ) w
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:80
def checkCNF (vars : List Nat) (w : List Bool) : CNF → TimeM Nat Bool
| [] => pure true
| C :: Cs =>
checkClause vars w C >>= fun ok =>
if ok = true then checkCNF vars w Cs else pure false
CSLibExt/Computability/SatTimeM.lean:94
def varsOf (φ : CNF) : List Nat := φ.flatMap fun C => C.map Prod.fst
CSLibExt/Computability/SatTimeM.lean:70
Uses 12 · Used by 1
TheoremThe SAT verifier's answer through the occurrence table#✓fully proved
For all lists \(x\) and \(w\) of bits, the value returned by the SAT verifier on \((x, w)\), ignoring the time count, is false if the complete length-prefixed CNF decoder fails on \(x\), and is the clause check of \(\varphi\) against the occurrence table of \(\varphi\) and \(w\) if \(x\) decodes to the CNF formula \(\varphi\).
theorem satVerifier_ret_eq (x w : List Bool) :
(satVerifier (x, w)).ret = ((decodeCNF x).map fun φ => checkSpec φ (ents φ w)).getD false
def satVerifier : List Bool × List Bool → TimeM Nat Bool := fun xw =>
match decodeCNF xw.1 with
| none => pure false
| some φ => checkCNF (varsOf φ) xw.2 φ
CSLibExt/Computability/SatTimeM.lean:103
def decodeCNF (input : List Bool) : Option CNF := do
let (φ, rest) ← decodeCNFAux input
if rest.isEmpty then some φ else none
CSLibExt/Computability/CookLevin.lean:108
def checkSpec (φ : CNF) (es : List Ent) : Bool :=
φ.all fun C => C.any fun l => liveVal es (encodeNat l.1) == l.2
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:87
def ents (φ : CNF) (w : List Bool) : List Ent := entsOf (varsOf φ) w
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:80
Uses 10 · Used by 2
TheoremA clause has at most as many tokens as code bits#✓fully proved
For every CNF clause \(C\), the number of tokens of \(C\) is at most the length of the binary code of \(C\).
theorem clauseToks_length_le (C : CNFClause) :
(clauseToks C).length ≤ (encodeClause C).length
abbrev CNFClause := List (Nat × Bool)
CSLibExt/Logics/Propositional/CNF/Basic.lean:30
def clauseToks (C : CNFClause) : List Sym := C.flatMap litToks ++ [.cl]
CSLibExt/Computability/Complexity/SatVerifierSpec.lean:54
def encodeClause (C : CNFClause) : List Bool :=
List.replicate C.length true ++ false :: C.flatMap encodeLit
CSLibExt/Computability/CookLevin.lean:82
Uses 7 · Used by 2
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.