How Much Independence Is Enough?
Imagine assigning students to tables by drawing cards. Perfect randomness would require a fresh, unrelated card for every student. Often the task needs much less: if the only concern is whether any particular pair meets, it is enough that every pair of assignments behaves independently. Questions about groups of four require four-wise independence, but still not a completely random assignment of everyone.
Hashing in streaming algorithms works the same way. A truly random function from a universe $U$ to $m$ buckets needs enough information to describe an arbitrary output for every key—roughly $|U|\log_2m$ bits. That is impossible when $U$ is enormous. A hash family is a compact set $\mathcal H$ of functions. We sample a short seed to choose $h\in\mathcal H$, then compute $h(x)$ deterministically. The proof must establish that this smaller family supplies exactly the joint randomness the algorithm uses.
This deep dive builds on the prerequisite treatment of streaming, hashing, and randomness. That chapter explains collision probability and randomized sketches; the unresolved engineering question is how to implement their “random hash” assumptions without storing a random table over the whole universe.
For a tiny warning, choose independent fair bits $A$ and $B$, and define $C=A\oplus B$. Each bit is fair and every pair among $A,B,C$ is independent. Yet the triple is not independent because $A\oplus B\oplus C=0$ always. Thus pairwise independence reproduces every one- and two-variable calculation, but it does not justify a proof step involving three variables jointly.
Formally, $\mathcal H$ is $k$-wise independent from $U$ to range $R$ when, for any distinct $x_1,\ldots,x_k$ and any $y_1,\ldots,y_k\in R$,
$$ \Pr_{h\leftarrow\mathcal H}[h(x_1)=y_1,\ldots,h(x_k)=y_k]=|R|^{-k}. $$
A family is universal when every distinct pair collides with probability at most $1/|R|$. Pairwise independence implies universality and uniform marginals, but universality alone does not imply pairwise-independent output values. The seed length is the number of random bits required to identify a family member. In real systems it affects memory, reproducibility, serialization, merge compatibility, and exposure to adversarially selected inputs.
Limited independence is a proof resource: choose the smallest order that validates every joint expectation or moment used by the analysis. “Universal,” “uniform,” and “pairwise independent” are different guarantees, and a fast hash function does not acquire one merely because its outputs look random in a histogram.
| Concept | Intuitive meaning | Exact example | Non-example or boundary | Main assumption | Question answered |
|---|---|---|---|---|---|
| Universal family | Distinct keys rarely collide | $\Pr[h(x)=h(y)]\le1/m$ | Uniform outputs with always-correlated pairs | Probability is over sampled family member | Is pair collision controlled? |
| Pairwise independence | Any two distinct outputs are independent and uniform | $h_{a,b}(x)=ax+b$ over $\mathbb F_p$ | $A,B,A\oplus B$ are not three-wise | Distinct field inputs; uniform coefficients | Are all two-variable calculations valid? |
| Four-wise independence | Every four distinct outputs match independent uniforms | Cubic polynomial over $\mathbb F_p$ | Affine family is only pairwise | Four distinct inputs; four fresh coefficients | Is a fourth-moment calculation valid? |
| $k$-wise independence | Every subset of at most $k$ outputs is fully independent | Degree-$(k-1)$ polynomial over $\mathbb F_p$ | Claim about $k+1$ outputs | Field arithmetic and uniform seed | Which degree-$k$ expectations are preserved? |
| Polynomial hashing | Coefficients are seed; key is evaluation point | $a_0+a_1x+\cdots+a_{k-1}x^{k-1}\bmod p$ | Naive machine overflow with undocumented ring semantics | Work over a field, not arbitrary modulus | How can $k$-wise independence be constructed? |
| Tabulation hashing | Split key into characters and XOR table lookups | Simple tabulation with random character tables | Cryptographic or arbitrary $k$-wise guarantee | Truly random initialized tables; fixed key representation | When is a fast practical family enough? |
| Seed length | Random state naming one function | $k\lceil\log_2p\rceil$ bits before encoding overhead | Counting a PRNG state as information-theoretic independence | Uniform sampling and stable serialization | What randomness and storage does the family cost? |
How Much Independence Is Enough?
Let $A,B$ be independent fair bits and $C=A\oplus B$. Enumerate the four equally likely rows:
| $A$ | $B$ | $C$ |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
- Each column contains two zeros and two ones, so every marginal is fair.
- For $(A,C)$, each pair $00,01,10,11$ occurs once; repeat for $(B,C)$. All pairs are independent.
- The triple $001$ never occurs, whereas three fully independent fair bits would assign it probability $1/8$.
- Checkpoint: $A\oplus B\oplus C=0$ in every row, exposing a global constraint invisible to pair tests.
Expected result: pairwise independence holds, three-wise independence fails. Reflection: would a variance proof using only products of two indicators notice the constraint, and would a third-moment proof be allowed to ignore it?
Building Pairwise and k-Wise Hash Families
Let $p$ be prime and identify keys and outputs with the finite field $\mathbb F_p$. Sample $a,b$ independently and uniformly from $\mathbb F_p$, and define
$$ h_{a,b}(x)=ax+b\pmod p. $$
For distinct $x,y$ and requested outputs $u,v$, the constraints $ax+b=u$ and $ay+b=v$ have exactly one solution. Subtracting gives $a(x-y)=u-v$. Since $x-y$ is nonzero and every nonzero field element has an inverse,
$$ a=(u-v)(x-y)^{-1},\qquad b=u-ax. $$
There are $p^2$ equally likely coefficient pairs and exactly one produces $(u,v)$, so the joint probability is $1/p^2$. This proves pairwise independence, not merely the collision statement. Summing over the $p$ choices with $u=v$ gives collision probability $1/p$.
The same linear-algebra idea generalizes. Sample coefficients $a_0,\ldots,a_{k-1}$ uniformly from $\mathbb F_p$ and define
$$ h_{\mathbf a}(x)=\sum_{j=0}^{k-1}a_jx^j\pmod p. $$
For $k$ distinct inputs $x_1,\ldots,x_k$ and target outputs $y_1,\ldots,y_k$, the coefficient vector solves a Vandermonde system. Its determinant is $\prod_{i\lt j}(x_j-x_i)$, which is nonzero because inputs are distinct. Therefore there is exactly one coefficient vector for every output vector. Of the $p^k$ seeds, one realizes the requested vector, proving probability $p^{-k}$ and hence $k$-wise independence.
The seed contains $k$ field elements, or $k\lceil\log_2p\rceil$ stored bits with possible rejection or encoding overhead for uniform sampling. Horner's rule evaluates the polynomial in $k-1$ multiplications and $k-1$ additions. If outputs need $m\lt p$ buckets, applying ordinary remainder modulo $m$ can introduce bias unless $m$ divides the source range. Rejection, multiply-high range reduction with a proven distribution, or a construction tailored to the range must be analyzed explicitly.
The field condition is essential. Modulo a composite number, a nonzero difference need not be invertible. Over $\mathbb Z_8$, $x-y=2$ has no inverse, so the uniqueness proof collapses. Another boundary is domain encoding: two application keys that map to the same field element are not distinct inputs to the theorem.
flowchart TD
A[Choose prime field Fp] --> B[Encode distinct keys as field elements]
B --> C[Sample k uniform coefficients]
C --> D[Evaluate degree k minus 1 polynomial]
D --> E[Fix k distinct inputs and target outputs]
E --> F[Vandermonde determinant is nonzero]
F --> G[Exactly one seed realizes outputs]
G --> H[Joint probability p to minus k]
H --> I[k-wise independent family]
B --> X{Distinct encoding and field arithmetic?}
X -->|no| Y[Proof invalid: collisions or noninvertible differences]
X -->|yes| C
classDef navy fill:#17365D,color:#fff,stroke:#17365D;
classDef teal fill:#147D84,color:#fff,stroke:#0D565B;
classDef purple fill:#6C3BAA,color:#fff,stroke:#472675;
classDef crimson fill:#C6284D,color:#fff,stroke:#861B35;
class A,B,C navy;
class D,E,F purple;
class G,H,I teal;
class X,Y crimson;
A uniformly seeded degree-$(k-1)$ polynomial over $\mathbb F_p$ is $k$-wise independent because $k$ distinct evaluations form an invertible Vandermonde system. The guarantee depends on true field arithmetic, distinct encodings, uniform coefficients, and an analyzed range reduction; it says nothing about joint behavior of more than $k$ keys.
Moments That Survive Limited Randomness
Why does the independence order map to a moment? Expand a statistic as a polynomial in random variables. Its expectation is a sum of expectations of monomials. If every monomial involves at most $k$ distinct hash outputs, $k$-wise independence makes its expectation identical to the fully independent case. Repeated powers do not increase the number of distinct variables, but a product containing $k+1$ distinct outputs exceeds the guarantee.
Let $I_i$ indicate that key $x_i$ lands in bucket zero, and let $S=\sum_{i=1}^n I_i$. Under a pairwise-independent uniform hash into $m$ buckets, $\mathbb E[I_i]=1/m$ and $\mathbb E[I_iI_j]=1/m^2$ for distinct keys. Therefore
$$ \mathbb E[S]=\frac nm,\qquad \operatorname{Var}(S)=\sum_i\operatorname{Var}(I_i)=n\frac1m\left(1-\frac1m\right). $$
All covariance terms vanish. This matches full independence exactly, so Chebyshev-based occupancy analysis needs only pairwise independence. But $\mathbb E[(S-\mathbb E S)^4]$ expands into products involving up to four distinct indicators; reproducing the fully independent fourth moment generally needs four-wise independence. Exponential Chernoff tails usually require substantially more independence or a special limited-independence theorem with explicit parameters.
The parity example $A,B,C=A\oplus B$ demonstrates the boundary. The sum $T=A+B+C$ takes only values $0$ and $2$, with probabilities $1/4$ and $3/4$. Three fully independent bits yield $0,1,2,3$ with probabilities $1/8,3/8,3/8,1/8$. Both models have mean $3/2$ and variance $3/4$, but their third and higher distributional behavior differs. Pairwise tests cannot certify a tail statement that depends on the missing triple independence.
Moments That Survive Limited Randomness
Use the affine family $h_{a,b}(x)=ax+b\pmod5$ with $(a,b)$ uniform in $\mathbb F_5^2$. Track keys $x=1,2,3$ and let $I_x$ indicate $h(x)=0$.
- There are $25$ seeds. For a fixed key, exactly five seeds produce zero, so $\Pr[I_x=1]=1/5$.
- For two distinct keys, exactly one seed maps both to zero: $a=b=0$. Hence $\mathbb E[I_xI_y]=1/25=\mathbb E[I_x]\mathbb E[I_y]$.
- With $S=I_1+I_2+I_3$, $\mathbb E[S]=3/5$ and $\operatorname{Var}(S)=3(1/5)(4/5)=12/25$.
- Exact enumeration of all seeds confirms these values. But all three keys map to zero for the same single seed, so $\Pr[I_1=I_2=I_3=1]=1/25$, not the fully independent value $1/125$.
- Perturbed case: replace the affine family by quadratic polynomials $ax^2+bx+c\pmod5$. With $125$ seeds, three distinct outputs are independent and the all-zero event has probability $1/125$.
Invariant: degree-two calculations survive pairwise independence; the three-variable event does not. The supplied verifier exhaustively checks both families.
| Family or method | Independence guarantee | Seed/state cost | Evaluation cost | Strength | Failure mode | Prefer when |
|---|---|---|---|---|---|---|
| Affine polynomial over $\mathbb F_p$ | Pairwise | $2\lceil\log_2p\rceil$ bits | One multiply and add | Exact, simple collision and variance proofs | Composite modulus, biased coefficients, duplicate encoding | Collision, expectation, and variance arguments |
| Degree-$(k-1)$ polynomial over $\mathbb F_p$ | $k$-wise | $k\lceil\log_2p\rceil$ bits | $O(k)$ field operations | Exact order selected from proof | Cost grows with $k$; no $(k+1)$-wise promise | Bounded-order moment proofs |
| Simple tabulation | Three-wise, plus stronger problem-specific properties | Random tables per key character | Few table reads and XORs | Very fast on word keys | Not four-wise; table initialization and cache footprint | Proven compatible algorithms needing speed |
| Multiply-shift style families | Often universal or pairwise depending on construction | One or a few machine words | Constant-time word operations | Excellent practical throughput | Guarantee changes with truncation and variant | Word-RAM proofs matching the exact construction |
| Cryptographic keyed hash | Pseudorandom, computational assumption | Key plus implementation state | Higher constant cost | Resists chosen-input prediction | Not information-theoretic $k$-wise independence | Adversarial public services and security boundaries |
| Fully random function idealization | All outputs independent | $\lvert U\rvert\log_2\lvert R\rvert$ bits conceptually | Table lookup after impossible initialization | Simplest theoretical model | Infeasible over large universes | Reference analysis, not implementation |
Small Seeds in Large Sketches
In a teaching example, hash $n$ distinct balls into $m$ bins and study one bin's load. Pairwise independence supplies the exact mean and variance needed for Chebyshev's inequality. Moving to a fourth-moment tail changes the proof polynomial and therefore the required family: this is a clean demonstration that the algorithm name does not determine independence—the analysis does.
At professional scale, consider a Count Sketch service with $d$ rows and $w$ counters per row. A typical proof uses a bucket hash and random sign hash in each row, then controls a second moment before taking a median across rows. The bucket and sign families, their independence orders, and whether row seeds are independent must match that proof. Seeds must be serialized with sketch state so distributed workers evaluate identical functions before merging; changing a seed changes the coordinate system and makes direct counter-wise merging invalid.
For a public endpoint, an adversary may observe outputs and choose later keys. Information-theoretic pairwise independence describes a seed selected independently of a fixed key set; it does not automatically protect a reused, exposed seed against adaptive collision finding. If denial-of-service resistance is required, a keyed cryptographic hash or periodic secret rotation may be preferable even when it is slower. Likewise, using a noncryptographic PRNG to expand a short seed changes the claim from exact $k$-wise independence to a computational or empirical assumption unless the generated family has a proof.
Evidence that invalidates a choice includes failed exhaustive tests on a small field, biased coefficient sampling, unexpectedly correlated row errors, seed reuse where the proof needs separation, cross-language arithmetic disagreement, overflow that no longer implements the stated field, range-reduction bias, or an adaptive attack that raises collision rates.
flowchart TD
A[Expand the sketch proof] --> B[List every joint hash product]
B --> C[Find maximum distinct-variable degree k]
C --> D[Select family with proved order at least k]
D --> E[Specify field domain range and seed format]
E --> F[Test exhaustive small cases and vectors]
F --> G{Inputs adaptive or seed exposed?}
G -->|yes| H[Add keyed cryptographic protection or revise model]
G -->|no| I[Benchmark cost and deploy]
H --> I
I --> J[Monitor bias correlation and merge compatibility]
J --> K{Evidence matches assumptions?}
K -->|yes| J
K -->|no| L[Reject rotate or upgrade family]
classDef navy fill:#17365D,color:#fff,stroke:#17365D;
classDef teal fill:#147D84,color:#fff,stroke:#0D565B;
classDef purple fill:#6C3BAA,color:#fff,stroke:#472675;
classDef crimson fill:#C6284D,color:#fff,stroke:#861B35;
class A,B,C navy;
class D,E,F purple;
class I,J teal;
class G,H,K,L crimson;
Small Seeds in Large Sketches: Limited-Independence Hash Families
Scenario. A distributed frequency sketch has $d=7$ rows, processes 64-bit item IDs, and is merged across 200 workers. Its proof uses pairwise-independent bucket hashes, pairwise-independent sign hashes, and independent rows. Each row has $w=2^{16}$ counters. The service also accepts customer-controlled keys.
- Proof inventory: record the exact expectation and variance steps. Confirm that no fourth-moment or Chernoff step is hidden behind the published SLO. If such a step exists, pairwise independence is insufficient.
- Construction: choose a documented field or word-RAM family whose output reduction to $2^{16}$ is proven. Assign separate domain-separated seeds to bucket and sign roles and independent seeds across seven rows.
- State contract: serialize algorithm version, family identifier, modulus or word semantics, key encoding, range-reduction version, and all seeds. A merge proceeds only when these fields match.
- Validation: exhaustively enumerate a small-field implementation; run cross-language golden vectors; apply chi-square only as a bug detector, not as proof; compare row-error correlations; test maximum keys, leading zeros, duplicates, and malformed encodings.
- Adversarial protocol: reveal neither production secret nor raw diagnostic seed. Replay chosen-key attacks. Compare the selected exact family with a keyed cryptographic front-end when collision denial of service is in scope.
- Expected observations: correct small cases have exact pair distributions; independent rows show low residual correlation; deliberate seed reuse raises cross-row correlation; mismatched serialized seeds make merge validation fail.
Selection decision: use the pairwise family only if the complete fixed-input proof stops at second moments and the external threat is separately controlled. Upgrade the independence order when the proof demands it, and add keyed cryptographic hashing when adaptive collision resistance—not merely sketch accuracy—is required.
Select Independence from the Proof
The reliable workflow runs backward from the theorem. Expand the estimator and its failure proof until every expectation is expressed as monomials in hash-derived variables. Count distinct inputs in the largest monomial, not merely the written exponent. Then select and implement a family with at least that independence order, including domain encoding and range reduction in the claim.
This connects backward to basic hash collisions and randomized streaming models. It connects forward to Count-Min, Count Sketch, AMS moments, sparse recovery, pseudorandom generators, and adversarially robust streaming. In each topic, replacing “assume a random hash” with a named family, seed format, and verified proof obligation turns an idealized algorithm into an auditable system.
Practice: Select Independence from the Proof
Starter setting: $n=20$ distinct keys, $m=5$ buckets, indicators $I_i=1$ when key $i$ lands in bucket zero, and $S=\sum_iI_i$. Available families are affine, cubic-polynomial, simple tabulation, and keyed cryptographic hashing.
Tier 1 — Vocabulary and hand calculation
- Define universality, pairwise independence, and four-wise independence without using one as a synonym for another.
- Under pairwise independence, calculate $\mathbb E[S]=4$ and $\operatorname{Var}(S)=20(1/5)(4/5)=3.2$.
- Use Chebyshev to bound $\Pr[|S-4|\ge4]$ by $3.2/16=0.2$.
Expected artifact: a one-page derivation that labels every use of uniformity and pairwise independence. Completion criterion: covariance terms are expanded before being set to zero.
Tier 2 — Construction proof
For $p=23$, prove that $h_{a,b}(x)=ax+b\pmod{23}$ is pairwise independent. Solve explicitly for $(a,b)$ using distinct inputs $x=4,y=9$ and targets $u=7,v=3$. Check your solution by substitution.
Hint: invert $x-y=-5\equiv18\pmod{23}$. Debugging prompt: if multiple coefficient pairs appear, verify the modular inverse and field modulus.
Tier 3 — Moment audit
Expand $S^2$ and $S^4$. Mark the maximum number of distinct indicators in each monomial. Select affine hashing for the variance calculation and a four-wise family for matching the full-independent fourth moment. Explain why repeated powers such as $I_i^4=I_i$ do not themselves require four distinct variables.
Expected artifact: color-coded monomials grouped by distinct-variable count. Completion criterion: the chosen order covers every term, including four-distinct-index products.
Tier 4 — Verification and failure injection
Adapt the Python verifier to $p=7$. Test all pairs for affine hashing and all quadruples for cubic hashing. Then inject three defects: duplicate key encoding, coefficient $a$ fixed at zero, and arithmetic modulo $8$. Record the first invariant each defect breaks.
Edge cases: zero coefficients are valid when sampled uniformly; repeated application keys are not distinct theorem inputs; output reduction can be biased; machine overflow is valid only when the construction proves the corresponding ring semantics.
Tier 5 — Professional selection
Choose a family for: a fixed offline variance estimate; a fourth-moment sketch proof; and a public adaptive API. Include seed length, throughput, serialization, merge checks, and threat model. State measurable invalidation evidence for every choice.
Stretch goal: compare the exact seed cost $k\lceil\log_2p\rceil$ with a PRNG-expanded seed. Identify which guarantee becomes computational rather than information-theoretic.
Rubric (10 points): definitions 2; construction proof 2; moment-to-order mapping 2; executable verification 2; operational and adversarial judgment 2. Mastery requires at least 8 points and no unsupported claim that statistical testing proves independence.
Reflection: is your selected family justified by the algorithm's name, or by the highest-order joint term actually present in its proof?
Decision checklist: expand the proof, count distinct hash variables per monomial, choose a proved family of sufficient order, specify field/domain/range semantics, budget and serialize seeds, and test merge plus adversarial boundaries. Never infer $k$-wise independence from attractive histograms; the next step is applying these exact contracts to sketch-specific estimators and robustness models.