Documentation

CslibFrontier.Computability.PolyTime.CNF.GreedyParitySearch

Runtime greedy parity-row search for CNF formulas #

In §6 and Lemma 6.2 of [OAI26k] (pp. 40, 42), given an initial parity-check matrix where every passing nonsatisfying assignment violates at least m / P clauses, a deterministic greedy loop runs for 3n rounds, streaming all (2m)^P tuples γ ∈ ([m] × {0, 1})^P via Cslib.GenericRAM.IndexFold.run, materializing h_γ mod 2, and—whenever the candidate space is nonempty (0 < candidateTupleCount m P)—appending the first candidate in enumeration order minimizing countSys (rows ++ [h_γ]) (falling back to the length-m zero row List.replicate m false when candidateTupleCount m P = 0, i.e., m = 0 and P > 0).

Scope and fixed-counter quantifier #

In the native certificates (selectBestStepCertificate, selectBestTestRowCertificate, greedyParityRowsCertificate), the candidate counter countSys : List (List Bool) → ℕ and its certificate cCount : NativeCertificate countSys (encList encBits) encNat are fixed before the runtime inputs (m, P, rows) / (n, m, P, rows). Neither the original CNF formula φ nor an arbitrary encoded context is a runtime input to this machine: choosing a separate countSys per φ allows a different machine and polynomial bound per φ. Uniform composition with a variable-CNF Theorem 2.2 common-zero counter therefore requires a captured-context certificate interface—for example, a counter on (context, rows) whose encoded context is retained and charged throughout IndexFold and the outer 3n-round loop. GreedyParityContext supplies that interface; its unit-context case gives the fixed-counter time and workspace bounds computableInO_selectBestTestRow, computableInO_greedyParityRows and computableInPolySpace_greedyParityRows.

Main definitions #

Main results #

References #

Candidate-tuple count and base-2m tuple decoding #

Number (2 * m) ^ P of ordered candidate lists γ ∈ ([m] × {0, 1})^P (Lemma 6.2, p. 42).

The binary encoding of (2 * m) ^ P has bit-length at most P * (2 * m) + 1.

Decode a binary candidate index j : ℕ in base 2 * m into ((e₁, c₁), …, (e_P, c_P)) via Cslib.Radix.digit without materializing (2 * m) ^ P lists ([OAI26k], §6, p. 40; Lemma 6.2, p. 42). At m = 0, digits default to 0 so clause indices remain bounded in unary.

Little-endian base-2m encoder inverse to decodeTestTuple m P on lists with clause indices < m, defined via Nat.ofDigits (2 * m).

theorem Cslib.Logic.PL.CNF.fst_lt_of_mem_decodeTestTuple {m P j : ℕ} (hm : 1 ≤ m) {p : ℕ × Bool} (hp : p ∈ decodeTestTuple m P j) :
p.1 < m

Every pair (e, c) produced by decodeTestTuple m P j satisfies e < m when 1 ≤ m.

theorem Cslib.Logic.PL.CNF.encodeTestTuple_lt {m : ℕ} {γ : List (ℕ × Bool)} (hγ : ∀ p ∈ γ, p.1 < m) :

Encoding any list γ with clause indices < m yields an index < (2 * m) ^ γ.length.

theorem Cslib.Logic.PL.CNF.decodeTestTuple_encodeTestTuple {m : ℕ} {γ : List (ℕ × Bool)} (hγ : ∀ p ∈ γ, p.1 < m) :

Decoding the index of any valid list γ recovers γ exactly.

Encoding the decoded tuple of any j < (2 * m) ^ P recovers j.

theorem Cslib.Logic.PL.CNF.mem_map_decodeTestTuple_range {m P : ℕ} (γ : Fin P → Fin m × Bool) :
(List.ofFn fun (r : Fin P) => (↑(γ r).1, (γ r).2)) ∈ List.map (decodeTestTuple m P) (List.range (candidateTupleCount m P))

Completeness of decodeTestTuple m P over List.range ((2 * m) ^ P).

theorem Cslib.Logic.PL.CNF.exists_fin_of_lt_candidateTupleCount {m P j : ℕ} (hj : j < candidateTupleCount m P) :
∃ (γ : Fin P → Fin m × Bool), decodeTestTuple m P j = List.ofFn fun (r : Fin P) => (↑(γ r).1, (γ r).2)

Every valid candidate index j < (2 * m) ^ P decodes to a typed γ : Fin P → Fin m × Bool.

@[reducible, inline]

Test tuples γ = ((e₁, c₁), …, (e_P, c_P)) with clause indices in unary: the concatenation of the framed pairs, each pair the framed unary clause index e followed by the bit c.

Mod-2 row materialization #

Materialize the length-m binary row h_γ from a test list γ, summing coefficients c_r modulo 2 (xor) across occurrences of e ([OAI26k], §6, p. 40; Lemma 6.2, p. 42).

theorem Cslib.Logic.PL.CNF.materializeTestRow_ofFn {m P : ℕ} (γ : Fin P → Fin m × Bool) :
materializeTestRow m (List.ofFn fun (r : Fin P) => (↑(γ r).1, (γ r).2)) = List.ofFn (BitString.testRow γ)

Exact bridge to Cslib.BitString.testRow on γ : Fin P → Fin m × Bool.

Every materialized row has at most γ.length ones (fewer when repeated indices cancel).

Every decoded candidate row for (m, P) has Hamming weight at most P.

Streaming (2m)^P min-count selector and 3n-round greedy loop #

@[reducible, inline]

Live streaming accumulator: (m, P), rows, and optional (bestRow, bestVal).

Callback body of IndexFold.run for candidate index j, replacing the incumbent only on strict improvement candVal < best.2 ([OAI26k], Lemma 6.2, p. 42).

def Cslib.Logic.PL.CNF.selectBestTestRow (countSys : List (List Bool) → ℕ) (m P : ℕ) (rows : List (List Bool)) :

Stream j ∈ 0 .. (2 * m) ^ P - 1 via Cslib.GenericRAM.IndexFold.run: when the candidate space is nonempty (0 < candidateTupleCount m P), select the first candidate parity-test row in enumeration order attaining the minimum of countSys (rows ++ [h_γ]); if candidateTupleCount m P = 0 (m = 0, P > 0), return the total fallback length-m zero row List.replicate m false.

def Cslib.Logic.PL.CNF.greedyParityRowsAt (countSys : List (List Bool) → ℕ) (m P : ℕ) (initRows : List (List Bool)) (i : ℕ) :

Prefix sequence of rows after i greedy rounds from initRows.

def Cslib.Logic.PL.CNF.greedyParityRows (countSys : List (List Bool) → ℕ) (n m P : ℕ) (initRows : List (List Bool)) :

Append 3 * n greedily selected parity-test rows of list length P and width m, starting from initRows ([OAI26k], Lemma 6.2, p. 42).

@[simp]
theorem Cslib.Logic.PL.CNF.greedyParityRowsAt_zero (countSys : List (List Bool) → ℕ) (m P : ℕ) (initRows : List (List Bool)) :
greedyParityRowsAt countSys m P initRows 0 = initRows
theorem Cslib.Logic.PL.CNF.greedyParityRowsAt_succ (countSys : List (List Bool) → ℕ) (m P : ℕ) (initRows : List (List Bool)) (i : ℕ) :
greedyParityRowsAt countSys m P initRows (i + 1) = greedyParityRowsAt countSys m P initRows i ++ [selectBestTestRow countSys m P (greedyParityRowsAt countSys m P initRows i)]

Prefix invariant, tie-breaking, and minimality #

theorem Cslib.Logic.PL.CNF.exists_min_index_selectBestTestRow (countSys : List (List Bool) → ℕ) {m P : ℕ} (rows : List (List Bool)) (hpos : 0 < candidateTupleCount m P) :
∃ jStar < candidateTupleCount m P, selectBestTestRow countSys m P rows = materializeTestRow m (decodeTestTuple m P jStar) ∧ (∀ j < candidateTupleCount m P, countSys (rows ++ [materializeTestRow m (decodeTestTuple m P jStar)]) ≤ countSys (rows ++ [materializeTestRow m (decodeTestTuple m P j)])) ∧ ∀ j < jStar, countSys (rows ++ [materializeTestRow m (decodeTestTuple m P jStar)]) < countSys (rows ++ [materializeTestRow m (decodeTestTuple m P j)])

Enumeration-order tie-breaking characterization of selectBestTestRow when (2 * m) ^ P > 0: jStar < (2 * m) ^ P attains the minimum count and strictly beats every j < jStar.

@[simp]
theorem Cslib.Logic.PL.CNF.length_selectBestTestRow (countSys : List (List Bool) → ℕ) (m P : ℕ) (rows : List (List Bool)) :
(selectBestTestRow countSys m P rows).length = m
theorem Cslib.Logic.PL.CNF.count_true_selectBestTestRow_le (countSys : List (List Bool) → ℕ) (m P : ℕ) (rows : List (List Bool)) :
List.count true (selectBestTestRow countSys m P rows) ≤ P

The selected parity-test row has Hamming weight (count true) at most P.

theorem Cslib.Logic.PL.CNF.countSys_selectBestTestRow_le (countSys : List (List Bool) → ℕ) {m P : ℕ} (rows : List (List Bool)) (γ : Fin P → Fin m × Bool) :
countSys (rows ++ [selectBestTestRow countSys m P rows]) ≤ countSys (rows ++ [List.ofFn (BitString.testRow γ)])

Minimality over all test tuples γ : Fin P → Fin m × Bool.

theorem Cslib.Logic.PL.CNF.exists_fin_selectBestTestRow (countSys : List (List Bool) → ℕ) {m P : ℕ} (rows : List (List Bool)) (hpos : 0 < candidateTupleCount m P) :
∃ (γ : Fin P → Fin m × Bool), selectBestTestRow countSys m P rows = List.ofFn (BitString.testRow γ)

Whenever (2 * m) ^ P > 0, selectBestTestRow equals List.ofFn (testRow γ) for some γ.

Row counts, widths, weights, and CNF bridge for greedyParityRows #

@[simp]
theorem Cslib.Logic.PL.CNF.length_greedyParityRowsAt (countSys : List (List Bool) → ℕ) (m P : ℕ) (initRows : List (List Bool)) (i : ℕ) :
(greedyParityRowsAt countSys m P initRows i).length = initRows.length + i
@[simp]
theorem Cslib.Logic.PL.CNF.length_greedyParityRows (countSys : List (List Bool) → ℕ) (n m P : ℕ) (initRows : List (List Bool)) :
(greedyParityRows countSys n m P initRows).length = initRows.length + 3 * n
theorem Cslib.Logic.PL.CNF.mem_greedyParityRowsAt (countSys : List (List Bool) → ℕ) {m P : ℕ} {initRows : List (List Bool)} {i : ℕ} {r : List Bool} (hr : r ∈ greedyParityRowsAt countSys m P initRows i) :
r ∈ initRows ∨ r.length = m ∧ List.count true r ≤ P

Every greedy row is an initial row or a selected row of length m and weight at most P.

theorem Cslib.Logic.PL.CNF.length_of_mem_greedyParityRowsAt (countSys : List (List Bool) → ℕ) {m P : ℕ} {initRows : List (List Bool)} (hinit : ∀ r ∈ initRows, r.length = m) (i : ℕ) {r : List Bool} (hr : r ∈ greedyParityRowsAt countSys m P initRows i) :
r.length = m
theorem Cslib.Logic.PL.CNF.length_of_mem_greedyParityRows (countSys : List (List Bool) → ℕ) {n m P : ℕ} {initRows : List (List Bool)} (hinit : ∀ r ∈ initRows, r.length = m) {r : List Bool} (hr : r ∈ greedyParityRows countSys n m P initRows) :
r.length = m
theorem Cslib.Logic.PL.CNF.countSys_greedyParityRows_eq_card_sat {V : Type u_1} [Fintype V] [DecidableEq V] (φ : CNF V) {P : ℕ} (hn : 1 ≤ Fintype.card V) (hP : 1 ≤ P) {countSys : List (List Bool) → ℕ} {initRows : List (List Bool)} (hinit_len : ∀ r ∈ initRows, r.length = List.length φ) (hcount : ∀ (rows : List (List Bool)), (∀ r ∈ rows, r.length = List.length φ) → rows.length ≤ initRows.length + 3 * Fintype.card V → (∀ r ∈ rows, r ∈ initRows ∨ List.count true r ≤ P) → countSys rows = BitString.numPassing φ.violations (List.map (BitString.ofList (List.length φ)) rows)) (hinit : ∀ (σ : V → Bool), BitString.PassesTests φ.violations (List.map (BitString.ofList (List.length φ)) initRows) σ → eval σ φ = false → List.length φ ≤ P * BitString.weight (φ.violations σ)) :
countSys (greedyParityRows countSys (Fintype.card V) (List.length φ) P initRows) = {σ : V → Bool | eval σ φ = true}.card

Exact bridge from greedyParityRows to CNF.numPassing_greedy ([OAI26k], Lemma 6.2). Under hn : 1 ≤ Fintype.card V and hP : 1 ≤ P, when initRows has row width φ.length, countSys computes numPassing φ.violations on width-φ.length candidate row lists of length at most initRows.length + 3 * Fintype.card V whose appended rows have weight ≤ P, and initRows satisfies Lemma 6.1's φ.length ≤ P * weight (φ.violations σ) bound, 3 * Fintype.card V greedy rounds yield countSys finalRows = #{σ : V → Bool | φ.eval σ = true}. Positivity is material: for V = Fin 0, φ = [[]], P = 1, initRows = [], and countSys given by numPassing, the agreement and support conditions hold, yet 0 rounds leave count 1 while #sat = 0.

theorem Cslib.Logic.PL.CNF.numPassing_greedyParityRows_fin {n P : ℕ} (φ : CNF (Fin n)) (hn : 1 ≤ n) (hP : 1 ≤ P) (initRows : List (List Bool)) (hinit_len : ∀ r ∈ initRows, r.length = List.length φ) (hinit : ∀ (σ : Fin n → Bool), BitString.PassesTests φ.violations (List.map (BitString.ofList (List.length φ)) initRows) σ → eval σ φ = false → List.length φ ≤ P * BitString.weight (φ.violations σ)) :
have countSys := fun (rows : List (List Bool)) => BitString.numPassing φ.violations (List.map (BitString.ofList (List.length φ)) rows); have finalRows := greedyParityRows countSys n (List.length φ) P initRows; countSys finalRows = {σ : Fin n → Bool | eval σ φ = true}.card ∧ {σ : Fin n → Bool | BitString.PassesTests φ.violations (List.map (BitString.ofList (List.length φ)) finalRows) σ ∧ eval σ φ = false}.card = 0

Concrete Fin n specialization of Lemma 6.2: under hn : 1 ≤ n and hP : 1 ≤ P, 3 * n greedy rounds yield N(A) = #F and D(A) = 0.

Encodings for native IndexFold certificates #

Binary encoding of the live streaming accumulator ((m, P), (rows, bestOpt)).

Input encoding for selectBestTestRow (and outer-loop state): unary (m, P) and rows.

Input encoding for greedyParityRows: unary (n, m, P) and framed bit-rows initRows.

Native IndexFold certificates and ComputableInO / ComputableInPolySpace bounds #

Candidate test row decoded and materialized from an IndexFold state (j, acc).

Existing parity-test rows extended with the candidate row at IndexFold state s.

Update SelectBestAcc after evaluating the candidate score p.2 at IndexFold state p.1.

Native streaming machine certificate for selectBestTestRow via IndexFold.certificate, for a fixed counter (countSys, cCount) supplied before runtime inputs (m, P, rows).

Native machine certificate for the 3 * n-round greedyParityRows procedure for a fixed counter (countSys, cCount).

Here countSys and cCount are fixed before the runtime inputs (n, m, P, rows) encoded by encGreedyIn; neither the original CNF nor an arbitrary encoded context is an input to this machine, and choosing a separate countSys per φ allows a different machine and polynomial per φ. Uniform composition with a variable-CNF Theorem 2.2 counter requires a captured-context certificate interface (such as a counter on (context, rows) retaining and charging context throughout the loop).

Live-state length bound #

Live accumulator length bound during IndexFold.run (selectBestStep countSys), independent of the number k of visited candidates.