Computation

Two weak sources make one fair bit

No fixed rule can turn every weakly random source into fair bits: for any rule, some source with almost full unpredictability makes it constant. Two independent sources are different. Multiply their bits in pairs, add, and keep the parity — and if the two together carry more unpredictability than the length of one, the result is nearly fair, whatever else the sources do. The reason is that the table of those parities is balanced on every large rectangle.

Worth reading first: Fair bits from an unfair coin · Randomness that has to be earned.

Von Neumann’s trick turns a biased coin into fair bits by reading its flips in pairs, and it needs only one assumption: that the flips are independent. Real sources of randomness — the timing of keystrokes, the noise in a sensor, the jitter of a clock — do not satisfy it. Their bits are correlated with one another in ways nobody can write down, and the most that can honestly be said about them is a lower bound on how unpredictable they are: that no outcome is more likely than, say, one in 2k2^{k} for strings of nn bits. That quantity, kk, is the source’s min-entropy, and a source with kk near nn is nearly uniform while one with kk much less than nn is badly defective.

This is a different problem from the one the rest of this subject has been about. A linear generator and the twister stretch a short seed into a long sequence that looks random; a cryptographic generator does the same with a guarantee that nobody can tell the difference. All of them need a seed that is genuinely unpredictable to begin with, and the seed has to come from the physical world, defects and all. Turning a defective physical source into a few truly fair bits — extraction — is the step before any of them runs, and it is the one that cannot be done by cleverness alone.

The essay on fair bits ended with the fact that for such sources no single function works. This essay is about what does: two independent sources, combined by a rule so simple that its success looks accidental — and is not.

Why one source is never enough

The obstruction is a counting argument, a pigeonhole principle with two boxes. Take any rule ff that turns an nn-bit string into one bit. One of its two outputs is produced by at least half of all strings — at least 2n−12^{n-1} of them. A source that is uniform on those strings has min-entropy at least n−1n - 1, almost as unpredictable as a string can be, and yet ff gives the same bit on every one of its outputs. So for every fixed rule there is a nearly perfect source that the rule turns into a constant.

The defect is not in any particular rule; it is that a single source, however unpredictable, can be arranged against the rule after the rule is fixed. The same thing is visible in the simplest rule of all, exclusive-or.

XOR of biased bits, and of copied bits. The share of ones in the XOR of k flips of a coin biased 0.8, for k = 1 to 12, alternating around one half and closing on it; beside it the XOR of k copies of a single flip, which jumps between 0.8 and 0 and never approaches one half.
Fig. 1 The share of ones in the XOR of k flips of a coin biased 0.8, for k = 1 to 12, alternating around one half and closing on it; beside it, the XOR of k copies of a single flip, which jumps between 0.8 and 0 and never approaches one half. XOR purifies independent bias and does nothing for dependence.

XOR of many independent biased bits is nearly fair — each further XOR multiplies the distance from one half by the same factor, 0.6 for this coin. But XOR of dependent bits can be anything: a source whose bits are copies of one flip has a lot of min-entropy per block if the flip is fair, and its XOR tells the copying and not the flip. A rule that relies on independence within a source fails as soon as the source is correlated.

The rule for two sources

Take two sources, independent of each other, each producing nn-bit strings xx and yy. Output

⟨x,y⟩=x1y1+x2y2+⋯+xnyn(mod2),\langle x, y \rangle = x_1 y_1 + x_2 y_2 + \cdots + x_n y_n \pmod 2,

the parity of the number of positions where both strings have a 1. Benny Chor and Oded Goldreich showed in 1988 that if the two sources’ min-entropies add up to more than nn, this bit is nearly unbiased, with a bias that shrinks exponentially in the excess. Nothing is assumed about either source beyond its min-entropy and the independence of the two.

The whole argument lives in one picture.

A rectangle of the parity table, nearly balanced. A 32 by 32 grid of +1 and −1 entries — the parity of the inner product of row and column — with a 15 by 14 rectangle of chosen rows and columns highlighted; its entries sum to 8.
Fig. 2 The 32 × 32 table of inner-product parities of 5-bit strings: +1 where x and y share an even number of 1s and −1 where odd. A random set of 15 rows and 14 columns is picked out — orange where +1, blue where −1. The chosen rectangle holds 210 entries and they nearly cancel: +1s minus −1s is 8, within Lindsey’s bound of 82. A bit made as the parity of x·y, with x from those rows and y from those columns, has bias 0.019.

Write the output as ±1\pm1 instead of 0/10/1, and lay all possible pairs (x,y)(x, y) in a table, 2n2^n rows by 2n2^n columns, entry (−1)⟨x,y⟩(-1)^{\langle x, y\rangle}. A source for xx that is uniform on a set AA of strings picks a row from AA; a source for yy uniform on BB picks a column from BB. The output’s bias is the imbalance of the rectangle A×BA \times B: the number of +1+1 entries minus the number of −1-1 entries, divided by twice its size. In the figure the rectangle of 210 entries has 109 of one sign and 101 of the other, so the output is fair to within two percent.

The rectangle that does not cancel

Not every rectangle is balanced, and the exceptions show exactly how much entropy the sources need.

A rectangle of the parity table that does not cancel. A 32 by 32 grid of +1 and −1 entries — the parity of the inner product of row and column — with a 4 by 8 rectangle of chosen rows and columns highlighted; its entries sum to 32.
Fig. 3 The same table with rows chosen as the 4 strings using only the low two bits and columns as the 8 strings using only the high three. Every row chosen is perpendicular to every column chosen, so the whole rectangle is +1 — 32 entries, meeting Lindsey’s bound exactly — and two sources uniform on these sets always output 0. Together they carry 5 bits, which is not more than 5.

If xx only ever uses the first half of the positions and yy only the second half, their inner product is always zero, and the output is constant. Each source can have min-entropy up to n/2n/2 this way — half of all possible unpredictability — and together they carry exactly nn bits, not more. So the condition “together more than nn” cannot be weakened: at exactly nn, arranged adversarially, the rule fails completely.

This is the two-source version of the one-source obstruction. A single source can be aligned against any fixed rule; two sources, each constrained only by min-entropy, can be aligned against each other, and the inner product is defeated precisely when their alignment is perfect. Min-entropy above nn in total makes perfect alignment impossible.

The block example is the only way to fail completely, but it is not the only way to fail partly. Sources uniform on two subspaces that are nearly perpendicular — whose inner products vanish on most pairs — give a rectangle that is mostly one sign, and the output is biased without being constant. Lindsey’s lemma, below, is the statement that no arrangement of sets does much better than the perpendicular subspaces at unbalancing the table: the extreme case is the linear one.

Lindsey’s lemma

The theorem behind the picture is a statement about the table alone.

How far a rectangle of the parity table can fail to cancel. A scatter of 599 random rectangles: imbalance against size on logarithmic axes, all under the line of Lindsey's bound, and the line y = x for a rectangle of one sign.
Fig. 4 599 random rectangles of the 64 × 64 parity table: the number of entries each holds against how far its +1s and −1s fail to cancel, on doubling axes. Every rectangle lies under Lindsey’s bound entries×64\sqrt{\text{entries} \times 64} (blue), and far under the dashed line of a rectangle all of one sign once it holds more than 64 entries.

Lindsey’s lemma: for any sets AA and BB of rows and columns of the N×NN \times N table, N=2nN = 2^n, the rectangle’s sum satisfies

∣∑a∈A, b∈B(−1)⟨a,b⟩∣≤∣A∣ ∣B∣ N.\left| \sum_{a \in A,\, b \in B} (-1)^{\langle a, b \rangle} \right| \le \sqrt{|A|\,|B|\,N}.

The proof is one application of the Cauchy–Schwarz inequality, using the fact that the rows of the table are orthogonal: any two distinct rows agree in exactly half their entries, which is the fact that makes the table a Hadamard matrix and its rows the codewords of a code with the largest possible distances. A rectangle’s sum is the inner product of a combination of rows with a combination of columns, and orthogonality stops the rows from reinforcing each other.

Divide by 2∣A∣∣B∣2|A||B| and the bias of the output is at most 12N/(∣A∣∣B∣)\tfrac12\sqrt{N/(|A||B|)}. A source of min-entropy k1k_1 can be taken to be uniform on a set of size 2k12^{k_1} — more general sources are mixtures of those, and a mixture cannot be more biased than its worst component — so the bias is at most 12⋅2(n−k1−k2)/2\tfrac12 \cdot 2^{(n - k_1 - k_2)/2}. When k1+k2k_1 + k_2 exceeds nn, that is less than one half, and every further bit halves it by a factor of 2\sqrt2.

The bias of the inner-product bit, as the sources gain entropy. Bias of the two-source inner-product extractor against the entropy k of each source, for 10-bit strings on a logarithmic axis: one half up to k = 5, then falling, always under the general bound.
Fig. 5 Two independent sources of 10-bit strings, each uniform on 2ᵏ strings, combined by the inner-product parity: the output’s bias for the worst sources built from blocks of coordinates (dots), against the bound ½·2^((n − 2k)/2) that holds for every pair (line). Up to k = 5 the sources can be made perpendicular and the output is constant; past half the length, each extra bit in each source halves the bias at least.

The dots are sources built from blocks of coordinates — xx using the first kk positions and yy the last kk — which overlap in 2k−n2k - n positions once kk passes n/2n/2, and then the inner product is a parity of that many independent fair bits’ products, with bias exactly 12⋅2−(2k−n)\tfrac12 \cdot 2^{-(2k - n)}. They sit below the general bound, which also covers every unstructured source, and they show that the bound’s threshold at n/2n/2 is real.

Defective sources, simulated

The theorem is about the worst case; the practical point is that it asks so little of the sources.

Three ways of making a bit from two defective sources. Horizontal bars for the share of 1s from three rules applied to a sticky source and a lumpy source: 69.4%, 63.6%, 48.3%.
Fig. 6 Two defective sources of 16-bit blocks: a sticky one, whose bits repeat the previous bit four times in five and start as 1 seven times in ten, and a lumpy one, whose blocks never have more than four 1s; 20,000 blocks from each, independently. One bit of the sticky source is 1 69.4% of the time; XORed with the lumpy source’s first bit, 63.6%; the parity of the whole blocks’ inner product, 48.3%.

The sticky source has strong correlations between neighbouring bits and a bias at the start; the lumpy source is sparse, most of its bits zero. Neither is anywhere near uniform, and simple rules inherit their defects: the sticky source’s first bit is 1 almost seven times in ten, and XORing it with the lumpy source’s first bit barely helps, because that bit is usually 0. The inner product of the whole blocks is within two percentage points of fair. It uses nothing about how either source is defective, only that the two are independent and that between them there is enough unpredictability.

The remaining 1.7 percentage points of bias are what the bound allows for these sources. Each 16-bit block of the sticky source has far less than 16 bits of min-entropy — its likeliest block, all ones, occurs about one time in forty, so it carries only about five and a half bits — and the lumpy source’s likeliest blocks, those with a single 1, each occur one time in sixty-four, which is six bits. Their sum is below the sixteen the theorem asks for, so no guarantee applies, and the rule still does well: the worst case is rare, and these sources are not arranged against each other.

Why independence is the whole assumption

Everything above leans on one assumption, that the two sources are independent, and it is worth seeing how completely the rule fails without it. If the second source simply copies the first, y=xy = x, then ⟨x,x⟩\langle x, x \rangle is the parity of the number of 1s in xx — a single fixed function of one source, and so defeated by a single source arranged against it, as the counting argument showed. A partial dependence gives a partial failure: the rectangle picture no longer applies, because the pair (x,y)(x, y) is no longer uniform on a product A×BA \times B but on some set that can be shaped to follow the table’s signs.

So independence is not a technical convenience. It is what turns the adversary’s single choice — a source aligned against the rule — into two choices that must be made separately, neither knowing the other. The table’s balance on rectangles is exactly the statement that two separate choices cannot coordinate to find a region of one sign. In practice that is also the assumption hardest to certify, because physical sources that look unrelated often share a hidden cause.

More than one bit

A single fair bit is rarely enough; a seed is hundreds of bits. The inner product generalises. Treat each nn-bit string as an element of the field with 2n2^n elements, multiply xx by yy there, and keep several bits of the product instead of one. Each output bit is an inner product of xx with a string that depends linearly on yy, and the same rectangle argument, applied to every combination of output bits at once, shows that the output is close to uniform on all its bits together, provided the sources carry enough more than nn bits between them. The price is that each extra output bit costs some of the excess entropy, so the number of fair bits extracted is limited by how far above nn the sources are. Two sources of 1,000 bits each with 600 bits of min-entropy carry 200 bits more than the length, and a multiplication in the field of 210002^{1000} elements can extract dozens of nearly fair bits from them — enough to seed any generator in this collection, with the error in each bit smaller than anything that could ever be measured.

Two sources and a colouring nobody can draw

The two-source problem has a twin in combinatorics that makes its difficulty vivid. A function f(x,y)f(x, y) of two nn-bit strings is a colouring of the edges of a complete bipartite graph with 2n2^n vertices on each side. A good two-source extractor for min-entropy kk says that every 2k×2k2^k \times 2^k rectangle — every complete bipartite subgraph of that size — contains edges of both colours, in nearly equal numbers. That is a bipartite Ramsey graph: a colouring with no large monochromatic rectangle.

The finite version of the question is the one six people at a party began: how large can a colouring be with no large one-coloured structure? Random colourings have this property for kk as small as about log⁡n\log n — Erdős’s counting argument — and nobody can write one down. The inner product is an explicit colouring that works for kk just above n/2n/2, and for decades that was the best any explicit construction could do. Jean Bourgain pushed the threshold slightly below one half in 2005. In 2016 Eshan Chattopadhyay and David Zuckerman constructed explicit two-source extractors for min-entropy polylogarithmic in nn, and with them explicit Ramsey graphs far better than any known before — the same problem, solved from the randomness side, with tools from pseudorandomness that no graph theorist had used.

What the figures establish

Every rectangle sum is exact. The tables have 32 or 64 rows, the sums are whole numbers computed entry by entry, and every one is checked against Lindsey’s bound. The bound itself is a theorem; the 599 random rectangles are a check that it is never violated, not a proof that it never is.

Sources uniform on sets stand in for all sources. The figures use sources that are uniform on a set of strings. A general source of min-entropy kk is a mixture of such flat sources, and a mixture’s bias is at most the largest bias among its components, so the flat case is the worst case — a standard reduction the figures assume rather than show.

The simulation measures a share, not a bias bound. Twenty thousand blocks give a share of 1s accurate to about a third of a percentage point, so the 48.3% is distinguishable from 50% and the difference is real. It is a property of these two sources, not a guarantee about others.

The simulated sources are two examples. The sticky and lumpy sources were chosen to be defective in ways that defeat simple rules, and the inner product handles both. That is illustration; the theorem is what guarantees it for every pair with enough min-entropy.

Still open: how little entropy two sources need

Random functions are excellent two-source extractors down to min-entropy about log⁡n\log n. Explicit ones — rules anyone can write down and compute quickly — now work down to min-entropy polylogarithmic in nn, after the breakthrough of 2016 and a series of improvements since, but the output they give has only constant error, not the exponentially small error the inner product achieves in its range, and they extract only one or a few bits rather than many. An explicit two-source extractor matching what random functions achieve — logarithmic min-entropy, tiny error, many output bits — is not known, and constructing one would, by the Ramsey connection, also give explicit Ramsey graphs as good as random ones, a problem open since Erdős posed it in 1947.

There is also the question of independence, which every theorem here assumes and no physical system guarantees. Two noise sources on one chip share a power supply and a temperature. Extractors for sources that are only approximately independent, or for many sources of which some unknown few are adversarial, are an active area, and the models themselves — what kind of weak independence real hardware provides — are still being argued.

Randomness from two directions

A single weak source can always be defeated by a rule fixed in advance, because the source can be chosen afterwards. Two independent weak sources cannot both be aligned against the inner product unless they have too little unpredictability between them, and Lindsey’s lemma says exactly how much is too little: half the length each, nn in all. Above that, the parity of the bitwise product is nearly fair, and the table of those parities — a pattern of pluses and minuses that is balanced on every large rectangle — is what does it. The same table is a colouring with no large one-coloured rectangle, which is why the best random-number extractors and the best explicit Ramsey graphs have turned out to be the same objects, found from two different sides.

It is also the end of the line this subject has been following. Linear generators were fast and predictable; the twister was fast, long-periodic and still linear; cryptographic generators bought unpredictability with an assumption about hard problems. All of them began from a seed. Extraction is where the seed comes from, and it is the one step at which no generator, however clever, can substitute for a physical source — only combine two of them in a way that no defect in either can defeat.