Documentation

CslibFrontier.Computability.StreamArithmetic.Interface

Uncompiled stream query schedules, lookahead composition, and allowance arithmetic #

This module provides uncompiled query-schedule / lookahead helpers and standalone arithmetic inequalities as intermediate steps after, and not formalizations of, [OpenAI2026LogSpace, Sections 10.5--10.6, Lemma 10.8, Theorem 10.9]. Native Turing-machine or counter-program space realization remains open and is tracked in #9181.

A StreamSchedule Op Struct at slack d ≥ 1 packages:

Because QueryProg continuations are arbitrary host Lean functions, StreamSchedule and BoolSchedule certify only exact signed-digit stream semantics and digit-query index lookahead; they certify neither uniformity, computability, query counts, nor Turing-machine workspace. Separately, AllowanceBound and its telescoping lemmas are pure arithmetic inequalities on natural-number parameters after [OpenAI2026LogSpace, (10.18)].

Main definitions #

Main results #

References #

A signed-digit stream in {-6, ..., 6} whose represented real value lies in [-1, 1].

def Cslib.StreamArithmetic.AllowanceBound (d a b c t : ℕ) (place? : Option ℕ) (L : ℕ) :

Standalone pure-arithmetic clock-overshoot and suspended-record inequality after, and not a machine-space formalization of, [OpenAI2026LogSpace, (10.18), Theorem 10.9] (native space realization is tracked in #9181). For a digit-query place some j it requires lookahead j ≤ t + c * d and L ≤ a * d + b * (t - j); for a clock-zero query none it requires L ≤ a * d + b * t.

theorem Cslib.StreamArithmetic.AllowanceBound.mono_ac {d a₀ a b c₀ c t L : ℕ} (ha : a₀ ≤ a) (hc : c₀ ≤ c) {place? : Option ℕ} (h : AllowanceBound d a₀ b c₀ t place? L) :
AllowanceBound d a b c t place? L
theorem Cslib.StreamArithmetic.AllowanceBound.mono_coeff {d a₀ b₀ b c₀ t L : ℕ} (hb : b₀ ≤ b) {place? : Option ℕ} (h : AllowanceBound d a₀ b₀ c₀ t place? L) :
AllowanceBound d (a₀ + (b - b₀) * c₀) b c₀ t place? L

Pure-arithmetic coefficient-unification helper after [OpenAI2026LogSpace, Theorem 10.9 proof] (not a machine-space bound; see #9181): increasing b₀ to b ≥ b₀ is absorbed by increasing a₀ to a₀ + (b - b₀) * c₀.

theorem Cslib.StreamArithmetic.AllowanceBound.mono_clock {d a b c t₁ t₂ L : ℕ} (ht : t₁ ≤ t₂) {place? : Option ℕ} (h : AllowanceBound d a b c t₁ place? L) :
AllowanceBound d a b c t₂ place? L
theorem Cslib.StreamArithmetic.AllowanceBound.shift_clock_up {d a b c t k L : ℕ} (hd : 1 ≤ d) {place? : Option ℕ} (h : AllowanceBound d a b c (t + k) place? L) :
AllowanceBound d (a + b * k) b (c + k) t place? L
theorem Cslib.StreamArithmetic.AllowanceBound.add_const {d a b c t L : ℕ} (hd : 1 ≤ d) (extra : ℕ) {place? : Option ℕ} (h : AllowanceBound d a b c t place? L) :
AllowanceBound d (a + extra) b c t place? (extra + L)
theorem Cslib.StreamArithmetic.AllowanceBound.comp_child {d a₁ a₂ b c₁ c₂ t u w L : ℕ} (hd : 1 ≤ d) (retBits : ℕ) (hu : u ≤ t + c₁ * d) (hw : ↑w ≤ ↑(a₁ * d) + ↑b * (↑t - ↑u)) {place? : Option ℕ} (hChild : AllowanceBound d a₂ b c₂ u place? L) :
AllowanceBound d (a₁ + a₂ + retBits) b (c₁ + c₂) t place? (w + retBits + L)

Pure-arithmetic clock-difference telescoping helper after [OpenAI2026LogSpace, Theorem 10.9] (not a machine-space bound; see #9181).

structure Cslib.StreamArithmetic.StreamSchedule (Op : Type u) (Struct : Type v) :
Type (max u v)

Uncompiled conditional query schedule for an exact signed-digit stream at slack slack ≥ 1. This is an intermediate query-semantics and lookahead helper after, and not a formalization of, [OpenAI2026LogSpace, Theorem 10.9] (native space realization is tracked in #9181): it packages exact signed-digit emission (emits_signed, emits_exact) and digit-query place lookahead (j ≤ t + lookaheadCoeff * slack) over host QueryProg trees, without certifying uniformity, computability, query counts, or Turing-machine workspace.

theorem Cslib.StreamArithmetic.StreamSchedule.emits_norm {Op : Type u} {Struct : Type v} (S : StreamSchedule Op Struct) {env : Op → ℕ → ℤ} {sEnv : Struct → Bool} (hV : S.ValidEnv env sEnv) :
IsNormSignedStream fun (t : ℕ) => (S.digitProg t).eval env sEnv

Emitted digits of a StreamSchedule form a normalized signed stream in [-1, 1] whenever S.ValidEnv env sEnv.

noncomputable def Cslib.StreamArithmetic.StreamSchedule.weakenValid {Op : Type u} {Struct : Type v} (S : StreamSchedule Op Struct) (V' : (Op → ℕ → ℤ) → (Struct → Bool) → Prop) (hV : ∀ {env : Op → ℕ → ℤ} {sEnv : Struct → Bool}, V' env sEnv → S.ValidEnv env sEnv) :
StreamSchedule Op Struct

Strengthen the environment precondition of a StreamSchedule.

noncomputable def Cslib.StreamArithmetic.StreamSchedule.congrTarget {Op : Type u} {Struct : Type v} (S : StreamSchedule Op Struct) (T' : (Op → ℝ) → (Struct → Bool) → ℝ) (hT : ∀ {env : Op → ℕ → ℤ} {sEnv : Struct → Bool}, S.ValidEnv env sEnv → S.targetVal (fun (op : Op) => SignedDigitStream.streamVal (env op)) sEnv = T' (fun (op : Op) => SignedDigitStream.streamVal (env op)) sEnv) :
StreamSchedule Op Struct

Rewrite the mathematical targetVal of a StreamSchedule on valid environments.

noncomputable def Cslib.StreamArithmetic.StreamSchedule.compOfLookahead {Op₁ : Type u} {Op₂ : Type u'} {Struct : Type v} (parent : StreamSchedule Op₁ Struct) (child : Op₁ → StreamSchedule Op₂ Struct) (cC : ℕ) (hSlack : ∀ (op : Op₁), (child op).slack = parent.slack) (hLookahead : ∀ (op : Op₁), (child op).lookaheadCoeff ≤ cC) :
StreamSchedule Op₂ Struct

Uncompiled stage-composition helper after, and not a formalization of, [OpenAI2026LogSpace, Theorem 10.9] (native space realization is tracked in #9181): substituting child StreamSchedules whose lookahead coefficients are uniformly bounded by cC preserves exact signed-digit stream evaluation and adds lookahead coefficients (parent.lookaheadCoeff + cC), without certifying uniformity, computability, or Turing-machine workspace.

noncomputable def Cslib.StreamArithmetic.StreamSchedule.condStruct {Op : Type u} {Struct : Type v} (sOp : Struct) (onTrue onFalse : StreamSchedule Op Struct) (hSlack : onFalse.slack = onTrue.slack) :
StreamSchedule Op Struct

Structural-leaf conditional branch between two StreamSchedules (uncompiled query-schedule helper after [OpenAI2026LogSpace, Section 10.5, Lemma 10.6]; see #9181). Only the branch selected by sEnv sOp is evaluated or required to satisfy ValidEnv.

structure Cslib.StreamArithmetic.BoolSchedule (Op : Type u) (Struct : Type v) :
Type (max u v)

Uncompiled clock-zero finite Boolean query schedule at slack slack ≥ 1. This is an intermediate query-semantics and lookahead helper after, and not a formalization of, [OpenAI2026LogSpace, Lemma 10.8] (native space realization is tracked in #9181): it records the digit-query lookahead bound j ≤ lookaheadCoeff * slack on executed queries without certifying uniformity, computability, query counts, or Turing-machine workspace.

def Cslib.StreamArithmetic.diffDigitProg {Op : Type u} {Struct : Type v} (resProg : ℕ → QueryProg Op Struct ℤ) :
ℕ → QueryProg Op Struct ℤ

Lift a mod-16 approximation residue query tree resProg ((resProg s).eval = N s % 16) to an exact difference-digit query tree via decodeDiffResidue 4 (after [OpenAI2026LogSpace, Lemma 10.1]).

theorem Cslib.StreamArithmetic.eval_diffDigitProg {Op : Type u} {Struct : Type v} (resProg : ℕ → QueryProg Op Struct ℤ) (N : ℕ → ℤ) {z : ℝ} (hz : |z| ≤ 1) (hN : SignedDigitStream.IsScaledApprox z N) {env : Op → ℕ → ℤ} {sEnv : Struct → Bool} (hRes : ∀ (s : ℕ), (resProg s).eval env sEnv = N s % 16) (t : ℕ) :
theorem Cslib.StreamArithmetic.lookahead_diffDigitProg {Op : Type u} {Struct : Type v} {d c : ℕ} (resProg : ℕ → QueryProg Op Struct ℤ) (hLook : ∀ (s : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) {op : Op} {j : ℕ}, QueryEvent.digit op j ∈ (resProg s).activeQueries env sEnv → j ≤ s + c * d) (t : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) {op : Op} {j : ℕ} (hev : QueryEvent.digit op j ∈ (diffDigitProg resProg t).activeQueries env sEnv) :
j ≤ t + c * d
noncomputable def Cslib.StreamArithmetic.scheduleOfMod16Prog {Op : Type u} {Struct : Type v} (d : ℕ) (hd : 1 ≤ d) (ValidEnv : (Op → ℕ → ℤ) → (Struct → Bool) → Prop) (targetVal : (Op → ℝ) → (Struct → Bool) → ℝ) (N : (Op → ℕ → ℤ) → (Struct → Bool) → ℕ → ℤ) (resProg : ℕ → QueryProg Op Struct ℤ) (c : ℕ) (hBound : ∀ {env : Op → ℕ → ℤ} {sEnv : Struct → Bool}, ValidEnv env sEnv → |targetVal (fun (op : Op) => SignedDigitStream.streamVal (env op)) sEnv| ≤ 1) (hApprox : ∀ {env : Op → ℕ → ℤ} {sEnv : Struct → Bool}, ValidEnv env sEnv → SignedDigitStream.IsScaledApprox (targetVal (fun (op : Op) => SignedDigitStream.streamVal (env op)) sEnv) (N env sEnv)) (hEval : ∀ {env : Op → ℕ → ℤ} {sEnv : Struct → Bool}, ValidEnv env sEnv → ∀ (s : ℕ), (resProg s).eval env sEnv = N env sEnv s % 16) (hLook : ∀ (s : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) {op : Op} {j : ℕ}, QueryEvent.digit op j ∈ (resProg s).activeQueries env sEnv → j ≤ s + c * d) :
StreamSchedule Op Struct

Package any mod-16 scaled-approximation residue query tree with bounded digit-place lookahead into an uncompiled StreamSchedule (not a machine-space certificate; see #9181).

def Cslib.StreamArithmetic.scanModAux {Op : Type u} {Struct : Type v} (op : Op) (W idx : ℕ) :
ℕ → ℤ → QueryProg Op Struct ℤ

Tail-recursive modular Horner scan over rem consecutive digits starting at idx.

def Cslib.StreamArithmetic.windowPrefixModProg {Op : Type u} {Struct : Type v} (op : Op) (W K : ℕ) :
QueryProg Op Struct ℤ

Uncompiled windowed low-residue reader computing intPrefix (env op) K % 2 ^ W by querying digits in Ico (K + 1 - W) (K + 1) (helper after [OpenAI2026LogSpace, Lemma 10.3]; see #9181).

theorem Cslib.StreamArithmetic.eval_windowPrefixModProg {Op : Type u} {Struct : Type v} (op : Op) (W K : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(windowPrefixModProg op W K).eval env sEnv = SignedDigitStream.intPrefix (env op) K % 2 ^ W
theorem Cslib.StreamArithmetic.mem_activeQueries_windowPrefixModProg {Op : Type u} {Struct : Type v} (op : Op) (W K : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) {ev : QueryEvent Op Struct} (hev : ev ∈ (windowPrefixModProg op W K).activeQueries env sEnv) :
∃ j ≤ K, ev = QueryEvent.digit op j
def Cslib.StreamArithmetic.cmpPrefixProg {Op : Type u} {Struct : Type v} (op₁ op₂ : Op) :
ℕ → QueryProg Op Struct ℤ

Uncompiled top-down prefix comparison query tree computing cmpPrefix (env op₁) (env op₂) K over places 0, ..., K (helper after [OpenAI2026LogSpace, Lemma 10.3]; see #9181).

theorem Cslib.StreamArithmetic.eval_cmpPrefixProg {Op : Type u} {Struct : Type v} (op₁ op₂ : Op) (K : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(cmpPrefixProg op₁ op₂ K).eval env sEnv = SignedDigitStream.cmpPrefix (env op₁) (env op₂) K
theorem Cslib.StreamArithmetic.mem_activeQueries_cmpPrefixProg {Op : Type u} {Struct : Type v} (op₁ op₂ : Op) (K : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) {ev : QueryEvent Op Struct} (hev : ev ∈ (cmpPrefixProg op₁ op₂ K).activeQueries env sEnv) :
∃ (op : Op), ∃ j ≤ K, ev = QueryEvent.digit op j
def Cslib.StreamArithmetic.cmpWithConstProg {Op : Type u} {Struct : Type v} (op : Op) (bound : ℕ → ℤ) :
ℕ → QueryProg Op Struct ℤ

Uncompiled top-down prefix comparator query tree comparing env op against a fixed digit sequence bound through place K (helper after [OpenAI2026LogSpace, Lemma 10.3]; see #9181).

theorem Cslib.StreamArithmetic.eval_cmpWithConstProg {Op : Type u} {Struct : Type v} (op : Op) (bound : ℕ → ℤ) (K : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(cmpWithConstProg op bound K).eval env sEnv = SignedDigitStream.cmpPrefix (env op) bound K
theorem Cslib.StreamArithmetic.mem_activeQueries_cmpWithConstProg {Op : Type u} {Struct : Type v} (op : Op) (bound : ℕ → ℤ) (K : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) {ev : QueryEvent Op Struct} (hev : ev ∈ (cmpWithConstProg op bound K).activeQueries env sEnv) :
∃ j ≤ K, ev = QueryEvent.digit op j
def Cslib.StreamArithmetic.cmpBufferedAux {Op : Type u} {Struct : Type v} (opS opU : Op) (idx : ℕ) :
ℕ → ℤ → QueryProg Op Struct ℤ

Tail-recursive buffered comparator query tree for bufferedTest (2 s - 3 u clamped to [-31, 31]).

def Cslib.StreamArithmetic.cmpBufferedProg {Op : Type u} {Struct : Type v} (opS opU : Op) (K : ℕ) :
QueryProg Op Struct ℤ

Uncompiled buffered comparator query tree computing cmpBuffered (env opS) (env opU) K across places 0, ..., K.

def Cslib.StreamArithmetic.bufferedTestProg {Op : Type u} {Struct : Type v} (opS opU : Op) (M R : ℕ) :
QueryProg Op Struct Bool

Uncompiled clock-zero query tree evaluating bufferedTest M R (env opS) (env opU) at cutoff K = M + R + 7 (helper after [OpenAI2026LogSpace, Lemma 10.8]; see #9181).

theorem Cslib.StreamArithmetic.eval_cmpBufferedProg {Op : Type u} {Struct : Type v} (opS opU : Op) (K : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(cmpBufferedProg opS opU K).eval env sEnv = SignedDigitStream.cmpBuffered (env opS) (env opU) K
theorem Cslib.StreamArithmetic.eval_bufferedTestProg {Op : Type u} {Struct : Type v} (opS opU : Op) (M R : ℕ) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(bufferedTestProg opS opU M R).eval env sEnv = SignedDigitStream.bufferedTest M R (env opS) (env opU)
def Cslib.StreamArithmetic.bufferedTestSchedule {Op : Type u} {Struct : Type v} (d : ℕ) (hd : 1 ≤ d) (opS opU : Op) (M R κ : ℕ) (hMR : M + R ≤ κ * d) :
BoolSchedule Op Struct

Uncompiled query-schedule helper after, and not a formalization of, [OpenAI2026LogSpace, Lemma 10.8] (native space realization is tracked in #9181): when M + R ≤ κ * d, bufferedTestProg queries only digit places j ≤ M + R + 7 ≤ (κ + 7) * d. No uniformity or machine workspace bound is claimed.

theorem Cslib.StreamArithmetic.bufferedTestSchedule_true_of_two_mul_lt {Op : Type u} {Struct : Type v} (d : ℕ) (hd : 1 ≤ d) (opS opU : Op) {M R κ : ℕ} (hMR : M + R ≤ κ * d) {env : Op → ℕ → ℤ} (sEnv : Struct → Bool) (hs : SignedDigitStream.IsSignedStream (env opS)) (hu : SignedDigitStream.IsSignedStream (env opU)) {sVal uVal ρ : ℝ} (hsVal : sVal = 2 ^ M * SignedDigitStream.streamVal (env opS)) (huVal : uVal = 2 ^ M * SignedDigitStream.streamVal (env opU)) (hρ : 1 / 2 ^ R ≤ ρ) (huρ : ρ ≤ uVal) (hlt : 2 * uVal < sVal) :
(bufferedTestSchedule d hd opS opU M R κ hMR).prog.eval env sEnv = true
theorem Cslib.StreamArithmetic.bufferedTestSchedule_false_of_le {Op : Type u} {Struct : Type v} (d : ℕ) (hd : 1 ≤ d) (opS opU : Op) {M R κ : ℕ} (hMR : M + R ≤ κ * d) {env : Op → ℕ → ℤ} (sEnv : Struct → Bool) (hs : SignedDigitStream.IsSignedStream (env opS)) (hu : SignedDigitStream.IsSignedStream (env opU)) {sVal uVal ρ : ℝ} (hsVal : sVal = 2 ^ M * SignedDigitStream.streamVal (env opS)) (huVal : uVal = 2 ^ M * SignedDigitStream.streamVal (env opU)) (hρ : 1 / 2 ^ R ≤ ρ) (huρ : ρ ≤ uVal) (hle : sVal ≤ uVal) :
(bufferedTestSchedule d hd opS opU M R κ hMR).prog.eval env sEnv = false