The binary coding of CNF formulas is injective
ProvedPvsNP.encodeCNF_injectiveThe map encodeCNF from CNF formulas (lists of lists of literals ) to binary strings is injective: two formulas with the same code are equal.
This certifies that the coding used to define and is a coding in Cook's sense ("the set of strings coding YES instances to the decision problem using standard coding methods", p. 5): a binary string is the code of at most one formula, so whether a code lies in depends only on the formula it codes. The code writes every symbol as a two-bit block, for a data bit (the sign of a literal, then the binary digits of its variable index, least significant first, without leading zeros), for the end of a literal and for the end of a clause, so it can be parsed from left to right; injectivity of the binary representation of natural numbers does the rest.
Formalization Note The statement is Function.Injective encodeCNF. The empty string codes exactly the empty formula and the string exactly the formula with one empty clause; the block structure means that the parity of positions matters, e.g. the string is the code of the one-literal clause followed by nothing and is not the concatenation of the blocks and read from position one.
import Definitions.Def_PvsNP import Mathlib
namespace PvsNP theorem encodeCNF_injective : Function.Injective encodeCNF := by sorry end PvsNP
Read-back
What the Lean code literally says, in plain math · claude-fable-5-1
Read-back: PvsNP.encodeCNF_injective
The statement. The declaration asserts that the map (defined below) from "CNF formulas" to finite bit-strings is injective; explicitly, for all of the type called CNF,
There are no other hypotheses, no typeclass assumptions and no further quantified variables. The equalities on both sides are equalities of finite lists: two lists are equal exactly when they have the same length and agree entry-by-entry in order. The theorem is stated with the proof omitted (a placeholder), so what is recorded is the claim itself.
What the objects are. Every notion below is a bare list type with no side conditions.
- A bit-string () is a finite list of Booleans ; below I write for and for .
- A literal is an ordered pair with a Boolean (a "sign" flag) and a natural number (a "variable index"). Every such pair is a literal; in particular is allowed, and both signs are allowed for every .
- A clause is a finite list of literals , . The empty clause is allowed; literals may repeat; order matters (the lists and are different clauses).
- A CNF formula is a finite list of clauses , . The empty formula is allowed; clauses may repeat; order matters. Nothing ties the variable indices to any bound, and nothing requires clauses to be non-empty or literals to be distinct.
Consequently the conclusion means: and have the same number of clauses, the -th clauses have the same number of literals for every , and the -th literal of the -th clause has the same sign flag and the same variable index in both.
The binary digits of a natural number. For , denotes the (Mathlib) list of binary digits of , least significant digit first, with no trailing zeros (i.e. no leading zeros in ordinary positional notation). It is determined by
where means the list with prepended. Thus , , , ; the list has length for , and length for . In particular is the only number whose digit list is empty, and the last entry of is whenever .
The encoding of a literal. For a literal , form the Boolean list (the sign flag followed by the digits of , ). Replace each entry of this list by the two-bit block and concatenate, then append the two-bit block :
This string has length . Examples: ; ; .
The encoding of a clause. For a clause , concatenate the encodings of its literals in order and append the two-bit block :
where is list concatenation. The empty clause encodes to .
The encoding of a formula. For a formula , concatenate the encodings of its clauses in order, with no terminator or header:
The empty formula encodes to the empty bit-string. Every encoded string has even length, and, read in consecutive two-bit blocks, each block is (a payload bit , either the sign flag or a digit of a variable index), (end of a literal) or (end of a clause).
Summary of the claim in these terms. For any two finite lists of finite lists of pairs (Boolean, natural number) and , if the bit-strings obtained by the above three-level concatenation coincide as lists, then and coincide as lists of lists of pairs. Equivalently, distinct formulas (distinct in number of clauses, order of clauses, multiplicity or order of literals within a clause, or sign flag or index of any literal) always have distinct encodings.