Documentation

Learning.DecisionListData

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 (lower bound). n ≤ tc cPred n: the predecessor costs at least the VALUE of its input — Θ(n), exponential in Nat.size n.

    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 #

    inductive DecisionList.IsList :
    ℕ → ℕ → Prop

    IsList L m: L is a flag-cons list of length m (nil = 0, cons e r = pair 1 (pair e r)). Structural — tracks length, which is all the count bound needs.

    Instances For
      def DecisionList.readK (inst : ℕ) :

      #features k, directly readable as inst.unpair.1.

      Equations
      Instances For
        def DecisionList.readM (inst : ℕ) :

        #examples m, directly readable as (inst.unpair.2).unpair.1.

        Equations
        Instances For

          The example-list data, at (inst.unpair.2).unpair.2.

          Equations
          Instances For

            The head example of data (flag-cons: head = left ∘ right).

            Equations
            Instances For

              The feature vector of the head example (example = ⟨label, fv⟩).

              Equations
              Instances For
                def DecisionList.WF (inst : ℕ) :

                Well-formedness. At least one example; data is a genuine length-m list; and the head example's feature vector is a genuine length-k list. Under WF, both counts are ≤ Nat.size inst.

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

                  Growth: a length-m flag-cons list has Nat.size ≥ m #

                  The key growth step. A flag-cons cell strictly increases Nat.size.

                  theorem DecisionList.isList_len_le_size {L m : ℕ} :
                  IsList L m → m ≤ L.size

                  Length ≤ bit-length. A genuine length-m flag-cons list L has m ≤ Nat.size L.

                  The load-bearing size bound (I2): the counts are poly-bit under WF #

                  theorem DecisionList.readData_le (inst : ℕ) :
                  readData inst ≤ inst
                  theorem DecisionList.readM_le_size (inst : ℕ) (h : WF inst) :
                  readM inst ≤ inst.size

                  KEY LEMMA (I2), examples. On a well-formed instance the stored example count is poly-bit: readM inst ≤ Nat.size inst — the value bound that discharges polyTime_loop's hCval.

                  theorem DecisionList.readK_le_size (inst : ℕ) (h : WF inst) :
                  readK inst ≤ inst.size

                  KEY LEMMA (I2), features. Symmetrically, readK inst ≤ Nat.size inst under WF.

                  Flat accessor Codes (rfind'-free, tc = O(1)), and their PolyTime certificates #

                  k-accessor: left (tc = 1).

                  Equations
                  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
                    Instances For

                      Flag-cons head (the current example): left ∘ right.

                      Equations
                      Instances For

                        peel L i: drop i list cells (tailL iterated i times).

                        Equations
                        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
                            theorem DecisionList.polyTime_peel {A C : ℕ → ℕ} (hA : TimeCost.PolyTime A) (hC : TimeCost.PolyTime C) (hCval : TimeCost.PolyBounded C) :
                            TimeCost.PolyTime fun (n : ℕ) => peel (A n) (C n)

                            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.

                            theorem DecisionList.polyTime_get_example {A C : ℕ → ℕ} (hA : TimeCost.PolyTime A) (hC : TimeCost.PolyTime C) (hCval : TimeCost.PolyBounded C) :
                            TimeCost.PolyTime fun (n : ℕ) => headL (peel (A n) (C n))

                            getExample is PolyTime given a poly-bit index: n ↦ headL (peel (A n) (C n)).

                            theorem DecisionList.polyTime_get_label {A C : ℕ → ℕ} (hA : TimeCost.PolyTime A) (hC : TimeCost.PolyTime C) (hCval : TimeCost.PolyBounded C) :
                            TimeCost.PolyTime fun (n : ℕ) => (Nat.unpair (headL (peel (A n) (C n)))).1

                            getLabel is PolyTime given a poly-bit index: the label is (example).unpair.1.

                            theorem DecisionList.polyTime_get_feature {A Ci Cj : ℕ → ℕ} (hA : TimeCost.PolyTime A) (hCi : TimeCost.PolyTime Ci) (hCival : TimeCost.PolyBounded Ci) (hCj : TimeCost.PolyTime Cj) (hCjval : TimeCost.PolyBounded Cj) :
                            TimeCost.PolyTime fun (n : ℕ) => headL (peel (Nat.unpair (headL (peel (A n) (Ci n)))).2 (Cj n))

                            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).

                            Correctness against a List model #

                            Encode a List ℕ as a flag-cons list.

                            Equations
                            Instances For
                              theorem DecisionList.get_example_encode (xs : List ℕ) (i : ℕ) (h : i < xs.length) :
                              headL (peel (encodeList xs) i) = xs[i]

                              getExample correctness. Under the List model, headL (peel (encodeList xs) i) is the i-th element xs[i] (for i < xs.length). Label/feature access follow by unpair/a second peel.

                              theorem DecisionList.get_label_encode (xs : List ℕ) (i : ℕ) (h : i < xs.length) :
                              (Nat.unpair (headL (peel (encodeList xs) i))).1 = (Nat.unpair xs[i]).1

                              getLabel correctness. With each example encoded as ⟨label, fv⟩, the i-th label is (xs[i]).unpair.1.

                              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
                              Instances For

                                The feature-vector of an example.

                                Equations
                                Instances For

                                  Feature j of example e: peel its feature-vector j cells and read the head bit.

                                  Equations
                                  Instances For

                                    Binary well-formedness of the instance. WF plus: every example's label and every feature bit is ≤ 1 (the binary regime), over the List model of the example data.

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