Uncompiled stream query schedules for arithmetic primitives #
This module constructs uncompiled StreamSchedule exact-evaluation and digit-lookahead helpers as
intermediate steps after, and not formalizations of,
[OpenAI2026LogSpace, Sections 10.2--10.6, Lemmas 10.3--10.7]. Native Turing-machine or
counter-program space realization remains open and is tracked in #9181.
Because QueryProg continuations are arbitrary host Lean functions, every StreamSchedule below
certifies only exact signed-digit stream evaluation (emits_signed, emits_exact) and
digit-query index lookahead (j ≤ t + lookaheadCoeff * slack); no uniformity, computability, or
machine workspace bound is claimed.
- Variables, rational constants, negation, and structural guards:
Cslib.StreamArithmetic.varSchedule,Cslib.StreamArithmetic.ratSchedule,Cslib.StreamArithmetic.StreamSchedule.neg, andCslib.StreamArithmetic.StreamSchedule.guardStruct. - Elementary operations and shift-clip (after Lemmas 10.3 & 10.7):
Cslib.StreamArithmetic.pairAvgSchedule,Cslib.StreamArithmetic.maxSchedule,Cslib.StreamArithmetic.minSchedule,Cslib.StreamArithmetic.shiftClipSchedule, and direct schedule combinatorsCslib.StreamArithmetic.StreamSchedule.pairAvg,Cslib.StreamArithmetic.StreamSchedule.max,Cslib.StreamArithmetic.StreamSchedule.min, andCslib.StreamArithmetic.StreamSchedule.shiftClip. - Balanced binary-tree averages (after Lemma 10.7):
Cslib.StreamArithmetic.balancedAvgPrimScheduleandCslib.StreamArithmetic.balancedAvgScheduleaveraging2 ^ rstreams (r ≤ κ * d) with lookaheadj ≤ t + 4 * r ≤ t + (4 * κ) * d. - Minimum-index dyadic band multiplication (after Lemma 10.4):
Cslib.StreamArithmetic.mulScheduleandCslib.StreamArithmetic.StreamSchedule.mulwith lookaheadj ≤ t + 16 * d. - Early-word reciprocal on
[1 / 4, 1]and unit prefix clamping (after Section 10.4, Lemma 10.5):Cslib.StreamArithmetic.clipUnitPrefix,Cslib.StreamArithmetic.clippedUnitPrefixProg,Cslib.StreamArithmetic.recip64Schedule, andCslib.StreamArithmetic.StreamSchedule.recip64. - Zero-padded detector rank (after Lemma 10.6 and Sections 4.2, 8.2):
Cslib.StreamArithmetic.zeroPaddedRankListScheduleandCslib.StreamArithmetic.zeroPaddedRankFinsetSchedule, computingFinset.kthLargest(clamping negative order statistics up to0) with lookaheadj ≤ t + 4 * d.
Main definitions #
Cslib.StreamArithmetic.varSchedule,Cslib.StreamArithmetic.ratSchedule,Cslib.StreamArithmetic.StreamSchedule.neg,Cslib.StreamArithmetic.StreamSchedule.guardStruct.Cslib.StreamArithmetic.pairAvgSchedule,Cslib.StreamArithmetic.maxSchedule,Cslib.StreamArithmetic.minSchedule,Cslib.StreamArithmetic.shiftClipSchedule,Cslib.StreamArithmetic.balancedAvgPrimSchedule,Cslib.StreamArithmetic.balancedAvgSchedule.Cslib.StreamArithmetic.mulSchedule,Cslib.StreamArithmetic.recip64Schedule,Cslib.StreamArithmetic.clipUnitPrefix,Cslib.StreamArithmetic.clippedUnitPrefixProg.Cslib.StreamArithmetic.zeroPaddedRankListSchedule,Cslib.StreamArithmetic.zeroPaddedRankFinsetSchedule.
Main results #
Cslib.StreamArithmetic.eval_pairAvgResProg,Cslib.StreamArithmetic.eval_maxResProg,Cslib.StreamArithmetic.eval_minResProg,Cslib.StreamArithmetic.eval_shiftClipResProg.Cslib.StreamArithmetic.balancedAvgDigitProg_emits: exactness and signed-digit emission for depth-rbalanced binary-tree averages.Cslib.StreamArithmetic.eval_intPrefixProg,Cslib.StreamArithmetic.eval_clippedUnitPrefixProg,Cslib.StreamArithmetic.clipUnitPrefix_le_two_pow,Cslib.StreamArithmetic.abs_clipUnitPrefix_div_sub_streamVal_le,Cslib.StreamArithmetic.eval_recip64ResProg.Cslib.StreamArithmetic.eval_zeroPaddedRankListResProg: exact mod-16 residue evaluation for zero-paddedFinset.kthLargestover duplicate-free lists.
References #
- OpenAI, Exact Derandomization of Logarithmic Space: L = RL = BPL,
Sections 10.2--10.6 (after Lemmas 10.3--10.7; 23 September 2026, revision
7ef5c0cc, not peer reviewed).
Variables, rational constants, negation, and structural guards #
Exact negation of a signed-digit stream negates its real value.
Identity StreamSchedule reading operand op directly at place t (lookaheadCoeff = 0).
Exact stream negation preserving lookaheadCoeff.
Structural indicator guard emitting S when sEnv sOp = true and 0 when
sEnv sOp = false, requiring S.ValidEnv only on the active branch sEnv sOp = true
(uncompiled helper after [OpenAI2026LogSpace, Section 10.5]; see #9181).
Pairwise average #
Uncompiled pairwise-average query schedule after, and not a machine-space formalization of,
[OpenAI2026LogSpace, Lemma 10.3] (native space realization is tracked in #9181): computes
(val 0 + val 1) / 2 with digit lookahead j ≤ t + 4 * d.
Uncompiled binary-maximum query schedule after, and not a machine-space formalization of,
[OpenAI2026LogSpace, Lemma 10.3] (native space realization is tracked in #9181): computes
max (val 0) (val 1) with digit lookahead j ≤ t + 4 * d.
Uncompiled binary-minimum query schedule after, and not a machine-space formalization of,
[OpenAI2026LogSpace, Lemma 10.3] (native space realization is tracked in #9181): computes
min (val 0) (val 1) with digit lookahead j ≤ t + 4 * d.
Binary schedule composition combinators #
Helper composing any normalized binary StreamSchedule on Fin 2 with two child schedules
S₁, S₂.
Compose two StreamSchedules with exact pairwise average (S₁ + S₂) / 2.
Compose two StreamSchedules with exact binary maximum max S₁ S₂.
Compose two StreamSchedules with exact binary minimum min S₁ S₂.
Shift-clip and balanced binary-tree averages #
Shift-clip schedule #
Public signed-digit stream whose K-place intPrefix equals 2 ^ m whenever m ≤ K + 3
and 4 ≤ m.
Mod-16 saturated positive boundary residue ⌊2 ^ (s + 4) / 16⌋ % 16 for shiftClipApprox.
Mod-16 saturated negative boundary residue (-2 ^ s) % 16 for shiftClipApprox.
Uncompiled mod-16 residue query tree for shiftClipApprox v (env ()) s using at most two
constant-bound prefix comparisons and an 8-bit low-residue window (helper after
[OpenAI2026LogSpace, Lemma 10.7]; see #9181).
Uncompiled shift-and-clip query schedule after, and not a machine-space formalization of,
[OpenAI2026LogSpace, Lemma 10.7] (native space realization is tracked in #9181): computes
max (-1) (min 1 (2 ^ v * streamVal x)) for any integer shift v ≤ κ * d with digit lookahead
j ≤ t + (κ + 4) * d.
Apply exact shift-and-clip max (-1) (min 1 (2 ^ v * S)) (v ≤ κ * d) to a
StreamSchedule.
Balanced binary-tree averages #
Uncompiled balanced binary-tree average query schedule after, and not a machine-space
formalization of, [OpenAI2026LogSpace, Lemma 10.7] (native space realization is tracked in #9181):
averages 2 ^ r normalized streams (r ≤ κ * d) with digit lookahead
j ≤ t + 4 * r ≤ t + (4 * κ) * d.
Compose 2 ^ r (r ≤ κ * d) child StreamSchedules with balancedAvgPrimSchedule
(uncompiled helper after [OpenAI2026LogSpace, Lemma 10.7]; see #9181).
Minimum-index dyadic band multiplication #
Band window geometry and scanning programs #
Decidable membership predicate for (i, j) ∈ bandWindowPairs s 4 k.
Instances For
Evaluation correctness #
Active queries and lookahead bound #
Uncompiled multiplication schedule #
Uncompiled minimum-index dyadic band multiplication query schedule after, and not a
machine-space formalization of, [OpenAI2026LogSpace, Lemma 10.4] (native space realization is
tracked in #9181): computes val 0 * val 1 with digit lookahead j ≤ t + 16 * d.
Compose two StreamSchedules with exact multiplication S₁ * S₂.
Early-word reciprocal and unit prefix clamping #
Integer prefix queries and unit-interval clamping #
Clamp a K-place signed-digit integer prefix into the canonical nonnegative range
{0, ..., 2 ^ K} (after [OpenAI2026LogSpace, Section 10.4, Lemma 10.5]).
Virtual reciprocal composition and evaluation #
Fixed slack-1 inner StreamSchedule computing (v₀ + v₁ * v₂) / 2 over virtual streams
Fin 3.
Uncompiled early-word / suffix child query trees realizing recipVirtualEnv: streams 0, 1
query places j ≤ recipCutoff s and stream 2 (suffixStream) queries env () directly only
at places r > recipCutoff s (helper after [OpenAI2026LogSpace, Lemma 10.5]; see #9181).
Active queries and lookahead bound #
Uncompiled reciprocal schedule #
Uncompiled early-word reciprocal query schedule on [1 / 4, 1] after, and not a machine-space
formalization of, [OpenAI2026LogSpace, Lemma 10.5] (native space realization is tracked in #9181):
computes 1 / (64 * val ()) for streamVal (env ()) ∈ [1 / 4, 1] with digit lookahead
j ≤ t + (8 + recipHalfVirtualSchedule.lookaheadCoeff) * d.
Compose a StreamSchedule whose target value lies in [1 / 4, 1] with recip64Schedule to
obtain 1 / (64 * S).
Zero-padded detector rank #
Counting and fold query trees #
Uncompiled outer scan over candidate elements rem for the zero-padded detector rank, tracking
the index best : Option Op with largest positive intPrefix among elements exceeded or matched
by at least k members of items.
Uncompiled mod-16 residue query tree for zeroPaddedRankApprox k items.toFinset env s
(clamping negative order statistics up to 0 as in Finset.kthLargest; helper after
[OpenAI2026LogSpace, Lemma 10.6] and Sections 4.2, 8.2; see #9181).
Evaluation correctness #
Active queries and lookahead bound #
Uncompiled rank schedules #
Uncompiled zero-padded detector-rank query schedule over a duplicate-free list (intermediate
helper after, and not a machine-space formalization of, [OpenAI2026LogSpace, Lemma 10.6] and
Sections 4.2, 8.2; native space realization is tracked in #9181): computes
Finset.kthLargest k items.toFinset (clamping negative order statistics up to 0) with digit
lookahead j ≤ t + 4 * d.
Noncomputable Finset wrapper for zeroPaddedRankListSchedule (uncompiled helper after
[OpenAI2026LogSpace, Lemma 10.6]; see #9181). Because Finset.toList uses Classical.choose to
pick an arbitrary list ordering, any future machine-realizable stage must pass an explicit
duplicate-free list directly to zeroPaddedRankListSchedule.