Manuscript Offprint
arXiv:2610.26396Universal coding with the exhaustive peres transform
Abstract
Peres’s iteration of von Neumann’s procedure is completed into a bijection of : 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 bits above for every input and bias . Code C uses Rice codes instead. In experiments up to 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, fair bits per input bit for a coin of bias , is far from the entropy . 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 of pair XORs and the sequence of values of the equal pairs still contain randomness and can be fed back to the same procedure; truncated at depth , the recursion extracts at a rate that increases to . 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 , 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 onto pairs of fair bits and residual bits, which is both an extractor and the core of a lossless code. The contributions are as follows.
-
Reversible completion. T is a bijection with an explicit inverse; the residuals form a complete prefix code 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.
-
Likelihood factorisation and entropy rate. For a Bernoulli source,
where the bias 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 and almost surely and in (Theorem 7). The lower bound is proved by an entropy-decrease argument that applies verbatim to an XOR transform on (Proposition 9).
-
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 for every input and every (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).
-
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].
- 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 rather than of one type class: the residual strings form a single complete prefix code that the decoder parses without knowing its length and that determines the type, so that 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 . 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; is the length of , its Hamming weight, the concatenation, addition modulo 2. Logarithms are to base 2 unless written . The Bernoulli source of bias gives to , and . The regret of a code on is , its expected redundancy . The KT probability is with ; its regret is at most for every [13], and the minimax expected redundancy of the Bernoulli family is [11,12].
2.1 One Level
Let , with . With the pairs , , define by ; , of length ; , of length ; and if , otherwise. Write . The string is von Neumann's output.
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
Lemma 1. is a bijection from onto , and
Proof. Given , set to the next unread bit of if and of if , then , and if . An unequal pair has weight 1, an equal pair weight .
Equation (1) does not involve y: re-orienting an unequal pair changes neither u, v, r nor the weight.
2.2 Iteration to Exhaustion
Definition 2 (Exhaustive Peres transform). For with , . For , with , and ,
is the string of fair bits, the string of residual bits, and .
The calls of T form a binary tree: a node of length at least 2 has a u-child and a v-child, nodes of length at most 1 are leaves, and an odd remainder is attached to the node that produced it. A node is named by its path from the root, and a residual bit inherits the path of the node that produced it. Since , the depth is at most . Fig. 1 shows the example of [20], for which and .
Decoding. For each , define , which reads a prefix of each of the two streams and returns with the unread parts . reads nothing and returns ; returns the first bit of . For , with : ; with , is the first bits of and the rest; ; is the first bits of and the rest; the output is .
Proposition 3. For every , . Hence is injective and is inverted by a decoder that reads both streams from left to right without knowing their lengths.
Proof. By induction on , for all and all strings , . The length of each piece is known when it is needed: , and , once is rebuilt; the encoder emits , , and , , in the order in which the decoder requests them.
In Fig. 1, Dec₁₂ calls Dec₆ for the u-string of the root, which calls Dec₃ for node uu, which calls Dec₁: the first residual bit, 1, is the u-string of uu. Then k = 1, the first fair bit is y, the v-string is empty and the second residual bit is the odd remainder, so node uu is 010. Back at node u, k = 1, the next fair bit is its y, and Dec₂ rebuilds node uv = 10 from the third residual bit and the next fair bit. Back at the root, k = 3, the next three fair bits are y = 011, Dec₃ rebuilds node v = 101 from the last two residual bits and the last fair bit, and both streams are exhausted exactly when the root returns.
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM

Figure 1. Exhaustive transform of . Each node shows its path, its string in pairs (a bar precedes the odd remainder), , the fair bits , the string passed to the -child and the remainder ; empty -children are omitted. The last line is the bias of Section 3. The residual bits, in decoding order, are at paths uuu, uu, uvu, vu, v; the fair bits are .
2.3 The Residual Prefix Code
The decoder’s only decisions are the weights of the nodes, which by (1) are functions of residual bits already read.
Corollary 4 (Image of T). Let , , for , and for , , :
Then is a complete prefix-free set, , and is a bijection from onto , with .
Proof. Induction on . Since and are prefix-free, the decomposition is unique and is well defined. For , with , so , , and by (1). Conversely, for and , consumes exactly , fair bits, , , and the fair stream has exactly the bits it requests, so is the transform of the output. Two residual strings are parsed identically as long as they agree, so a proper prefix of a residual string would stop the decoder early: is prefix-free. Completeness follows from the induction.
The image is not a product set: the number of fair bits is dictated by the residual. Restricted to one weight, the Kraft equality reads , so the type class is split
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
into blocks of strings sharing a residual. For , ; for , and is 0.42 at and 0.19 at . Since is prefix-free, the single string of length determines , and is read off its length.
2.4 Exact Uniformity
Theorem 5. Let be exchangeable, i.e., depends on only through . Then is a function of and, conditionally on , is uniform on .
Proof. By Corollary 4, and are functions of , hence so is . As is a bijection, the strings with a given residual are in bijection with and have equal probabilities.
This is Peres’s Proposition 1 [4] and Pae’s structure lemma [7] for the exhaustive recursion, here a direct consequence of the bijection.
3 Bernoulli Sources
3.1 Causal Factorisation of the Likelihood
Define the bias maps
For two independent Bernoulli( ) bits, is the probability that they differ and the probability that an equal pair is 11. For a path , composes the maps along , first letter first: , , . In the natural log-odds ,
so a v step doubles the log-odds and a u step brings them towards 0, quadratically when they are small and by about per step when they are large. Along mixed paths the bias need not move monotonically.
Theorem 6. For every and , with the path of the -th residual bit ,
Consequently, if , then conditionally on , which determine whether an -th residual bit is requested and its path , is Bernoulli( ); and conditionally on , is uniform.
Proof. With and , , while and . Hence ; induct on and . For the second statement, the decoder fed with fair bits and with residual bits drawn, at the moment of their request, from Bernoulli() produces each in the image of with probability , which by (3) is of its output.
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
The causal form is essential. Conditioning on the whole shape of the recursion, which depends on residual bits not yet requested, changes the biases: for , an empty -child means that the pair is unequal, and the residual bit is then 1 with probability one, not . In Fig. 1, (3) reads , and both sides equal at .
Taking expectations in (3) at one level gives Peres's identity . Globally, by the chain rule along the residual bits in request order, , and since is a bijection and is uniform given ,
3.2 Entropy Rate
Theorem 7. For every of weight , . If are i.i.d. Bernoulli( ) and , then for every , and almost surely and in .
Proof. By Corollary 4, the strings sharing the residual of have weight , so . Concavity of gives , and the strong law with the continuity of gives a.s. The lower bound a.s. is the case of Proposition 9 below; it also follows from Peres's Propositions 2 and 3 [4], since the exhaustive recursion extracts at least as many bits as its truncation at any depth . Convergence in follows from .
Since , for every the expected number of residual bits with is : the residual bits that are not nearly deterministic are negligible relative to the input length. For , , so their proportion among the residual bits tends to 0 in probability; for every residual bit is fair, and there are of them. This is the sense in which the transform polarises, without a rate; Fig. 2 shows it on a string of length 64. Convergence is slow for skewed sources (Section 8).
4 Larger Alphabets: The XOR Transform
Let with bitwise XOR, and for let be the position of the leading 1 of . For a pair of symbols, let . If , keep . If , let , (the element of whose bit is 0), and the string with bit deleted. The unordered pair is , so determines it and records its orientation. The one-level map sends to the -string, the fair bits , the -string, one string over for each (the 's of the pairs with XOR ), and the odd remainder. It is a bijection, and the type of is a function of . The transform recurses on and over and on each over , emits , and stops at strings of length at most 1 or on the alphabet . For it is .
For a law on , let with , , and for with , , a law on , where is with a inserted at position .
Theorem 8. (i) If the law of depends only on its type, then conditionally on the residual of , is uniform on . (ii) For every law and every with (so that no branch of zero mass is visited), with the law obtained by applying the maps along the path , over the residual symbols .
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM

Figure 2. The recursion tree of a Bernoulli(0.3) string of length 64. Each node shows its string and its bias ; an odd remainder follows a bar, in red; leaves of length 1 (red boxes) are the other residual bits; empty nodes are not drawn. Along u branches the biases go to 0.5, under v steps towards 0.
Proof. (i) is the proof of Theorem 5, the type being a function of the residual. (ii) An equal pair has probability , an unequal pair , and . Induct.
The map U is the XOR autocorrelation, the first step of a polar transform over . The one-level fair-bit rate is per symbol, and taking expectations gives
(4)
Proposition 9. For every of type and empirical law , . If are i.i.d. of law on and , then and almost surely and in .
The proof, in Appendix A, assigns masses to the nodes of the recursion tree and shows, using (4), that the mass-weighted entropy remaining at depth decreases by the fair-bit rate of depth ; a compactness argument shows that it tends to 0. Pae asserts the rate for all tree-defined Peres-style recursions [5,7]; the argument above is a direct proof, and for it reproves [4] without the fixed point of the recursion.
Code B (Section 5) extends verbatim: by Theorem 8(ii), sending the type in bits, the fair bits as they are and the residual at its plug-in laws gives regret at most . The alternative is to binarise first: for every prefix of a symbol, the next bits of the symbols with prefix form a binary sequence; for an i.i.d. source, conditionally on the bits at shorter prefixes, which select its positions, it is i.i.d. with bias , and T applies to it. This is the complete binarisation of [8] and the binarisation tree of [6]. In our experiments binarisation extracts more: on its residual entropy is about half that of , and on text it extracts 1.7 to 1.8 times as many fair bits
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
per character as T , whose information is spread over 255 groups too small for the recursion. The text experiments therefore binarise.
5 Codes for Memoryless Sources
The codes below are fixed-to-variable length codes for a length known to the decoder; a file format stores in a header. Both codes send in bits, code the residual and store the fair bits as they are; they differ in how they code the residual. Encoder and decoder use the plug-in bias and carry down the recursion, so the bias of each residual bit is known to both when it is produced or requested.
5.1 Code B
Definition 10 (Code B). Each residual bit is coded at the fixed probability of its node. The ideal length of code B is .
Theorem 11. For every and ,
Proof. By (3) at , plus the residual cost equals , which is . For , (3) is an identity between rational functions continuous on , so it holds at : there is no fair bit and every residual bit has probability one.
An actual code realises the ideal length within one bit. By Theorem 6, is a probability law on the prefix code (the residual bits are drawn causally), so the weight in bits, a Shannon codeword for under , and the fair bits form a prefix code of length at most . This is the wire format we take as the definition of code B; an exact arithmetic realisation of this residual law attains within a constant termination cost. The finite-precision compressor of Section 8.4 codes a different effective law (clipped probabilities, Table 8) and is not covered by this bound. In the rest of the paper, statements about code B concern , and actual sizes are reported as such.
Code B therefore has the length of the two-part code [12]: the transform does not shorten plug-in codes, it changes which bits need a coder. About bits are stored as they are and only the residual, at biases that are mostly close to 0 or 1, passes through the coder. The expected regret is ; quantising on a grid of about points in the arcsine scale would bring it to [12], which we do not implement.
Remark 12 (Fair bits with the KT length). For a weight , let for with . By the Kraft equality restricted to one weight (Section 2), is a probability law, and coding under followed by its fair bits costs exactly ideal bits given . If is coded with the beta-binomial law , the total ideal length is , since depends on only through . Exactly fair bits and the KT length are therefore compatible. This is an existence statement; factorises along the recursion (at a node of length and weight , the remainder is with probability , and at a node of length the number of unequal pairs
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
has probability , which gives a recursive enumerative code [10] with the large binomials that code B avoids. Sending the type with BB and then the index of s in its type class (code E) has the same length: it is enumerative coding with Jeffreys' prior, i.e., KT, and it is not new. For in a compact subset of , code E is shorter than code B by bits.
5.2 Code C: Rice Classes
A residual bit of bias has a minority symbol (1 if , else 0) of probability ; the other value is its majority symbol. A Rice code of parameter writes a run length as in unary followed by in bits [21,22]. The class of a residual bit is , capped at ( in our experiments), with when . This is the usual approximation of the best parameter for geometric runs; it is a heuristic, since the exact expected length per run is k + 1/(1 - (1 - \varepsilon)^2^k) [23] and the rule picks for where is better, at a cost of up to 0.31 bits per run.
Definition 13 (Code C). Header: w, then for each class the number of minority symbols among the residual bits of that class, as the Elias-gamma codeword of . Body, in decoding order: the fair bits as they are and, for class , before each of its minority symbols, the number of majority symbols of the class since the previous one, as a Rice codeword of parameter . When the decoder requests a residual bit of class , it outputs the majority symbol if the minority symbols of the class have all been seen; otherwise it reads a Rice codeword if no gap of that class is pending.
The decoder knows the class and the majority symbol of every requested bit from its bias, so the interleaving is well defined; the header removes the need to code a final run. Code C needs, besides the biases, only XORs, selections, run counting and unary and fixed-width writes. For a homogeneous Bernoulli( ) minority process, the Rice code with the uncapped parameter is within 0.21 bits per run of the entropy of the run length when (about 0.12 with the best integer parameter), a loss of order bits per bit; for nearly fair bits written in class 0 the loss is per bit. This motivates the class rule but gives no bound for code C: its classes combine different biases, and with the cap the loss per run is unbounded as (57 bits per run at for ), which is the obstruction below. The header costs at most bits, but this says nothing about the body: the bits of a class do not share one bias and their gaps are not i.i.d. geometric. In fact no polylogarithmic regret bound holds uniformly: for and , there is no fair bit, the single 1 is the odd remainder of the root, a minority symbol of class K for large N, and it is preceded in decoding order by the zeros of the v-subtree, also of class K, so its Rice codeword costs at least bits while . The obstruction persists at a fixed bias.
On typical inputs the residual has three regimes, in decoding order. The decoder visits u-children first, so R opens with the bits of the all-u branch, which are nearly fair and fall in class 0, where the Rice code writes the minority indicators in unary, essentially as they are. Then come branches with v steps, where the class rises and the runs of the majority symbol lengthen; under several v steps the classes are high and the bits are almost all majority symbols, which cost nothing beyond the header. For a Bernoulli(0.3) string of length 256 with 79 ones, the transform gives 181 fair bits and 75 residual bits: 27 bits of class 0 cost 27 bits, the 22 bits of classes 1 to 3 cost 20, and the 26 bits of classes contain no minority
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
symbol and cost nothing; with the 48 header bits the total is 276 bits against , the header being logarithmic in N. For a Bernoulli(0.1) string of length , 34487 of the 36007 residual bits are in classes , and none of them is a minority symbol.
Proposition 14. Let be code C with cap and , so that a minority probability below falls in class K. For every , with X i.i.d. Bernoulli( ) of length N,
The proof is in Appendix B. For the bound concerns and its coefficient at is about bits per bit, invisible at the lengths of Table 3, but code C with a fixed cap is not universal. Emitting the odd remainder before the v-subtree does not remove the obstruction (the same argument on the u-child gives the coefficient ). A selector between codes B and C, one mode bit and the shorter stream, is universal, its length being at most one bit more than that of the actual code B, i.e., at most , but it uses the arithmetic coder on some inputs. A code that never uses an arithmetic coder and is universal, with a cap growing with N or an escape code for long gaps, would need a new analysis.
5.3 What Each Part of the Codeword Reveals
Up to a header of bits, the codeword of code B or C consists of the fair part Y and the coded residual. The following identities are exact for every N.
Proposition 15. Let X be exchangeable, and . Then Y and R are conditionally independent given , and . Moreover , and .
Proof. By Theorem 5, the law of Y given R is uniform on and depends on R only through ; hence , and . Given , is uniform on strings, so . Given , the law of is proportional to on , i.e., it is the law of given , and is a function of .
Thus, given the number of fair bits, every function of (the weight, the number of unequal pairs at every node, the residual bits) is independent of the content of the fair part, which carries only the orientations of the unequal pairs at the various levels; without conditioning, reveals bits about through its length. This is an accounting of information, not a secrecy statement: which pairs are unequal is not a function of (0001 and 0100 share the residual 10), and individual bits of are informative given either part.
6 Sources With Memory
For a Markov source of order k, the likelihood factorises over the subsequences of bits following each context of length k, each contributing a Bernoulli likelihood. The BWT of the reversed string produces these subsequences for all orders at once.
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
Table 1. BWT of for : sorted suffixes (first six symbols), the symbol preceding each, and the bit of it is.
| row | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| suffix | $ | 001$ | 001011 | 01$ | 010111 | 011100 | 1$ | 1001$ | 100101 | 101110 | 11001$ | 110010 | 111001 |
| 1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | $ | 0 | |
| bit | - |
6.1 The BWT of the Reversed String as a Context Tree
Let and , the reversed string followed by a sentinelN+1tLp inandthe stringwithx \mapsto (L', p)L'xtijxL_i = x_jx_i = 0i \le 0N+1c = c_1 \cdots c_dc_1I(c)I(c) = I(c0) \cup I(c1)I(c0)cbcL'I(c)xcx = 100111010011L' = 111001011010x$that follow a 1, and rows 1 and 2 are the two bits that follow the substring 100 (context 001).
Hence the order- context subsequences are the intervals of depth of one binary tree, and every pruned subtree is a valid partition whose context lengths vary from branch to branch. For a Markov source of order started from the zero context, over the leaves of any tree whose leaves have depth at least, with and the length and weight ofonandthe transition probability of the context of lengththatextends. This is a likelihood identity, not an independence statement: the interval lengths carry information about the symbols, so Theorem 5 does not apply to a leaf as it stands, and a tree chosen from the data adds a second obstruction. We do not claim that the fair bits of a leaf are exactly fair; the codes below use only the likelihood identity and decodability.
6.2 The BWT-Tree Code
Definition 16 (BWT-tree code). Fix a maximal depth and a pruned context tree. Emit in bits, then traverse the tree: at a node with interval , a flag says whether it is a leaf; an internal node emits its split point in bits and recurses; a leaf codes its bits of with a code for Bernoulli strings of known length (code B or KT; a leaf with no bit of , possibly holding only the sentinel row, costs nothing, ). Nodes with at most one bit or at depth are leaves without a flag. The tree minimises the total length by a bottom-up dynamic programme over the nonempty intervals.
The complete tree of depth without flags codes exactly the order- context subsequences. The dynamic programme is never worse than the complete tree of depth encoded with the flags required by Definition 16, which gives an oracle bound.
Proposition 17. Let , , and . For every and every Markov law of order started from the zero context, the ideal length of
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
the BWT-tree code with KT leaves satisfies
With code-B leaves, the same holds with in place of .
Proof. The dynamic programme minimises the total length, so is at most the length of the complete tree of depth , in which nodes with at most one bit of are made leaves. That tree costs for , at most flags, and at most split points, each in at most bits since an interval has at most rows. A leaf with bits of costs at most with a KT code [13], where is the Bernoulli likelihood of its bits at the transition probability of the context ; a leaf of depth less than has at most one bit, which costs at most one bit, and we use the transition probability of its order- context. Fewer leaves only lower the count of flags and split points. By the likelihood identity above, these likelihoods multiply to , and by Jensen's inequality since . For code-B leaves the regret per leaf is at most (Theorem 11).
This gives an upper bound of order on the regret: the split points cost each, which sequential conditional KT (regret about ) and CTW do not pay. With fixed, the code adapts to orders up to without choosing one. Since the bound of Proposition 17 does not depend on , any depth gives, for every Markov source of finite order started from the zero context, an ideal regret once , hence a vanishing regret per bit; the stronger condition makes the bound vanish uniformly over the orders . This concerns the ideal code with explicit splits, not the clipped compressor, the pooled Rice mode or the heuristic free-split tree; sources that are not of finite order would need the arguments of [19], which we do not pursue.
6.3 Free Split Points
Count rows including the sentinel row and write .
Proposition 18. For every context c and bit s, equals the number of bits equal to s in restricted to , plus 1 if s = 0 and c consists only of zeros.
Proof. The rows of are the positions with and older context ; the bits equal to in are the positions with context and . The shift is a bijection between the two sets, except for , whose zero-padded context is exactly when and is all zeros.
A tree is suffix-closed if, whenever sc is a node, c is a node.
Corollary 19. Let the tree be suffix-closed, and let the decoder know N, the shape of the tree, the weight of every leaf, and the zero-padded context of the sentinel row. For a node c, let be the sum of the weights of the leaves below c and if the sentinel row lies in , otherwise. Then and, for every node sc with ,
These equations determine every by induction on the depth, in time linear in the number of nodes.
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
Proof. The leaves below partition , so restricted to has ones and zeros, and Proposition 18 gives the two equations. If has depth , then has depth and is a node by suffix closure, is known from the leaf weights, from the sentinel context ( is a prefix of it), and by the induction hypothesis.
Definition 20 (Free-split code). Choose a suffix-closed tree (the dynamic programme with flag and leaf costs only, followed by closure under suffixes, a heuristic; or the complete tree of depth k). Header: p; one bit reserved for a fallback to explicit splits (never used); the last D bits of x, completed with zeros if x is shorter, which give the sentinel context (for a complete tree of depth k, our implementation sends bits, although k would suffice); one flag per node of depth < D (or in 4 bits for a complete tree); the leaf weights in pre-order, each with a Rice code of parameter , L being the number of leaves. Body: for every leaf, the code-B body (residual and fair bits) at the plug-in bias of its weight, the weight being already in the header; the leaf lengths are recovered by Corollary 19.
Our implementation computes the lengths by this integer recursion; it returned the true length of every node on 3208 test trees (dynamic-programme, complete and random suffix-closed trees on i.i.d., Markov, constant and periodic strings, including strings shorter than D). The regret for an order-k source becomes about plus flags: one exact count per leaf instead of a count and a split. This is the cost of the separate-count format tested here, not a lower bound for block codes; coding the counts jointly, each child's given its parent's, would lower it.
Relation to known work. Proposition 18 is the occurrence count of backward search in the FM-index [16,17]: the rows prefixed by sc are the images under the LF mapping of the rows of that hold s, so their number is a difference of two values of ; the extra row is our zero padding. We claim nothing for the identity; ours is the deduction of Corollary 19, that on a suffix-closed tree the leaf weights, which a leaf code of known length needs anyway, fix every interval. Compression boosting [18] uses the same BWT of the reversed string and the same additive cost model, for any leaf coder, and finds an exactly optimal leaf cover of the suffix tree in linear time. Its covers are arbitrary and its decoder never learns them: each piece is compressed with an end-of-string symbol or its own length, a cost absorbed in the additive constant of its per-piece bound. Our trees refine one bit at a time up to depth D; the BWT-tree code pays the splits explicitly, and the free-split code drops them at the price of suffix closure, under which our choice of tree is a heuristic, not an optimum.
Text. For bytes, the sort is refined bit by bit of each context character, so the tree stays binary with depth 8k for k characters of context, and a leaf is a segment of bytes coded through the bit-plane binarisation of Section 4, each binary sequence with KT or code B at a length known to the decoder. Proposition 18 holds for bytes, but a leaf's statistics are then a histogram and the split point is a small part of the leaf header, so we keep explicit splits for text.
7 Computational Cost
One level of on a string of length is an XOR of two half-length vectors and two compactions, bit operations. The nodes at a given depth have total length at most and the depth is at most , so and its inverse cost bit operations and memory, with no multiplication; each level is data-parallel. Code B adds a static binary
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
arithmetic coder on the residual bits, and one evaluation of U and V per node to carry the biases down the recursion (a doubling and a ln cosh in log-odds, or products and a division in probabilities), in floating or fixed point. Exact rational biases would not have constant cost, their denominators growing doubly exponentially along v steps ( ), so the bit-operation count above concerns the transform, not exact model evaluation; code C replaces the coder by two passes over the residual and unary and fixed-width writes. KT, by contrast, runs an adaptive update and an arithmetic coder on all N bits, with word operations. The BWT is a suffix sort, words by SA-IS; the dynamic programme over a tree of depth D costs ; and the recursion of Corollary 19 is linear in the number of nodes (2 ms for the complete tree of depth 8 in Python). As orders of magnitude, our Python implementation transforms bits in 0.4 s and inverts in 0.7 s on one core of an Intel Core i7-1265U, the time being dominated by interpreter overhead on the nodes of length at most 1 (for ); the speed and memory of the C tool, which runs the whole pipeline, are given in Section 8.4.
Elias’s extractor [2] needs the rank of the input in its type class, a sum of binomial coefficients of up to N bits, quasi-linear only with fast multiplication [3]. Wuille [24] computes this rank in fixed-width words without division, on batches short enough for the class size to fit a word, carrying the unextracted remainder between batches and identifying values on overflow; the output is exactly uniform for i.i.d. input, but values are discarded, so the scheme is not invertible, and its yield is reported numerically. The exhaustive transform is a bijection whose fair bits are exact under exchangeability, whose remaining information is kept in the residual, and whose finite-length loss is larger than Elias’s.
8 Experiments
The Python implementation contains T and its inverse, the ideal lengths of KT and of code B, and a complete encoder and decoder for code C producing an actual bit stream. It checks, for all strings of length at most 10, the round trip, that is a function of R, that the fair strings over each residual are exactly , and that for every w; it checks (3) numerically and the decoding of code C on random and constant inputs. A C implementation of the full pipeline is described in Section 8.4. Both implementations, the scripts that produce every table of this paper and the text corpus are deposited on HAL [25].
8.1 Bernoulli Sources
For and we draw five strings per cell (one pseudorandom stream, seed 0); Table 3 gives the results from . The fraction converges to , slowly for skewed sources. Code B is on average bits above , about above KT, as Theorem 11 predicts (on a single string its ideal regret is , where KL is the binary divergence in bits). The mean regret of code C grows from 40 to 200 bits up to , and its largest value over all draws is 203 bits; at this is 0.01% to 0.1% of . This is an observation on five draws per cell, not a bound (Proposition 14). Rice coding of the raw input, even with the best integer parameter for each string and a raw escape (Rice*), loses a fixed fraction of the entropy on skewed sources (0.8%, 1.4%, 0.4% at ), because a Rice code fits geometric runs well only near particular biases; the heuristic rule of code C applied to the raw input does at most 31 bits worse on these skewed sources at . On the residual the mismatch
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
Table 2. Residual at , averages over five draws: fraction of fair bits; residual entropy per input bit, at the true bias, whose expectation is ; and fraction of input bits whose residual bias has in each bin.
| θ | h(θ) | |Y|/N | res. ent./N | [0,.05) | [.05,.5) | [.5,.95) | [.95,1] |
|---|---|---|---|---|---|---|---|
| 0.50 | 1.0000 | 0.9832 | 0.0168 | 0.0000 | 0.0000 | 0.0000 | 0.0168 |
| 0.30 | 0.8813 | 0.8670 | 0.0145 | 0.1175 | 0.0011 | 0.0007 | 0.0137 |
| 0.10 | 0.4690 | 0.4612 | 0.0082 | 0.5292 | 0.0015 | 0.0009 | 0.0072 |
| 0.02 | 0.1414 | 0.1383 | 0.0030 | 0.8578 | 0.0010 | 0.0005 | 0.0025 |
affects only the bits of intermediate bias: at , the residual bits whose bias has entropy in [0.05, 0.95) are less than 0.3% of the input for every tested, while the nearly fair ones are stored at no loss (Table 2). The raw baseline remains better for short strings, where code C pays its header of 25 counts: the crossing point lies between and for and 0.1, and between and for . For the raw input is incompressible and Rice* stores it with one selector bit, whereas code C pays its header.
8.2 Binary Markov Sources
Sources: i.i.d. (); an order-1 chain with , ; order-3 and order-6 chains with transition probabilities drawn once from . Table 4 gives regrets against the true likelihood (ideal lengths, three draws). Sequential conditional KT with the true order is best throughout, and CTW of depth 8 is within a factor 1.4 of it without knowing the order. With explicit splits and KT leaves, the BWT-tree code costs about four times the conditional code that knows the order at for orders 3 and 6, as Proposition 17 leads one to expect once its additive constants are counted. The free-split code removes the splits: 168 and 918 bits for orders 3 and 6 at , 3.2 and 3.0 times cKT(), and the complete tree of the right depth gives 157 and 843. For order 0 its fixed header (the bits that locate the sentinel row and the reserved fallback bit) makes it slightly worse than the explicit-split tree with the same leaves; from order 1 on it is better. It beats cKT(8) for orders 0 to 3, whereas over-estimating the order by two (cKT()) remains cheaper at every order in the table.
8.3 ASCII Text: Ideal Lengths
We use three Project Gutenberg books reduced to ASCII (Gutenberg header and footer removed, line ends normalised, bytes above 127 replaced by ?). Table 5 compares exact ideal lengths, computed in Python, of the BWT-tree code with binarised KT or code-B leaves (contexts refined up to three characters), and of conditional coding of fixed order with the same leaf coders, with the actual output sizes of zlib, bzip2 and lzma at maximal settings. With KT leaves (tree-KT), the BWT-tree code beats every fixed-order conditional coder with the same leaf coder and zlib on all three books, is within 0.12 bits per character of lzma (ahead on the two longer books), and is 0.3 to 0.4 bits per character behind bzip2, which codes the sorted string adaptively with unbounded contexts and no split cost. With code-B leaves (tree-B) the cost is 0.13 to 0.22 bits per character higher, the per-sequence half-logarithm of Remark 12 multiplied by the many short binarised sequences, and tree-B is behind zlib on Alice; in exchange, 52% to 59% of the tree-B output consists of fair bits stored as they are. These bits are not claimed exactly fair (Section 6).
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
Table 3. Bernoulli sources: fraction of fair bits and regret in bits of KT and code B (ideal lengths), code C (actual bit streams) and Rice* (exact serialised lengths), averaged over five draws per cell, with the maximum over the draws for code C. Rice* codes the raw input as bits, : a selector bit, then either the input as it is, or its weight (which gives the majority symbol and the number of minority symbols, so that the final run is implicit), the best parameter in 5 bits and the Rice codewords of the gaps ; last columns: mean loss in % of .
| θ | N | |Y|/N | KT | B | C | C max | Rice* | C% | Rice* % | |
|---|---|---|---|---|---|---|---|---|---|---|
| h = 1.000 | 0.50 | 0.862 | 3.5 | 9.2 | 48.2 | 52.0 | 1.0 | 4.71 | 0.10 | |
| 0.907 | 6.1 | 12.8 | 53.2 | 55.0 | 1.0 | 1.30 | 0.02 | |||
| 0.940 | 6.5 | 14.2 | 60.0 | 62.0 | 1.0 | 0.37 | 0.01 | |||
| 0.961 | 7.0 | 15.7 | 64.2 | 66.0 | 1.0 | 0.10 | 0.00 | |||
| 0.974 | 8.4 | 18.1 | 69.2 | 72.0 | 1.0 | 0.03 | 0.00 | |||
| 0.983 | 9.7 | 20.3 | 75.0 | 78.0 | 1.0 | 0.01 | 0.00 | |||
| h = 0.881 | 0.30 | 0.766 | 4.2 | 9.9 | 54.6 | 57.8 | 24.8 | 6.05 | 2.75 | |
| 0.807 | 5.7 | 12.4 | 68.2 | 74.8 | 48.0 | 1.89 | 1.33 | |||
| 0.831 | 6.7 | 14.3 | 76.4 | 80.7 | 148.2 | 0.53 | 1.03 | |||
| 0.847 | 8.0 | 16.7 | 102.3 | 111.3 | 480.1 | 0.18 | 0.83 | |||
| 0.860 | 7.7 | 17.4 | 135.1 | 157.2 | 1853.1 | 0.06 | 0.80 | |||
| 0.867 | 10.0 | 20.6 | 193.6 | 201.3 | 7319.6 | 0.02 | 0.79 | |||
| h = 0.469 | 0.10 | 0.408 | 4.7 | 10.4 | 51.2 | 58.5 | 22.8 | 10.67 | 4.76 | |
| 0.426 | 5.6 | 12.3 | 63.5 | 70.1 | 47.7 | 3.30 | 2.48 | |||
| 0.441 | 7.2 | 14.9 | 75.3 | 80.2 | 129.7 | 0.98 | 1.69 | |||
| 0.451 | 8.0 | 16.7 | 106.3 | 115.9 | 459.3 | 0.35 | 1.49 | |||
| 0.455 | 8.6 | 18.3 | 140.0 | 169.1 | 1699.2 | 0.11 | 1.38 | |||
| 0.461 | 9.1 | 19.7 | 195.8 | 202.8 | 6953.8 | 0.04 | 1.41 | |||
| h = 0.141 | 0.02 | 0.098 | 3.9 | 9.5 | 41.9 | 44.2 | 14.9 | 28.93 | 10.29 | |
| 0.125 | 5.4 | 12.1 | 53.6 | 57.7 | 21.0 | 9.25 | 3.63 | |||
| 0.127 | 6.8 | 14.4 | 68.1 | 70.3 | 31.1 | 2.94 | 1.34 | |||
| 0.135 | 8.0 | 16.6 | 82.2 | 95.4 | 54.2 | 0.89 | 0.59 | |||
| 0.137 | 9.1 | 18.8 | 106.0 | 116.6 | 196.6 | 0.29 | 0.53 | |||
| 0.138 | 9.1 | 19.8 | 142.4 | 152.7 | 619.2 | 0.10 | 0.42 |
8.4 A File Compressor: Actual Sizes
The C implementation is a file compressor: suffix array by SA-IS, BWT of the reversed input, context tree by dynamic programming with contexts refined bit by bit up to 32 bits, bit-plane binarisation of the leaves, and for every binary sequence the transform with code B (mode peres), the transform with Rice classes and no arithmetic coder (mode rice), adaptive KT (mode kt), code E (mode enum, within 0.001 bits per byte of mode kt on every file and not shown), or the transform with its residual coded adaptively (mode adapt: one KT estimator per Rice class and majority symbol, shared across the file). Except in mode rice, one binary range coder with 16-bit probabilities carries everything, fair bits included at probability , so they are not literally raw; in mode rice the stream consists of raw bits, fixed-width integers, Elias-gamma counts and Rice codewords. Table 6 lists what each mode implements. The dynamic programme is optimal for its additive objective, the ideal cost of code B or of KT per leaf; modes rice and adapt, whose costs are not additive over leaves, reuse the tree of code B as a heuristic, and the guarantees of Sections 5 and 6 concern the ideal codes, not these variants. The tool is tested by unit tests, by round trips over edge cases under the address
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
Table 4. Binary sources with memory: average regret in bits against the true likelihood (ideal lengths, three draws per cell). cKT(k): sequential conditional KT of order ; cB(k): code B per order- context with counts sent; tree-B, tree-KT: BWT-tree code with explicit splits (); free-B, free(k)-B: free-split code with the closed dynamic-programme tree and with the complete tree of depth ; leaves: number of leaves of the explicit-split tree.
| source | CTW | cKT() | cKT() | cKT(8) | cB() | tree-B | tree-KT | free-B | free()-B | leaves | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| iid () | 3610 | 6 | 6 | 15 | 284 | 25 | 26 | 20 | 35 | 38 | 1 | |
| 14439 | 7 | 6 | 21 | 529 | 28 | 29 | 22 | 38 | 41 | 1 | ||
| 57756 | 9 | 8 | 27 | 792 | 34 | 35 | 26 | 44 | 47 | 1 | ||
| 231025 | 10 | 9 | 31 | 1062 | 38 | 39 | 29 | 48 | 51 | 1 | ||
| M1 () | 2266 | 14 | 11 | 32 | 179 | 49 | 52 | 40 | 49 | 50 | 2 | |
| 9065 | 15 | 12 | 37 | 309 | 56 | 59 | 45 | 54 | 55 | 2 | ||
| 36261 | 18 | 15 | 46 | 486 | 65 | 68 | 52 | 61 | 62 | 2 | ||
| 145046 | 20 | 17 | 52 | 724 | 72 | 75 | 58 | 66 | 67 | 2 | ||
| M3 () | 1546 | 35 | 28 | 62 | 143 | 165 | 126 | 101 | 89 | 102 | 5 | |
| 6183 | 48 | 37 | 84 | 216 | 198 | 171 | 136 | 116 | 121 | 6 | ||
| 24731 | 58 | 45 | 104 | 308 | 229 | 226 | 181 | 150 | 139 | 7 | ||
| 98925 | 66 | 52 | 130 | 399 | 261 | 262 | 205 | 168 | 157 | 8 | ||
| M6 () | 1570 | 173 | 135 | 241 | 241 | 1114 | 648 | 538 | 414 | 463 | 36 | |
| 6280 | 261 | 191 | 393 | 393 | 1365 | 934 | 768 | 589 | 589 | 41 | ||
| 25121 | 335 | 249 | 570 | 570 | 1617 | 1252 | 1015 | 758 | 719 | 48 | ||
| 100485 | 408 | 305 | 768 | 768 | 1865 | 1579 | 1256 | 918 | 843 | 58 |
Table 5. ASCII text, bits per character. : empirical conditional entropies; tree-KT, tree-B, cKT, cB: exact ideal lengths (Python) of the BWT-tree code and of fixed-order conditional coding with binarised KT or code-B leaves; zlib, bzip2, lzma: actual sizes; last columns: leaves of the tree and share of fair bits in the tree-B output.
| file | chars | tree-KT | tree-B | cKT | cKT | cKT | cB | zlib | bzip2 | lzma | leaves | fair | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| alice | 151097 | 4.514 | 3.401 | 2.526 | 1.825 | 2.628 | 2.851 | 3.457 | 2.851 | 2.840 | 3.191 | 2.805 | 2.248 | 2.508 | 962 | 52% |
| frankenstein | 421541 | 4.405 | 3.463 | 2.747 | 2.089 | 2.563 | 2.729 | 3.485 | 2.891 | 2.645 | 3.042 | 3.033 | 2.273 | 2.577 | 1868 | 59% |
| pride | 737948 | 4.485 | 3.504 | 2.656 | 1.981 | 2.321 | 2.453 | 3.520 | 2.759 | 2.369 | 2.870 | 2.865 | 2.023 | 2.340 | 2765 | 59% |
and undefined-behaviour sanitisers, and by rejection of corrupted streams; round trips are verified for every coded entry of Tables 7 and 8. The tool reads the stored files as they are, without the preprocessing of Section 8.3, so its inputs differ from the strings of Table 5 (Alice: 151 191 bytes against 151 097 characters; Frankenstein: 448 885 against 421 541); the four books are the concatenation of the three of Table 5 and Moby-Dick, 2 614 437 bytes in all.
In mode kt the tool beats xz on three of the four books and brotli on two, and both on their concatenation; it is 0.08 bits per byte behind xz on Alice, and 0.17 and 0.01 behind brotli on Alice and Frankenstein; bzip2 is better on single books and equal on the concatenation. Mode peres is 0.09 to 0.21 bits per byte above mode kt on text, and mode rice within 0.4% of mode peres on text and 0.75% on source code and the executable. The binary Markov source of order 3 has transition probabilities drawn once from Beta(, ) (seed 0) and starts from the zero context; its entropy rate is 3.019 bits per byte, the 2 MiB sample has a surprisal of 3.018 bits per byte under the true law, and modes kt, peres and rice exceed it by 0.012, 0.023 and 0.025 bits per byte, where the byte-oriented compressors are above 3.6. On source code and the executable the tool is 0.5 to 0.8 bits per byte behind the best of them, and on source
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
Table 6. Modes of the file compressor: objective of the dynamic programme that chooses the tree, model of each binary sequence of a leaf, scope of the model state, and coder (mode rice uses no arithmetic coder).
| mode | tree objective | model of a binary sequence | state | coder |
|---|---|---|---|---|
| peres | code B | weight, then transform; residual at plug-in biases (32-bit fixed point, probabilities clipped to [2-16, 1 - 2-16]) | per sequence | range coder |
| rice | code B | weight, then transform; Rice classes of the residual (code C) | class counts and gaps shared by the file | Rice codes |
| adapt | code B | weight, then transform; residual with one KT estimator per Rice class and majority symbol | 50 KT models shared by the file | range coder |
| kt | KT | adaptive KT | per sequence | range coder |
| enum | KT | weight under BB, then index in its class (code E) | per sequence | range coder |
Table 7. File compressor, bits per byte (actual sizes). Modes peres, rice, kt at context depth 32 bits. samba: source code, file of the Silesia corpus [26] (21 606 400 bytes); bash: the executable /bin/bash of Ubuntu 24.04 (bash 5.2.21); random: numpy default_rng(1); Markov(3): order-3 binary source packed into bytes, entropy rate 3.019 bits per byte; brotli through its Python binding (quality 11, window 24). The SHA-256 of every input is recorded with the code.
| file | peres | rice | kt | gzip | bzip2 | xz | brotli |
|---|---|---|---|---|---|---|---|
| alice | 2.807 | 2.816 | 2.602 | 2.823 | 2.262 | 2.521 | 2.428 |
| frankenstein | 2.649 | 2.656 | 2.483 | 3.007 | 2.251 | 2.547 | 2.475 |
| pride | 2.353 | 2.361 | 2.223 | 2.868 | 2.020 | 2.343 | 2.303 |
| moby-dick | 2.583 | 2.591 | 2.464 | 3.204 | 2.438 | 2.621 | 2.587 |
| four books | 2.383 | 2.391 | 2.296 | 3.045 | 2.298 | 2.421 | 2.412 |
| samba | 2.148 | 2.164 | 2.110 | 2.002 | 1.685 | 1.394 | 1.395 |
| bash (ELF) | 3.951 | 3.977 | 3.729 | 3.826 | 3.594 | 3.229 | 3.264 |
| random 1 MiB | 8.004 | 8.004 | 8.002 | 8.001 | 8.040 | 8.001 | 8.000 |
| Markov(3) | 3.042 | 3.043 | 3.030 | 3.973 | 3.705 | 3.644 | 3.789 |
code even behind gzip: long exact repetitions are exploited by Lempel–Ziv coders and by bzip2's move-to-front stage, whereas our leaves are coded independently. In the benchmark (minimum of two runs on one core of an Intel Core Ultra 7 265H, gcc 13.3, -02; with frequency scaling, repeated runs vary by up to a factor of two, so these are orders of magnitude), modes peres, rice and kt compress the four books at 2.6 to 4.3 MB/s and decompress them at 6 to 8 MB/s; the executable and random bytes compress at 0.5 to 1.2 MB/s, because the dynamic programme then explores the tree to full depth, and decompress at 3.6 to 8 MB/s. For comparison, xz -9 compresses at 2 to 4 MB/s and bzip2 -9 at 11 to 19 MB/s. Mode rice is the slowest of the three to compress, because of its two passes, and at most 30% faster than mode peres to decompress: in this implementation the arithmetic coder is not the bottleneck. Peak resident memory (measured with /usr/bin/time) in compression is about 20 bytes per input byte on the four books, 88 on the executable and 141 on random bytes, where the dynamic programme keeps the records of every explored node; decompression needs 11 to 16 bytes per input byte.
Exact, clipped and adaptive. Mode peres is not the exact code B: it codes the residual at fixed-point biases handed to the range coder as probabilities clipped to . Table 8 separates the two. At depth 0 (one leaf, the whole BWT output), exact code B costs 4.680 bits per byte on Alice, the order-0 cost, since its length depends only on the type, whereas mode peres costs 3.808. The ideal length of the same residual at biases clipped to is
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
Table 8. Ablation, bits per byte versus context depth (bits). Mode peres as shipped (floor , fixed-point biases, 32-bit range coder); the same stream with biases in double precision, clipped only when coded at or , and a 64-bit range coder (wide): actual sizes; floor and exact code B: ideal lengths of the same residual; adapt, kt: actual sizes. Round trips verified for every coded entry.
| file | depth | shipped | wide | ideal | adapt | kt | ||
|---|---|---|---|---|---|---|---|---|
| exact B | ||||||||
| alice | 0 | 3.808 | 3.822 | 3.932 | 4.115 | 4.680 | 2.770 | 4.676 |
| 8 | 3.156 | 3.179 | 3.292 | 3.408 | 3.484 | 2.724 | 3.435 | |
| 32 | 2.807 | 2.815 | 2.832 | 2.837 | 2.837 | 2.739 | 2.602 | |
| four books | 0 | 3.636 | 3.641 | 3.691 | 3.789 | 4.584 | 2.418 | 4.584 |
| 8 | 2.986 | 2.995 | 3.068 | 3.191 | 3.529 | 2.397 | 3.523 | |
| 32 | 2.383 | 2.388 | 2.406 | 2.416 | 2.417 | 2.339 | 2.296 | |
3.821, and a 64-bit range coder with 16-bit probabilities at the same floor produces 3.822: clipping accounts for 0.86 of the 0.87 bits per byte, and the remaining 0.013 comes from the shipped coder, whose integer split of the range favours symbol 1 and so changes the effective probabilities of the most biased bits; the fixed-point biases change the ideal length by 0.0003 bits per byte, invisible at the precision of Table 8. The gain persists over the tested floors, although its magnitude changes: with biases in double precision, clipped only when coded, a floor of gives 3.932, and even at the ideal length is 4.115. It is carried by few bits: on Alice at depth 0, 946 minority residual bits have an exact bias below and cost bits in exact code B. On data that are not exchangeable within a leaf, events that the plug-in model declares nearly impossible do occur, and a floor caps their cost at bits. The effect shrinks as the tree resolves the contexts: at depth 32 exact code B and mode peres differ by 0.03 bits per byte. Mode adapt is a different matter: it models the residual, and is shorter than mode peres at every depth on text, by 1.04 bits per byte on Alice at depth 0, where none of the tested floors brings mode peres below 3.8. With no context tree at all it codes the four books at 2.418 bits per byte, where KT at depth 0 is at the order-0 cost: the -sequences record the equality pattern of the sorted string at every scale, and the adaptive classes record how far it deviates from what an exchangeable leaf would give. A KT estimator per class sees counts, not order, so this is aggregate modelling, not a run-length model.
Orientation bits on structured data. On the BWT output of Alice taken as one leaf, the transform produces 2.28 fair bits per character whose empirical conditional entropies of orders 0 to 8 lie between 0.9988 and 0.9996 bits per bit and which lzma expands. These are diagnostics, not a proof of uniformity. What holds exactly is weaker: for a stationary binary process, , so the orientation of the pair at a fixed index, given that it is unequal, is fair; but the -th orientation bit need not be (for the periodic sequence 001001 with a uniform phase, the first one is 0 with probability ).
9 Discussion: Peres Versus Elias
In yield, the type-class extractor of Elias wins at every length: its expected yield under the uniform law on a type class is at least the logarithm of the class size minus three bits [2], whatever the alphabet, whereas the exhaustive transform still loses of the entropy at for (Table 3). Prasitsupparote et al. [9] reach the same verdict numerically. The extraction loss is not a compression loss: for code B, plus the ideal residual cost is
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
whatever the yield, a lower yield only moving information from the fair part to the residual. The half-logarithm between codes B and E comes from the way the type is coded, and Remark 12 keeps Peres's fair bits at the KT length. What the transform offers is of a different kind. Its fair bits are exactly uniform under exchangeability, at a rate approaching the entropy, in bit operations with no multiplication, and it is a bijection: nothing is discarded. It is one fixed recursion for all lengths, with no length-dependent constants. And it leaves a residual whose bits have explicit biases, iterates of two maps that push most of them to 0, 1 or , which is what makes a variant without arithmetic coder such as code C possible; Elias's leftover is the type, and the index that completes it is a large integer unless an arithmetic coder produces it. In this sense the transform is a nonlinear, parameter-free parallel of source polarization [15], whose kernel is the same XOR of pairs. For Elias's procedure as for the transform, exchangeability is what makes the fair bits exact, a sufficient condition rather than a necessary one. What extends to sources with memory by context splitting is lossless coding with a likelihood-based cost analysis, not exact extraction (Section 6).
10 Conclusion
Running Peres’s recursion to exhaustion and keeping what it does not extract gives a bijection with three properties: the residual is a complete prefix code that determines the weight, so the fair bits are exactly uniform given the residual for every exchangeable input; the Bernoulli likelihood factorises in decoding order into fair bits and residual bits with explicit biases; and the number of fair bits reaches the entropy, almost surely, on and on . Code B turns this into a universal two-part code in which only the residual passes through an arithmetic coder. Code C replaces the arithmetic coder by Rice codes; it performs well on the lengths tested, but with a fixed cap it is not universal. A selector between codes B and C is universal but uses the arithmetic coder on some inputs; a universal code with no arithmetic coder at all, with a cap growing with N or an escape for long gaps, needs a new analysis. For sources with memory, the BWT of the reversed string makes all context orders one tree of intervals, and on suffix-closed trees the leaf weights determine the partition. The remaining gap to sequential coding is the exact count of each leaf in our format; coding the leaf types jointly, each child’s given its parent’s, and letting the depth grow with N are the natural next steps.
A Proof of Proposition 9
Upper bound. Every is the fair string of a message with the residual of , and all these messages have the type of ; hence is at most the size of the type class, itself at most . The concavity and continuity of and the strong law give and a.s.
Asymptotic rates. A node is a path of steps , and ( ); its alphabet loses one bit at each step, and its law is obtained from by the maps of Theorem 8. Give the root the mass and the children of a node of mass and law the masses ( ), ( ) and ( ), omitting branches of zero mass; then at every depth . Let , where nodes on the alphabet , of zero entropy and zero rate, are dropped; the remaining masses at depth add up to at most 1, which is all that is used below. Identity (4), divided by 2, says that the entropy of a node is its rate plus the
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
mass-weighted entropies of its children, so
Thus decreases to some , and is the fair-bit rate of the first levels. Suppose . The nodes with contribute less than to , so those with contribute at least and, their entropies being at most , have total mass at least . On each alphabet , , the set of laws with is compact and is continuous on it and vanishes only at point masses, which have zero entropy; hence on it for some . Then for every , contradicting . So and .
Lower bound. Work on the infinite sequence . The -string of the first symbols is the prefix of length of , which is i.i.d. of law ; the -string and each -string are prefixes of the subsequences selected by , resp. , which are i.i.d. of laws , resp. , by the one-level computation of Theorem 8. By induction, the string at node is the prefix of length of an infinite i.i.d. sequence of law , and by the strong law applied level by level, a.s. and the number of fair bits extracted at divided by tends to a.s. Summing over the finitely many nodes of depth less than , a.s. for every , hence a.s. With the upper bound, a.s., and in since .
B Proof of Proposition 14
Let and , the ideal plug-in cost of the residual, an identity by (3) at ; every summand is nonnegative. By Theorem 7 and the strong law, and almost surely, and in since both are bounded. Let be the number of residual bits that are majority symbols of class , and . Every other residual bit costs at least in : a minority symbol has probability at most , and a majority symbol of a class below has minority probability at least . Hence , and since , in ; this controls the classes, which depend on , without any independence assumption.
Let be odd and , of probability tending to since . On , the odd remainder of the root, , is a minority symbol of bias , hence of class , and it is the last residual bit requested. Every majority symbol of class therefore precedes a coded minority symbol of that class, the gaps of class add up to , and their Rice codewords cost . Headers and other classes being nonnegative, . Taking expectations, , and because in . The bound follows.
Acknowledgment
Aurélien Garivier acknowledges the support of Chaire SeqALO (ANR-20-CHIA-0020-01) and PEPR-IA project FOUNDRY (ANR-23-PEIA-0003).
References
[1] J. von Neumann, "Various techniques used in connection with random digits," in Monte Carlo Method, Nat. Bur. Standards Appl. Math. Ser., vol. 12, pp. 36–38, 1951.
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
[2] P. Elias, "The efficient construction of an unbiased random sequence," Ann. Math. Statist., vol. 43, no. 3, pp. 865–870, 1972.
[3] B. Ryabko and E. Matchikina, "Fast and efficient construction of an unbiased random sequence," IEEE Trans. Inf. Theory, vol. 46, no. 3, pp. 1090–1093, May 2000.
[4] Y. Peres, "Iterating von Neumann's procedure for extracting random bits," Ann. Statist., vol. 20, no. 1, pp. 590–597, 1992.
[5] S. Pae, "A generalization of Peres's algorithm for generating random bits from loaded dice," IEEE Trans. Inf. Theory, vol. 61, no. 2, pp. 751–757, Feb. 2015.
[6] S. Pae, "Binarization trees and random number generation," IEEE Trans. Inf. Theory, vol. 66, no. 4, pp. 2581–2587, Apr. 2020.
[7] S. Pae, "Peres-style recursive algorithms," arXiv:1805.04610v2, 2018.
[8] H. Zhou and J. Bruck, "A universal scheme for transforming binary algorithms to generate random bits from loaded dice," arXiv:1209.0726, 2012.
[9] A. Prasitsupparote, N. Konno, and J. Shikata, "Numerical and non-asymptotic analysis of Elias's and Peres's extractors with finite input sequences," Entropy, vol. 20, no. 10, art. 729, 2018.
[10] T. M. Cover, "Enumerative source encoding," IEEE Trans. Inf. Theory, vol. 19, no. 1, pp. 73–77, Jan. 1973.
[11] R. E. Krichevsky and V. K. Trofimov, "The performance of universal encoding," IEEE Trans. Inf. Theory, vol. 27, no. 2, pp. 199–207, Mar. 1981.
[12] J. Rissanen, "Universal coding, information, prediction, and estimation," IEEE Trans. Inf. Theory, vol. 30, no. 4, pp. 629–636, Jul. 1984.
[13] F. M. J. Willems, Y. M. Shtarkov, and T. J. Tjalkens, "The context-tree weighting method: Basic properties," IEEE Trans. Inf. Theory, vol. 41, no. 3, pp. 653–664, May 1995.
[14] K. Visweswariah, S. R. Kulkarni, and S. Verdú, "Source codes as random number generators," IEEE Trans. Inf. Theory, vol. 44, no. 2, pp. 462–471, Mar. 1998.
[15] E. Arikan, "Source polarization," in Proc. IEEE Int. Symp. Inf. Theory (ISIT), 2010, pp. 899–903.
[16] P. Ferragina and G. Manzini, "Opportunistic data structures with applications," in Proc. 41st IEEE Symp. Found. Comput. Sci. (FOCS), 2000, pp. 390–398.
[17] P. Ferragina and G. Manzini, "Indexing compressed text," J. ACM, vol. 52, no. 4, pp. 552–581, 2005.
[18] P. Ferragina, R. Giancarlo, G. Manzini, and M. Sciortino, "Boosting textual compression in optimal linear time," J. ACM, vol. 52, no. 4, pp. 688–713, 2005.
[19] M. Effros, K. Visweswariah, S. R. Kulkarni, and S. Verdú, "Universal lossless source coding with the Burrows–Wheeler transform," IEEE Trans. Inf. Theory, vol. 48, no. 5, pp. 1061–1081, May 2002.
UNIVERSAL CODING WITH THE EXHAUSTIVE PERES TRANSFORM
[20] Y. Polyanskiy and Y. Wu, Lecture Notes on Information Theory, MIT 6.441, ch. 28, 2016.
[21] R. F. Rice, "Some practical universal noiseless coding techniques," Jet Propulsion Lab., Pasadena, CA, JPL Publ. 79-22, 1979.
[22] R. G. Gallager and D. C. Van Voorhis, "Optimal source codes for geometrically distributed integer alphabets," IEEE Trans. Inf. Theory, vol. 21, no. 2, pp. 228–230, Mar. 1975.
[23] A. Kiely, "Selecting the Golomb parameter in Rice coding," Jet Propulsion Lab., IPN Progress Rep. 42-159, 2004.
[24] P. Wuille, "Efficient division-free randomness extraction," technical note, Apr. 2026. [Online]. Available: https://wuille.net/posts/binomial-randomness-extractors/
[25] A. Garivier, "ExhaustivePeres: companion code of Universal coding with the exhaustive Peres transform," version 1.0, software, HAL Id hal-05802360, 2026. [Online]. Available: https://hal.science/hal-05802360
[26] S. Deorowicz, "Silesia compression corpus." [Online]. Available: https://sun.aei.polsl.pl/~sdeor/index.php?page=silesia