Deutsch's algorithm
Deutsch's algorithm solves the parity problem for the special case that In the context of quantum computing this problem is sometimes referred to as Deutsch's problem, and we'll follow that nomenclature in this lesson.
To be precise, the input is represented by a function from one bit to one bit. There are four such functions:
The first and last of these functions are constant and the middle two are balanced, meaning that the two possible output values for the function occur the same number of times as we range over the inputs. Deutsch's problem is to determine which of these two categories the input function belongs to: constant or balanced.
Deutsch's problem
Input: a function
Output: if is constant, if is balanced
If we view the input function in Deutsch's problem as representing random access to a string, we're thinking about a two-bit string:
When viewed in this way, Deutsch's problem is to compute the parity (or, equivalently, the exclusive-OR) of the two bits.
Every classical query algorithm that correctly solves this problem must query both bits: and If we learn that for instance, the answer could still be or depending on whether or respectively. Every other case is similar; knowing just one of two bits doesn't provide any information at all about their parity. So, the Boolean circuit described in the previous section is the best we can do in terms of the number of queries required to solve this problem.
Quantum circuit description
Deutsch's algorithm solves Deutsch's problem using a single query, therefore providing a quantifiable advantage of quantum over classical computations. This may be a modest advantage — one query as opposed to two — but we have to start somewhere. Scientific advances sometimes have seemingly humble origins.
Here is a quantum circuit that describes Deutsch's algorithm:
Analysis
To analyze Deutsch's algorithm, we will trace through the action of the circuit above and identify the states of the qubits at the times suggested by this figure:
The initial state is and the two Hadamard operations on the left-hand side of the circuit transform this state to
(As always, we're following Qiskit's qubit ordering convention, which puts the top qubit to the right and the bottom qubit to the left.)
Next, the gate is performed. According to the definition of the gate, the value of the function for the classical state of the top/rightmost qubit is XORed onto the bottom/leftmost qubit, which transforms into the state
We can simplify this expression by observing that the formula
works for both possible values More explicitly, the two cases are as follows.
Thus, we can alternatively express like this:
Something interesting just happened! Although the action of the gate on standard basis states leaves the top/rightmost qubit alone and XORs the function value onto the bottom/leftmost qubit, here we see that the state of the top/rightmost qubit has changed (in general) while the state of the bottom/leftmost qubit remains the same — specifically being in the state before and after the gate is performed. This phenomenon is known as the phase kickback, and we will have more to say about it shortly.
With one final simplification, which is to pull the factor of outside of the sum, we obtain this expression of the state :
Notice that in this expression, we have in the exponent of as opposed to which is what we might expect from a purely algebraic viewpoint, but we obtain the same result either way. This is because the value for any integer depends only on whether is even or odd.
Applying the final Hadamard gate to the top qubit leaves us with the state
which leads to the correct outcome with probability when the right/topmost qubit is measured.
Further remarks on the phase kickback
Before moving on, let's look at the analysis above from a slightly different angle that may shed some light on the phase kickback phenomenon.
First, notice that the following formula works for all choices of bits
This can be verified by checking it for the two possible values and :
Using this formula, we see that
for every choice of bits Because this formula is true for and we see by linearity that
for all qubit state vectors and therefore
The key that makes this work is that In mathematical terms, the vector is an eigenvector of the matrix having eigenvalue
We'll discuss eigenvectors and eigenvalues in greater detail in the upcoming lesson on Phase estimation and factoring, where the phase kickback phenomenon is generalized to other unitary operations.
Keeping in mind that scalars float freely through tensor products, we find an alternative way of reasoning how the operation transforms into in the analysis above: