Data layer for the 1-DL and conjunction consistency solvers #
Provenance: the native cost model (CodeLayer/TimeCost.lean). Builds on CodeLayer/PolyTime.lean
(PolyTime, PolyBounded, the base/comp closures, polyTime_loop, tc_prec_le',
exists_two_pow_gt_poly). Downstream: the greedy 1-decision-list consistency solver
(DecisionListSolver.lean) and the conjunction consistency solver (ConjunctionSolver.lean), whose
scan/peel loops iterate over the m examples and k features.
Besides the instance encoding (WF, the flat/indexed accessors, peel/cPeel), this module also
carries the labelled bit-example layer shared by every rule-class solver that reads examples
against a Boolean feature vector: lblOf/fvOf/featOf (an example's label, feature vector, and
j-th feature bit) and WFBits (the binary well-formedness regime both solvers assume).
The decode-cost verdict, and the flag-cons PIVOT #
An offset-cons encoding cons e r = Nat.pair e r + 1 would need a predecessor to decode. There is
no primitive predecessor in the rfind'-free fragment; the smallest cPred (prec, recursing on the
value) iterates VALUE-many times, so n ≤ tc cPred n (cpred_tc_ge) and hence tc cPred is NOT
poly-bounded (cPred_tc_not_polyBounded) — a predecessor-based peel step is value-linear, so route
(a) FAILS. We therefore PIVOT to a flag cons: nil = 0, cons e r = Nat.pair 1 (Nat.pair e r),
which decodes by pure unpair (flag = left, head = left ∘ right, tail = right ∘ right), all
tc = O(1). The flag 1 disambiguates nil from cons and each cons still strictly grows
Nat.size (size_cons_gt), so the size bound re-proves cleanly.
Encoding #
inst = Nat.pair k (Nat.pair m data) — k, m are flat slots. data is a flag-cons list of m
examples; an example is Nat.pair label fv with fv a flag-cons list of k bits.
What this establishes (C2a, the data layer — complete) #
Part 1: encoding + WF, the flat accessors cReadK/cReadM (PolyTime, tc = O(1)), and the
size bound readM/readK inst ≤ Nat.size inst under WF (I2). Part 2: the decode-cost verdict +
pivot; the peel loop (cPeel, O(1)-tc step) and the indexed accessors
getExample/getLabel/getFeature, each PolyTime GIVEN a poly-bit index (polyTime_peel); and
List-model correctness (get_example_encode). One residual — polyTime_peel needs the index's
PolyBounded as a HYPOTHESIS, since the natural index (readM) is only poly-bit under WF; that
is what the solver layer (C2b, Learning/DecisionListSolver.lean) must thread.
Step 0 — the predecessor cost verdict: value-linear, hence the flag-cons pivot #
The smallest rfind'-free predecessor: prec zero (comp left right) recursing on the value
returns the previous index, i.e. n - 1. It first pairs ⟨0, n⟩ (the shaper
pair zero (pair left right)).
Equations
Instances For
The verdict. The predecessor's native cost is NOT poly-bounded — route (a) (a predecessor-based peel) is value-linear, forcing the flag-cons pivot below.
The flag-cons list predicate and the instance layout #
#features k, directly readable as inst.unpair.1.
Equations
- DecisionList.readK inst = (Nat.unpair inst).1
Instances For
#examples m, directly readable as (inst.unpair.2).unpair.1.
Equations
- DecisionList.readM inst = (Nat.unpair (Nat.unpair inst).2).1
Instances For
The example-list data, at (inst.unpair.2).unpair.2.
Equations
- DecisionList.readData inst = (Nat.unpair (Nat.unpair inst).2).2
Instances For
The head example of data (flag-cons: head = left ∘ right).
Equations
- DecisionList.firstExample inst = (Nat.unpair (Nat.unpair (DecisionList.readData inst)).2).1
Instances For
The feature vector of the head example (example = ⟨label, fv⟩).
Equations
- DecisionList.firstFV inst = (Nat.unpair (DecisionList.firstExample inst)).2
Instances For
Flat accessor Codes (rfind'-free, tc = O(1)), and their PolyTime certificates #
k-accessor: left (tc = 1).
Equations
Instances For
m-accessor: comp left right (tc = 3).
Instances For
The k-accessor is PolyTime. The WF-conditional VALUE bound is readK_le_size.
The m-accessor is PolyTime. The WF-conditional VALUE bound is readM_le_size.
The peel loop and the indexed accessors #
Flag-cons tail: right ∘ right.
Equations
- DecisionList.tailL L = (Nat.unpair (Nat.unpair L).2).2
Instances For
Flag-cons head (the current example): left ∘ right.
Equations
- DecisionList.headL L = (Nat.unpair (Nat.unpair L).2).1
Instances For
The step Code for the peel loop: apply tailL to the accumulator. tc = 7,
magnitude-INDEPENDENT (pure unpair — the whole point of the flag-cons pivot).
Equations
Instances For
The peel accessor is PolyTime given a poly-bit index. For any PolyTime shaper A
(initial list) and index C that is ALSO poly-bit as a VALUE (hCval), n ↦ peel (A n) (C n) is
PolyTime. A direct polyTime_loop instance: count = C discharges hCval; the accumulator (a
suffix) is ≤ A n (peel_le), so hacc is A's size clause; the step cost is the constant 7
(tc_cTailStep) — routed through tc_prec_le'. The hCval premise is the residual C2b must
supply: the natural index readM is poly-bit only under WF.
getExample is PolyTime given a poly-bit index: n ↦ headL (peel (A n) (C n)).
getLabel is PolyTime given a poly-bit index: the label is (example).unpair.1.
getFeature is PolyTime given poly-bit indices Ci (example) and Cj (feature): peel
the i-th example's feature vector Cj n times and read the head bit. A second polyTime_peel,
with the inner shaper being getExample's feature-vector projection (itself PolyTime).
Encode a List ℕ as a flag-cons list.
Equations
- DecisionList.encodeList [] = 0
- DecisionList.encodeList (x_1 :: xs) = Nat.pair 1 (Nat.pair x_1 (DecisionList.encodeList xs))
Instances For
The labelled bit-example encoding #
Shared by every consumer that reads a ⟨label, fv⟩-encoded example against a Boolean feature
vector — the 1-DL solver (DecisionListSolver.lean, DecisionListPredictor.lean) and the
conjunction solver (ConjunctionSolver.lean) alike. Moved here (from DecisionListSolver.lean)
since none of it is about decision lists: it is the shared instance-encoding layer every rule-class
solver reads examples through.
The label of an example e = ⟨label, fv⟩.
Equations
- DecisionList.lblOf e = (Nat.unpair e).1
Instances For
Feature j of example e: peel its feature-vector j cells and read the head bit.