Quantumania 17 - More Function, More Mystery
We ended up being slightly less impressed than we might have been about the Hadamard gate’s ability to narrow down the identity of a mystery function from four possibilities to two with a single measurement, given that we could make the same amount of progress by invoking the function once directly. If you give the function as the input, it can only output
or
, and that divides the four possible functions into two pairs.
Even so, there’s still something neat about the idea that we’ve “rotated a function” so that we can, with a single invocation, narrow it down to being either a constant that ignores its input or being dependent on its input, something that seems to absolutely require two invocations. I used the term balanced for the latter kind, in anticipation of the upgrade we’re going to embark on today.
That upgrade is going to show off our ability to casually string together many qubits into a register of qubits. I think it’s quite cool that we’re using terminology from classical computing. Registers in this context, as in mechanisms for temporarily storing numbers, have existed for as long as mechanical calculators (hundreds of years.) A long time ago there was something called a cash register (ask your grandma.)
We can build states for compound systems of three qubits by using the tensor product to stitch their spaces together:
Rather than writing out absurdly long kets as we increase the number of qubits to a large number , you’ll sometimes see this notation:
We’re just raising to the power of
(but using the tensor product.) So that’s a really quick way to say I have a system of
qubits. Now, with such a system I can apply a unitary operation like Hadamard (symbolised here by
) to individual qubits:
If I have two qubits in and put each through Hadamard, and multiply out:
Now for the first time (it’s a big day) we’re actually going to interpret the bit patterns in qubit tensor products as actual binary numbers. What happens if we have a system of qubits, in which
would signify
, but ours are initially all zero, and put each them through Hadamard and multiply out?
It’s an equal superposition of every number in the range to
. Why is the normalisation factor
? Because this is Pythagoras in
dimensions: all those ingredients are unit vectors, the square of the length of each is
, there are
of them, so the square of the “hypotenuse” of this ultra-hyper-bonkers-triangle is
, thus its length is
, so that’s what we need to divide by to shrink it down to
.
In general, for qubits treated in this way the result is the state vector:
Here can be thought of the value between
and
but represented in binary and used as the label for one of the ingredients.
Now we have what we need to upgrade our mystery function scenario so that function takes an -bit number as its input and produces a single bit as output. But to make this work we’re going to have to introduce a restriction on the mystery function that will seem a little contrived: it either ignores the input number entirely (it’s a constant), or it is balanced, meaning that for exactly half the range of possible values it produces output
and for the other half
. Supposing it is balanced, we have no idea which input values produce
. To be sure it’s not constant, you’d have to test the function on just over half the possible input values,
, potentially a huge number.
When we had one-bit input, the mystery function was wrapped in a unitary operator, by passing the first qubit straight through unchanged (at least, according to the definition) and using the result of the function to affect the second qubit’s output.
Now we’re going to do the same thing except is our qubit register, carrying some
-bit number.
is just an extra qubit that will carry the encoded output, and at input it is
, so the complete input state is:
When acts on this, being linear, it distributes over all the summed terms. Each term is in effect acted on like this:
This means that if , it adds nothing and this particular term is unchanged:
Whereas if it in effect swaps the labels of the output bit ingredients:
A nifty way to capture this optional negative factor effect, given that and
, is:
And (like we saw with the single qubit version of this problem), our interest in the extra qubit ends at this point because it is unaffected. We can focus on the input
-qubit register, which now looks like this:
It’s starting to look a bit garbled, but it’s just saying that the state is the sum of different vector terms that have been flipped to negative if
for term
. For example, if
then there are
terms represented by
in the sum, such as
,
,
, and so on up to
. If
, then the
term will be negative in the sum. And then all will be scaled down by
to make it unitary.
As if it weren’t garbled enough, the last step is (as before) to apply Hadamard one more time. As we saw above, when we apply it to an all-zeros state , the result is an expansion containing a term for every bit pattern. Well, now we’re applying it to the sum of terms for every bit pattern. If you’re into coding, this is what you might call a nested loop. Again, supposing
, we have a sum of
terms, some positive, some negative, and each of those will now expand out into
terms, some positive, some negative, so we’ll have
terms. But these can then be grouped together because there will be
repetitions of
, also
of
, and so on.
Actually multiplying them all out even for would be rather tedious. It’s more instructive to think through how each term ends up with its effective final sign. The way Hadamard works on the basis vectors is that it only introduces a negative factor when the input is
, and it only places that negative factor on the output
term. So an all-zeros
state put through Hadamard produces only positive terms.
With the other terms, those with at least one , something remarkable happens: when we group the remaining
multiplied-out terms into their
types, among the
copies of (say)
,
are positive and
are negative, so they cancel out. This happens for every basis vector apart from all-zeros. This shouldn’t be that surprising though, as we know that Hadamard is self-inverting:
. So that can only mean:
So if the mystery function is constant, and thus applies the same sign-flip to every term, there are only two possibilities. If , there’s no overall sign-flip:
Whereas if , the sign is flipped:
Either way, this state will with certainty produce a on every qubit. No other pattern has a non-zero amplitude.
The only other form the mystery function is allowed to take is to be balanced, and I said that was going to seem contrived. What it means for the state is that exactly half the terms contributing to it will be positive and half will be negative, and this will be entirely the function’s doing (Hadamard leaves all-zeros states alone.) The first (inner) Hadamard makes a term for every possible value, all of them positive, the mystery function flips the sign of half of them, and the final (outer) Hadamard creates from each a
contribution that preserves the sign of the term it came from. This means that all the
contributions cancel out, leaving a zero probability of measuring the all-zeros pattern.
The end result is that a measurement of will only happen if it was absolutely certain to happen, because the mystery function is constant. If it is balanced,
is impossible, so something else will be found (at least one qubit will be in the
state.)
Because of the peculiar contrivance of the setup, this is not at all useful. But it demonstrates how a quantum algorithm can produce a deterministic result, and seemingly explore a potentially huge problem space in a simple and practically instantaneous process. With qubits, the number of basis vectors is
, about the number of atoms in the visible universe, and yet we seem to be able to probe the behaviour of a function on all of them, all at once.
Not yet regretting the time you've spent here?
Keep reading: