Rectangular CNF constructor for sparse Boolean functions
DefinitionCNFEncComplexity_sparseRectangleBuildcnfencodingsparse-functions
Given a list of Boolean words and an input width , this constructor arranges the words in a table with columns and rows. It generates a CNF formula with row and column selectors, a prefix counter for the row selectors, and two guarded clauses per column and bit. Each guarded clause lists only rows whose occupied cell has the required bit. The input variables have indices . At width zero the constructor returns the empty formula.
The construction follows the rectangle method of Lemma 13. It uses one positive selector per column with an at-least-one clause. Empty cells are excluded by the guarded bit clauses.
Definition code
import Init.Data.Nat.Sqrt
import Definitions.Def_CookLevin_Satisfiability
namespace CNFEncComplexity
open CookLevin
def rowPred {n : Nat} (i : Fin n) : Fin n :=
⟨i.val - 1, Nat.lt_of_le_of_lt (Nat.sub_le _ _) i.isLt⟩
def guardedRowStep {n : Nat} (guard : Literal) (x s : Fin n → Nat) (i : Fin n) :
Formula :=
let first := [guard, .Neg (x i), .Pos (s i)]
if i.val = 0 then
[first, [guard, .Neg (s i), .Pos (s i)], [guard, .Neg (s i), .Pos (s i)]]
else
[first, [guard, .Neg (s (rowPred i)), .Pos (s i)],
[guard, .Neg (x i), .Neg (s (rowPred i))]]
def guardedRowAmo {n : Nat} (guard : Literal) (x s : Fin n → Nat) : Formula :=
(List.finRange n).flatMap (guardedRowStep guard x s)
/-- Rows whose entry in the selected column has the specified value in a given bit. -/
def matchingRows {R C n : Nat} (row : Fin R → Nat)
(entry : Fin R → Fin C → Option (Fin n → Bool)) (c : Fin C) (i : Fin n) (bit : Bool) :
List Literal :=
((List.finRange R).filter (fun r => (entry r c).any (fun v => v i == bit))).map
(fun r => .Pos (row r))
def rectangleBitClause {R C n : Nat} (x : Fin n → Nat) (row : Fin R → Nat)
(col : Fin C → Nat) (entry : Fin R → Fin C → Option (Fin n → Bool))
(c : Fin C) (i : Fin n) (bit : Bool) : Clause :=
.Neg (col c) :: (if bit then .Neg (x i) else .Pos (x i)) ::
matchingRows row entry c i bit
/-- With the column selected, each input bit must be supported by a matching selected row. -/
def rectangleBitBlock {R C n : Nat} (x : Fin n → Nat) (row : Fin R → Nat)
(col : Fin C → Nat) (entry : Fin R → Fin C → Option (Fin n → Bool)) : Formula :=
(List.finRange C).flatMap fun c =>
(List.finRange n).flatMap fun i =>
[rectangleBitClause x row col entry c i false, rectangleBitClause x row col entry c i true]
def sparseEntry {n R C : Nat} (L : List (List Bool)) (r : Fin R) (c : Fin C) :
Option (Fin n → Bool) :=
L[r.val * C + c.val]?.map fun v i => v[i.val]?.getD false
/-- Rectangular table width and row count for a sparse truth table. -/
def sparseWidth (n M : Nat) : Nat := Nat.sqrt (M / n) + 1
def sparseRows (n M : Nat) : Nat := M / sparseWidth n M + 1
def sparseRowVar (n : Nat) {R : Nat} (i : Fin R) : Nat := n + i.val
def sparsePrefixVar (n : Nat) {R : Nat} (i : Fin R) : Nat := n + R + i.val
def sparseColVar (n R : Nat) {C : Nat} (i : Fin C) : Nat := n + 2 * R + i.val
def sparseGuard (n R C : Nat) : Nat := n + 2 * R + C
/-- The rectangle construction, with a row selector and a positive selector for each column. -/
def sparseRectangleBuild (data : Nat × List (List Bool)) : Formula :=
let (n, L) := data
if n = 0 then [] else
let C := sparseWidth n L.length
let R := sparseRows n L.length
let row := sparseRowVar n (R := R)
let flags := sparsePrefixVar n (R := R)
let col := sparseColVar n R (C := C)
let guard := sparseGuard n R C
[[.Neg guard], (List.finRange R).map (fun i => .Pos (row i)),
(List.finRange C).map (fun i => .Pos (col i))] ++
guardedRowAmo (.Pos guard) row flags ++
rectangleBitBlock (fun i : Fin n => i.val) row col (sparseEntry L)
end CNFEncComplexity
Source
Krapivin, Przybocki, Subercaseaux, The CNF Encoding Complexity of Boolean Functions, arXiv:2611.05614v1, Section 3.3, Lemma 13 and proof. https://arxiv.org/html/2611.05614v1#S3.SS3