Documentation

CslibFrontier.Computability.GenericRAM.Native.MeasurementFold

Streaming signed measurement values #

The dimension is a runtime unary natural and the radius a runtime binary natural. The decoder uses the existing radix digits to produce ordinary signed integer lists. Count preparation and individual visits are polynomial in their full encoded input, even though the number of visits need not be. All coordinates remain present at radius zero; dimension zero has one empty tuple.

Only the current binary index, full parameters and captured accumulator persist. The decoder may use polynomial scratch (including a dimension-length range), but never constructs the whole measurement box. Index/box lists in the ordered-fold specification are not used by the native loop. The generic callback may grow its accumulator: polynomial whole-loop workspace requires an actual all-prefix accumulator invariant, not just a polynomial per-visit certificate.

This is the measurement-VALUE enumeration of [OAI26k], Lemma 3.2 and Proposition 3.4 (pp. 22–26). It is not formal mode-exponent enumeration, subset-pair traversal, rational coefficient accumulation or a complete runtime/ETH result.

The actual number of signed measurement tuples in dimension c and radius D.

An actual fixed native count-preparation machine; no unary exponential count is produced.

Both preparation bounds are polynomial in the complete runtime pair encoding.

The binary count has polynomial bit length, rather than polynomial numeric value.

Decode the actual signed measurement values with unary dimension and binary radius/index. No fitting-index hypothesis is needed for this total polynomial-time decoder.

The two selected decoder bounds are polynomial in its complete encoded runtime input.

The tuple code is polynomial in dimension and binary radius length, not in radius value.

@[reducible, inline]

Persistent streaming state (index, (params, acc)) of MeasurementFold.

@[reducible, inline]

Retained (params, acc) payload of a MeasurementFold state.

def Cslib.GenericRAM.MeasurementFold.visit {β : Type} (body : ((ℕ × ℕ) × List ℤ) × β → β) (p : ℕ × (ℕ × ℕ) × β) :
(ℕ × ℕ) × β

Decode the current index while retaining the full runtime parameters outside the user body.

def Cslib.GenericRAM.MeasurementFold.runPrefix {β : Type} (body : ((ℕ × ℕ) × List ℤ) × β → β) (p : ℕ × ℕ) (j : ℕ) (initial : β) :
ℕ × (ℕ × ℕ) × β

A streaming prefix stores only the binary index, complete parameters and captured state.

def Cslib.GenericRAM.MeasurementFold.run {β : Type} (body : ((ℕ × ℕ) × List ℤ) × β → β) (p : ℕ × ℕ) (initial : β) :
ℕ × (ℕ × ℕ) × β

Traverse the signed measurement-value box by increasing binary index.

@[simp]
theorem Cslib.GenericRAM.MeasurementFold.prefix_parameters {β : Type} (body : ((ℕ × ℕ) × List ℤ) × β → β) (p : ℕ × ℕ) (j : ℕ) (initial : β) :
(StreamState.payload (runPrefix body p j initial)).1 = p

Neither dimension nor radius can be overwritten by the callback.

theorem Cslib.GenericRAM.MeasurementFold.prefix_accumulator {β : Type} (body : ((ℕ × ℕ) × List ℤ) × β → β) (p : ℕ × ℕ) (j : ℕ) (initial : β) :
(StreamState.payload (runPrefix body p j initial)).2 = List.foldl (fun (acc : β) (i : ℕ) => body ((p, Radix.measurementValues p.1 p.2 i), acc)) initial (List.range j)

All prefixes follow the increasing-index order, with full parameters and captured state.

theorem Cslib.GenericRAM.MeasurementFold.run_accumulator {β : Type} (body : ((ℕ × ℕ) × List ℤ) × β → β) (p : ℕ × ℕ) (initial : β) :
(StreamState.payload (run body p initial)).2 = List.foldl (fun (acc : β) (word : List ℤ) => body ((p, word), acc)) initial (List.map (Radix.measurementValues p.1 p.2) (List.range (count p)))

Exact ordered-fold specification. With measurementValues_coverage, every fitting signed word is visited once. The materialized index/word lists occur only in this specification.

@[reducible, inline]

Streaming state (j, ((c, D), acc)) of runPrefix, a StreamState β: the current index j in binary, then the dimension c in unary and the radius D in binary, then the captured accumulator under encB. The index, the parameter pair and c inside it are framed; D and the accumulator are not.

@[reducible, inline]

Input (((c, D), values), acc) of one callback: the dimension c in unary and the radius D in binary, then the signed measurement values as a list of binary integers (encIntBin), then the captured accumulator under encB. The triple ((c, D), values) is framed, and inside it so are the parameter pair, c and each value; D and the accumulator are not.

theorem Cslib.GenericRAM.MeasurementFold.length_prefix_le {β : Type} {encB : β ↪ List Bool} (body : ((ℕ × ℕ) × List ℤ) × β → β) (c D j B : ℕ) (initial : β) (hj : j ≤ count (c, D)) (hB : (encB (StreamState.payload (runPrefix body (c, D) j initial)).2).length ≤ B) :
((encStreamState encB) (runPrefix body (c, D) j initial)).length ≤ 2 * (c * (D.size + 1) + 1) + 4 * c + 2 * D.size + 4 + B

Full encoded persistent-state bound under the actual prefix accumulator bound. It includes both retained parameters and the final binary counter, including at base one/dimension zero.

theorem Cslib.GenericRAM.MeasurementFold.length_callback_input_le {β : Type} {encB : β ↪ List Bool} (c D j : ℕ) (acc : β) :
((encCallbackInput encB) (((c, D), Radix.measurementValues c D j), acc)).length ≤ 4 * (2 * c + 1 + D.size) + 2 * (c * (2 * (D.size + 1) + 1)) + 3 + (encB acc).length

Preparing a callback charges both parameters, every signed coordinate and the full captured accumulator. This bound is about the encoded input, not uncharged machine scratch.

Prepare the complete runtime parameter/tuple/captured-state input to the callback.

The actual captured callback uses the proved direct decoder, retaining both parameters.

Polynomial per-visit bounds are derived from the actual callback and decoder machines.

noncomputable def Cslib.GenericRAM.MeasurementFold.certificate {β : Type} {encB : β ↪ List Bool} {α : Type} {encIn : α ↪ List Bool} {parameters : α → ℕ × ℕ} {initial : α → β} {body : ((ℕ × ℕ) × List ℤ) × β → β} (cp : NativeCertificate parameters encIn (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encNat)) (ci : NativeCertificate initial encIn encB) (cb : NativeCertificate body (encCallbackInput encB) encB) :
NativeCertificate (fun (a : α) => run body (parameters a) (initial a)) encIn (encStreamState encB)

One fixed native machine streams all measurement values. Count preparation is charged, time retains the visit-count factor, and workspace uses the existing all-prefix maxima. No whole-loop polynomial-time bound or polynomial accumulator invariant is assumed.