Documentation

CslibFrontier.Computability.PolyTime.CNF.GreedyParityContext

Greedy parity search with an encoded context #

The selector and greedy program are those of GreedyParitySearch; this module supplies one native machine for a counter on (context, rows). The context is part of every live state and counter input. Its encoding is charged even when candidate enumeration or the outer loop is empty. This closes the fixed-counter interface gap without constructing the common-zero counter or the initial Tanner matrix of [OAI26k], §§6.2–6.3 (pp. 42–43). A counter fixed before the runtime inputs is the unit context, which gives the fixed-counter bounds for GreedyParitySearch.

Main definitions #

Main results #

References #

The certificate construction extends Anton Kovsharov's GreedyParitySearch implementation.

@[reducible, inline]

Counter input: the pair (c, rows) of the framed context c, then the concatenation of the framed rows, each row a bit string written as is (encBits).

Full selector input: context, unary width and tuple length, and retained rows.

Full greedy input: context, unary round parameter, width and tuple length, and rows.

noncomputable def Cslib.Logic.PL.CNF.GreedyContext.selectCertificate {C : Type} {encC : C ↪ List Bool} {count : C × List (List Bool) → ℕ} (cCount : GenericRAM.NativeCertificate count (encContextRows encC) Turing.MultiTapeTM.encNat) :
GenericRAM.NativeCertificate (fun (x : C × ℕ × ℕ × List (List Bool)) => match x with | (c, m, P, rows) => selectBestTestRow (fun (rows : List (List Bool)) => count (c, rows)) m P rows) (encInput encC) Turing.MultiTapeTM.encBits

One fixed native selector for all encoded contexts. Empty candidate spaces return the zero row, exactly as selectBestTestRow; otherwise its first-minimum semantics are unchanged.

noncomputable def Cslib.Logic.PL.CNF.GreedyContext.greedyCertificate {C : Type} {encC : C ↪ List Bool} {count : C × List (List Bool) → ℕ} (cCount : GenericRAM.NativeCertificate count (encContextRows encC) Turing.MultiTapeTM.encNat) :
GenericRAM.NativeCertificate (fun (x : C × ℕ × ℕ × ℕ × List (List Bool)) => match x with | (c, n, m, P, rows) => greedyParityRows (fun (rows : List (List Bool)) => count (c, rows)) n m P rows) (encGreedyInput encC) (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encBits)

One fixed machine runs 3n greedy rounds for the runtime context. The context survives every candidate and round; the returned rows are the original greedyParityRows specialization.

theorem Cslib.Logic.PL.CNF.GreedyContext.count_greedy_eq_card_sat {C : Type} {V : Type u_1} [Fintype V] [DecidableEq V] (count : C × List (List Bool) → ℕ) (c : C) (φ : CNF V) {P : ℕ} (hn : 1 ≤ Fintype.card V) (hP : 1 ≤ P) {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) → count (c, 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 σ)) :
count (c, greedyParityRows (fun (rows : List (List Bool)) => count (c, rows)) (Fintype.card V) (List.length φ) P initRows) = {σ : V → Bool | eval σ φ = true}.card

The existing Lemma 6.2 correctness theorem, specialized at a runtime context. Positivity, initial support, and counter agreement on the stated bounded candidate systems are essential. This statement constructs neither that counter nor the initial rows.

theorem Cslib.Logic.PL.CNF.GreedyContext.computableInO_select {C : Type} {encC : C ↪ List Bool} {count : C × List (List Bool) → ℕ} (cCount : GenericRAM.NativeCertificate count (encContextRows encC) Turing.MultiTapeTM.encNat) (hSpace : Turing.MultiTapeTM.PolyBounded (fun (r : C × List (List Bool)) => ((encContextRows encC) r).length) cCount.space) (R : C × ℕ × ℕ × List (List Bool) → ℕ) (hR : ∀ (a : C × ℕ × ℕ × List (List Bool)), match a with | (c, m, P, rows) => ∀ j ≤ candidateTupleCount m P, cCount.time (c, rows ++ [materializeTestRow m (decodeTestTuple m P j)]) ≤ R a) :
∃ (poly : ℕ → ℕ), PolynomiallyBounded poly ∧ Turing.MultiTapeTM.ComputableInO (fun (x : C × ℕ × ℕ × List (List Bool)) => match x with | (c, m, P, rows) => selectBestTestRow (fun (r : List (List Bool)) => count (c, r)) m P rows) (encInput encC) Turing.MultiTapeTM.encBits (fun (a : C × ℕ × ℕ × List (List Bool)) => match a with | (fst, m, P, snd) => (candidateTupleCount m P + 1) * (poly ((encInput encC) a).length + R a)) fun (a : C × ℕ × ℕ × List (List Bool)) => poly ((encInput encC) a).length

Uniform selector time and polynomial workspace, measured in the full context/input encoding. The counter-time premise includes j = (2m)^P: the native iterator uses inclusive prefix maxima, so this endpoint is charged even though that candidate is not executed.

theorem Cslib.Logic.PL.CNF.GreedyContext.computableInO_greedy {C : Type} {encC : C ↪ List Bool} {count : C × List (List Bool) → ℕ} (cCount : GenericRAM.NativeCertificate count (encContextRows encC) Turing.MultiTapeTM.encNat) (hSpace : Turing.MultiTapeTM.PolyBounded (fun (r : C × List (List Bool)) => ((encContextRows encC) r).length) cCount.space) (R : C × ℕ × ℕ × ℕ × List (List Bool) → ℕ) (hR : ∀ (a : C × ℕ × ℕ × ℕ × List (List Bool)), match a with | (c, n, m, P, rows) => ∀ i ≤ 3 * n, ∀ j ≤ candidateTupleCount m P, cCount.time (c, greedyParityRowsAt (fun (r : List (List Bool)) => count (c, r)) m P rows i ++ [materializeTestRow m (decodeTestTuple m P j)]) ≤ R a) :
∃ (poly : ℕ → ℕ), PolynomiallyBounded poly ∧ Turing.MultiTapeTM.ComputableInO (fun (x : C × ℕ × ℕ × ℕ × List (List Bool)) => match x with | (c, n, m, P, rows) => greedyParityRows (fun (r : List (List Bool)) => count (c, r)) n m P rows) (encGreedyInput encC) (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encBits) (fun (a : C × ℕ × ℕ × ℕ × List (List Bool)) => match a with | (fst, n, m, P, snd) => (3 * n + 1) * (candidateTupleCount m P + 1) * (poly ((encGreedyInput encC) a).length + R a)) fun (a : C × ℕ × ℕ × ℕ × List (List Bool)) => poly ((encGreedyInput encC) a).length

One uniform machine and polynomial for all encoded contexts, with independent native time O((3n + 1) ((2m)^P + 1) (poly(L) + R)) and workspace O(poly(L)), where L is the full context/input encoding length. The binary clock, retained rows/context, incumbent count, and final output are charged; workspace is not multiplied by either loop length.

The inclusive resource maxima require hR also at i = 3n and j = (2m)^P. These are resource obligations on extra endpoint candidates, not extra calls in the executable program. In particular, their row-length bound can exceed the correctness theorem's candidate bound by one. Polynomial counter workspace is a separate, global joint-input assumption; counter time need not be polynomial. This supplies the context interface for [OAI26k], §6.3, not its common-zero counter.

Whenever cCount uses polynomial workspace, greedyParityRows runs in polynomial space.

Fixed counters as the unit context #

A counter fixed before the runtime inputs is the case C := Unit of the context interface. The fixed-counter bounds below transfer GreedyContext.computableInO_select and GreedyContext.computableInO_greedy along the linear re-encoding a ↦ ((), a).

theorem Cslib.Logic.PL.CNF.computableInO_selectBestTestRow {countSys : List (List Bool) → ℕ} (cCount : GenericRAM.NativeCertificate countSys (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encNat) (hSpace : Turing.MultiTapeTM.PolyBounded (fun (r : List (List Bool)) => ((Turing.MultiTapeTM.encList Turing.MultiTapeTM.encBits) r).length) cCount.space) (R : ℕ × ℕ × List (List Bool) → ℕ) (hR : ∀ (a : ℕ × ℕ × List (List Bool)), match a with | (m, P, rows) => ∀ j ≤ candidateTupleCount m P, cCount.time (rows ++ [materializeTestRow m (decodeTestTuple m P j)]) ≤ R a) :
∃ (poly : ℕ → ℕ), PolynomiallyBounded poly ∧ Turing.MultiTapeTM.ComputableInO (fun (x : ℕ × ℕ × List (List Bool)) => match x with | (m, P, rows) => selectBestTestRow countSys m P rows) encSelectBestIn Turing.MultiTapeTM.encBits (fun (a : ℕ × ℕ × List (List Bool)) => match a with | (m, P, snd) => (candidateTupleCount m P + 1) * (poly (encSelectBestIn a).length + R a)) fun (a : ℕ × ℕ × List (List Bool)) => poly (encSelectBestIn a).length

Fixed-counter per-round ComputableInO time and polynomial-workspace bound for selectBestTestRow (with countSys and cCount fixed before runtime inputs (m, P, rows)).

theorem Cslib.Logic.PL.CNF.computableInO_greedyParityRows {countSys : List (List Bool) → ℕ} (cCount : GenericRAM.NativeCertificate countSys (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encNat) (hSpace : Turing.MultiTapeTM.PolyBounded (fun (r : List (List Bool)) => ((Turing.MultiTapeTM.encList Turing.MultiTapeTM.encBits) r).length) cCount.space) (R : ℕ × ℕ × ℕ × List (List Bool) → ℕ) (hR : ∀ (a : ℕ × ℕ × ℕ × List (List Bool)), match a with | (n, m, P, rows) => ∀ i ≤ 3 * n, ∀ j ≤ candidateTupleCount m P, cCount.time (greedyParityRowsAt countSys m P rows i ++ [materializeTestRow m (decodeTestTuple m P j)]) ≤ R a) :
∃ (poly : ℕ → ℕ), PolynomiallyBounded poly ∧ Turing.MultiTapeTM.ComputableInO (fun (x : ℕ × ℕ × ℕ × List (List Bool)) => match x with | (n, m, P, rows) => greedyParityRows countSys n m P rows) encGreedyIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encBits) (fun (a : ℕ × ℕ × ℕ × List (List Bool)) => match a with | (n, m, P, snd) => (3 * n + 1) * (candidateTupleCount m P + 1) * (poly (encGreedyIn a).length + R a)) fun (a : ℕ × ℕ × ℕ × List (List Bool)) => poly (encGreedyIn a).length

Fixed-counter 3n-round ComputableInO time and polynomial-workspace bound for greedyParityRows. For fixed countSys and cCount (supplied before runtime inputs (n, m, P, rows)), runs in time O((3 * n + 1) * ((2 * m) ^ P + 1) * (poly(|input|) + R)) and polynomial workspace O(poly(|input|)), never storing (2 * m) ^ P lists or counts ([OAI26k], §6.3, p. 43).

For a fixed counter (countSys, cCount) using polynomial workspace, greedyParityRows runs in polynomial space on runtime inputs (n, m, P, rows).