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.
Instances For
Reads as Codes #
headL as a Code (comp left right).
Instances For
tailL as a Code (comp right right).
Instances For
The packed input and its projections #
n = ⟨inst, ⟨mask, ⟨j, p⟩⟩⟩.
The instance component of the packed input.
Equations
- DecisionList.instOf n = (Nat.unpair n).1
Instances For
The remaining-examples mask.
Equations
- DecisionList.maskOf n = (Nat.unpair (Nat.unpair n).2).1
Instances For
The literal's feature index j.
Equations
- DecisionList.jOf n = (Nat.unpair (Nat.unpair (Nat.unpair n).2).2).1
Instances For
The literal's polarity bit p.
Equations
- DecisionList.pOf n = (Nat.unpair (Nat.unpair (Nat.unpair n).2).2).2
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.
maskOf as a Code.
Instances For
The accumulator ⟨maskSuf, ⟨exSuf, ⟨sawZero, sawOne⟩⟩⟩ and the initial-state code #
The unscanned suffix of the example list.
Equations
- DecisionList.exOf acc = (Nat.unpair (Nat.unpair acc).2).1
Instances For
The sawZero flag: some covered example so far carried label 0.
Equations
- DecisionList.z0Of acc = (Nat.unpair (Nat.unpair (Nat.unpair acc).2).2).1
Instances For
The sawOne flag: some covered example so far carried label 1.
Equations
- DecisionList.z1Of acc = (Nat.unpair (Nat.unpair (Nat.unpair acc).2).2).2
Instances For
The initial accumulator: full suffixes, both flags 0.
Equations
- DecisionList.initAcc mask data = Nat.pair mask (Nat.pair data (Nat.pair 0 0))
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 accumulator.
Instances For
The literal's feature index j, from the seed.
Instances For
The literal's polarity bit p, from the seed.
Instances For
The mask suffix.
Instances For
The example suffix.
Equations
Instances For
The sawZero flag.
Equations
Instances For
The sawOne flag.
Equations
Instances For
The current mask bit: is this example still in play?
Instances For
The current example.
Instances For
The current example's label.
Instances For
The current example's feature vector.
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?
Instances For
Coverage: the example is still remaining AND the literal matches it.
Instances For
The current example's label, negated.
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
The step: peel both suffixes one cell and carry the two updated flags.
Equations
Instances For
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
Characterising the fold: sawZero/sawOne as coverage existentials #
A (maskBit, example) pair is covered by literal (j,p): still remaining and the gate
accepts its feature-j bit against p.
Equations
- DecisionList.Covered j p be = (be.1 ≠ 0 ∧ DecisionList.bEq (DecisionList.featOf be.2 j) p ≠ 0)
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).
The sawZero flag of the final accumulator.
Equations
Instances For
The sawOne flag of the final accumulator.
Equations
Instances For
sawAny = sawZero ∨ sawOne: the literal covered at least one remaining example.
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).
Instances For
The iteration count readM (instOf n) — the number of examples.
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
Purity correctness (fold form). On encoded inputs the primitive returns
⟨¬(sawZero ∧ sawOne), sawOne⟩, the covered-label fold over zip msks exs.
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) #
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
prefix field of the reverse accumulator (acc.2).
Equations
Instances For
The reverse step code: ⟨tailL remaining, cons (headL remaining) prefix⟩.
Equations
Instances For
Shaper: ⟨L, m⟩ ↦ ⟨L, 0⟩ — the initial reverse accumulator.
Instances For
Shaper: ⟨L, m⟩ ↦ m — the loop count.
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.
Pack a literal query ⟨inst, ⟨mask, ⟨j, p⟩⟩⟩ (the input shape shared by
cPurity/maskUpdate).
Equations
- DecisionList.packLit inst mask j p = Nat.pair inst (Nat.pair mask (Nat.pair j p))
Instances For
The working-list field acc.2.2.
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
The refine scan run readM inst times.
Equations
Instances For
maskUpdate's code: run the scan, extract the reversed working list, then cReverse it.
Equations
Instances For
maskUpdate inst mask j p — refine the working set mask by literal (j,p).
Equations
- DecisionList.maskUpdate inst mask j p = DecisionList.maskUpdateVal (DecisionList.packLit inst mask j p)
Instances For
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.
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⟩⟩⟩.
Has a literal been committed to yet?
Equations
- DecisionList.flFound acc = (Nat.unpair acc).1
Instances For
The committed literal's feature index.
Equations
- DecisionList.flJ acc = (Nat.unpair (Nat.unpair acc).2).1
Instances For
The committed literal's polarity bit.
Equations
- DecisionList.flP acc = (Nat.unpair (Nat.unpair (Nat.unpair acc).2).2).1
Instances For
The committed literal's common label.
Equations
- DecisionList.flL acc = (Nat.unpair (Nat.unpair (Nat.unpair acc).2).2).2
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).
The is-pure bit: the examples this literal covers did not disagree on their label.
Equations
- DecisionList.isPureLit inst mask j p = (Nat.unpair (DecisionList.purityVal (DecisionList.packLit inst mask j p))).1
Instances For
The common label of the examples this literal covers.
Equations
- DecisionList.litLabel inst mask j p = (Nat.unpair (Nat.unpair (DecisionList.purityVal (DecisionList.packLit inst mask j p))).2).1
Instances For
The covering witness: this literal covers at least one remaining example.
Equations
- DecisionList.sawAnyLit inst mask j p = (Nat.unpair (Nat.unpair (DecisionList.purityVal (DecisionList.packLit inst mask j p))).2).2
Instances For
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
- DecisionList.coverLit inst mask j p = DecisionList.bAnd (DecisionList.isPureLit inst mask j p) (DecisionList.sawAnyLit inst mask j p)
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 instance, out of the seed.
Instances For
The mask, out of the seed.
Instances For
The round index i — the feature the two candidate literals test.
Instances For
The accumulator, carried through unchanged.
Instances For
The purity call for the negative literal (i, 0).
Equations
Instances For
The purity call for the positive literal (i, 1).
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.
The accumulator.
Instances For
The verdict for the negative literal (i, 0).
Equations
Instances For
The verdict for the positive literal (i, 1).
Equations
Instances For
Has a literal been committed to yet?
Instances For
The committed feature index.
Equations
Instances For
The committed polarity bit.
Equations
Instances For
The committed common label.
Equations
Instances For
The common label (i, 0) would carry.
Instances For
The common label (i, 1) would carry.
Instances For
Nothing committed yet.
Instances For
At least one of this round's two literals is a legal pick.
Instances For
This round commits: nothing found yet AND something is available.
Instances For
Commit to (i, 0).
Instances For
Commit to (i, 1) — only when (i, 0) is unavailable, which is the "prefer p = 0"
tie-break.
Equations
Instances For
Updated found flag.
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.
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 #
The literal count readK (flInst N).
Instances For
findLit's code: run the greedy scan readK inst rounds.
Equations
Instances For
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
The well-formed domain for findLit.
Equations
Instances For
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) #
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⟩⟩.
How many rules have been emitted.
Equations
- DecisionList.svCnt acc = (Nat.unpair (Nat.unpair acc).2).1
Instances For
The output decision list, in prepend (reversed) order.
Equations
- DecisionList.svDL acc = (Nat.unpair (Nat.unpair acc).2).2
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 instance.
Instances For
The accumulator.
Instances For
The working mask, out of the accumulator.
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.
The instance.
Equations
Instances For
The accumulator.
Instances For
This round's literal.
Instances For
The working mask.
Instances For
Was a covering literal found this round?
Instances For
The literal's feature index.
Equations
Instances For
The literal's polarity bit.
Equations
Instances For
The literal's common label.
Equations
Instances For
The rule count.
Equations
Instances For
The output list so far.
Equations
Instances For
The mask refined by the found literal — the examples it covers drop out.
Equations
Instances For
The emitted rule ⟨j, ⟨p, label⟩⟩.
Instances For
The rule prepended to the output list, as a flag-cons cell.
Equations
Instances For
The bumped rule count.
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.
Instances For
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.
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.
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
The well-formed domain for solve.
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.
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:
- an exp-size lower bound on the INPUT (
two_pow_length_le:2^(length) ≤ size(encodeList) + 1), so2^(readM) ≤ Nat.size n + 1— the instance already PAYS (exponentially) for itsmexamples; svCnt ≤ readMrules, each anO(size n)-bit triple, so the output list has≤ readMcells and an exp-size upper boundsize_encodeList_legivessize ≤ (4·size V + 8)·4^(svCnt). Then4^(svCnt) ≤ 4^(readM) = (2^readM)² ≤ (size n + 1)², and the output is a cubic inNat.size n.
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))
O(1), soO(m·k²)per round andO(m²·k²)overall, plus anO(m)finalcReverse. The per-round budget is uniform over the visited rounds because the working mask staysMaskValid(maskValid_svAcc), so every round'sfindLit/maskUpdatequery is well-formed withreadK/readMfixed at the instance's.
Per-round maskUpdate budget (O(m·k)), uniform in the round via jOf ≤ readK.
Equations
- DecisionList.BsvMask inst = (8 * DecisionList.readK inst + 2401) * DecisionList.readM inst + 41 * DecisionList.readM inst + 100
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
The full per-round budget.
Equations
- DecisionList.Bsv inst = DecisionList.BsvMask inst + DecisionList.BsvFind inst + 341
Instances For
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.
Feature index of an encoded rule triple ⟨j,⟨p,label⟩⟩.
Equations
- DecisionList.ruleJ r = (Nat.unpair r).1
Instances For
Polarity of an encoded rule triple.
Equations
- DecisionList.ruleP r = (Nat.unpair (Nat.unpair r).2).1
Instances For
Output label of an encoded rule triple.
Equations
- DecisionList.ruleL r = (Nat.unpair (Nat.unpair r).2).2
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
- One or more equations did not get rendered due to their size.
- DecisionList.evalDLn [] x✝¹ x✝ = x✝¹
Instances For
Consistency. Every example is classified to its own label by the DL.
Equations
- DecisionList.Consistent rules d exs = ∀ e ∈ exs, DecisionList.evalDLn rules d e = DecisionList.lblOf e
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
- DecisionList.ExistsConsistentDL inst exs = ∃ (rules : List ℕ) (d : ℕ), (∀ r ∈ rules, DecisionList.ruleJ r < DecisionList.readK inst) ∧ DecisionList.Consistent rules d exs
Instances For
Engine Lemma 1 — PROGRESS #
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).
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:
- PROGRESS (
fire_of_active): while the mask has an active bit, a consistent DL forces a covering-pure literal (progress), sofindLitfires that round; - SHRINK (
activeCount_fire_lt): a firing round zeroes ≥1 active bit (coverLit_covers+maskUpdate_get_bit), soactiveCountstrictly drops. From the all-ones mask (activeCount = m), aftermrounds the count is0, i.e. the mask is empty. The converse is Engine Lemma 2 (output_consistent). Packaged assolve_decides.
The monovariant: number of still-active bits among the first m mask slots.
Equations
- DecisionList.activeCount M m = ∑ i ∈ Finset.range m, DecisionList.headL (DecisionList.peel M i)
Instances For
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.
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].