Documentation

ReflectiveSubsystems.Collector

The orbit collector collector cR — discharging Prop 2.2's modeled premise #

Provenance: [SQ] §2.2 / Prop 2.2 (~lines 107–119), the FV-AC row. Extends CodeLayer/AdditiveComplexity.lean (E, elen, KE, KE_t, E_len_comp) and CodeLayer/BinaryConstant.lean (bconst, eval_bconst, elen_bconst_le, prop_2_2_core).

Status: PROVED (eval level). Target B (an explicit evaln budget) is a documented WALL; Target C (H_T) is a declared model boundary. See the boundary note below.

What this replaces #

prop_2_2_core (in BinaryConstant.lean) took the collector coll : Code as an ARBITRARY code and ASSUMED the assembly halts on some output y (h : y ∈ evaln T (comp coll (comp cR (bconst n))) 0). That is the "modeled premise". This file CONSTRUCTS a genuine collector and PROVES the assembly computes the orbit prefix, so the premise is discharged at the eval level.

The construction — a fixed iterator template with the rule plugged in #

A rule-INDEPENDENT collector receiving cR(n) cannot re-run cR (first-order Code, no internalized universal evaluator). So the collector is a fixed template collector · := prec zero (stepWrap ·) applied to the rule code cR — the rule appears as the subterm comp cR projState inside stepWrap. This is faithful: elen (collector cR) = elen cR + 60 (a fixed constant plus the rule), so the assembled length is still elen cR + O(log n) = r + O(log n).

I/O convention (fixed here; consumed by prop_2_2_eval) #

Boundaries #

Length law for prec #

The additive length law for prec (identical shape to E_len_comp/E_len_pair).

The orbit accumulator (Lean-level) and its orbit certification #

The encoded orbit prefix: a single ℕ built by the same recursion the collector code runs. orbitAcc rs n = Nat.pair (current state) (encoded prefix o_0 … o_{n-1}).

Equations
Instances For
    theorem ReflectiveSubsystems.orbitAcc_fst (rs : ℕ → ℕ) (n : ℕ) :
    (Nat.unpair (orbitAcc rs n)).1 = rs^[n] 0

    Orbit certification: the current-state component after n steps is exactly rs^[n] 0 — so the collected stream genuinely is the rule's orbit o_t = rs^[t] x₀ with x₀ = 0.

    The collector code #

    Extract the recursion accumulator from a prec-step input Nat.pair a (Nat.pair y m): two right unpairings give m.

    Equations
    Instances For

      The step template: given Nat.pair a (Nat.pair y m), output Nat.pair (rs m₁) (Nat.pair m₂ m₁) where m₁ = m.unpair.1, m₂ = m.unpair.2. The rule cR enters as the subterm comp cR projState.

      Equations
      Instances For

        The collector (fixed iterator template with the rule plugged in): primitive recursion with base zero (= orbitAcc rs 0) and step stepWrap cR. On Nat.pair 0 n it outputs orbitAcc rs n.

        Equations
        Instances For

          The assembly collector ∘ (pair zero (bconst n)): on input 0, forms Nat.pair 0 n from the binary constant and iterates. This is the honest realization of the paper's collector ∘ R ∘ bconst n (the rule is inside collector cR, not a separate middle factor — see the module note).

          Equations
          Instances For

            Eval correctness #

            Projection eval laws on a step input Nat.pair a (Nat.pair y m).

            theorem ReflectiveSubsystems.eval_collector {cR : Nat.Partrec.Code} {rs : ℕ → ℕ} (hcR : ∀ (x : ℕ), cR.eval x = Part.some (rs x)) (n : ℕ) :

            The collector iterates the rule: on Nat.pair 0 n it outputs orbitAcc rs n. Induction on n via eval_prec_zero/eval_prec_succ and the step law.

            theorem ReflectiveSubsystems.eval_assembly {cR : Nat.Partrec.Code} {rs : ℕ → ℕ} (hcR : ∀ (x : ℕ), cR.eval x = Part.some (rs x)) (n : ℕ) :
            (assembly cR n).eval 0 = Part.some (orbitAcc rs n)

            Eval correctness of the full assembly: on input 0 it computes the orbit prefix orbitAcc rs n — the collector premise DISCHARGED.

            Length accounting #

            The collector's length is a fixed O(1) plus the rule — elen (collector cR) = elen cR + 60. So the collector contributes only a constant to the assembled program length.

            The assembled program's length: elen cR + elen (bconst n) + 69.

            Prop 2.2 core, DISCHARGED at the eval level #

            Prop 2.2 |P|-component, collector premise DISCHARGED (eval level). For a rule cR computing a total step map rs, the length-n orbit prefix orbitAcc rs n has additive complexity KE ≤ elen cR + κ·Nat.size n + (84 + elen dbl) with κ = 15 + elen dbl — i.e. r + O(log n), with the collector CONSTRUCTED (not modeled). The witness is assembly cR n; its length is additive by elen_assembly, and elen (bconst n) = O(Nat.size n) by elen_bconst_le.

            Target B — the honest ∃-budget fallback (explicit budget is walled; see the module note) #

            Prop 2.2 |P|-component, time-bounded form (∃-budget fallback). There EXISTS a step budget T under which KE_t T (orbitAcc rs n) ≤ elen cR + κ·Nat.size n + (84 + elen dbl). The budget is existential (via evaln_complete), NOT an explicit polynomial in n: evaln's k caps intermediate values, so any explicit budget for this iterator is ≥ orbitAcc rs n (super-exponential in n). The explicit-polynomial budget is a documented wall (module note), mirroring KE_t_eventually.

            The native-cost LINEAR bound, discharged for the collector #

            prop_2_2_t_exists above ships an EXISTENTIAL evaln budget because evaln's fuel caps intermediate VALUES (evaln_bound), so no explicit polynomial budget exists for this value-growing iterator. The native step count TimeCost.tc (see CodeLayer/TimeCost.lean) instead charges each prec/comp unfolding O(1) regardless of value magnitude, so it DOES admit an explicit linear bound. The projection/stepWrap cost lemmas below feed the generic TimeCost.tc_prec_le engine.

            One collector step costs a fixed 18 plus one call to the rule cR. The 18 is the proj/pair/comp overhead of stepWrap; the only value-dependent term is tc cR (val projState x), which a uniform per-call bound caps WITHOUT reference to the magnitude of val projState x.

            theorem ReflectiveSubsystems.prop_2_2_t_poly {cR : Nat.Partrec.Code} {rs : ℕ → ℕ} (_hcR : ∀ (x : ℕ), cR.eval x = Part.some (rs x)) {K : ℕ} (hK : ∀ (x : ℕ), TimeCost.tc cR x ≤ K) (a n : ℕ) :
            TimeCost.tc (collector cR) (Nat.pair a n) ≤ (K + 19) * n + 19

            Prop 2.2 |P|-component, native-time LINEAR bound — DISCHARGED for the collector. For a rule cR whose per-call native cost is ≤ K uniformly (hK), the collector's native sequential-time cost on Nat.pair a n is ≤ (K + 19)·n + 19 — LINEAR in the number of orbit steps n, with the explicit fixed constant C = 19 (the stepWrap proj/pair/comp overhead). The bound is MAGNITUDE-INDEPENDENT: it never mentions the accumulator values rs^[i] 0 — which grow super-exponentially and are exactly what forced the evaln value-cap wall behind prop_2_2_t_exists — because each step's rule call is capped by the uniform hK, not by the value threaded through it. This is the wall discharged: TimeCost.tc charges O(1) per prec/comp unfolding regardless of value size (value-agreement TimeCost.eval_eq_val certifies the value carries no cap). hcR (the rule genuinely computes the total step map rs) is unused in the bound; it certifies collector cR is the honest orbit collector of eval_collector, keeping the statement parallel to prop_2_2_t_exists.