arXiv:2610.26396cs.ITOct 2026

Manuscript Offprint

arXiv:2610.26396

Universal coding with the exhaustive peres transform

Aur{é}lien Garivier

Abstract

Peres’s iteration of von Neumann’s procedure is completed into a bijection of {0,1}N\{0,1\}^N: the recursion runs to exhaustion, nothing is discarded, and every input splits into fair bits and residual bits. The residual strings form a complete prefix code that determines the number of ones of the input, so the fair bits are exactly uniform given the residual for every exchangeable law. For a Bernoulli source the likelihood factorises exactly, in decoding order, into a factor 1/2 per fair bit and a Bernoulli factor per residual bit, with biases obtained by iterating two explicit maps. The number of fair bits per input symbol tends to the entropy almost surely, also on larger alphabets. Code B stores the fair bits and codes only the residual with an arithmetic coder; its ideal length is that of the two-part code, at most log⁡2(N+1)+1\log_2(N+1)+1 bits above −log⁡2Pθ(s)-\log_2\mathbb{P}_\theta(s) for every input ss and bias θ\theta. Code C uses Rice codes instead. In experiments up to N=220N=2^{20} its mean regret stays below 200 bits, where a Rice coder on the raw input loses a fixed fraction of the entropy on skewed sources. For sources with memory, the Burrows–Wheeler transform of the reversed string arranges all context orders in one tree of intervals; coding the leaves of a pruned tree as Bernoulli strings adapts to every Markov order up to its depth, and on suffix-closed trees the leaf weights determine the split points.

Keywords: Randomness extraction, universal coding, Peres algorithm, Rice codes, context trees.

1 Introduction

Von Neumann’s procedure [1] turns a coin of unknown bias into a fair one: read the bits in pairs, output the second bit of every unequal pair and discard the equal pairs. Its yield, θ(1−θ)\theta(1 - \theta) fair bits per input bit for a coin of bias θ\theta, is far from the entropy h(θ)h(\theta). Elias [2] attained the entropy by extracting from the index of the input in its type class, and Ryabko and Matchikina [3] computed the index fast, in quasi-linear time with fast multiplication. Peres [4] took another route: the sequence uu of pair XORs and the sequence vv of values of the equal pairs still contain randomness and can be fed back to the same procedure; truncated at depth vv, the recursion extracts at a rate rv(θ)r_v(\theta) that increases to h(θ)h(\theta). Pae generalised the recursion to loaded dice [5], to binarisation trees [6] and to a general class of Peres-style recursions [7], where the recursion run to exhaustion is called the Peres function and its asymptotic optimality is stated; Zhou and Bruck [8] gave a universal scheme to lift binary

*ENS de Lyon, France. E-mail: aurelien.garivier@ens-lyon.fr. ORCID: 0000-0002-4906-9573. Code and data: https://hal.science/hal-05802360.

UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM

extractors to larger alphabets. Prasitsupparote et al. [9] compared the extractors of Elias and Peres at finite lengths.

On the coding side, enumerative coding [10] codes the type of the input and then its index in the type class; the Krichevsky–Trofimov (KT) mixture [11] attains a regret of 12log⁡2N+O(1)\frac{1}{2} \log_2 N + O(1), which is first-order optimal [12]; Rissanen's two-part codes send an estimate of the parameter followed by the data coded with it. Context-tree weighting [13] extends KT to tree sources. Source codes and random number generators are related: the output of an asymptotically optimal source code is close to uniform in the asymptotic, normalised-divergence sense of [14], whereas the fair bits below are exactly uniform at every length. Finally, Arikan's source polarization [15] applies the same XOR of pairs, recursively and linearly, and shows that the conditional entropies of the transformed bits polarise to 0 or 1.

This paper studies what happens when Peres’s recursion is run to exhaustion and everything it does not extract is kept. The result is a bijection T of {0,1}N\{0,1\}^{N} onto pairs (Y;R)(Y;R) of fair bits and residual bits, which is both an extractor and the core of a lossless code. The contributions are as follows.

  1. Reversible completion. T is a bijection with an explicit inverse; the residuals form a complete prefix code RN\mathcal{R}_N that the decoder parses without knowing its length, and the weight of the input is a function of the residual alone (Corollary 4). Exact uniformity of the fair bits given the residual, for every exchangeable law (Theorem 5), follows without any argument on permutations.

  2. Likelihood factorisation and entropy rate. For a Bernoulli source,

Pθ(s)=2−∣Y∣∏iPϕπi(θ)(Ri),\mathbb{P}_{\theta}(s)=2^{-|Y|}\prod_{i}\mathbb{P}_{\phi_{\pi_{i}}(\theta)}(R_{i}),

where the bias ϕπi(θ)\phi_{\pi_i}(\theta) of each residual bit is obtained by composing two maps U, V along its path; the statement is causal, in decoding order, and not a conditional independence given the shape of the recursion (Theorem 6). The number of fair bits satisfies the pointwise bound ∣Y(s)∣≤log⁡2(Nw(s))|Y(s)| \leq \log_2 \binom{N}{w(s)} and ∣Y∣/N→h(θ)|Y|/N \to h(\theta) almost surely and in L1L^1 (Theorem 7). The lower bound is proved by an entropy-decrease argument that applies verbatim to an XOR transform on {0,1}b\{0,1\}^b (Proposition 9).

  1. Codes B and C. Code B sends the weight, stores the fair bits and codes the residual with a static arithmetic coder at the known biases; its ideal length is that of the two-part plug-in code, so its ideal regret is at most log⁡2(N+1)+1\log_2(N + 1) + 1 for every input and every θ\theta (Theorem 11), and an actual prefix code realises it within one more bit. Code C uses Rice codes on classes of residual bits of similar bias and no arithmetic coder; this is a structural property of the representation, not a speed gain in our implementation (Section 8.4). With a fixed cap on the Rice parameter it is not universal: along odd lengths, its expected redundancy per bit has a positive limit inferior for every bias below a threshold set by the cap (Proposition 14). We also state exactly what each part of the codeword reveals (Proposition 15).

  2. Sources with memory. The Burrows–Wheeler transform (BWT) of the reversed string places the bits that follow each context, for all orders at once, in nested intervals of a binary tree. A code that selects a pruned tree and codes each leaf with a code for Bernoulli strings adapts to Markov sources of order up to the depth D of the tree,

UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM

with an explicit bound on its regret (Proposition 17). On suffix-closed trees the leaf weights determine all interval lengths (Corollary 19); the underlying identity is the occurrence count of backward search in the FM-index [16,17], and our contribution is the deduction that leaf weights suffice. We compare with compression boosting [18].

  1. Experiments. Bernoulli and binary Markov sources (ideal lengths, and actual bit streams for code C and for Rice baselines), ASCII text (ideal lengths), and a C implementation benchmarked by actual file sizes, with an ablation that separates the exact code from its clipped implementation. The code is deposited with the paper (Section 8).

What is not new, and what is. The exhaustive recursion as an extractor and its asymptotic optimality are in [7]. Pae’s structure lemma [7, Lemma 4] maps each type class bijectively onto a product of type classes, one per component of the recursion (for Peres’s recursion: the von Neumann output, u and v), and exact uniformity follows by induction. What we add to it is a description of the whole space {0,1}N\{0,1\}^N rather than of one type class: the residual strings form a single complete prefix code RN\mathcal{R}_N that the decoder parses without knowing its length and that determines the type, so that s↦(Y;R)s \mapsto (Y; R) is a bijection in which nothing is discarded (Corollary 4); the law of the residual under a Bernoulli source is explicit and causal (Theorem 6), which turns the extractor into a lossless code that codes only the residual (Theorem 11) and makes a Rice-coded variant possible, with its limits (Proposition 14); and on suffix-closed trees of the BWT of the reversed string, the leaf weights determine the partition (Corollary 19). The entropy-rate proof replaces the fixed-point step of [4,7] by an entropy-decrease argument. Conversely, the length of code B is that of the classical two-part code [12]; coding the type with Jeffreys’ prior and then the index in the type class is enumerative coding [10] with the KT length (Remark 12); the cost-driven partition of the BWT into context segments is compression boosting [18], and coding BWT segments with KT is the piecewise coder of [19].

Organisation. Section 2 defines the transform and proves bijectivity and uniformity. Section 3 gives the factorisation and the entropy rate; Section 4 the extension to {0,1}b\{0,1\}^{b}. Section 5 defines codes B and C. Section 6 treats sources with memory, Section 7 computational costs, Section 8 the experiments, and Section 9 compares with Elias's extractor. Longer proofs are in the Appendices.

Notation. Strings are finite sequences of bits; ∣s∣|s| is the length of ss, w(s)\mathrm{w}(s) its Hamming weight, s∗ts \ast t the concatenation, ⊕\oplus addition modulo 2. Logarithms are to base 2 unless written ln⁡\ln. The Bernoulli source of bias θ∈(0,1)\theta \in (0,1) gives Pθ(s)=θw(s)(1−θ)N−w(s)\mathbb{P}_{\theta}(s) = \theta^{\mathrm{w}(s)}(1 - \theta)^{N - \mathrm{w}(s)} to s∈{0,1}Ns \in \{0,1\}^N, and h(θ)=−θlog⁡θ−(1−θ)log⁡(1−θ)h(\theta) = -\theta \log \theta - (1 - \theta) \log(1 - \theta). The regret of a code CC on ss is ∣C(s)∣+log⁡Pθ(s)|C(s)| + \log \mathbb{P}_{\theta}(s), its expected redundancy Eθ∣C(X)∣−Nh(θ)\mathbb{E}_{\theta}|C(X)| - Nh(\theta). The KT probability is KT(s)=Γ(w+12)Γ(N−w+12)/(πΓ(N+1))\mathrm{KT}(s) = \Gamma(w + \frac{1}{2})\Gamma(N - w + \frac{1}{2}) / (\pi \Gamma(N + 1)) with w=w(s)w = \mathrm{w}(s); its regret is at most 12log⁡N+1\frac{1}{2} \log N + 1 for every ss [13], and the minimax expected redundancy of the Bernoulli family is 12log⁡N+O(1)\frac{1}{2} \log N + O(1) [11,12].