Documentation

CslibFrontier.Computability.TreeEval.Ary.Packed.QueryGate

Packed interpolation using same-input table calls #

The assignment loop of interpolateGrid is a query-machine caller. Its state contains the parameters, one assignment index and one modular accumulator. Each iteration requests a table entry from a subroutine on the same original input, then adds its weighted contribution. The table is never materialized. An explicit context carries the address of the gate or output chunk needed by the supplier; no tree or truth table is built into this construction.

The supplied loop limit must equal s^n for the interpolation theorem. Computing that limit and the native costs of supplier initialization, its computation and extracting its answer are separate charged operations. The callee returns a state, not its output stream.

@[reducible, inline]

Supplier context, modulus, alphabet size, coordinate count, point and assignment limit: (context, (modulus, alphabet, coords), point, limit).

@[reducible, inline]

The field modulus p of Params.

@[reducible, inline]

The alphabet size s of Params.

@[reducible, inline]

The coordinate count n of Params.

@[reducible, inline]

The interpolation point of Params.

@[reducible, inline]

The assignment loop limit of Params.

@[reducible, inline]

Parameters, the current assignment index and the sum accumulator: (params, counter, acc).

@[reducible, inline]

The fixed interpolation parameters of a caller state.

@[reducible, inline]

The current assignment index of a caller state.

@[reducible, inline]

The running modular sum accumulator of a caller state.

The fixed parameters with fresh assignment and sum counters.

def Cslib.TreeEval.Ary.Packed.QueryGate.resume {γ τ : Type} (answer : τ → ℕ) (q : State γ) (t : τ) :

One local sum update after the table subroutine returns.

def Cslib.TreeEval.Ary.Packed.QueryGate.request {γ τ : Type} (start : State γ → τ) (q : State γ) :

Request one entry whenever the assignment index is below the explicit loop limit.

The controller only advances when its table subroutine returns.

def Cslib.TreeEval.Ary.Packed.QueryGate.machine {γ τ : Type} (q : Params γ) (N : Turing.QueryMachine τ) (start : State γ → τ) (answer : τ → ℕ) :

The complete assignment loop and its same-original-input table subroutine.

def Cslib.TreeEval.Ary.Packed.QueryGate.sumState {γ : Type} (q : Params γ) (table : ℕ → ℕ) (j : ℕ) :

Pure assignment-loop states, used only to state the simulation invariant.

@[simp]
theorem Cslib.TreeEval.Ary.Packed.QueryGate.sumState_zero {γ : Type} (q : Params γ) (table : ℕ → ℕ) :
sumState q table 0 = initial q
theorem Cslib.TreeEval.Ary.Packed.QueryGate.sumState_counter {γ : Type} (q : Params γ) (table : ℕ → ℕ) (j : ℕ) :
(sumState q table j).counter = j

The assignment counter advances by one after each returned entry.

theorem Cslib.TreeEval.Ary.Packed.QueryGate.sumState_acc_lt {γ : Type} (q : Params γ) (table : ℕ → ℕ) (j : ℕ) (hp : 0 < q.modulus) :
(sumState q table j).acc < q.modulus

Every caller-prefix accumulator is reduced; no earlier table values are retained.

theorem Cslib.TreeEval.Ary.Packed.QueryGate.resume_sumState {γ τ : Type} (q : Params γ) (table : ℕ → ℕ) (j : ℕ) (answer : τ → ℕ) (t : τ) (ht : answer t = table j) :
resume answer (sumState q table j) t = sumState q table (j + 1)

A correct returned table value performs precisely the next existing sum step.

theorem Cslib.TreeEval.Ary.Packed.QueryGate.runFrom_one {γ τ : Type} (q : Params γ) (N : Turing.QueryMachine τ) (start : State γ → τ) (answer : τ → ℕ) (w : List Bool) (table : ℕ → ℕ) (j T : ℕ) (hj : j < q.limit) (hpre : ∀ i < T, N.halted (N.runFrom w (start (sumState q table j)) i) = false) (hhalt : N.halted (N.runFrom w (start (sumState q table j)) T) = true) (hanswer : answer (N.runFrom w (start (sumState q table j)) T) = table j) :
(machine q N start answer).runFrom w (Sum.inl (sumState q table j)) (T + 2) = Sum.inl (sumState q table (j + 1))

One table call implements one sum iteration, with one entry and one return step.

theorem Cslib.TreeEval.Ary.Packed.QueryGate.exists_runFrom_sumState {γ τ : Type} (q : Params γ) (N : Turing.QueryMachine τ) (start : State γ → τ) (answer : τ → ℕ) (w : List Bool) (table : ℕ → ℕ) (hsupplier : ∀ j < q.limit, ∃ (T : ℕ), (∀ i < T, N.halted (N.runFrom w (start (sumState q table j)) i) = false) ∧ N.halted (N.runFrom w (start (sumState q table j)) T) = true ∧ answer (N.runFrom w (start (sumState q table j)) T) = table j) (j : ℕ) (hj : j ≤ q.limit) :
∃ (T : ℕ), (machine q N start answer).runFrom w (Sum.inl (initial q)) T = Sum.inl (sumState q table j)

Every finite prefix of the assignment loop is realized by finitely many same-input calls. The supplier contract is required at each actual requested state, including the current sum.

theorem Cslib.TreeEval.Ary.Packed.QueryGate.exists_runFrom_interpolateGrid {γ τ : Type} (q : Params γ) (N : Turing.QueryMachine τ) (start : State γ → τ) (answer : τ → ℕ) (w : List Bool) (table : ℕ → ℕ) (hlimit : q.limit = q.alphabet ^ q.coords) (hsupplier : ∀ j < q.limit, ∃ (T : ℕ), (∀ i < T, N.halted (N.runFrom w (start (sumState q table j)) i) = false) ∧ N.halted (N.runFrom w (start (sumState q table j)) T) = true ∧ answer (N.runFrom w (start (sumState q table j)) T) = table j) :
∃ (T : ℕ), (machine q N start answer).runFrom w (Sum.inl (initial q)) T = Sum.inl (q, q.limit, interpolateGrid q.modulus q.alphabet q.coords table q.point)

With the full grid limit, the same-input caller returns the existing streamed interpolation. Its final accumulator, rather than the deliberately empty output stream, is the result.

def Cslib.TreeEval.Ary.Packed.QueryGate.gateTable {s b d r : ℕ} (hs : 0 < s) (encode : (Fin b → Bool) → Fin r → Fin s) (decode : (Fin r → Fin s) → Fin b → Bool) (f : Gate d b) (i : Fin r) :
ℕ → ℕ

The one-entry table consumed by the existing counter gate extension.

def Cslib.TreeEval.Ary.Packed.QueryGate.gateParams {γ : Type} {p s d r : ℕ} (context : γ) (x : Fin d → Fin r → ZMod p) :

Parameters for one output coordinate of the existing packed extension.

theorem Cslib.TreeEval.Ary.Packed.QueryGate.exists_runFrom_counterGateExtension {γ τ : Type} {p s b d r : ℕ} (hs : 0 < s) (context : γ) (encode : (Fin b → Bool) → Fin r → Fin s) (decode : (Fin r → Fin s) → Fin b → Bool) (f : Gate d b) (x : Fin d → Fin r → ZMod p) (i : Fin r) (N : Turing.QueryMachine τ) (start : State γ → τ) (answer : τ → ℕ) (w : List Bool) (hsupplier : ∀ j < s ^ (d * r), ∃ (T : ℕ), (∀ k < T, N.halted (N.runFrom w (start (sumState (gateParams context x) (gateTable hs encode decode f i) j)) k) = false) ∧ N.halted (N.runFrom w (start (sumState (gateParams context x) (gateTable hs encode decode f i) j)) T) = true ∧ answer (N.runFrom w (start (sumState (gateParams context x) (gateTable hs encode decode f i) j)) T) = gateTable hs encode decode f i j) :
∃ (T : ℕ) (z : ℕ), (machine (gateParams context x) N start answer).runFrom w (Sum.inl (initial (gateParams context x))) T = Sum.inl (gateParams context x, s ^ (d * r), z) ∧ ↑z = counterGateExtension hs encode decode f x i

A table supplier with the explicit same-input contract realizes the actual packed gate extension used by the iterative evaluator, rather than a separate interpolation specification.