Over the course of this series, we have developed a solid foundational understanding of quantum computing, as we learned about the basic paradigms, mathematics and various computational concepts that characterize this unique disciple. We are now well equipped to start exploring some of the most important quantum algorithms - starting with today’s part 14, which will be devoted to a simple oracle problem formulated by David Deutsch.
Historical background 🔗
The problem dates back to David Deutsch’s 1985 paper Quantum Theory, the Church-Turing Principle and the Universal Quantum Computer. In that paper, which is widely considered to have jump-started the entire research field of quantum computing, contained a reformulation of the Church-Turing thesis, which underpinned classical computation model. In 1936, an American mathematician Alonzo Church and the British mathematician Alan Turing independently of each other formulated a following hypothesis (the wording below is a rephrasing by Deutsch himself):
Every function which would naturally be regarded as computable can be computed by the universal Turing machine.
It is worth noting that the above statement is not provable - and as such it is not a theorem, but instead is taken as an axiom in computer science. The problem that Deutsch identified was with the word “naturally”, which according to him was creating mathematical ambiguity. Additionally, Deutsch pointed out that the Church-Turing conjecture is quite vague in light of the strong nature of principles in science, such as for example the law of thermodynamics. He therefore proposed a stricter version of the thesis, namely one that he referred to as ‘principle’ and which he reformulated in the following way:
Every finitely realizable physical system can be perfectly simulated by a universal model computing machine operating by finite means.
This principle was so strongly formulated that it was no longer satisfied by the Turing machine, due to the simple fact that classical computing is discrete and there exist problems e.g. classical dynamics, that are at their heart continuous. Deutsch went on to provide a description of such “perfect simulation”, which, in order to satisfy his formulation of the Church-Turing principle, led him to a conclusion that the principle requires a new computation model, namely a quantum computer:
Every existing general model of computation is effectively classical. That is, a full specification of its state at any instant is equivalent to the specification of a set of numbers, all of which are in principle measurable. Yet according to quantum theory there exist no physical systems with this property. The fact that classical physics and the classical universal Turing machine do not obey the Church-Turing principle in the strong physical form is one motivation for seeking a truly quantum model. The more urgent motivation is, of course, that classical physics is false.
The spectacular achievement of Deutsch was that he managed to not only identify the need for, but to also present the first general, fully quantum, model for computation, the so-called “Universal Quantum Computer”. Going in-depth through it - while extremely interesting from both historical and the quantum-theoretical point of view - would be out of scope for this series. However, the paper also introduced, and that would be of particular interest to us today, the first ever problem statement which a quantum computational model could be proven to solve more efficiently than its classical counterpart, at least in terms of the apparent query complexity.
Deutsch’s problem can be formulated as follows:
Given an unknown (blackbox) function that takes a single bit as an input, and produces a single bit as an ouput
, determine if the function is constant or balanced.
A single bit function is constant if
It is worth noting that in the original paper from Deutsch, the solution to the problem on a quantum computer was not deterministic and was successful only 50% of time. The solution we will discuss here is a generalized variant of the original problem that is deterministic.
Deutsch’s problem 🔗
Classically, we need two oracle calls (“function evaluations”) to solve Deutsch’s problem. For example, imagine we call
Thanks to the phenomenon of superposition, as Deutsch proved, we can use an oracle running on a quantum computer to answer this question in a single logical query. This is a key feature of quantum computing - the ability to achieve a superposition of different function evaluations is commonly called “quantum parallelism”. As Nielsen and Chuang point out:
Heuristically, and at the risk of over-simplifying, quantum parallelism allows quantum computers to evaluate a function
for many different values of simultaneously. In this section we explain how quantum parallelism works, and some of its limitations.
Let’s now consider how we could construct a quantum circuit that could answer this problem.
Since we use the concept of gates to express computational steps in quantum computing, an oracle will also be represented by a single quantum gate. Later on in this text, we shall nonetheless see how the internals of the oracle will look like for Deutsch’s problem use case, but for now it would be most helpful to treat it as an indivisible component. We already stated earlier in this series that any quantum gate must be unitary - which means it should be reversible. This also implies that our black box, let’s call it
The presence of the second qubit applying the XOR logic is mandatory to guarantee reversibility - it will not be measured as part of the alogirthm though. The reversability using XOR is easy to calculate using linear algebra. Applying
As we already know from earlier parts, we can send a qubit into a uniform superposition by using the Hadamard gate. Therefore, both
Once we leave the oracle, the only measurement we need to make is on the
In order to explore the full circuit algebraically, let’s first consider what happens to the
Continuing this line of though, let’s apply the
From there, we have two possibilities to go, either
This is exactly the point where we encounter quantum parallelism. Nielsen and Chuang provide additional context:
Naively, one might think that the state
corresponds rather closely to a probabilistic classical computer that evaluates with probability one-half, or with probability one-half. The difference is that in a classical computer these two alternatives forever exclude one another; in a quantum computer it is possible for the two alternatives to interfere with one another to yield some global property of the function , by using something like the Hadamard gate to recombine the different alternatives, as was done in Deutsch’s algorithm.
At this point,
What we managed to achieve here, due to the above mentioned interference, is the so called global phase kickback. The global phase now encodes the information about our function
If we now swap
After going through the final Hadamard gate with the
At this point all that is left is to measure the
To finalize our theoretical discussions, let’s define how
is a constant , namely is a constant , namely is a balanced same function, namely is a balanced flipped function, namely
Keeping in mind the basic requirement that
Do nothing for
Deutsch’s problem in Q# 🔗
Let’s now turn our attention to implementing Deutsch’s algorithm in Q# code. The exercise should not be too challenging, as we only need to translate the above linear algebra into Q#. Just like in previous posts, we can use a standalone Q# application for running the code sample.
The first thing to do is to write the four
operation OracleF0(q1 : Qubit, q2 : Qubit) : Unit is Adj {
// constant 0
// f(0) = f(1) = 0
}
operation OracleF1(q1 : Qubit, q2 : Qubit) : Unit is Adj {
// constant 1
// f(0) = f(1) = 1
X(q2);
}
operation OracleF2(q1 : Qubit, q2 : Qubit) : Unit is Adj {
// balanced same
// f(0) = 0, f(1) = 1
CNOT(q1, q2);
}
operation OracleF3(q1 : Qubit, q2 : Qubit) : Unit is Adj {
// balanced opposite
// f(0) = 1, f(1) = 0
CNOT(q1, q2);
X(q2);
}
Next, let’s define an orchestrator operation that can act as the implementation of the entire Deutsch’s algorithm circuit. As an input, it will accept a delegate pointing to one of the four oracle functions, and will invoke it internally, allowing us a bit more elegant approach to code and its reuse. The orchestrator function is shown next.
operation RunDeutschAlogirthm(oracle : ((Qubit, Qubit) => Unit)) : Bool {
mutable isFunctionConstant = true;
using ((q1, q2) = (Qubit(), Qubit())) {
X(q2);
H(q1);
H(q2);
oracle(q1, q2);
H(q1);
set isFunctionConstant = MResetZ(q1) == Zero;
Reset(q2);
}
return isFunctionConstant;
}
According to the discussion earlier, the orchestrator starts with two qubits in states
Finally, the last piece of code to write is the create an entry point that will invoke the algorithm for all four oracles. Given the functions
@EntryPoint()
operation Main() : Unit {
Message($"f0 is {RunDeutschAlogirthm(OracleF0) ? "constant" | "balanced"}.");
Message($"f1 is {RunDeutschAlogirthm(OracleF1) ? "constant" | "balanced"}.");
Message($"f2 is {RunDeutschAlogirthm(OracleF2) ? "constant" | "balanced"}.");
Message($"f3 is {RunDeutschAlogirthm(OracleF3) ? "constant" | "balanced"}.");
}
This is everything that is needed for the entire implementation - at this point all that is left is to invoke the program, which should produce the following output, in line with our expectations.
f0 is constant.
f1 is constant.
f2 is balanced.
f3 is balanced.
Summary 🔗
While Deutsch’s problem is not really useful for any real life situations, it was a landmark achievement in terms of logically proving that quantum computers can solve a class of problems using more efficient query complexity than classical counterparts. It also demonstrated first hints of the possible quantum advantage that quantum computers can bring to the field of computing.
In the next post we shall discuss a generalization of the Deutsch’s algorithm, the so called Deutsch-Jozsa algorithm.