Documentation

CslibFrontier.Foundations.Analysis.SignedDigitStream.Basic

Avizienis signed-digit streams and approximation residues #

This module formalizes the redundant radix-2 signed-digit stream representation over the alphabet {-6, ..., 6} and the reduction of exact stream generation to mod-2^q integer approximation residues from [OpenAI2026LogSpace, Section 10.1, Lemma 10.1].

A sequence x : ℕ → ℤ with |x j| ≤ 6 represents the real number streamVal x = ∑' j, (x j : ℝ) / 2 ^ j, with finite K-place truncation streamPrefix x K = ∑ j ∈ range (K + 1), (x j : ℝ) / 2 ^ j satisfying |streamVal x - streamPrefix x K| ≤ 6 / 2 ^ K.

Conversely, if |z| ≤ 1 and deterministic integers N : ℕ → ℤ satisfy the scaled approximation bound |N t - 2 ^ t * z| < 2 for every t : ℕ, then the difference digits diffDigit N 0 = N 0 and diffDigit N (t + 1) = N (t + 1) - 2 * N t belong to {-6, ..., 6}, telescope to N T / 2 ^ T, sum to z, and can be decoded uniquely from N t % 2 ^ q and N (t - 1) % 2 ^ q for any q ≥ 4. Moreover, signed floor shifts preserve residues: (a / 2 ^ s) % 2 ^ q equals (a % 2 ^ (q + s)) / 2 ^ s for every signed integer a : ℤ.

Main definitions #

Main results #

References #

A redundant radix-2 signed digit in the alphabet {-6, ..., 6}.

A stream of redundant radix-2 signed digits in {-6, ..., 6}.

The scaled integer prefix ∑_{j = 0}^K x_j 2^{K - j} of a digit stream.

noncomputable def Cslib.SignedDigitStream.streamPrefix (x : ℕ → ℤ) (K : ℕ) :

The real K-place prefix x^{[K]} = ∑_{j = 0}^K x_j 2^{-j} of a digit stream.

noncomputable def Cslib.SignedDigitStream.streamVal (x : ℕ → ℤ) :

The real number ∑_{j = 0}^∞ x_j 2^{-j} represented by a digit stream.

The remainder stream with zeros through place K and x j for j > K.

Deterministic integer approximations N t to 2 ^ t * z within strict error 2 [OpenAI2026LogSpace, (10.3)].

Telescoping difference digits z_0 = N_0 and z_{t+1} = N_{t+1} - 2 N_t [OpenAI2026LogSpace, (10.4)].

Centered representative of r modulo 2 ^ q in (-2 ^ (q - 1), 2 ^ (q - 1)].

Decode the place-t difference digit solely from the mod-2^q residues rCurr = N_t mod 2^q and rPrev = N_{t-1} mod 2^q (at t = 0, rPrev is unused).

theorem Cslib.SignedDigitStream.intPrefix_succ (x : ℕ → ℤ) (K : ℕ) :
intPrefix x (K + 1) = 2 * intPrefix x K + x (K + 1)
theorem Cslib.SignedDigitStream.streamPrefix_succ (x : ℕ → ℤ) (K : ℕ) :
streamPrefix x (K + 1) = streamPrefix x K + ↑(x (K + 1)) / 2 ^ (K + 1)
theorem Cslib.SignedDigitStream.IsSignedStream.summable {x : ℕ → ℤ} (hx : IsSignedStream x) :
Summable fun (j : ℕ) => ↑(x j) / 2 ^ j

Tail truncation bound [OpenAI2026LogSpace, (10.2)]: truncating a signed-digit stream after place K incurs error at most 6 / 2 ^ K.

Lemma 10.1 (digit range) [OpenAI2026LogSpace, Lemma 10.1]: difference digits of any scaled approximation to z ∈ [-1, 1] lie in {-6, ..., 6} (indeed |z_0| ≤ 2 and |z_{t+1}| ≤ 5).

theorem Cslib.SignedDigitStream.streamVal_diffDigit {z : ℝ} {N : ℕ → ℤ} (hz : |z| ≤ 1) (hN : IsScaledApprox z N) :

Lemma 10.1 (exact representation) [OpenAI2026LogSpace, Lemma 10.1]: the difference digits of N sum to z.

theorem Cslib.SignedDigitStream.hasSum_diffDigit {z : ℝ} {N : ℕ → ℤ} (hz : |z| ≤ 1) (hN : IsScaledApprox z N) :
HasSum (fun (j : ℕ) => ↑(diffDigit N j) / 2 ^ j) z
theorem Cslib.SignedDigitStream.decodeDiffResidue_eq_diffDigit {q : ℕ} (hq : 4 ≤ q) {z : ℝ} {N : ℕ → ℤ} (hz : |z| ≤ 1) (hN : IsScaledApprox z N) (t : ℕ) :
decodeDiffResidue q (N t % 2 ^ q) (N (t - 1) % 2 ^ q) t = diffDigit N t

Lemma 10.1 (residue decoding) [OpenAI2026LogSpace, Lemma 10.1]: for q ≥ 4, the place-t difference digit is uniquely determined by N t % 2 ^ q and N (t - 1) % 2 ^ q.

theorem Cslib.SignedDigitStream.ediv_two_pow_emod_eq (a : ℤ) (q s : ℕ) :
a / 2 ^ s % 2 ^ q = a % 2 ^ (q + s) / 2 ^ s

Signed floor-shift residue identity [OpenAI2026LogSpace, (10.11)]: discarding the low s bits of the canonical (q + s)-bit Euclidean residue computes the mod-2^q residue of the signed floor quotient a / 2 ^ s for every signed integer a : ℤ.