The Deutsch-Jozsa algorithm
Deutsch's algorithm outperforms all classical algorithms for a query problem, but the advantage is quite modest: one query versus two. The Deutsch-Jozsa algorithm extends this advantage — and, in fact, it can be used to solve a couple of different query problems.
Here's a quantum circuit description of the Deutsch-Jozsa algorithm. An additional classical post-processing step, not shown in the figure, may also be required depending on the specific problem being solved.
Of course, we haven't actually discussed what problems this algorithm solves; this is done in the two sections that follow.
The Deutsch-Jozsa problem
We'll begin with the query problem the Deutsch-Jozsa algorithm was originally intended to solve, which is known as the Deutsch-Jozsa problem.
The input function for this problem takes the form for an arbitrary positive integer Like Deutsch's problem, the task is to output if is constant and if is balanced, which again means that the number of input strings on which the function takes the value is equal to the number of input strings on which the function takes the value .
Notice that, when is larger than there are functions of the form that are neither constant nor balanced. For example, the function defined as
falls into neither of these two categories. For the Deutsch-Jozsa problem, we simply don't worry about functions like this — they're considered to be "don't care" inputs. That is, for this problem we have a promise that is either constant or balanced.
Deutsch-Jozsa problem
Input: a function
Promise: is either constant or balanced
Output: if is constant, if is balanced
The Deutsch-Jozsa algorithm, with its single query, solves this problem in the following sense: if every one of the measurement outcomes is then the function is constant; and otherwise, if at least one of the measurement outcomes is then the function is balanced. Another way to say this is that the circuit described above is followed by a classical post-processing step in which the OR of the measurement outcomes is computed to produce the output.
Algorithm analysis
To analyze the performance of the Deutsch-Jozsa algorithm for the Deutsch-Jozsa problem, it's helpful to begin by thinking about the action of a single layer of Hadamard gates. A Hadamard operation can be expressed as a matrix in the usual way,
but we can also express this operation in terms of its action on standard basis states:
These two equations can be combined into a single formula,
which is true for both choices of
Now suppose that instead of just a single qubit we have qubits, and a Hadamard operation is performed on each. The combined operation on the qubits is described by the tensor product ( times), which we write as for conciseness and clarity. Using the formula from above, followed by expanding and then simplifying, we can express the action of this combined operation on the standard basis states of qubits like this:
Here, by the way, we're writing binary strings of length as and following Qiskit's indexing convention.
This formula provides us with a useful tool for analyzing the quantum circuit above. After the first layer of Hadamard gates is performed, the state of the qubits (including the leftmost/bottom qubit, which is treated separately from the rest) is
When the operation is performed, this state is transformed into
through exactly the same phase kick-back phenomenon that we saw in the analysis of Deutsch's algorithm.
Then the second layer of Hadamard gates is performed, which (by the formula above) transforms this state into
This expression looks somewhat complicated, and not too much can be concluded about the probabilities to obtain different measurement outcomes without knowing more about the function
Fortunately, all we need to know is the probability that every one of the measurement outcomes is — because that's the probability that the algorithm determines that is constant. This probability has a simple formula.
In greater detail, if is constant, then either for every string in which case the value of the sum is or for every string in which case the value of the sum is Dividing by and taking the square of the absolute value yields
If, on the other hand, is balanced, then takes the value on half of the strings and the value on the other half, so the terms and terms in the sum cancel and we're left with the value
We conclude that the algorithm operates correctly provided that the promise is fulfilled.
Classical difficulty
The Deutsch-Jozsa algorithm works every time, always giving us the correct answer when the promise is met, and requires a single query. How does this compare with classical query algorithms for the Deutsch-Jozsa problem?
First, any deterministic classical algorithm that correctly solves the Deutsch-Jozsa problem must make exponentially many queries: queries are required in the worst case. The reasoning is that, if a deterministic algorithm queries on or fewer different strings, and obtains the same function value every time, then both answers are still possible. The function might be constant, or it might be balanced but through bad luck the queries all happen to return the same function value.
The second possibility might seem unlikely — but for deterministic algorithms there's no randomness or uncertainty, so they will fail systematically on certain functions. We therefore have a significant advantage of quantum over classical algorithms in this regard.
There is a catch, however, which is that probabilistic classical algorithms can solve the Deutsch-Jozsa problem with very high probability using just a few queries. In particular, if we simply choose a few different strings of length randomly, and query on those strings, it's unlikely that we'll get the same function value for all of them when is balanced.
To be specific, if we choose input strings uniformly at random, evaluate and answer if the function values are all the same, and if not, then we'll always be correct when is constant, and wrong in the case that is balanced with probability just If we take for instance, this algorithm will answer correctly with probability greater than %.
For this reason, we do still have a rather modest advantage of quantum over classical algorithms — but it is nevertheless a quantifiable advantage representing an improvement over Deutsch's algorithm.
The Bernstein-Vazirani problem
Next, we'll discuss a problem known as the Bernstein-Vazirani problem. It's also called the Fourier sampling problem, although there are more general formulations of this problem that also go by that name.
First, let's introduce some notation. For any two binary strings and of length we define
We'll refer to this operation as the binary dot product. An alternative way to define it is like so.
Notice that this is a symmetric operation, meaning that the result doesn't change if we swap and so we're free to do that whenever it's convenient. Sometimes it's useful to think about the binary dot product as being the parity of the bits of in positions where the string has a or equivalently, the parity of the bits of in positions where the string has a
With this notation in hand we can now define the Bernstein-Vazirani problem.
Bernstein-Vazirani problem
Input: a function
Promise: there exists a binary string for which for all
Output: the string
We don't actually need a new quantum algorithm for this problem; the Deutsch-Jozsa algorithm solves it. In the interest of clarity, let's refer to the quantum circuit from above, which doesn't include the classical post-processing step of computing the OR, as the Deutsch-Jozsa circuit.
Algorithm analysis
To analyze how the Deutsch-Jozsa circuit works for a function satisfying the promise for the Bernstein-Vazirani problem, we'll begin with a quick observation. Using the binary dot product, we can alternatively describe the action of Hadamard gates on the standard basis states of qubits as follows.
Similar to what we saw when analyzing Deutsch's algorithm, this is because the value for any integer depends only on whether is even or odd.
Turning to the Deutsch–Jozsa circuit, after the first layer of Hadamard gates is performed, the state of the qubits is
The query gate is then performed, which (through the phase kickback phenomenon) transforms the state into
Using our formula for the action of a layer of Hadamard gates, we see that the second layer of Hadamard gates then transforms this state into
Now we can make some simplifications, in the exponent of inside the sum. We're promised that for some string so we can express the state as
Because and are binary values, we can replace the addition with the exclusive-OR — again because the only thing that matters for an integer in the exponent of is whether it is even or odd. Making use of the symmetry of the binary dot product, we obtain this expression for the state:
(Parentheses have been added for clarity, though they aren't really necessary because it's conventional to treat the binary dot product as having higher precedence than the exclusive-OR.)
At this point we will make use of the following formula.
We can obtain the formula through a similar formula for bits,
together with an expansion of the binary dot product and bitwise exclusive-OR:
This allows us to express the state of the circuit immediately prior to the measurements like this:
The final step is to make use of yet another formula, which works for every binary string
Here we're using a simple notation for strings that we'll use several more times in the lesson: is the all-zero string of length
A simple way to argue that this formula works is to consider the two cases separately. If then for every string so the value of each term in the sum is and we obtain by summing and dividing by On the other hand, if any one of the bits of is equal to then the binary dot product is equal to for exactly half of the possible choices for and for the other half — because the value of the binary dot product flips (from to or from to ) if we flip any bit of in a position where has a
If we now apply this formula to simplify the state of the circuit prior to the measurements, we obtain
owing to the fact that if and only if Thus, the measurements reveal precisely the string we're looking for.
Classical difficulty
While the Deutsch-Jozsa circuit solves the Bernstein-Vazirani problem with a single query, any classical query algorithm must make at least queries to solve this problem.
This can be reasoned through a so-called information theoretic argument, which is very simple in this case. Each classical query reveals a single bit of information about the solution, and there are bits of information that need to be uncovered — so at least queries are needed.
It is, in fact, possible to solve the Bernstein-Vazirani problem classically by querying the function on each of the strings having a single in each possible position, and for all other bits, which reveals the bits of one at a time. So, the advantage of quantum over classical algorithms for this problem is query versus queries.
Remark on nomenclature
In the context of the Bernstein-Vazirani problem, it is common that the Deutsch-Jozsa algorithm is referred to as the "Bernstein-Vazirani algorithm." This is slightly misleading, because the algorithm is the Deutsch-Jozsa algorithm, as Bernstein and Vazirani were very clear about in their work.
What Bernstein and Vazirani did after showing that the Deutsch-Jozsa algorithm solves the Bernstein-Vazirani problem (as it is stated above) was to define a much more complicated problem, known as the recursive Fourier sampling problem. This is a highly contrived problem where solutions to different instances of the problem effectively unlock new levels of the problem arranged in a tree-like structure. The Bernstein-Vazirani problem is essentially just the base case of this more complicated problem.
The recursive Fourier sampling problem was the first known example of a query problem where quantum algorithms have a so-called super-polynomial advantage over probabilistic algorithms, thereby surpassing the advantage of quantum over classical offered by the Deutsch-Jozsa algorithm. Intuitively speaking, the recursive version of the problem amplifies the versus advantage of quantum algorithms to something much larger.
The most challenging aspect of the mathematical analysis establishing this advantage is showing that classical query algorithms can't solve the problem without making lots of queries. This is quite typical; for many problems it can be very difficult to rule out creative classical approaches that solve them efficiently.
Simon's problem, and the algorithm for it described in the next section, does provide a much simpler example of a super-polynomial (and, in fact, exponential) advantage of quantum over classical algorithms, and for this reason the recursive Fourier sampling problem is less often discussed. It is, nevertheless, an interesting computational problem in its own right.