Documentation

Learning.DecisionListSolver

Inner scan primitives of the greedy 1-DL consistency solver #

Provenance: the native cost model (CodeLayer/TimeCost.lean). Builds on Learning/DecisionListData.lean (the data layer: readM/readK, peel/cPeel, headL/tailL, WF, readM_le_size/readK_le_size, encodeList, peel_encode, and the labelled bit-example accessors lblOf/fvOf/featOf/WFBits) and CodeLayer/PolyTime.lean (PolyTime, PolyBounded, PolyTimeOn, PolyBoundedOn, polyTime_loop, tc_prec_le', the closure toolkit).

The numbered layers below start at 2: layer 1 is the bit-logic gate library — cIsPos, cNot, cOr, cAnd, cEqBit, cSwap, cShape0 with their value laws, rfind'-freeness and tc bounds — which lives in CodeLayer/Code/BitGates.lean.

The construction is labeled in three layers, cited in comments below: C2a — the data layer (Learning/DecisionListData.lean); C2b — the polynomial-time account (the scan and the greedy outer loop solve; its outer loop is tagged C2b-outer); C2c — greedy correctness (solve decides 1-DL consistency).

Layer 2 — the purity scan cPurity #

purity inst mask j p scans the m examples; over the still-remaining (mask bit = 1) examples that satisfy literal (j, p) (feature j equals p) it decides whether all their labels agree, returning ⟨isPure, commonLabel⟩. To avoid value-arithmetic (label equality is value-linear), it tracks two bits over the covered examples: sawZero (some covered example is labelled 0) and sawOne (some covered example is labelled 1); then isPure = ¬(sawZero ∧ sawOne) and commonLabel = sawOne. Realized as a carried-suffix prec loop over i < readM inst.

The semantic bit-ops (mirror the gate val laws) #

¬ on a bit — mirrors val_cNot.

Equations
Instances For

    ∧ on bits — mirrors val_cAnd.

    Equations
    Instances For
      def DecisionList.bOr (a b : ℕ) :

      ∨ on bits — mirrors val_cOr.

      Equations
      Instances For
        def DecisionList.bEq (a b : ℕ) :

        bit-equality — mirrors val_cEqBit.

        Equations
        Instances For

          Reads as Codes #

          The packed input and its projections #

          n = ⟨inst, ⟨mask, ⟨j, p⟩⟩⟩.

          The instance component of the packed input.

          Equations
          Instances For

            The remaining-examples mask.

            Equations
            Instances For

              The literal's feature index j.

              Equations
              Instances For

                The literal's polarity bit p.

                Equations
                Instances For

                  readData (instOf n) — the example list of the packed input.

                  Equations
                  Instances For

                    The same four projections as Codes, plus the example list reached through the instance. Each is the unpair chain of its semantic twin spelled with left/right; the val_c* laws below are the identifications.

                    The accumulator ⟨maskSuf, ⟨exSuf, ⟨sawZero, sawOne⟩⟩⟩ and the initial-state code #

                    The unscanned suffix of the mask.

                    Equations
                    Instances For

                      The unscanned suffix of the example list.

                      Equations
                      Instances For

                        The sawZero flag: some covered example so far carried label 0.

                        Equations
                        Instances For

                          The sawOne flag: some covered example so far carried label 1.

                          Equations
                          Instances For
                            def DecisionList.initAcc (mask data : ℕ) :

                            The initial accumulator: full suffixes, both flags 0.

                            Equations
                            Instances For

                              The base code: build initAcc (maskOf n) (dataOf n) from the packed input.

                              Equations
                              Instances For

                                The step code cStep and its val law #

                                Gate val laws restated with the semantic bit-ops (definitional folds) so the step val lands in stepFn form. The step input is X = ⟨a, ⟨i, acc⟩⟩; the seed a carries j, p, and i is unused (carried-suffix scan — the current cell is the head of the carried suffix).

                                The step code's pieces, all read off the step input X = ⟨a, ⟨i, acc⟩⟩: the c*a pair reaches into the seed a for the literal, the rest into acc. They build up in one chain — the current mask bit and example, the example's label and feature, whether the literal covers it, and finally the two updated flags — and cStep reassembles the accumulator from the last of them. val_cStep identifies the whole with stepFn.

                                The literal's feature index j, from the seed.

                                Equations
                                Instances For

                                  The literal's polarity bit p, from the seed.

                                  Equations
                                  Instances For

                                    The current mask bit: is this example still in play?

                                    Equations
                                    Instances For

                                      The current example's feature vector.

                                      Equations
                                      Instances For

                                        Feature j of the current example: peel its feature vector j cells, read the head bit.

                                        Equations
                                        Instances For

                                          Does the current example's feature j match the literal's polarity p?

                                          Equations
                                          Instances For

                                            Coverage: the example is still remaining AND the literal matches it.

                                            Equations
                                            Instances For

                                              The current example's label, negated.

                                              Equations
                                              Instances For

                                                The updated sawZero: set it if this example is covered and labelled 0.

                                                Equations
                                                Instances For

                                                  The updated sawOne: set it if this example is covered and labelled 1.

                                                  Equations
                                                  Instances For
                                                    def DecisionList.stepFn (j p acc : ℕ) :

                                                    The semantic step: read the head bit / head example off the carried suffixes, test coverage (remaining ∧ satisfies (j,p)), fold the covered example's label into sawZero/sawOne, and peel both suffixes one cell. Independent of the loop index.

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For

                                                      The List-model fold and the scan characterisation #

                                                      def DecisionList.stepPair (j p : ℕ) (z be : ℕ × ℕ) :

                                                      One covered-label fold step on (sawZero, sawOne) for a (maskBit, example) pair.

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For

                                                        Characterising the fold: sawZero/sawOne as coverage existentials #

                                                        def DecisionList.Covered (j p : ℕ) (be : ℕ × ℕ) :

                                                        A (maskBit, example) pair is covered by literal (j,p): still remaining and the gate accepts its feature-j bit against p.

                                                        Equations
                                                        Instances For

                                                          The assembled purity code and its correctness #

                                                          Extract ⟨isPure, ⟨commonLabel, sawAny⟩⟩ = ⟨¬(sawZero ∧ sawOne), ⟨sawOne, sawZero ∨ sawOne⟩⟩ from the final accumulator. The third field sawAny witnesses that ≥1 remaining example is covered — so the greedy loop can reject vacuously-pure (0-covering) literals (findLit gates on isPure ∧ sawAny).

                                                          sawAny = sawZero ∨ sawOne: the literal covered at least one remaining example.

                                                          Equations
                                                          Instances For

                                                            The read-out verdict triple ⟨isPure, ⟨commonLabel, sawAny⟩⟩. Purity is ¬(sawZero ∧ sawOne) — the covered examples did not disagree — and the common label is sawOne.

                                                            Equations
                                                            Instances For

                                                              Identity shaper (the loop seed is the whole packed input).

                                                              Equations
                                                              Instances For

                                                                The iteration count readM (instOf n) — the number of examples.

                                                                Equations
                                                                Instances For

                                                                  The purity primitive cPurity: run the scan readM inst times, then read out the verdict.

                                                                  Equations
                                                                  Instances For

                                                                    The final accumulator after the full scan.

                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For

                                                                      The purity verdict ⟨isPure, ⟨commonLabel, sawAny⟩⟩.

                                                                      Equations
                                                                      • One or more equations did not get rendered due to their size.
                                                                      Instances For
                                                                        theorem DecisionList.purity_correct (n : ℕ) (msks exs : List ℕ) (hmask : maskOf n = encodeList msks) (hdata : dataOf n = encodeList exs) (hcount : readM (instOf n) = exs.length) (hlen : msks.length = exs.length) :
                                                                        purityVal n = Nat.pair (bNot (bAnd (List.foldl (stepPair (jOf n) (pOf n)) (0, 0) (msks.zip exs)).1 (List.foldl (stepPair (jOf n) (pOf n)) (0, 0) (msks.zip exs)).2)) (Nat.pair (List.foldl (stepPair (jOf n) (pOf n)) (0, 0) (msks.zip exs)).2 (bOr (List.foldl (stepPair (jOf n) (pOf n)) (0, 0) (msks.zip exs)).1 (List.foldl (stepPair (jOf n) (pOf n)) (0, 0) (msks.zip exs)).2))

                                                                        Purity correctness (fold form). On encoded inputs the primitive returns ⟨¬(sawZero ∧ sawOne), sawOne⟩, the covered-label fold over zip msks exs.

                                                                        theorem DecisionList.purity_is_pure_iff (n : ℕ) (msks exs : List ℕ) (hmask : maskOf n = encodeList msks) (hdata : dataOf n = encodeList exs) (hcount : readM (instOf n) = exs.length) (hlen : msks.length = exs.length) :
                                                                        (Nat.unpair (purityVal n)).1 ≠ 0 ↔ ¬((∃ be ∈ msks.zip exs, Covered (jOf n) (pOf n) be ∧ lblOf be.2 = 0) ∧ ∃ be ∈ msks.zip exs, Covered (jOf n) (pOf n) be ∧ lblOf be.2 ≠ 0)

                                                                        isPure characterisation. The verdict's first field is set iff NOT both a covered 0-label and a covered 1-label occur — i.e. iff all covered examples share a label (binary regime).

                                                                        Layer 3 — cPurity is PolyTime (WF/bit-conditional) #

                                                                        The step-cost bound needs, at each visited example, that the mask bit, the read feature bit, and the label are ≤ 1 (the binary-1-DL regime), plus p ≤ 1; the flags sawZero/sawOne are ≤ 1 by the accumulator invariant. Then every gate is O(1) and the only value-scaling cost is the feature peel, O(jOf n). The count readM (instOf n) and the index jOf n are poly-bit only under well-formedness, threaded here as PolyBounded hypotheses (exactly the polyTime_peel pattern).

                                                                        Accumulator-shape invariants #

                                                                        rfind'-freeness of the step code #

                                                                        Per-step cost bound (discharging hstep) #

                                                                        Sub-code val laws at the step input X = ⟨a, ⟨i, acc⟩⟩ (canonical reads), a tc bound for the feature peel, then bottom-up tc bounds culminating in tc_cStep_le: under bit operands every gate is O(1) and the only scaling cost is the feature peel to index jOf a.

                                                                        Structural PolyTime premises #

                                                                        The accumulator stays poly-bit (discharging hacc) #

                                                                        theorem DecisionList.polyTime_c_scan (hCval : TimeCost.PolyBounded fun (n : ℕ) => readM (instOf n)) (Bstep : ℕ → ℕ) (hBstep : TimeCost.PolyBounded Bstep) (hstep : ∀ (n i : ℕ), i < readM (instOf n) → TimeCost.tc cStep (Nat.pair n (Nat.pair i (TimeCost.val (cInit.prec cStep) (Nat.pair n i)))) ≤ Bstep n) :

                                                                        The scan loop is PolyTime — the assembled polyTime_loop closure. The three genuinely WF/bit-conditional analytic facts are threaded as premises (exactly the polyTime_peel pattern the C2a residual note flags): hCval — the example count readM (instOf n) is a poly-bit VALUE (from readM_le_size under WF); Bstep/hstep — a per-step cost bound holding over the visited iterations i < readM (instOf n) (poly-bit under the binary-bit regime: each read is ≤ 1 so every gate is O(1) and only the feature peel scales, O(jOf n)); hacc — the accumulator stays poly-bit (its two suffixes are ≤ maskOf n/dataOf n and its two flags are ≤ 1, by the accumulator invariants). All the STRUCTURAL premises (rfind'-freeness, the shaper PolyTimes, the base cost) are discharged here.

                                                                        Layer 4 — self-contained PolyTime on the binary well-formed domain #

                                                                        The threaded hstep/hCval premises of polyTime_c_scan are ∀-n PolyBounded facts that are FALSE on garbage inputs (a raw slot is exponential in the bit-length), so a meaningful statement must restrict to the well-formed domain. PolyTimeOn D f (CodeLayer/PolyTime.lean; poly-time cost + output size on D) is that honest notion; polyTime_purity proves it for the binary-1-DL domain, with NO poly-bit hypotheses left — they are discharged from readM_le_size/readK_le_size.

                                                                        Mask validity. The mask is a genuine length-m flag-cons list of bits.

                                                                        Equations
                                                                        Instances For

                                                                          The binary well-formed domain for purity: a bit-well-formed instance, a valid mask, p a bit, and a valid literal index j < k (so jOf n ≤ readK).

                                                                          Equations
                                                                          • One or more equations did not get rendered due to their size.
                                                                          Instances For

                                                                            polyTime_purity. With hstep discharged, purity-checking a literal against a working set is poly-time on the honest well-formed domain PurityWF — no PolyBounded side-hypotheses remain.

                                                                            Layer 5 — cReverse: reversing a flag-cons list by a prepending loop #

                                                                            The one genuinely new building block for maskUpdate. The scan that builds the updated mask prepends each new bit (natural in a forward pass), so the working list comes out reversed; one cReverse pass restores order. The step is pure pointer-shuffling (unpair/pair), so it is O(1)-tc regardless of the cell values — hence cReverse is O(m)-tc, uniformly in the list content.

                                                                            remaining field of the reverse accumulator (acc.1), read off the step input ⟨a,⟨i,acc⟩⟩.

                                                                            Equations
                                                                            Instances For

                                                                              Shaper: ⟨L, m⟩ ↦ ⟨L, 0⟩ — the initial reverse accumulator.

                                                                              Equations
                                                                              Instances For

                                                                                Shaper: ⟨L, m⟩ ↦ m — the loop count.

                                                                                Equations
                                                                                Instances For

                                                                                  cReverse: reverse the flag-cons list L given its length m, input packed as ⟨L, m⟩.

                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.
                                                                                  Instances For

                                                                                    cReverse correctness. On an encoded list (length supplied) it returns the encoded reverse.

                                                                                    Layer 6 — maskUpdate: refine the working set by one literal #

                                                                                    maskUpdate inst mask j p produces mask' with mask'[i] = mask[i] ∧ ¬(example i satisfies (j,p)). A forward carried-suffix scan over i < m reads the mask head and the feature-j bit, gates them, and PREPENDS the new bit to a working list (so it comes out reversed); one cReverse pass restores order. The output is again a length-m flag-cons list of bits — that structural fact (maskValid_maskUpdate) is what lets the outer greedy loop carry a valid working set across rounds.

                                                                                    def DecisionList.packLit (inst mask j p : ℕ) :

                                                                                    Pack a literal query ⟨inst, ⟨mask, ⟨j, p⟩⟩⟩ (the input shape shared by cPurity/maskUpdate).

                                                                                    Equations
                                                                                    Instances For

                                                                                      The new-bit gate mask-head ∧ ¬(feature = p) (reuses cB/cEqFP from the purity scan).

                                                                                      Equations
                                                                                      Instances For

                                                                                        The refine-scan step code.

                                                                                        Equations
                                                                                        • One or more equations did not get rendered due to their size.
                                                                                        Instances For

                                                                                          Base code: ⟨maskOf n, ⟨dataOf n, 0⟩⟩ — full suffixes, empty working list.

                                                                                          Equations
                                                                                          Instances For
                                                                                            def DecisionList.maskUpdate (inst mask j p : ℕ) :

                                                                                            maskUpdate inst mask j p — refine the working set mask by literal (j,p).

                                                                                            Equations
                                                                                            Instances For
                                                                                              theorem DecisionList.maskValid_maskUpdate (inst mask j p : ℕ) (hw : WFBits inst) (hm : MaskValid mask (readM inst)) :
                                                                                              MaskValid (maskUpdate inst mask j p) (readM inst)

                                                                                              THE CRUX. maskUpdate preserves mask validity: the refined working set is again a genuine length-m flag-cons list of bits. This is the induction step that lets the outer greedy loop carry a valid working set from round t to t+1.

                                                                                              theorem DecisionList.maskUpdate_get_bit (inst mask j p i : ℕ) (hw : WFBits inst) (hm : MaskValid mask (readM inst)) (hi : i < readM inst) :
                                                                                              headL (peel (maskUpdate inst mask j p) i) = bAnd (headL (peel mask i)) (bNot (bEq (featOf (headL (peel (readData inst) i)) j) p))

                                                                                              maskUpdate's i-th bit (i < m): the old mask bit at i AND NOT (example i satisfies (j,p)), against the List model.

                                                                                              maskUpdate is PolyTime on the well-formed binary domain #

                                                                                              The scan reuses the purity accumulator shape (msOf/exOf at the same slots), so the visited-state bit facts and the gate cost bricks transfer verbatim; the extra cReverse pass is O(m).

                                                                                              polyTime_maskUpdate. Refining the working set by one literal is poly-time on the honest well-formed domain PurityWF — the scan is O(m·k), the cReverse pass O(m), and the output (a length-m bit-list) is ≤ the input mask, hence poly-bit.

                                                                                              Layer 7 — findLit: pick the first pure literal for the working set #

                                                                                              findLit inst mask scans literals (j, p) with j < readK inst, p ∈ {0,1} in increasing order and commits (once) to the first whose purity verdict is pure, packaging ⟨found, j, p, commonLabel⟩. The outer loop is a prec over j; each step invokes cPurity twice (p = 0, p = 1) — a prec-in-prec nest — so the per-step cost is O(m·k) and findLit is O(m·k²), poly on the well-formed domain. The scan freezes after the first hit (never overwrites), so the recorded literal is genuinely pure.

                                                                                              A value-mux gate (bit selector) and the purity-verdict field accessors #

                                                                                              cMux ⟨⟨x,y⟩, c⟩ = if c = 0 then y else x — a value selector recursing on the bit c, hence O(1)-tc on bits regardless of the value operands x, y.

                                                                                              Equations
                                                                                              Instances For

                                                                                                The packed input ⟨inst, mask⟩ of findLit, and its accumulator ⟨found, ⟨j, ⟨p, label⟩⟩⟩.

                                                                                                The instance.

                                                                                                Equations
                                                                                                Instances For

                                                                                                  The remaining-examples mask.

                                                                                                  Equations
                                                                                                  Instances For

                                                                                                    Has a literal been committed to yet?

                                                                                                    Equations
                                                                                                    Instances For
                                                                                                      def DecisionList.flJ (acc : ℕ) :

                                                                                                      The committed literal's feature index.

                                                                                                      Equations
                                                                                                      Instances For
                                                                                                        def DecisionList.flP (acc : ℕ) :

                                                                                                        The committed literal's polarity bit.

                                                                                                        Equations
                                                                                                        Instances For
                                                                                                          def DecisionList.flL (acc : ℕ) :

                                                                                                          The committed literal's common label.

                                                                                                          Equations
                                                                                                          Instances For

                                                                                                            Purity verdict of literal (j,p) on (inst, mask): is-pure bit (.1), common label (.2.1), and covering witness sawAny (.2.2).

                                                                                                            def DecisionList.isPureLit (inst mask j p : ℕ) :

                                                                                                            The is-pure bit: the examples this literal covers did not disagree on their label.

                                                                                                            Equations
                                                                                                            Instances For
                                                                                                              def DecisionList.litLabel (inst mask j p : ℕ) :

                                                                                                              The common label of the examples this literal covers.

                                                                                                              Equations
                                                                                                              Instances For
                                                                                                                def DecisionList.sawAnyLit (inst mask j p : ℕ) :

                                                                                                                The covering witness: this literal covers at least one remaining example.

                                                                                                                Equations
                                                                                                                Instances For
                                                                                                                  def DecisionList.coverLit (inst mask j p : ℕ) :

                                                                                                                  The greedy selection bit: literal (j,p) is a legal pick iff it is pure AND covers ≥1 remaining example (isPure ∧ sawAny). Vacuously-pure (0-covering) literals fail this gate.

                                                                                                                  Equations
                                                                                                                  Instances For

                                                                                                                    The step code: cExpand (two purity calls) then cCombine (bit-logic + muxes) #

                                                                                                                    cFold ⟨isPure, ⟨label, sawAny⟩⟩ = ⟨isPure ∧ sawAny, label⟩ — collapse a 3-field purity verdict into the 2-field ⟨coverLit, litLabel⟩ the greedy combine consumes. Doing the covering ∧ here (not in cCombine) keeps cPurity an honest purity primitive and leaves cCombine unchanged.

                                                                                                                    Equations
                                                                                                                    Instances For

                                                                                                                      cExpand ⟨N,⟨i,acc⟩⟩ = ⟨i, ⟨acc, ⟨⟨cover0,label0⟩, ⟨cover1,label1⟩⟩⟩⟩ — compute both purity verdicts ONCE (exactly two cPurity evaluations), fold each to its covering-pick bit, so the per-step cost is 2·(purity) + O(1).

                                                                                                                      The round index i — the feature the two candidate literals test.

                                                                                                                      Equations
                                                                                                                      Instances For

                                                                                                                        The accumulator, carried through unchanged.

                                                                                                                        Equations
                                                                                                                        Instances For

                                                                                                                          Both verdicts computed and folded, alongside i and the untouched accumulator.

                                                                                                                          Equations
                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                          Instances For

                                                                                                                            cCombine ⟨i,⟨acc,⟨v0,v1⟩⟩⟩ — the greedy update, reading the already-computed verdicts v0,v1. All gates and muxes are O(1) on the bit fields (the only value operands, i/jR, feed muxes whose cost is selector-only).

                                                                                                                            Its pieces, on the input ⟨i, ⟨acc, ⟨v0, v1⟩⟩⟩: the four accumulator fields, the two verdicts' fields, the three commit conditions built from them, and the four updated fields. Note that cFold has already ANDed purity with the covering witness, so a verdict's first field is the covering-pick bit, not bare purity — the IsP in the names is historical. Primed names are the updated fields.

                                                                                                                            Covering-pick bit of the (i, 0) verdict: coverLit — (i, 0) is a pure literal covering ≥ 1 still-live row. This is the verdict's first field, which cFold has already ANDed purity with the covering witness into, so it reads the covering-pick bit, not bare purity.

                                                                                                                            Equations
                                                                                                                            Instances For

                                                                                                                              Covering-pick bit of the (i, 1) verdict: coverLit — (i, 1) is a pure literal covering ≥ 1 still-live row. Its first field is the covering-pick bit (purity already ANDed with the covering witness by cFold), not bare purity.

                                                                                                                              Equations
                                                                                                                              Instances For

                                                                                                                                At least one of this round's two literals is a legal pick.

                                                                                                                                Equations
                                                                                                                                Instances For

                                                                                                                                  This round commits: nothing found yet AND something is available.

                                                                                                                                  Equations
                                                                                                                                  Instances For

                                                                                                                                    Commit to (i, 1) — only when (i, 0) is unavailable, which is the "prefer p = 0" tie-break.

                                                                                                                                    Equations
                                                                                                                                    Instances For

                                                                                                                                      Updated feature index: this round's i if it commits, else the one already held.

                                                                                                                                      Equations
                                                                                                                                      Instances For

                                                                                                                                        Polarity pinned to 0 when (i, 0) is the pick; otherwise the one already held.

                                                                                                                                        Equations
                                                                                                                                        Instances For

                                                                                                                                          Whichever of the two candidate labels belongs to the literal being picked.

                                                                                                                                          Equations
                                                                                                                                          Instances For

                                                                                                                                            Updated label: the chosen one if this round commits, else the one already held.

                                                                                                                                            Equations
                                                                                                                                            Instances For

                                                                                                                                              The updated accumulator ⟨found, ⟨j, ⟨p, label⟩⟩⟩.

                                                                                                                                              Equations
                                                                                                                                              Instances For

                                                                                                                                                One greedy round: expand to both verdicts, then combine.

                                                                                                                                                Equations
                                                                                                                                                Instances For

                                                                                                                                                  Base code: the constant zero accumulator ⟨0, ⟨0, ⟨0, 0⟩⟩⟩.

                                                                                                                                                  Equations
                                                                                                                                                  Instances For

                                                                                                                                                    Correctness of the greedy scan #

                                                                                                                                                    The assembled findLit and its top-level correctness #

                                                                                                                                                    cFindLit's value: the accumulator ⟨found, ⟨j, ⟨p, label⟩⟩⟩ the greedy literal scan settles on for the packed input N = ⟨inst, mask⟩.

                                                                                                                                                    Equations
                                                                                                                                                    Instances For
                                                                                                                                                      theorem DecisionList.find_lit_found_iff (N : ℕ) :
                                                                                                                                                      flFound (findLitVal N) ≠ 0 ↔ ∃ i < readK (flInst N), coverLit (flInst N) (flMask N) i 0 ≠ 0 ∨ coverLit (flInst N) (flMask N) i 1 ≠ 0

                                                                                                                                                      findLit completeness (covering form). found fires iff some literal (j, ·) with j < readK inst is a covering pure pick — pure AND covering ≥1 remaining example.

                                                                                                                                                      findLit soundness (covering form). If found, the recorded ⟨j, p, label⟩ is a valid literal (j < readK inst, p a bit) that is a covering pure pick (coverLit ≠ 0, i.e. pure AND covering ≥1 remaining example — see coverLit_covers) with its common label.

                                                                                                                                                      Accumulator invariants (for the cost/size bounds) #

                                                                                                                                                      The per-step cost: two purity calls (cExpand) plus an O(1) combine #

                                                                                                                                                      rfind'-freeness and the PolyTimeOn capstone #

                                                                                                                                                      polyTime_find_lit. Selecting the first pure literal for the working set is poly-time on the honest well-formed domain FindLitWF — O(m·k²) (k rounds, each two purity calls of O(m·k)), with a bit/index-sized output. No PolyBounded side-hypotheses remain.

                                                                                                                                                      Layer 8 — the greedy outer loop solve (C2b-outer) #

                                                                                                                                                      solve inst mask0 runs readM inst rounds of: find the first covering pure literal for the current working set; if found, append its rule and refine the mask; else freeze. Termination is by construction (a prec of readM inst = m rounds — enough because each covering round strictly drops the mask's set-bit count, so ≤ m covering rounds empty it; the count-decrease measure and covering-soundness are the two ingredients C2c consumes). The accumulator is ⟨mask, ⟨cnt, outDL⟩⟩: the working mask, the rule count, and the output decision-list built by prepend (a flag-cons list of ⟨j,⟨p,label⟩⟩ triples); one final cReverse (length cnt) restores forward order.

                                                                                                                                                      Packed-input and accumulator accessors #

                                                                                                                                                      The input is ⟨inst, mask0⟩ and the accumulator ⟨mask, ⟨cnt, outDL⟩⟩.

                                                                                                                                                      The instance.

                                                                                                                                                      Equations
                                                                                                                                                      Instances For

                                                                                                                                                        The starting mask.

                                                                                                                                                        Equations
                                                                                                                                                        Instances For

                                                                                                                                                          The current working mask.

                                                                                                                                                          Equations
                                                                                                                                                          Instances For

                                                                                                                                                            How many rules have been emitted.

                                                                                                                                                            Equations
                                                                                                                                                            Instances For

                                                                                                                                                              The output decision list, in prepend (reversed) order.

                                                                                                                                                              Equations
                                                                                                                                                              Instances For

                                                                                                                                                                The semantic round #

                                                                                                                                                                The round as a Code: cSvStep = cSvB ∘ cSvA (one findLit, then one maskUpdate + #

                                                                                                                                                                mux)

                                                                                                                                                                Stage A: from ⟨n, ⟨i, acc⟩⟩ build ⟨inst, ⟨acc, lit⟩⟩ — exactly one findLit evaluation, so the round pays for the literal scan once.

                                                                                                                                                                The working mask, out of the accumulator.

                                                                                                                                                                Equations
                                                                                                                                                                Instances For

                                                                                                                                                                  Stage A assembled: the instance, the accumulator, and this round's literal.

                                                                                                                                                                  Equations
                                                                                                                                                                  Instances For

                                                                                                                                                                    Stage B: from ⟨inst, ⟨acc, lit⟩⟩ build the new accumulator — one maskUpdate, then a single mux over the whole accumulator on whether a literal was found. The cB* names project the three components and their fields; cBupd is the found-branch accumulator.

                                                                                                                                                                    Was a covering literal found this round?

                                                                                                                                                                    Equations
                                                                                                                                                                    Instances For

                                                                                                                                                                      The mask refined by the found literal — the examples it covers drop out.

                                                                                                                                                                      Equations
                                                                                                                                                                      Instances For

                                                                                                                                                                        The rule prepended to the output list, as a flag-cons cell.

                                                                                                                                                                        Equations
                                                                                                                                                                        Instances For

                                                                                                                                                                          The found-branch accumulator: refined mask, bumped count, extended list.

                                                                                                                                                                          Equations
                                                                                                                                                                          Instances For

                                                                                                                                                                            Stage B assembled: take cBupd if a literal was found, else freeze the accumulator.

                                                                                                                                                                            Equations
                                                                                                                                                                            Instances For

                                                                                                                                                                              One greedy round: stage A then stage B.

                                                                                                                                                                              Equations
                                                                                                                                                                              Instances For

                                                                                                                                                                                The loop, the assemble (cReverse), and solve #

                                                                                                                                                                                Base code: start from the given mask with no rules emitted.

                                                                                                                                                                                Equations
                                                                                                                                                                                Instances For

                                                                                                                                                                                  The accumulator after t greedy rounds.

                                                                                                                                                                                  Equations
                                                                                                                                                                                  Instances For

                                                                                                                                                                                    The round budget readM inst — one round per example.

                                                                                                                                                                                    Equations
                                                                                                                                                                                    Instances For

                                                                                                                                                                                      The final cReverse (length cnt) turns the prepend-order list forward and repackages ⟨finalMask, forwardDL⟩.

                                                                                                                                                                                      Equations
                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                      Instances For

                                                                                                                                                                                        solve's code: run the greedy loop readM inst rounds, then reverse-and-repackage.

                                                                                                                                                                                        Equations
                                                                                                                                                                                        Instances For

                                                                                                                                                                                          cSolve's value: the pair ⟨finalMask, forwardDL⟩. The mask is empty exactly when the emitted decision list is consistent with every example (solve_decides).

                                                                                                                                                                                          Equations
                                                                                                                                                                                          Instances For

                                                                                                                                                                                            Obligation 4 — the round-to-round MaskValid invariant #

                                                                                                                                                                                            The load-bearing invariant for both the poly-time accumulator bound and C2c: the working mask stays a valid length-m bit-list and never grows. maskValid_maskUpdate gives validity on a found round; maskUpdateVal_le (via updBit_le) gives the shrink; the no-op round preserves both trivially.

                                                                                                                                                                                            theorem DecisionList.dl_model_svAcc (n t : ℕ) :
                                                                                                                                                                                            ∃ (L : List ℕ), svDL (svAcc n t) = encodeList L ∧ svCnt (svAcc n t) = L.length ∧ ∀ e ∈ L, e ≤ Nat.pair (readK (svInst n)) 3

                                                                                                                                                                                            The output-list List model. After t rounds svDL is the flag-cons encoding of a genuine List of svCnt rule-triples, each ≤ ⟨readK, 3⟩ (index ≤ readK, two bits). Unconditional: the literal bounds flJ ≤ readK, flP,flL ≤ 1 hold on every round. This is what lets cReverse produce an encodeList (hence bound its Nat.size) for the output-size clause.

                                                                                                                                                                                            MaskValid of solve's output mask — the C2c-facing packaging.

                                                                                                                                                                                            Obligation 3, part A — the per-round native cost (one findLit + one maskUpdate + O(1)) #

                                                                                                                                                                                            cSvA evaluates findLit once, cSvB evaluates maskUpdate once and muxes; both surrounding stages are O(1) pointer-shuffles. findLit/maskUpdate are kept OPAQUE atoms (their val/tc hide symbolic scans) so omega never whnf-descends into them.

                                                                                                                                                                                            Obligation 3, part B — the output is poly-bit despite the exponential flag-cons encoding #

                                                                                                                                                                                            The flag-cons encoding cons e r = pair 1 (pair e r) SQUARES the tail (Nat.pair a b ≈ (max a b)²), so the encoded output list's Nat.size grows ~×4 per rule — EXPONENTIAL in the rule count svCnt. The output would be super-polynomial were svCnt free; it is not. Two facts close the gap:

                                                                                                                                                                                            Obligation 3, part C — the native cost is poly-bit (k rounds × O(m·k²) per round) #

                                                                                                                                                                                            solve runs readM inst rounds; each round is one findLit (O(m·k²)) + one maskUpdate (O(m·k))

                                                                                                                                                                                            Per-round maskUpdate budget (O(m·k)), uniform in the round via jOf ≤ readK.

                                                                                                                                                                                            Equations
                                                                                                                                                                                            Instances For

                                                                                                                                                                                              Per-round findLit budget (O(m·k²)), uniform in the round.

                                                                                                                                                                                              Equations
                                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                                              Instances For
                                                                                                                                                                                                def DecisionList.Bsv (inst : ℕ) :

                                                                                                                                                                                                The full per-round budget.

                                                                                                                                                                                                Equations
                                                                                                                                                                                                Instances For
                                                                                                                                                                                                  theorem DecisionList.tc_cSolve_raw (n : ℕ) (hw : WFBits (svInst n)) (hm0 : MaskValid (svMask0 n) (readM (svInst n))) :

                                                                                                                                                                                                  cSolve's native cost on a well-formed instance: the O(m) read-out (tc_cAssemble_le) + the (Bsv+1)·m loop (tc_prec_le' + tc_cSvStep_visited_le) + O(1) shapers sum to ≤ (Bsv+42)·m + 67.

                                                                                                                                                                                                  rfind'-freeness of the solve code (structural — every atom is a bounded loop) #

                                                                                                                                                                                                  polyTime_solve. The greedy 1-DL consistency solver is poly-time on the honest well-formed domain SolveWF — O(m²·k²) native cost, output a poly-bit decision list. No PolyBounded side-hypotheses remain; the exponential flag-cons output stays poly-bit because the instance pays (exponentially) for its m examples (two_pow_readM_le). C2c owns greedy CORRECTNESS.

                                                                                                                                                                                                  Layer 9 — C2c: greedy correctness (solve decides 1-DL consistency) #

                                                                                                                                                                                                  The capstone that makes the poly(m,k) timing meaningful: solve empties its mask iff a consistent 1-decision-list over the Boolean features exists. Worked entirely at the List model, over the SAME featOf/lblOf accessors the solver's bridge lemmas (find_lit_sound, coverLit_covers, purity_*, maskUpdate_get_bit) speak. A rule is a Nat-triple ⟨j,⟨p,label⟩⟩ (matching the emitted svDL), decoded by ruleJ/ruleP/ruleL; a rule FIRES on example e iff feature j of e equals p.

                                                                                                                                                                                                  The List-model 1-decision-list semantics #

                                                                                                                                                                                                  Feature index of an encoded rule triple ⟨j,⟨p,label⟩⟩.

                                                                                                                                                                                                  Equations
                                                                                                                                                                                                  Instances For

                                                                                                                                                                                                    Polarity of an encoded rule triple.

                                                                                                                                                                                                    Equations
                                                                                                                                                                                                    Instances For

                                                                                                                                                                                                      Output label of an encoded rule triple.

                                                                                                                                                                                                      Equations
                                                                                                                                                                                                      Instances For

                                                                                                                                                                                                        1-DL evaluation (first-match). evalDLn rules default e = the label of the first rule that fires on e, else default. A rule fires iff its feature-ruleJ bit of e matches ruleP (bEq … ≠ 0 — the SAME gate the solver's Covered uses, so on bit-polarities it is featOf = ruleP).

                                                                                                                                                                                                        Equations
                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                          def DecisionList.Consistent (rules : List ℕ) (d : ℕ) (exs : List ℕ) :

                                                                                                                                                                                                          Consistency. Every example is classified to its own label by the DL.

                                                                                                                                                                                                          Equations
                                                                                                                                                                                                          Instances For

                                                                                                                                                                                                            Existence of a consistent 1-DL over VALID feature literals (ruleJ < readK inst) — the literal space the solver searches. This is what solve decides.

                                                                                                                                                                                                            Equations
                                                                                                                                                                                                            Instances For

                                                                                                                                                                                                              Abstract evalDLn laws (pure list algebra) #

                                                                                                                                                                                                              Bridging the semantic Covered/label facts to coverLit/litLabel #

                                                                                                                                                                                                              Engine Lemma 1 — PROGRESS #

                                                                                                                                                                                                              theorem DecisionList.progress (inst mask : ℕ) (hk : 0 < readK inst) (msks exs : List ℕ) (hmeq : mask = encodeList msks) (hdeq : readData inst = encodeList exs) (hcount : readM inst = exs.length) (hlen : msks.length = exs.length) (hfeat1 : ∀ e ∈ exs, ∀ (j : ℕ), featOf e j ≤ 1) (hne : ∃ be ∈ msks.zip exs, be.1 ≠ 0) (rules : List ℕ) (d : ℕ) (hval : ∀ r ∈ rules, ruleJ r < readK inst) (hcons : ∀ be ∈ msks.zip exs, be.1 ≠ 0 → evalDLn rules d be.2 = lblOf be.2) :
                                                                                                                                                                                                              ∃ (j : ℕ) (p : ℕ), j < readK inst ∧ p ≤ 1 ∧ coverLit inst mask j p ≠ 0

                                                                                                                                                                                                              ENGINE LEMMA 1 — PROGRESS. If the currently-remaining examples (be.1 ≠ 0 in msks.zip exs) admit a consistent 1-DL (with valid indices), and there is ≥1 remaining, then some feature-literal (j,p) with j < readK is COVERING PURE on them (coverLit ≠ 0) — so findLit cannot stall.

                                                                                                                                                                                                              ⚠️ The two cases: (B) some rule of the DL fires on a remaining example — take the FIRST such rule r0; every remaining example it covers is (by first-ness + consistency) classified by r0 alone, so they share ruleL r0 ⇒ pure. (A) NO rule fires on any remaining example — then all remaining fall to the DEFAULT, so they are monochromatic; picking feature 0 (needs readK ≥ 1) against any remaining example's own bit gives a covering pure literal.

                                                                                                                                                                                                              Engine Lemma 2 — OUTPUT CONSISTENCY #

                                                                                                                                                                                                              The round invariant, tracking the forward emitted DL D and the working mask M: every removed example is classified by D to its own label (via a firing rule), every remaining example fires NO rule of D. The firing-step is factored as corrInvD_fire with the literal (j,p,l) ABSTRACT — so no tactic ever whnf-descends the symbolic findLitVal (the opaque-verdict convention: folded verdicts stay symbolic behind an opaque literal).

                                                                                                                                                                                                              theorem DecisionList.output_consistent (n : ℕ) (hw : WFBits (svInst n)) (hm0 : MaskValid (svMask0 n) (readM (svInst n))) (hone : svMask0 n = encodeList (List.replicate (readM (svInst n)) 1)) (hfinal : ∀ i < readM (svInst n), headL (peel (svMask (svAcc n (readM (svInst n)))) i) = 0) (exs : List ℕ) (hdeq : readData (svInst n) = encodeList exs) (hdlen : exs.length = readM (svInst n)) :
                                                                                                                                                                                                              ∃ (rules : List ℕ) (d : ℕ), (∀ r ∈ rules, ruleJ r < readK (svInst n)) ∧ ∀ e ∈ exs, evalDLn rules d e = lblOf e

                                                                                                                                                                                                              ENGINE LEMMA 2 — OUTPUT CONSISTENCY. If solve (from the all-ones mask) empties its mask, its emitted forward DL D is a consistent 1-DL (valid indices) for ALL examples: every example is removed at the round whose covering rule first fires on it, and by purity that rule's label is the example's.

                                                                                                                                                                                                              C2c-ii — the monovariant and the decision theorem #

                                                                                                                                                                                                              The greedy loop runs a FIXED readM rounds, so turning "a consistent 1-DL exists" into "the final mask is empty" needs a monovariant. Track activeCount M = ∑_{i<m} bit_i — the number of still-remaining examples. Two facts drive it to zero within m rounds:

                                                                                                                                                                                                              The monovariant: number of still-active bits among the first m mask slots.

                                                                                                                                                                                                              Equations
                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                theorem DecisionList.activeCount_bound (n : ℕ) (hw : WFBits (svInst n)) (hk : 0 < readK (svInst n)) (hm0 : MaskValid (svMask0 n) (readM (svInst n))) (hone : svMask0 n = encodeList (List.replicate (readM (svInst n)) 1)) (exs : List ℕ) (hdeq : readData (svInst n) = encodeList exs) (hdlen : exs.length = readM (svInst n)) (hcons : ExistsConsistentDL (svInst n) exs) (t : ℕ) :
                                                                                                                                                                                                                activeCount (svMask (svAcc n t)) (readM (svInst n)) + t ≤ readM (svInst n) ∨ ∀ i < readM (svInst n), headL (peel (svMask (svAcc n t)) i) = 0

                                                                                                                                                                                                                The monovariant bound. For a consistent 1-DL, after t rounds either the count has fallen by t (so activeCount + t ≤ m) or the mask is already empty. At t = m both force the mask empty.

                                                                                                                                                                                                                theorem DecisionList.solve_decides (n : ℕ) (hn : SolveWF n) (hk : 0 < readK (svInst n)) (hone : svMask0 n = encodeList (List.replicate (readM (svInst n)) 1)) (exs : List ℕ) (hdeq : readData (svInst n) = encodeList exs) (hdlen : exs.length = readM (svInst n)) :
                                                                                                                                                                                                                (∀ i < readM (svInst n), headL (peel (svMask (svAcc n (readM (svInst n)))) i) = 0) ↔ ExistsConsistentDL (svInst n) exs

                                                                                                                                                                                                                C2c CAPSTONE — greedy correctness. From the all-ones mask, solve empties its mask iff a consistent 1-DL over valid feature literals exists. (⇒) is Engine Lemma 2 (output_consistent); (⇐) is the monovariant (activeCount_bound), driving the count to 0 within readM rounds.

                                                                                                                                                                                                                Axiom-cleanliness guards (CI-enforced) #

                                                                                                                                                                                                                Each guard fails lake build if the theorem's axiom set ever drifts from the standard [propext, Classical.choice, Quot.sound].