Manuscript Offprint
arXiv:2608.20234Algorithms, Complexity, and Entropy of the Bernard-Letac Fair-Sampling Construction
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
Bernard and Letac (1971) introduced a method for uniform random sampling among outcomes from an unknown biased source of independent and identically distributed symbols. The process terminates when the multinomial coefficient of the cumulative symbol counts equals zero modulo . This study extends the computational and information-theoretic analysis of their construction by presenting five algorithms with formal correctness guarantees and comprehensive complexity analyses. For prime , the Bernard–Letac framework is analyzed in greater detail. The Rényi entropies of the source yield an exact product formula for the expected number of draws. A first-order approximation consistently overestimates this value, and the entropy lower bound is never attained. As , treated as a continuous parameter, approaches 1, the expected cost converges to a constant greater than 1, determined by the entire source distribution. Furthermore, for every prime modulus and every finite alphabet , an explicit automaton with states computes the mod- first-passage kernel of the walk from the base- digits of its arguments, reducing the fair assignment cost from quadratic to nearly linear.
2020 Mathematics Subject Classification. Primary 60G40; Secondary 05A10, 11B65, 94A17, 68W20.
Keywords. Random number generation; stopping times; multinomial coefficients; Kummer’s theorem; Rényi entropy.
1 Introduction and Background
A central problem in probability and computation concerns the following question. Given access to a biased source of randomness, specifically a device producing independent and identically distributed (i.i.d.) draws from an unknown distribution over a finite alphabet, can one generate a fair outcome that is uniform over possibilities using a finite, albeit random, number of draws? The procedure must succeed for every admissible , without any prior knowledge of the underlying bias.
The earliest solution to this problem was proposed by von Neumann [21], who in 1951 demonstrated that a fair coin flip can be simulated using a biased coin through a simple rejection scheme. Letting and denote the probabilities of the two outcomes, each trial of this scheme consumes a pair of draws and succeeds with probability . Thus, the expected cost is pairs, or equivalently, draws. In 1970, Hoeffding and Simons [13] revisited the problem, developing improved procedures for the binary case that achieve a smaller expected stopping time and characterizing the class of all valid stopping rules. Notably, they introduced a walk on tracked by the parity of the binomial coefficient , where is the number of draws made so far and is the number of those equal to one fixed outcome. This device served as a direct precursor to the Bernard–Letac construction.
In 1971, Bernard and Letac [4] extended both previous works in two significant directions. They allowed the alphabet to be arbitrary, whether finite or countable, and aimed to produce an -way fair partition rather than only a fair binary split. Their principal contribution is a construction based on the set , where denotes the free abelian monoid on and represents the multinomial coefficient. The random walk defined by the cumulative draw counts terminates upon first reaching . The authors demonstrate that the paths to any stopping state can be partitioned into exactly equiprobable classes, regardless of the bias .
The results of the original paper are primarily combinatorial and number-theoretic, with no consideration of computational or information-theoretic perspectives. The present work addresses these gaps by (1) extracting from the original theorems a family of five distinct algorithms (Section 2), each presented formally with correctness guarantees, complexity analyses, and explicit pseudocode; (2) deriving new and precise results regarding the expected complexity of the central fair-sampling algorithm, expressed in terms of Rényi and Shannon entropy (Section 3); and (3) establishing a transfer theorem for the mod- first-passage kernel of the walk, for every prime and every finite alphabet (Section 4). Additionally, worked examples (Section 2.1) and numerical illustrations (Section 5) are provided to concretely demonstrate the construction.
To state the results, let be a probability distribution on a finite or countable alphabet , non-degenerate in the sense that for every , and let denote the number of draws the Bernard–Letac sampler consumes when run with modulus , that is, the first time the walk of cumulative symbol counts enters . Write for the Shannon entropy of the source and for its Rényi entropy of order ; all logarithms are natural.
The first main theorem gives the entropy form of the expected stopping time.
Theorem A.
Let be a prime and set for , so that . Then
and the first-order approximation
always strictly overestimates, in the sense that for every non-degenerate .
The exact product form is due to Bernard and Letac (Corollaire 4 of [4], restated as Theorem 3.1); the entropy reading, the first-order approximation, and the strict inequality are established in Theorem 3.8.
The second main theorem identifies the Shannon limit of the expected cost.
Theorem B.
Treat as a continuous parameter in the product of Theorem A. Then has a finite limit as , namely
The constant is strictly greater than , depends on the full distribution rather than on its Shannon entropy alone, and is not in general equal to . For the symmetric binary source one has , whereas .
This is proved as Theorem 3.10.
The third main theorem gives the information-theoretic lower bound and describes the efficiency of the sampler.
Theorem C.
Every procedure that observes the source at a stopping time and returns an exactly uniform outcome among alternatives for every non-degenerate satisfies
The inequality is never attained. For the Bernard–Letac sampler with prime modulus , define the efficiency . Then tends to both as and as , and it attains its maximum at an interior point .
The lower bound is proved as Theorem 3.11 by a Wald-type entropy identity, its strictness is Proposition 3.12, and the behavior of the efficiency is Corollary 3.13.
The fourth main theorem states, in informal form, the transfer theorem for the first-passage kernel.
Theorem D.
Let be a prime and let the alphabet be finite with letters. For a stopping state and a lattice point , let count the monotone lattice paths from to whose points other than avoid . An explicit automaton with exactly states reads the base- digits of the coordinates of , one digit column per step from the least significant position upward, and computes modulo ; the automaton is minimal, and the kernels attached to its states span a space of dimension exactly over . Consequently the exact fair group assignment of the sampler is carried out in automaton transitions, which for on the binary alphabet is bit operations, in place of the bit operations of the direct dynamic program (Proposition 3.5) run modulo .
The automaton is constructed in Section 4; the precise statements are Theorems 4.4 and 4.5, the seven-state case is Corollary 4.15, and the complexity consequence is Corollary 4.18.
Related work
In addition to the direct progression from Von Neumann through Hoeffding–Simons to Bernard–Letac, several subsequent developments contextualize the present results. Elias [8] developed an asymptotically optimal block procedure whose efficiency approaches as the block length increases, so that its output rate approaches outcomes per draw; the price of this optimality is unbounded delay. In contrast, the Bernard–Letac algorithm operates online and sequentially, prioritizing immediacy over efficiency. Peres [18] demonstrated that iterating Von Neumann’s procedure yields, in the limit, a number of unbiased bits arbitrarily close to the entropy bound, so that its efficiency tends to . The relationship between iterated extraction and the -adic limit of Algorithm 5 remains an open problem of interest. The Knuth–Yao framework [14] establishes the minimum expected number of fair coin flips required to simulate any distribution, leading to the lower bound stated in Theorem 3.11. The Bernard–Letac construction extends this framework to arbitrary source alphabets and moduli. Lumbroso [16] provided an optimal implementation of the Knuth–Yao discrete distribution generating (DDG) tree for uniform distributions (the “Fast Dice Roller”), which recycles entropy from rejections and serves as the natural benchmark for competing uniform samplers. The composite-modulus comparison in Section 5.2 employs the Von Neumann plus Lumbroso method as the strongest baseline.
From a technical perspective, the combinatorial foundation of the paper, specifically the congruences of multinomial coefficients modulo prime powers, is explored in detail by Fray [10], Granville [12], and Deutsch–Sagan [6]. The -adic convergence result of Algorithm 5 is connected to the theory of -adic -functions, as discussed by Morita [17]; standard background on -adic numbers and valuation theory is given by Bachman [3]. The emergence of Rényi entropy as the natural complexity parameter for algorithms involving -th power sums is well documented; see the survey by Aczél and Daróczy [1]. Theorem 3.8 appears to represent the first instance of this connection within the context of fair sampling.
Notation and background
Throughout, let denote a finite or countable alphabet and the free abelian monoid generated by , identified with the set of finitely supported sequences of non-negative integers . The notation is used, and the multinomial coefficient is defined as follows.
We fix a prime . For a non-negative integer , we write for its base- expansion with , and define
with and . For one extends these componentwise: , , , and . The monoid carries the componentwise partial order, in which means for every .
A probability distribution on is a vector with , , and for all (the non-degenerate condition). We write for the monomial associated with .
A comprehensive development of the Bernard–Letac theory, including all proofs, is provided in [4]. For convenience, the three principal results underpinning the algorithms of Section 2 are restated here without proof.
Let be a non-degenerate source. Form the product space
with canonical projections and natural filtration . Define the -valued random walk by and , where is the -th standard unit vector, the indicator vector of symbol . Then records the empirical count of each symbol after draws, and
For a set define the hitting time . Let be the class of stopping times such that there exists an -measurable partition of with for all and all admissible .
A central quantity is , the number of paths from to in that do not touch .
The following fundamental theorem is due to Bernard and Letac; see §2 of [4].
Theorem 1.1.
For , the following are equivalent:
(a) for all ; (b) for all ; (c) for all .
The next theorem, also from §2 of [4], identifies the stopping set used throughout this paper.
Theorem 1.2.
Let . Then , i.e., the stopping rule based on produces a fair -way partition.
The following theorem of Kummer [15, 7] is the key number-theoretic tool. (See §1 of [4] for the original proof.)
Theorem 1.3.
For , , where is the carry in column when adding the base- representations of .
An immediate corollary is the multinomial analogue of Lucas’ theorem, namely that if and only if for every digit position .
2 The Algorithms
Five distinct algorithms are extracted from the results of [4], each accompanied by a formal correctness statement and a complexity guarantee. Theorem 1.3 directly provides an efficient procedure for computing .
Proposition 2.1.
Algorithm 1 correctly computes in time, with the convention , so that is a valid input.
Proof.
Correctness follows from Theorem 1.3, provided the loop runs until the carry is exhausted. At each digit position , one performs a single pass over the components to compute . There are at most positions at which some has a non-zero digit. Beyond them the column sum is the carry alone; since the invariant is maintained throughout, so the carry is extinguished within a further iterations. The total work is therefore . ∎
The incremental variant, which updates as changes by at each step, requires time per step. This is because only one coordinate changes and carries propagate through at most positions.
Algorithm 1 -adic Valuation of via Kummer Carries
1: , prime
2:
3: , ,
4: with the convention
5: while or do trailing carries survive past when
6: digit sum at position plus incoming carry
7: carry into position
8:
9: ,
10: end while
11: return val
In addition to its function within the sampler, the carry structure computed by Algorithm 1 is relevant to a corollary of Section 5 in [4], which provides an upper bound on the number of zero-one matrices with specified margins. Improving this bound remains an open problem, designated as Open Problem P7 (Section 6).
Theorems 1.1 and 1.2 provide the theoretical foundation for the following procedure.
Theorem 2.2.
Algorithm 2 halts almost surely for every non-degenerate , and produces a random variable with for all , independently of .
Proof.
Almost sure termination holds since for all , the walk is multi-dimensional, and the probability of never hitting is zero [4, Theorem 4], whose proof proceeds via the recurrence of the induced walk on (see [9] for the underlying recurrence criteria).
For the fairness of the output, we have that since is a first hitting time, the trajectories that can be observed at are precisely the paths from to avoiding . A path that meets earlier stops earlier and never reaches at time . Each such path has probability , so conditionally on for , the observed path is uniform over these paths. Since for every by definition, the implication (b) (a) of Theorem 1.1 gives . Partitioning the avoiding paths into groups of size therefore yields ; summing over stopping states gives for every admissible , because the counts are combinatorial quantities independent of the weights. ∎
The demonstrated distribution-free fairness depends on the stopping set being specified prior to any sampling. Whether a data-adaptive stopping boundary can decrease while preserving exact fairness remains unresolved and is identified as Open Problem P4 (Section 6).
Algorithm 2 Fair -way Sampling from a Biased Source
1: Alphabet , modulus , access to i.i.d. draws from unknown
2: Outcome with
3: ;
4: repeat
5: Draw ; append to path;
6: For each prime power , compute via Algorithm 1 valuations per draw, as in Proposition 3.5
7: until for every , i.e.
8: for in the box , in decreasing order of do
9: if , else outside
10: end for counts the paths avoiding ;
11: rank of observed path among the paths avoiding
12: return which group of size the path falls in
Remark 2.3 (The partition must respect first hitting).
One might consider partitioning all paths to into groups. This approach would create lexicographic blocks of size , requiring only arithmetic operations. However, this method is not equiprobable because the observable paths are not necessarily distributed evenly among the blocks. For example, when and , the state has but only two observable paths, and . The remaining two paths pass through and terminate there. Both observable paths are contained within the first lexicographic block, while both observable paths to the mirror state are in the second block. The two contributions, and , cancel only for the unbiased source. Exact enumeration with yields , indicating that the block rule essentially reproduces the bias it was intended to eliminate.
The following result of [4], known as the Triangle Theorem, provides a fast membership test. (See §4 of [4] for the full proof.)
Theorem 2.4.
Let with . If for all and , then . In particular, if then for all such perturbations .
The membership oracle built on this test has the following guarantees.
Proposition 2.5.
Algorithm 3 decides in time. Suppose moreover that a set of -adically deep generators, meaning points with for every , has been precomputed. Such generators exist, for example the points with ; these lie in because , the base- carries of Theorem 1.3 being invariant under the digit shift . Then membership is decided in time for every obtained from some by a perturbation that is shallow in the sense of Theorem 2.4.
Algorithm 3 Membership Oracle for with Triangle Acceleration
1: Query , prime , exponent , generator set
2: Boolean: ?
3: for do
4: if and for all then
5: return true Triangle Theorem: implies
6: end if
7: end for
8: Compute via Algorithm 1
9: return
The following periodicity theorem of [4] makes a precomputed lookup table possible. (See §5 of [4] for the proof.)
Theorem 2.6.
For fixed , with , and :
Theorem 2.6 yields the following guarantee for the lookup table of Algorithm 4.
Proposition 2.7.
Algorithm 4 precomputes a table of for in time and space, after which any query is answered in . When the period is , as one would expect.
Theorem 2.6 controls only modulo at period , so a table of length is in general too short. Invoking the theorem at exponent restores a guaranteed period modulo . For , , (so ) the length- table is , yet while ; the length- table is periodic.
Algorithm 4 Periodic Lookup Table for
1: Base with , index , prime , exponent
2: Precomputed table ,
3: Theorem 2.6 at exponent : period modulo
4: for do
5:
6: end for
7: return Query:
The following theorem of [4] establishes -adic convergence of the multinomial coefficients. (See §6 of [4] for the proof.)
Theorem 2.8.
For , :
Consequently, converges in to a -adic integer .
Theorem 2.8 yields the following guarantee for Algorithm 5.
Proposition 2.9.
Algorithm 5 computes in iterations, with each iteration requiring arithmetic operations.
For an index set we write for the free abelian monoid on , so that an element is a finitely supported matrix, and its margins are its row-sum vector in and its column-sum vector in . The limit satisfies a product identity (Théorème 10 of [4]). If and (for a second index set ) satisfy and , then
where ranges over the elements of whose margins are and for some and which satisfy ; the series converges -adically. The restriction is only a normalization, since .
Determining whether the limit possesses an information-theoretic interpretation, such as through the entropy of a distribution associated with , constitutes Open Problem P5 (Section 6).
Algorithm 5 -adic Limit
1: , prime , target precision
2:
3:
4: for do
5:
6: if then
7: return curr Convergence detected at precision
8: end if
9:
10: end for
11: return curr
2.1 Two worked examples
Example 1: prime modulus
Let and (prime). The random walk records draws of each symbol; . The stopping condition is . The level of the walk is the set of states with ; since , the walk occupies level exactly at time .
For the first stopping level, we have according to Lucas’ theorem, first occurs at for . If all five draws are identical, the random walk does not stop at this stage; otherwise, it stops at .
The state is reached when two symbols and three symbols have appeared. In this case, . Since no state with lies in , no path can stop before . Therefore, , and every path to is observable. This property is unique to the first stopping level; see Example 2 and Remark 2.3.
Each path to corresponds to a sequence of five draws containing exactly two 0s and three 1s. There are such paths, which can be listed lexicographically:
| Path | Sequence | Path | Sequence |
|---|---|---|---|
| 1 | 6 | ||
| 2 | 7 | ||
| 3 | 8 | ||
| 4 | 9 | ||
| 5 | 10 |
Each path has probability . Since , assign two consecutive paths to each group:
| Group | Paths | Probability |
|---|---|---|
| 1, 2 | ||
| 3, 4 | ||
| 5, 6 | ||
| 7, 8 | ||
| 9, 10 |
Each group accounts for exactly of the total probability mass at the stopping event , regardless of . For instance, the observed sequence is Path 6, yielding outcome .
Example 2: composite modulus
Let and (composite). The state records draw counts; . The stopping condition is .
For the first stopping level at , we have
| and permutations | ||
| and permutations | ||
The unique stopping state at is . The 6 paths are all permutations of :
| Group | Path | Sequence |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 |
Each singleton group has probability ; the walk stops optimally in just 3 draws whenever all three symbols appear in the first round.
For the continuation at , if the first 3 draws are, say, then and . At :
| (up to permutation) | ||
|---|---|---|
| 1 | 1 | |
| 4 | 4 | |
| 6 | 0 | |
| 12 | 0 |
Both and , together with their permutations, therefore lie in and stop the walk at .
For the state , the total number of paths is . However, six of these twelve paths pass through at , specifically those whose fourth symbol is the repeated , and would have terminated at that point. The observable paths are the avoiding ones, listed in lexicographic order as , , , , , and ; these form six singleton groups. The observed path has avoiding rank , which yields group .
Composite modulus ’s irregularity makes the group sizes vary, and more notably, some states of are unreachable. Every path to encounters at an earlier stage, so and the walk never terminates at this state. Furthermore, no stopping is possible at , since all three -states at that level are unreachable; the same situation occurs for at . This irregularity is the primary obstacle to obtaining a closed-form expression for when is composite (see Section 3).
| Representative state | Group size | |||
|---|---|---|---|---|
| 3 | 6 | 6 | 1 | |
| 4 | 12 | 6 | 1 | |
| 4 | 6 | 6 | 1 | |
| 5 | 30 | 0 | unreachable | |
| 6 | 60 | 12 | 2 | |
| 6 | 30 | 18 | 3 | |
| 6 | 90 | 0 | unreachable |
3 Complexity and Entropy
The exact expected stopping time of Algorithm 2 for prime modulus is now derived. The following theorem is Corollaire 4 in §3 of [4].
Theorem 3.1.
Let be a prime and any non-degenerate distribution on . Define .
Proof.
See §3 of [4]. The proof follows from the generating function identity (§3 of [4]) using the tail-sum representation . ∎
Remark 3.2.
A naïve renewal argument at the first scale gives
This is a renewal estimate, not a truncation of the product to its factor. Retaining only that factor would give , a different quantity. The discrepancy arises because the shifted walk from does not exhibit the same carry structure as a new walk. When the position- digit in base is non-zero, carries from digit may propagate to digit and higher, resulting in additional stopping events not present in the original walk. (For with a fair binary source, the simple formula yields while the exact product yields .)
The accuracy of the approximation increases rapidly as grows; the two correction factors relating (1) to the exact product are quantified in the proof of Theorem 3.8. Empirically, the simple formula is accurate to within for all non-degenerate once , while at the error can exceed ; like the unimodality observed in Section 5.1, this accuracy claim is numerical and we do not prove it. Theorem 3.8 shows that the simple formula always overestimates .
For the uniform source the product specializes as follows.
Proposition 3.3.
Under the uniform distribution for all :
For sufficiently large or , the expression is well approximated by .
The following proposition summarizes the principal monotonicity properties.
Proposition 3.4.
Let be a prime and a non-degenerate distribution on a finite or countable alphabet . The quantity of Theorem 3.1, which depends on both and , satisfies:
(a) strictly, with equality approached for uniform sources as and, for fixed , as . (b) is Schur-convex in ; it therefore decreases under majorization towards the uniform distribution, and along the binary family it is strictly decreasing in . (c) as for any fixed (near-degenerate sources). (d) For fixed , as .
Proof.
Write , which is strictly increasing on and exceeds there, so that
Since every factor is strictly greater than , giving the strict inequality in (a); the stated limits hold because both for uniform as and for fixed as .
For part (b), each is a coordinatewise sum of the convex function and is therefore Schur-convex; composing with the increasing map preserves Schur-convexity, and a sum of Schur-convex functions is Schur-convex, so (2) makes Schur-convex in ; since the exponential is increasing, is Schur-convex as well. On the binary family with , majorization is a total order along which is strictly decreasing, so is there strictly decreasing in . Note that no such statement can hold for general alphabets in terms of alone, since depends on all the Rényi entropies . The source has and at , whereas has the larger and the larger .
Part (c) holds because as for every fixed , while increases to ; hence for every fixed , , and , although no single factor diverges. For part (d), put ; then , a bound valid also for countable , and , so and . Since , once is large enough that we get . ∎
The computational cost of the sampler is summarized next.
Proposition 3.5.
Along a run of Algorithm 2 that stops at time , the stopping test costs operations at step , where denotes the number of distinct prime factors of , so the total cost of the walk is
operations, and in expectation, where the expectation is finite because has a geometric tail. The path-assignment step, which ranks the observed path among the paths avoiding using the backward dynamic program of Algorithm 2, incurs an additional arithmetic operations and requires storing integers at termination. These integers have bits, since every count is at most , where . This cost is polynomial in for fixed but exponential in the alphabet size. For every prime modulus , the transfer theorem of Section 4 reduces the assignment cost to automaton transitions (Corollary 4.18), which for on a binary alphabet is bit operations; composite moduli remain Open Problem P1 (Section 6).
The geometric tail is seen as follows. Let and be two symbols of positive probability and . From any state, at most further draws of the symbols and bring the walk to a state with and , at which every prime power dividing produces carries in base and Theorem 1.3 gives ; hence the walk enters within draws with probability at least , and for every . Since , the cost of step is . For prime one has , and since is of order by Proposition 3.4(d), the cost is per draw on average.
Remark 3.6 (No closed form for composite ).
For composite no analogue of the closed form of Theorem 3.1 is known, and its derivation does not extend. The generating-function argument behind Theorem 3.1 rests on the product structure of the avoiding path counts over the base- digit positions (§3 of [4]), which supposes a single prime base. The stopping set couples the digit and carry structures of the distinct bases , and these are not simultaneously controllable; even within a single prime base there is no exact renewal regeneration (Remark 3.2). The irregularities of Example 2 in Section 2.1, where contains unreachable states and the group sizes vary, are symptoms of this coupling.
One might hope to recover a bound of the form by observing that by time most draw patterns have a multinomial coefficient divisible by some prime factor of . This is not sufficient. Membership in requires the valuation conditions to hold simultaneously for all . At , for instance, the state has , which is divisible by but not by and so does not lie in ; the axis states have at every . Moreover no bound can hold uniformly in , since as degenerates for each fixed . For fixed non-degenerate , we expect , and the benchmark of Section 5.2 is consistent with this, but we do not prove it; see Open Problem P2 (Section 6).
Remark 3.6 motivates two questions addressed in Section 6. The first asks whether a formula for in terms of the prime-power Rényi entropies nonetheless exists (Open Problem P2). The second asks whether, given that prime moduli admit closed-form analysis, rounding up to the nearest prime is preferable in practice (Open Problem P3).
We now establish the precise relationship between the expected stopping time and the information-theoretic properties of the source.
Definition 3.7.
The Rényi entropy of order , of a distribution on is
with (the Shannon entropy).
The entropy reading of Theorem 3.1, together with its first-order approximation, can now be stated.
Theorem 3.8.
For prime , let and note that where is the Rényi entropy of order . Then:
(a) Exact: . (b) First-order approximation: .
The approximation (b) is a renewal estimate at the first scale rather than a truncation of the product, and it always overestimates, in the sense that strictly for every non-degenerate ; in particular the estimate is never exact.
Proof.
Part (a) is Theorem 3.1. For part (b), split the product at and rearrange to obtain the exact identity
so the estimate (1) is multiplied by two correction factors, each tending to . For the first, , whence , which tends to as grows. For the second, , so and the tail converges to doubly exponentially. For the strict inequality, note that for every
letting and using , established just above, gives
Since is non-degenerate, at least two of the are positive, so strictly for every . Hence every factor in the last product lies in , and the product, which is positive because it equals , is strictly less than . ∎
A key observation is that the complexity of the Bernard–Letac algorithm is governed by the Rényi entropies of the source at orders , with the principal contribution from the Rényi entropy associated with the modulus. The theorems above are stated without assuming is finite, and Bernard and Letac themselves work throughout with finite or countable, so the product formula and its Rényi reading apply verbatim on countable alphabets. What is not settled at the boundary, for sources of infinite Shannon entropy, is a replacement for the lower bound of Theorem 3.11; this is Open Problem P6 (Section 6).
The limit of as is determined next. The following lemma collects the elementary bounds on which the argument rests.
Lemma 3.9.
Let , , and for put
Then for every ,
Moreover is strictly increasing on with , as , and as .
Proof.
Since , one has with . Put , so that . The inequalities , valid for , give
The inequalities , valid for , then give , which is the first inequality in (3), and
which is the second. For the third, the inequality , valid for , applied at gives , hence , and together with , proved below, this yields .
The derivative of is , which is positive on because for . The bound is equivalent to , which is for . Finally, as gives , and as gives . ∎
Theorem 3.10.
Treating as a continuous parameter, the expected stopping time , with , has a finite limit as :
The constant is strictly greater than , depends on the full distribution rather than on its Shannon entropy alone, and is not in general equal to . For the symmetric binary source one has , whereas .
Consequently, the Bernard–Letac sampler does not achieve the Shannon optimum as . The lower bound in Theorem 3.11 scales as , while remains bounded below by the positive constant . Thus, the efficiency approaches zero (Corollary 3.13). The naive reduction of the product to its single factor is invalid because the tail consists of infinitely many factors, each approaching , yet their product converges to a nontrivial constant. This phenomenon is the same carry-coupling effect that differentiates the exact product in Theorem 3.1 from the single-scale approximation in Remark 3.2.
Proof.
Write with , and set , so that with . Taking logarithms,
with as in Lemma 3.9. Let and be as in that lemma, put for , and put and , so that and the points form a mesh of width on .
The function is continuous and strictly decreasing on , since each is continuous and decreasing in and is dominated by , with and for . By Lemma 3.9, is therefore strictly decreasing on with , as , and as . Moreover is integrable on . Indeed, for one has , the last step because , while with , valid also for countable since . Hence once , which decays doubly exponentially, and before that. The integral is thus finite, and it is strictly positive because .
Since is decreasing and nonnegative, and for every , where . Summing these inequalities gives
for every . In particular the series converges, and since the first part of (4) yields
Now apply (3) at , which gives for every . In particular , so the series converges. Let . Summing the two-sided bound over and the one-sided bound over gives
by the second part of (4). As , one has and , so the right side tends to because is integrable, while
Consequently , and since ,
Exponentiating yields and . For the symmetric binary source, , and numerical quadrature of the integral gives . The constant is not a function of the Shannon entropy alone. For instance, the uniform source on four symbols and the source both have Shannon entropy , while numerical quadrature gives for the former and for the latter. ∎
The following theorem gives the information-theoretic lower bound.
Theorem 3.11.
For any algorithm in ,
Proof.
If there is nothing to prove, so assume . Since the source is i.i.d. and is a stopping time with finite expectation, Wald’s identity applied to the variables gives the entropy identity
The output is -measurable, so , while is uniform on values and hence . Combining the two gives . ∎
The following proposition shows that the lower bound is never attained.
Proposition 3.12.
For every , every non-degenerate distribution , and every algorithm in , the inequality of Theorem 3.11 is strict.
Proof.
Write for the law of the draw sequence under an admissible , and suppose that equality holds for some algorithm in at some non-degenerate . If the right-hand side vanishes while , and if while the left-hand side alone is infinite, so in either case the inequality is strict; assume therefore that both quantities are finite. Equality forces equality in the step of the proof of Theorem 3.11, and since is a function of the stopped trajectory, this reads under . Hence for each there is a single word , of length and letter-count vector with , such that and differ by a -null set; the are pairwise distinct, since otherwise two disjoint events of probability would coincide up to null sets.
Write for the cylinder of draw sequences beginning with the word of length . The event lies in , so its intersection with is either empty or all of . This intersection is the event , of -probability , hence it equals as a set, and in particular , while for every admissible . Likewise lies in , is empty or all of , and has -probability , whence as sets. Consequently, for every admissible ,
If used only one letter , the left-hand side would approach as increases to within the admissible distributions, so every uses at least two distinct letters. The maximum of the monomial over the whole simplex is then attained at the point , which has all coordinates strictly below and is therefore admissible, and the maximum equals , uniquely attained by the Gibbs inequality [11, Chapter XI]. The display gives , so by uniqueness , whence , that is, . The distinct words therefore share one length and one letter-count vector , which forces . On the other hand, summing over all with gives , the inequality being strict because the type , for any letter in the support of , differs from and carries positive probability. Hence , a contradiction. ∎
In particular, the efficiency of Corollary 3.13 satisfies for every prime and every non-degenerate .
Corollary 3.13.
The efficiency of the Bernard–Letac algorithm,
regarded as a function of the continuous parameter through the product formula, as in Theorem 3.10, tends to at both extremes of the scale. As approaches , converges to (Theorem 3.10) while approaches zero. As approaches infinity, is asymptotically equivalent to (Proposition 3.4(d)), so behaves as and also approaches zero. Since is continuous and positive on with limits of zero at both ends, it attains a maximum at some interior point . The sampler therefore achieves its highest efficiency at an intermediate scale. Under the first-order approximation (Theorem 3.8(b)),
For instance, with , the efficiency increases from near zero as approaches to a maximum value of near , and then decreases (Figure 1). For the more skewed source , the maximum efficiency is near . Two distinct effects reduce efficiency at the extremes. For large , because Rényi entropy is non-increasing in order, so the algorithm detects less randomness than is present in the source. As approaches , the target contains vanishing information (), while remains bounded below by the positive constant , resulting in most draws being wasted.
Proposition 3.14.
The following asymptotic regimes hold for the expected stopping time of Algorithm 2:
| Regime | Governing quantity | |
|---|---|---|
| full law of (Thm 3.10); | ||
| moderate | Rényi- entropies | |
| moderate (approx.) | Rényi- entropy | |
| () | floor; correction | |
| near-degenerate | ||
| uniform | for all |
4 A Transfer Theorem for the First-Passage Kernel
Proposition 3.5 identifies group assignment as the computational bottleneck of Algorithm 2. This section removes it for every prime modulus and every finite alphabet . It is demonstrated that the first-passage kernel underlying the ranking step can, modulo , be computed by an explicit automaton with states that processes the base- digits of its arguments. Consequently, each kernel value requires automaton transitions, replacing the need for a dynamic program over the box , and the exact fair assignment incurs transitions in total (Corollary 4.18), which for on the binary alphabet amounts to bit operations. That classical case, corresponding to the extraction of a single fair bit from a biased source, is worked out explicitly as a seven-state automaton and presented as self-contained pseudocode in Algorithm 4. Only one step of the proof does not constitute an exact path bijection, namely the free action of the cyclic group of order on the orderings of a terminal mixed block, introducing the reduction modulo ; for this action is a fixed-point-free involution.
The term transfer is employed in the transfer-matrix sense, rather than the singularity-analysis sense from analytic combinatorics. The section operators defined below transfer a kernel evaluation at one base- scale to an evaluation at the next, enabling the global value to be constructed by composing local digit rules. Here, the digit expansion serves as the chain along which local transfer data are multiplied. Equivalently, Theorem 4.4 establishes that the family of sections of (its -kernel in the terminology of automatic sequences [2]) is finite, which defines -automaticity. The term kernel is reserved for itself, while sections are used to distinguish between these concepts.
Throughout this section is a fixed prime and a finite alphabet with letters. We identify with , equipped with the componentwise partial order, the unit steps , and the coordinate sum , which we call the level of . A monotone path is a finite sequence of points in which each point is obtained from its predecessor by adding some . For and the digit column lies in ; a column is called pure when at most one coordinate of is positive and mixed otherwise. For the multinomial coefficient counts the orderings of a monotone path with increment . By the multinomial Lucas criterion following Theorem 1.3,
with , which defines the continuation region of the walk. For and this reads and , where denotes bitwise and.
The first-passage kernel is defined next.
Definition 4.1.
For and , let denote the number of monotone paths from to all of whose points except the terminal point lie in ; such paths are called counted paths for the pair . In particular and when . The kernel is
extended by whenever or . A kernel is any function .
The relation is the componentwise order fixed in the notation of Section 1. In contrast, the lexicographic order is used solely for ranking paths and for organizing the columns of Table 1. The extension for simply indicates that no monotone path exists from to .
The kernel takes values in and is not normalized; thus, it does not constitute a stochastic kernel. However, the integer count serves as the combinatorial foundation for such a kernel. From any starting point , the walk reaches almost surely. Indeed, from every point of at most suitably chosen draws produce a bottom digit column of sum , hence a point of , and each block of draws realizes such a choice with probability at least . The probability that a walk starting at first enters at is given by , since each path from to that avoids has probability . Therefore, . The mapping defines the stochastic first-passage (harmonic-measure) kernel for the stopped walk from to , with preserving only the combinatorial structure.
The barrier being crossed at time is the combinatorial set rather than a scalar level, and is not absorbing for the unstopped walk. From on the binary alphabet the step lands at . Higher-order passages are therefore definable, but they play no role here, because the walk is stopped at and the convention for forbids interior visits to in the count.
The kernel provides a unified framework for the two path counts discussed in this paper. For , , so that part (c) of Theorem 1.1 involves the evaluation , while the ranking quantities in Algorithm 2 are given by . Two reductions ensure that the kernel modulo is sufficient to achieve exact fairness.
The first reduction is the following residue rule.
Lemma 4.2.
For any modulus , replacing the return value of Algorithm 2 by preserves exact fairness, in the sense that for every admissible .
Proof.
Conditional on the observed path is uniform over the avoiding paths, by using the proof of Theorem 2.2, whose ranks are the consecutive integers . Since , each residue class modulo contains exactly of them. ∎
Second, the rank reduces to kernel evaluations along the observed path. Fix the linear order on used for ranking. The counted paths from to that precede the observed path lexicographically are those that agree with it before some time and take a letter at time . The branch points are therefore the points with , and their counts vanish for , which is precisely the convention built into . It follows that
On the binary alphabet with the inner sum has a single term at the steps with and no term otherwise.
Statement of the transfer theorem
For digit columns , define the section operator on kernels by , so that iterated sections read the digit columns of the two arguments least significant first. A transfer system is a finite set of kernels containing and closed under all section operators.
The members of the transfer system are the following kernels. For and set
together with , the scalar multiples , and the zero kernel . The kernels are called carry kernels, since they record an unfinished digit block in the letter , and the diagonal kernels are called certificates. Two linear identities relate them.
Lemma 4.3.
, and .
Proof.
The first identity holds because and partition . For the second, evaluate at . If both sides equal , since each vanishes, the point not being below . If and , both sides vanish. If and , the right side is , which is the first-step decomposition of the counted paths from ; the convention for a non-terminal makes the decomposition exact. If both sides vanish. ∎
The transfer theorem can now be stated.
Theorem 4.4.
The family
is a transfer system for of cardinality exactly . Its members are pairwise distinct, and each is a section of . The sections of every member are given by Proposition 4.13 and Lemma 4.14 below. Consequently is computed by the deterministic finite automaton with output whose states are the members of , whose initial state is , whose input is the sequence of digit columns read for (least significant first, zero-padded), whose transition on the column sends a state to , and whose output in the final state is , namely at , at , and elsewhere. This automaton is minimal, and every state is fixed by the zero column, so the computation is stable under zero-padding.
The linear structure of the system is equally rigid. The next theorem computes the exact dimension of the -weighted transfer system.
Theorem 4.5.
Fix a letter . The -linear span of the iterated sections of admits the basis , and hence has dimension exactly .
Two clarifications regarding finiteness are necessary. The kernel is an infinite array even over the finite alphabet. Only its columns are finite, with the column of supported in the box . This property explains why the dynamic program of Proposition 3.5 is finite but increases in size with . According to Theorem 4.4, the family of sections of is finite. This finiteness is established by the theorem itself and does not result from the finiteness of the alphabet, which only enters through the number of carry kernels. The structure of the system is transparent. Besides and the zero kernel there are carry kernels, one per letter, and certificates, namely two indicator kernels, their sum, and the nonzero scalar multiples of one of them. The scalars are the Lucas coefficients of partial digit blocks, and they are the only place where the prime enters.
Digit lemmas
The first lemma records the effect of one digit column on membership in ; it is the base- form of the doubling rule of the binary case.
Lemma 4.6.
For and , the point lies in if and only if and , and lies in if and only if or .
Proof.
The digit columns of are followed by the columns of , since every coordinate of is smaller than ; the Lucas criterion following Theorem 1.3 applies column by column. ∎
The second lemma shows that a continuation point at a level divisible by is divisible by in every coordinate. It generalizes the parity structure of the binary case.
Lemma 4.7.
If and , then divides every coordinate of , so with .
Proof.
The bottom column satisfies and , hence . The membership follows from Lemma 4.6. ∎
The third lemma isolates the arithmetic of ordering numbers. Its second part is the only source of cancellation modulo in this section.
Lemma 4.8.
Let . If , then . If and , then is mixed, the cyclic group acts freely by rotation on the orderings of a path with increment , and .
Proof.
If , then all factorials in involve integers smaller than and are prime to . If and , then no single coordinate can carry the whole sum, so at least two coordinates are positive. A word of prime length fixed by a nontrivial rotation is constant, and constant words are excluded, so every orbit of the rotation action has exactly elements and divides the number of words; this is also the case of Theorem 1.3 in which the bottom column carries. At the rotation is the transposition of the two orders of a mixed pair. ∎
Localization of counted paths
The next two lemmas pin down the continuation points of a path near its terminal and near its start. They replace the block bookkeeping of the binary case.
Lemma 4.9.
Let , , and . If and divides every coordinate of , then with . If , , and , then , where satisfies and .
Proof.
For the first claim, gives . For the second, write with , so because , and by the first claim applied to . From and we get , hence , and . ∎
Lemma 4.10.
Let , , and . If , , and , then , where satisfies and .
Proof.
Write with and as before. From we get . From we get , hence , and . ∎
The head lemma shows that a counted path starting at a non-aligned point can reach a point divisible by only by completing a pure column, and only from a pure starting column.
Lemma 4.11.
Let , , and let be a counted path from . Suppose contains a point at level all of whose coordinates are divisible by . Then for a unique letter and a unique integer , the first steps of are all equal to , the point equals , and the points of below level are exactly for , each of which lies in if and only if . Moreover, every non-terminal point of at level is of the assumed form by Lemma 4.7.
Proof.
The predecessor of on , for the appropriate letter , lies at level and is not the terminal of , hence lies in , and Lemma 4.10 gives with and . Every coordinate of is divisible by , so for every , which forces . From and we get with , and . Every earlier point of lies in , lies between and , and is of the form with by Lemma 4.10, hence equals with ; conversely all these points occur on , one per level. Each lies in if and only if by Lemma 4.6. ∎
The contraction lemma identifies aligned counted paths with counted paths at the next scale. It is an exact bijection.
Lemma 4.12.
For all , as integers.
Proof.
Both sides vanish unless , and both equal when , so assume . Let be a counted path from to . For let be the point of at level . Each with is non-terminal, hence lies in , and equals with by Lemma 4.7; also , and we set . The segment of between and consists of unit steps with increment , so , say , and all steps of the segment equal . The segment is therefore determined by and , and its interior points with lie in exactly when by Lemma 4.6, a condition already imposed at . The map is thus a bijection between the counted paths from to and the counted paths from to , the memberships of corresponding points in and agreeing by Lemma 4.6. ∎
The section table of the kernel
The following proposition computes every section of in closed form.
Proposition 4.13.
Let . As kernels,
where in case the scalar is , which is nonzero by Lemma 4.8. In case the result does not depend on .
Proof.
Fix and put and , so that the left side evaluated at is . If , then and each right side vanishes as well, the inequality with being equivalent to together with the stated digit relations in each case. So assume , which gives , and split according to .
Aligned terminals, . If , Lemma 4.12 and Lemma 4.6 give , which is case .
Let . The terminal lies at the level , which is at least because the start level is smaller than for any nonempty path and ; a trivial path is impossible since . Every counted path therefore contains a point at level , namely its terminal if and a non-terminal point otherwise, and in both cases the point has all coordinates divisible by , by assumption in the first case and by Lemma 4.7 in the second. Lemma 4.11 then forces for a unique letter ; when is mixed there is no counted path and the section is the zero kernel, part of case .
For , Lemma 4.11 shows that every counted path begins with the forced pure head from to , whose points lie in exactly when , and continues with an arbitrary counted path from to . The head has exactly one realization, independently of . By Lemma 4.12,
where Lemma 4.6 converts the terminal membership. This is , and case holds, including the degenerate instance in which the head itself terminates the path.
Low terminals, . The terminal level is not divisible by , and it exceeds . Suppose first that some point of the path lies in at level . Then by Lemmas 4.7 and 4.9, so by Lemma 4.6. But the terminal satisfies if and only if , again by Lemma 4.6 since , so and .
Otherwise no point of the path lies in at level . A point of the path at that level could only be the start lying in , every other non-terminal point being in ; a start in admits only the trivial path, whose terminal would lie at the start level, below the terminal level. Hence the start level exceeds , which with forces . If , then , so by Lemma 4.6; a nontrivial path dies at its start, and the trivial path would need , impossible since . Hence the section vanishes there. If , then and gives . All points of a counted path lie strictly between the levels and , so by Lemma 4.9, together with the domination of , every non-terminal point has the form with , and it lies in exactly when . If , the only path is trivial and contributes , which over all assembles to , case . If , a nontrivial counted path requires at its start and , hence , at its terminal, a contradiction, and the section vanishes, completing this range within case .
Full terminals, . Here always, and the terminal level is . No non-terminal point can lie at that level, for such a point would equal with by Lemmas 4.7 and 4.9, whereas its level forces .
Suppose some point of the path lies in at level . As before that point is , so , and the path decomposes uniquely into a counted path from to with all points in , followed by a final segment of unit steps from to with increment . The interior points of the final segment are with a partial sum of the increment, so , and they lie in by Lemma 4.6 since ; hence every one of the orders of the final segment yields a counted path. The number of counted paths through is therefore times the number of initial segments, and by Lemma 4.8 because is mixed. These contributions vanish modulo .
Otherwise, disposing of a start in at level exactly as in the previous case, the start level exceeds , so . If , then , the start lies in , and the trivial path would need with , impossible; the contribution is zero. If , then and . When the start lies in and only the trivial path survives, which requires , hence , and contributes ; over all this assembles to , the instance of case . When , so that , every counted path stays strictly between the levels and except for its terminal, so by Lemma 4.9, together with the domination of , its non-terminal points are with and , all lying in exactly when , while the terminal lies in unconditionally. The counted paths correspond to the orders of the increment , of which there are , so the contribution at is . Over all this assembles to with , which is nonzero by Lemma 4.8 since . This is case . For every contribution passes through and vanishes as shown above, part of case .
High terminals, . Again always. The level is strictly below the terminal level. A path reaching across it would contain a non-terminal point there, equal to with by Lemmas 4.7 and 4.9 while , a contradiction. Hence the start level is at least , so , the start lies in , and only trivial paths survive. A trivial path requires and and contributes , assembling to , the instance of case ; all other pairs give zero, completing case .
The six cases are exhaustive and pairwise disjoint, and the proof is complete. All identities except the vanishing arguments through hold at the level of the integer counts ; the reduction modulo is used only through Lemma 4.8. ∎
Sections of the derived kernels
The next lemma closes the family by computing every section of the carry and certificate kernels.
Lemma 4.14.
Let , , and . Then
and
where is nonzero. Sections of the zero kernel are zero.
Proof.
The equation holds exactly when and , which together with Lemma 4.6 for the indicators and gives the three certificate rows.
For the carry kernel, , and Lemma 4.6 splits the indicator as . If the section vanishes. Assume .
If , then with , so the section equals times , and Proposition 4.13 applies with the column . Case there requires pure and , hence with , and yields . Case yields , since no point lies in both and . Case , which requires , , , and , yields with and . Case , which here occurs exactly when and , hence and , yields , matching . Case yields zero. The stated second row merges cases and , and by Lemma 4.8 since .
If , then forces , and , so the section equals . By cases and of Proposition 4.13 with the zero column, this is when and zero otherwise, consistent with the first row at ; the second row cannot occur since fails for every . ∎
Proofs of Theorems 4.4 and 4.5
Proof of Theorem 4.4.
Closure under every section operator is the content of Proposition 4.13 and Lemma 4.14, and the cardinality count is provided the members are pairwise distinct. Each member is reached from in one step. Indeed and and ; for take , which has ; and for with take and , so that has , while , , and .
For distinctness, note first the diagonal values. One has , since , , and . Evaluating at and at therefore separates all members pairwise, except for the pair and , which agree on the diagonal, and the pairs formed by two carry kernels or by a carry kernel and the zero kernel, which all vanish there. Off the diagonal every certificate vanishes, while , the unique path being a single step from a point of to a point of ; this separates from . Finally, for pick a letter and set , so that and by Lemma 4.6. Then , while for every because . Hence the carry kernels are nonzero and pairwise distinct, and all members of are pairwise distinct.
The automaton evaluation proceeds by induction on the number of digit columns of . Consuming the least significant column replaces the current kernel evaluated at with evaluated at . After all columns have been processed, the arguments reduce to , and the output of the final state is the value sought; at the origin , , the , and evaluate to , since , while evaluates to and to . Since the states are pairwise distinct functions, any two of them differ at some pair , and the runs started at the two states on the digit columns of that pair produce different outputs; no two states are equivalent, and the automaton is minimal by the Myhill–Nerode criterion. Finally, fixes every member of by Proposition 4.13 and Lemma 4.14, so appending zero columns does not change the final state, which is the stability under zero-padding. ∎
Proof of Theorem 4.5.
The span of the iterated sections of is contained in the span of , since is closed under sections and contains , and it contains by Theorem 4.4, so the two spans coincide. By Lemma 4.3, and , and every is a scalar multiple of , so the displayed set spans. For independence, relabel the letters so that and suppose
Evaluating on the diagonal at gives . Evaluating at the pair , where equals and every with vanishes because , gives . Evaluating on the diagonal at gives . Evaluating at for each , where equals and every other vanishes, gives . ∎
The binary case
The classical case of a single fair bit is the specialization , , in which the family has seven members.
Corollary 4.15.
For and the transfer system consists of the seven kernels
that is, , , , , , , and . The sixteen sections act as in Table 1, and the automaton of Theorem 4.4 has initial state and accepting set , the two states with output .
| digit column , | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| in lexicographic order | ||||||||||||||||
| 0 | 1 | 1 | 1 | 2 | 3 | 1 | 4 | 5 | 1 | 3 | 4 | 1 | 1 | 1 | 6 | |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
| 2 | 1 | 1 | 4 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 4 | 1 | 1 | 1 | 1 | |
| 3 | 1 | 1 | 1 | 1 | 3 | 1 | 1 | 1 | 1 | 3 | 1 | 1 | 1 | 1 | 6 | |
| 4 | 1 | 1 | 1 | 1 | 4 | 1 | 1 | 1 | 1 | 4 | 1 | 1 | 1 | 1 | 1 | |
| 5 | 1 | 1 | 4 | 1 | 1 | 1 | 4 | 5 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
| 6 | 1 | 1 | 1 | 1 | 6 | 1 | 1 | 1 | 1 | 6 | 1 | 1 | 1 | 1 | 6 |
Table 1: The transfer table for on the binary alphabet. Entry in row means .
Proof.
With the digit columns are the pairs in , the pure nonzero columns are and , and the only column of sum is , whose multinomial coefficient vanishes modulo ; the only nonzero scalar is , so has no proper multiples. The row of is Proposition 4.13. For it yields on the zero column by case and otherwise by case . For it yields for , by cases , , , and with ; the case yields in the same way, and yields on by case and otherwise. The rows of are the certificate rows of Lemma 4.14, where occurs only for . The row of is the carry row of Lemma 4.14 with . It returns on the columns with and , returns on the columns with and , that is , and returns elsewhere; the row of is the same with the two letters exchanged. The outputs are and for the other five kernels. ∎
As an initial consistency check, the row confirms part (c) of Theorem 1.1 on , and the general form of the check is the same for every prime. For , every input column has , so either self-loops (on the all-zero column) or moves to the dead state by cases and of Proposition 4.13. Since any contributes at least one nonzero column, such a run ends in the dead state, and itself evaluates to at the origin. Therefore, for every , as required, since .
The automaton described in Theorem 4.4 can be represented as the standard five-tuple of a deterministic finite automaton with output, where the state set is , the input alphabet is (representing the digit columns), the transition function is specified by Proposition 4.13 and Lemma 4.14, the initial state is , and the output function takes values in . For the output is or , and the automaton is the ordinary acceptor with accepting set and transition table Table 1. The zero kernel is the unique dead state; its row is constant and its output is .
Remark 4.16 (The involution of the binary case).
For , the only step of the proof that is not an exact path bijection is the vanishing of modulo in Lemma 4.8, which is realized by the fixed-point-free involution swapping the two orders of a terminal mixed block. For a general prime the same role is played by the free action of on the orderings of a terminal full block with mixed column , and the certificates acquire the scalars of the partial blocks, which are the Lucas coefficients of the splitting of a full column into the part present at the start and the increment of the path.
Algorithmic consequences
The automaton yields the following evaluation cost.
Corollary 4.17.
can be computed in transitions of the automaton, with the digit columns processed in a single pass. Once the transition function has been tabulated, a table of entries, each transition is a single lookup indexed by a column of digits.
Combining the automaton with the residue rule yields fast exact fair assignment.
Corollary 4.18.
For a prime modulus and a finite alphabet , Algorithm 2, when combined with the residue rule from Lemma 4.2 and rank computation via (5) and Theorem 4.4, achieves exact fair group assignment in automaton transitions. For and this is bit operations, whereas the dynamic program of Proposition 3.5 executed modulo requires bit operations.
Proof.
Exactness follows from Lemma 4.2 and (5). The sum in (5) contains at most terms, each corresponding to an automaton evaluation with transitions, as established by Corollary 4.17, since all coordinates of the branch points and of are at most . The digit columns of the branch points are maintained incrementally along the walk, with each step altering one coordinate at amortized constant cost. For the binary comparison, the box contains cells for , by the arithmetic mean–geometric mean inequality, which is of quadratic order when both letters occur with positive frequency. The dynamic program of Proposition 3.5 run modulo , which is also exact by Lemma 4.2, requires one bit operation per cell. In contrast, using the full integer counts in Algorithm 2, where entries reach bits, increases the cost to bit operations. ∎
Corollary 4.18 is implemented for through a self-contained specialization of Algorithm 2. The sampling loop (lines 1 to 5 of Algorithm 2) remains unchanged, except that for , the stopping test in line 4 simplifies, by Theorem 1.3, to the constant-time bitwise test . The group-assignment phase (lines 6 to 10), which involves the backward dynamic program for over the box , the rank , and the block rule , is entirely replaced. No count is computed; instead, the rank is accumulated modulo via (5) as a sum of automaton evaluations over the branch points of the observed path, and the residue rule of Lemma 4.2 finalizes the assignment. For a general prime the same procedure applies with the stopping test of Algorithm 1, the branch points for , the transition function of Theorem 4.4, and the rank accumulated in from the outputs.
Algorithm 6 Fair Bit Extraction via the Transfer Automaton (Algorithm 2 specialized to , )
1: Access to i.i.d. draws from unknown non-degenerate on
2: Outcome with
3: ;
4: repeat
5: Draw
6: if then append to branch point of this step; cf. (5)
7:
8: until , i.e. (Theorem 1.3)
9: ;
10: for in do
11:
12: for do
13: row of Table 1
14: end for
15: if then
16: end for
17: return residue rule, Lemma 4.2
Correctness and the complexity follow directly from Corollary 4.18. The outer loop executes at most automaton evaluations, each requiring digit columns; the truncation to these columns is exact (Remark 4.19). The digit columns of the stored branch points are incrementally maintained along the walk, consistent with the proof of the corollary.
Remark 4.19 (Digit width of the truncated run).
Algorithm 4 processes the binary columns with , whereas a branch point can occupy one further bit, namely when . This forces , so the binary expansion of consists of ones only and for every ; every state with therefore lies in . The walk occupies without stopping just before the final step, so , the walk stops at , and the offending branch point is , arising at the final step. The truncated run therefore reads only zero columns on the side and computes , since , which agrees with the true value , because implies . The truncation is exact in every case.
Remark 4.20 (Beyond prime moduli).
Theorem 4.4 does not extend as stated to composite moduli. For a modulus with several prime factors, the rank in Lemma 4.2 is taken among the paths avoiding itself, so the automata of the prime factors do not combine, and for a prime power with the cancellation of Lemma 4.8 is only of first order. The resulting questions are formulated as Open Problem P1 (Section 6).
5 Numerical Evidence
The following section presents numerical evidence addressing questions that remain unresolved by the theory.
5.1 Unimodality of the efficiency
Corollary 3.13 demonstrates that the efficiency satisfies as and as , implying that attains a maximum at some interior . However, it does not establish the uniqueness of this maximum. Figure 1 displays for two sources. In all computed cases, the curve is unimodal, exhibiting a single interior peak near for and near for the more skewed . This pattern suggests, but does not prove, that the interior maximum is always unique.
2510205010020050010000$$0.1$$0.2$$0.3$$0.4$$0.5$$p^{\star}\!\approx\!5$$p^{\star}\!\approx\!10modulus / scale (log scale)efficiency \eta(p)=\dfrac{\log p}{E(T)\,H(\boldsymbol{\pi})}$$\boldsymbol{\pi}=(0.7,0.3)$$\boldsymbol{\pi}=(0.9,0.1)
Figure 1: The efficiency of the Bernard–Letac sampler as a function of the modulus (treated as continuous, log scale) for two binary sources. This figure supports Corollary 3.13. Numerically, is unimodal, approaching zero as (where the target carries negligible information but ) and as (where ), with an interior maximum at that shifts to higher values as the source becomes more skewed. Although the uniqueness of the maximum is observed in all computed cases, it remains unproven. The curves are derived from the exact product formula in Theorem 3.1.
5.2 A composite-modulus benchmark
For composite , no closed-form prediction for is known (Open Problem P2). Therefore, the following comparison provides genuine empirical evidence rather than a verification of a theorem. The direct Bernard–Letac sampler (Algorithm 2) is compared against two Von Neumann (VN) methods for generating a uniform variable in from an i.i.d. biased binary source with . The metric used is the expected number of biased coin flips per uniform output.
VN + Reject: Von Neumann debiasing is followed by simple rejection sampling. The procedure reads fair bits, keeps the values , and rejects and retries whenever the result is at least .
VN + Lumbroso: Von Neumann debiasing is followed by Lumbroso’s Fast Dice Roller [16], which implements the optimal Knuth–Yao DDG tree for uniform distributions. This combination recycles entropy from rejections and is the strongest such method.
Bernard–Letac: This approach uses the direct sampler of Algorithm 2, operating on biased flips without intermediate debiasing.
All experiments utilize samples per configuration. The two VN columns report exact Markov-chain values, while the Bernard–Letac column presents the empirical mean. The final column, BL / Lum, reports the ratio of the Bernard–Letac mean to the VN+Lumbroso value. For prime , the analogous comparison involves only two closed-form quantities (Bernard–Letac via Theorem 3.1 and the VN methods via exact analysis) and is therefore omitted. No closed form for is known for composite (Remark 3.6). The empirical results presented below demonstrate that the Bernard–Letac method retains its advantage over both alternatives.
| VN+Reject | VN+Lumbroso | Bernard–Letac | BL / Lum | ||
|---|---|---|---|---|---|
| 4 | 0.50 | 8.00 | 8.00 | 5.86 | 0.73 |
| 4 | 0.70 | 9.52 | 9.52 | 6.30 | 0.66 |
| 6 | 0.50 | 16.00 | 14.67 | 6.65 | 0.45 |
| 6 | 0.70 | 19.05 | 17.46 | 7.18 | 0.41 |
| 10 | 0.50 | 25.60 | 18.40 | 7.37 | 0.40 |
| 10 | 0.70 | 30.48 | 21.90 | 8.97 | 0.41 |
A remark on the row is in order for readers cross-reading [4]. Remarque 3 of that paper prints for the fair coin, whereas the exact value is , in agreement with the empirical above; the printed figure is a hand estimate and is simply inaccurate. Their companion figure , the cost of extracting two fair bits through instead, is correct (exactly ).
The information-theoretic lower bound of Theorem 3.11 is substantially lower than the performance of all methods, indicating that none approaches optimality in absolute terms. The advantage of the Bernard–Letac method is structural. By omitting the debiasing stage, it extracts more useful information per biased flip.
6 Open Problems and Future Directions
Several open problems arise from the preceding analysis.
P1. Transfer systems beyond prime moduli. Theorem 4.4 settles the prime case of the transfer question. For every prime and finite alphabet , the kernel is computed by a minimal automaton with exactly states, the -weighted transfer system spanned by its states has dimension exactly (Theorem 4.5), and the group assignment of Algorithm 2 costs automaton transitions (Corollary 4.18). Composite moduli remain open. Since the rank of Lemma 4.2 is taken among the paths avoiding itself, the automata of the prime factors of do not combine, and the assignment for composite still costs the dynamic program of Proposition 3.5. Two questions arise. For a prime power with , the stopping set is itself -automatic, because the carries of Theorem 1.3 are bounded by and a finite automaton reading the digit columns least significant first can track their total up to ; but the cancellation of Lemma 4.8 is only of first order, since is divisible by and in general not by for a mixed column of sum , so the certificate structure of Theorem 4.4 must change. Does the kernel modulo admit a finite transfer system in base , and of what size? The case , on the binary alphabet is the first test. For a modulus with two distinct prime factors and , the stopping set is not semilinear. On the binary alphabet the integers with are those whose base- digits are all at most or whose base- digits are all at most ; this set is infinite, containing the powers of any odd prime among and , and has density zero, whereas an infinite eventually periodic set has positive density. By the theorem of Cobham and Semenov [5, 20], a subset of that is automatic in two multiplicatively independent bases is semilinear, so cannot be read by automata in both bases; whether it, or the kernel modulo , is automatic in a single base is unknown, and no exact assignment for composite running in time is known. The interaction with Kummer’s multi-carry criterion is also the obstacle in P2. P2. Closed-form for composite . Remark 3.6 explains why the derivation of Theorem 3.1 does not extend to composite . The question remains whether a formula for exists in terms of the Rényi entropies at the prime-power orders . The inclusion-exclusion structure of suggests that a Möbius-type inversion could be relevant. P3. Entropy order and the optimal modulus. Given a fixed source and a required number of outcomes , it is of interest to determine which decomposition of into prime powers minimizes . Since prime moduli allow for closed-form analysis, sampling instead with the modulus , the smallest prime satisfying , may often be more efficient in practice than using composite , even if this requires a slightly larger outcome alphabet. P4. Adaptive stopping boundaries. The set is predetermined. It is an open question whether a data-adaptive stopping boundary can be designed that, after estimating online, dynamically selects a subset of to reduce while maintaining fairness. P5. -adic limits and entropy. The -adic limit of Algorithm 5 is a -valued function on . It remains to be determined whether can be interpreted in terms of the entropy of a distribution associated with . The product formula of Théorème 10 of [4], in which ranges over matrices with margins and across all scales , resembles a convolution, and the connection to -adic -functions and -adic integration may yield further insights. P6. Sources of infinite Shannon entropy. On a countable alphabet every Rényi entropy of order is finite, since ; only the orders can diverge. Theorem 3.1 and its Rényi reading therefore carry over to countable unchanged, and strictly in every case by Proposition 3.4(a). The limit constant of Theorem 3.10 likewise remains finite. The convergence of the integral defining rests only on the behavior of near and on the doubly exponential decay of , neither of which involves . The open question concerns the boundary. For a source with but for every , what replaces the lower bound of Theorem 3.11, which becomes vacuous? P7. Multivariate Kummer carries and zero-one matrix counts. A corollary of §5 of [4] provides an upper bound on the number of zero-one matrices with specified margins. Refining this bound using the carry structure of Algorithm 1 remains an open problem, which is related to the longstanding challenge identified by Ryser [19].
Acknowledgements.
This work received no specific grant from any funding agency, commercial or not-for-profit sectors.
Competing interests.
The author declares none.
Data availability statement.
No external data were used in this work. The numerical results of Section 5 were produced by the author’s implementation of the algorithms described in the paper.
References
[1] J. Aczél and Z. Daróczy, On Measures of Information and Their Characterizations, Academic Press, New York, 1975.
[2] J.-P. Allouche and J. Shallit, Automatic Sequences: Theory, Applications, Generalizations, Cambridge University Press, Cambridge, 2003.
[3] G. Bachman, Introduction to -adic Numbers and Valuation Theory, Academic Press, New York, 1964.
[4] J. Bernard and G. Letac, Construction d’événements équiprobables et coefficients multinomiaux modulo , Illinois J. Math., vol. 17 (1973), pp. 317–332. First circulated as a manuscript, Université de Clermont, Clermont-Ferrand, France, received May 4, 1971.
[5] A. Cobham, On the base-dependence of sets of numbers recognizable by finite automata, Math. Systems Theory, vol. 3 (1969), pp. 186–192.
[6] E. Deutsch and B. E. Sagan, Congruences for Catalan and Motzkin numbers and related sequences, J. Number Theory, vol. 117 (2006), pp. 191–215.
[7] L. E. Dickson, History of the Theory of Numbers, vol. 1, G. E. Stechert, New York, 1934.
[8] P. Elias, The efficient construction of an unbiased random sequence, Ann. Math. Statist., vol. 43 (1972), pp. 865–870.
[9] W. Feller, An Introduction to Probability Theory and Its Applications, 2nd edition, vol. 1, Wiley, 1957.
[10] R. D. Fray, Congruence properties of ordinary and -binomial coefficients, Duke Math. J., vol. 34 (1967), pp. 469–480.
[11] J. W. Gibbs, Elementary Principles in Statistical Mechanics, Charles Scribner’s Sons, New York, 1902.
[12] A. Granville, Arithmetic properties of binomial coefficients I: Binomial coefficients modulo prime powers, in Organic Mathematics (Burnaby, BC, 1995), CMS Conference Proceedings, vol. 20, American Mathematical Society, Providence, RI, 1997, pp. 253–276.
[13] W. Hoeffding and G. Simons, Unbiased coin tossing with a biased coin, Ann. Math. Statist., vol. 41 (1970), pp. 341–352.
[14] D. E. Knuth and A. C. Yao, The complexity of nonuniform random number generation, in Algorithms and Complexity, Academic Press, 1976, pp. 357–428.
[15] E. E. Kummer, Über die Ergänzungssätze zu den allgemeinen Reciprocitätsgesetzen, J. Reine Angew. Math., vol. 44 (1852), pp. 93–146.
[16] J. Lumbroso, Optimal discrete uniform generation from coin flips, and applications, arXiv:1304.1916 (2013).
[17] Y. Morita, A -adic analogue of the -function, J. Fac. Sci. Univ. Tokyo Sect. IA Math., vol. 22 (1975), pp. 255–266.
[18] Y. Peres, Iterating von Neumann’s procedure for extracting random bits, Ann. Statist., vol. 20 (1992), pp. 590–597.
[19] H. J. Ryser, Combinatorial Mathematics, Wiley, New York, 1963.
[20] A. L. Semenov, Presburgerness of predicates regular in two number systems, Siberian Math. J., vol. 18 (1977), pp. 289–300.
[21] J. Von Neumann, Various techniques used in connection with random digits, Monte Carlo Method, Applied Mathematics Series No. 12, pp. 36–38, U.S. National Bureau of Standards, 1951.