Elementary stream operations, finite-state prefix comparisons, ranks, and buffered tests #
This module formalizes the deterministic scaled integer approximations and low-residue window identities for the elementary signed-digit stream operations of [OpenAI2026LogSpace, Sections 10.2 and 10.5, Lemmas 10.3, 10.6, 10.7, and 10.8]:
- Public rational streams (
ratApprox,ratStream): exact integer floor approximations⌊2 ^ t * r⌋for rational constantsr : ℚ. - Low-residue locality (
windowPrefix,intPrefix_emod_eq_windowPrefix_emod): modulo2 ^ W,intPrefix x Kdepends only on theWdigits inIco (K + 1 - W) (K + 1). - 27-state prefix comparison automaton (
cmpStep,cmpPrefix): scanning from place0toKwith state clamped to[-13, 13]decides the exact order ofstreamPrefix x KandstreamPrefix y K. - Elementary operations (
pairAvgApprox,maxApprox,minApprox,shiftClipApprox): pair averages(x + y) / 2, maxima, minima, and arbitrary2 ^ vshifts clipped to[-1, 1]. - Zero-padded detector ranks (
zeroPaddedRankApprox):Finset.kthLargestover stream prefixes att + 4(which inserts0so negative order statistics clamp up to0, matching the detector rank of Sections 4.2 and 8.2 rather than the general signed order statistic of Lemma 10.6), with error< 2byFinset.abs_kthLargest_sub_kthLargest_le. - Buffered margin tests (
cmpBuffered,bufferedTest): 63-state finite-precision test accepting alls > 2 uand rejecting alls ≤ uwhenu ≥ ρ ≥ 2 ^ (-R).
Main definitions #
Cslib.SignedDigitStream.ratApprox,Cslib.SignedDigitStream.ratStream: rational streams.Cslib.SignedDigitStream.windowPrefix: bounded-window suffix ofintPrefix.Cslib.SignedDigitStream.cmpStep,Cslib.SignedDigitStream.cmpPrefix:[-13, 13]prefix comparator.Cslib.SignedDigitStream.pairAvgApprox,Cslib.SignedDigitStream.maxApprox,Cslib.SignedDigitStream.minApprox,Cslib.SignedDigitStream.shiftClipApprox: scaled integer approximations for elementary operations and shifts with clipping.Cslib.SignedDigitStream.zeroPaddedRankApprox: scaled integer approximation for the zero-padded detector rankFinset.kthLargest.Cslib.SignedDigitStream.cmpBuffered,Cslib.SignedDigitStream.bufferedTest: fixed-precision buffered margin test.
Main results #
Cslib.SignedDigitStream.intPrefix_emod_eq_windowPrefix_emod: low-residue locality.Cslib.SignedDigitStream.cmpPrefix_eq_clamp_sub,Cslib.SignedDigitStream.cmpPrefix_pos_iff: exactness of the 27-state prefix comparison automaton.Cslib.SignedDigitStream.pairAvgApprox_isScaledApprox,Cslib.SignedDigitStream.maxApprox_isScaledApprox,Cslib.SignedDigitStream.minApprox_isScaledApprox,Cslib.SignedDigitStream.shiftClipApprox_isScaledApprox,Cslib.SignedDigitStream.zeroPaddedRankApprox_isScaledApprox:< 2scaled approximation bounds.Cslib.SignedDigitStream.bufferedTest_eq_true_of_two_mul_lt,Cslib.SignedDigitStream.bufferedTest_eq_false_of_le: soundness of buffered margin tests.
References #
- OpenAI, Exact Derandomization of Logarithmic Space: L = RL = BPL,
Sections 10.2 and 10.5, Lemmas 10.3 and 10.6--10.8 (23 September 2026, revision
7ef5c0cc, not peer reviewed).
Exact integer floor approximation (2 ^ t * r.num) / r.den for a rational constant r.
Computable signed-digit stream representing a rational constant r ∈ [-1, 1].
Low-residue locality [OpenAI2026LogSpace, Lemma 10.3]: modulo 2 ^ W, intPrefix x K
depends only on the at most W digits in Ico (K + 1 - W) (K + 1).
Transition step of the 27-state absorbing prefix comparison automaton on [-13, 13].
Exactness of the 27-state prefix comparator [OpenAI2026LogSpace, Lemma 10.3]: for valid
signed-digit streams, cmpPrefix x y K equals intPrefix x K - intPrefix y K clamped to
[-13, 13].
Real 2 ^ v scaling followed by clamping to [-1, 1].
Scaled integer approximation to shiftClipVal v (streamVal x) [OpenAI2026LogSpace, Lemma 10.7]:
returns 0 without querying x when t + v + 4 < 0, and otherwise clamps intPrefix x K at
K = (t + v + 4).toNat to [-2 ^ (t + 4), 2 ^ (t + 4)] before floor-shifting by 16.
Shift-and-clip approximation [OpenAI2026LogSpace, Lemma 10.7]: shiftClipApprox v x
approximates max (-1) (min 1 (2 ^ v * streamVal x)) within scaled error < 2.
Scaled integer approximation to the zero-padded detector rank
Finset.kthLargest k s (fun i => streamVal (x i)) using prefixes at K = t + 4.
Because Finset.kthLargest inserts 0 [OpenAI2026LogSpace, Sections 4.2 and 8.2], negative
order statistics clamp up to 0 (unlike the general signed order statistic of
[OpenAI2026LogSpace, Lemma 10.6]).
Zero-padded detector-rank approximation (adapting [OpenAI2026LogSpace, Lemma 10.6] to the
zero-padded Finset.kthLargest of Sections 4.2 and 8.2): zeroPaddedRankApprox k s x
approximates kthLargest k s (fun i => streamVal (x i)) within < 2.
Transition step of the 63-state absorbing 2 s - 3 u comparator on [-31, 31].
Lemma 10.8 (completeness of buffered test) [OpenAI2026LogSpace, Lemma 10.8]: if sVal and
uVal have normalized streams s, u at scale 2 ^ M, uVal ≥ ρ ≥ 1 / 2 ^ R, and
2 * uVal < sVal, then bufferedTest M R s u = true.
Lemma 10.8 (soundness of buffered test) [OpenAI2026LogSpace, Lemma 10.8]: under the same
scaling hypotheses, if sVal ≤ uVal, then bufferedTest M R s u = false.