5.1.3 Sign oracles
Since the bit oracle is a quantum operation, we can not only apply it to basis states but also to general quantum states. Why would we like to do such a thing? Well, if we only ever ask the oracle ‘classical’ questions then there is little hope of achieving a quantum speedup! Given this motivation, let us investigate how the bit oracle for an arbitrary function acts when the last register is set to . First, notice the following interesting fact:
That is, if we invert a qubit in state then we pick up a sign. We can similarly compute how the bit oracle acts on a state of the form . By linearity, Eq. 5.5 gives us
In other words, we end up returning the last qubit back in the state , but we pick up an overall minus sign when . Effectively, we have implemented the following quantum operation on the first qubits:
for all bitstrings . We call the sign oracle for .
Interestingly, for a function , the sign oracle operates on qubits since it stores the output in the amplitude. This is different from the bit oracle , which stores the output in an additional qubit and therefore operates on qubits.
At first glance, the sign oracle does not seem to do much since it only introduces an overall sign when acting on a basis state, which we know from 2.7 cannot be observed. However, when we apply it to a superposition then the sign oracle can introduce relative signs, so we can get an interesting result. For example, for qubits, if we apply a sign oracle to a general two-qubit state
then we obtain
As it turns out, the sign oracle is indeed useful and often much easier to apply in quantum algorithms than the bit oracle , so from now on we will not use the bit oracle anymore.
Exercise 5.2 (Sign oracle for a one-bit function).
Recall from 5.1 that there are four functions with a single input and output bit. Can you implement the sign oracle for each of them in Quirky?
Solution.
There are four functions: the ‘identity’ function , the NOT function, the all-zeros function, and the all-ones function.- •
- •
- •
-
•
For the all-ones function with :
which we can achieve by combining the first two oracles in sequence:
Indeed, the first oracle adds a minus sign if , while the second oracle adds a minus sign if , so we get a minus sign in either case:
In the second to last step, we used linearity to move the minus sign to the front.
Homework 5.1 (Determine the function from its sign oracle).
Consider the following two-qubit circuit (as usual, the bottom wire is the first qubit):
What function is it the sign oracle for?
Hint: Use that , which follows from 4.5.
Hack.
The circuit corresponds to the following two-qubit operation:
How does this act on a two-qubit basis state?
If , the controlled-NOT operation does not invert the second qubit, so:
since . But if , then the controlled-NOT operation inverts the second qubit, so:
(in the second to last step we used the hint). Thus:
and now we recognize that implements precisely the sign oracle for the function.
Let us briefly summarize what we have achieved so far: Using bit oracles, we can ask a quantum computer to evaluate a function in exactly the same way as we would ask an ordinary computer that operates reversibly (compare Eqs. 5.4 and 5.5). This is important, because it means that we are not comparing apples and oranges when we ask how many questions to the bit oracle are required to learn something about versus how many times one would have to evaluate on an ordinary computer to learn the same thing. And since we just showed that the sign oracle can always be implemented using the bit oracle , it makes no difference if we ask questions to the sign oracle instead.