11 min read
Constant and Balanced Functions
What "constant" and "balanced" really mean, how many balanced functions exist, and why a classical algorithm needs more than half the domain in the worst case.
Suggested before this lesson
The last lesson built oracles for specific functions. This one is about the two categories Deutsch-Jozsa's whole premise rests on, made precise, before you see the algorithm that tells them apart in a single query.
For :
Notice these two categories don't cover every possible . Take (AND): it outputs 1 only for input , one out of four inputs, 25%, neither all-same nor half-and-half. AND is neither constant nor balanced. Deutsch-Jozsa's algorithm only works because it's handed a promise that rules functions like this out ahead of time: "trust me, this is one or the other." Without that promise, a single query couldn't distinguish the cases; the promise is doing real work, not just narrating flavor text.
Out of all possible boolean functions on bits (each of the inputs independently maps to 0 or 1), only 2 are constant (all-0 or all-1), no matter how large gets. Balanced functions are far more common: there are of them, choosing which half of the inputs get mapped to 1. For that's ; for it's already . Almost every function on more than a handful of bits is neither, but within the constant-or-balanced promise, balanced functions vastly outnumber constant ones.
Suppose you're checking by querying inputs one at a time and comparing outputs, with no quantum tricks. Query inputs and every single one comes back . Are you done? No: an adversary choosing 's truth table to make your life hard can still make the unqueried half all s, which is a perfectly valid balanced function consistent with everything you've seen so far, or leave them all too, giving a constant function equally consistent with what you've seen. Only the query breaks the tie: however it comes back, you can now rule one case out for certain. So the classical worst case is queries, more than half the entire domain, and there's no cleverer classical strategy that beats this bound: it's a hard information-theoretic floor, not a limitation of any one algorithm.
Deutsch-Jozsa (next lesson) answers this with one query, period, regardless of . That gap, vs. , only grows as grows, which is why this is presented as a "speedup" rather than just "a faster trick."
The last lesson's XOR oracle used both input qubits. Balanced functions don't have to use every input: (ignoring entirely) is still balanced, exactly half of the 8 inputs give 0. The oracle just skips the CX for the input it doesn't depend on:
Circuit
cx
Step through the circuit: after gate 2 of 2
3 / 3
Exact State
| Basis state | Re | Im | Probability |
|---|---|---|---|
| 1.000 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 | ||
| 0 | 0 |
Live preview of the circuit detected in your code
Python
Python