In Mike and Ike's "Quantum Computation and Quantum Information", Grover's algorithm is explained in great detail. However, in the book, and in all explanations I have found online for Grover's algorithm, there seems to be no mention of how Grover's Oracle is constructed, unless we already know which state it is that we are searching for, defeating the purpose of the algorithm. Specifically, my question is this: given some f(x) such that for some x value, f(x)=1, but for all others, f(x)=0, how does one construct an oracle that will get us from our initial, arbitrary state |x>|y> to |x>|y+f(x)>? As much explicit detail as possible (perhaps an example?) would be greatly appreciated. If such a construction for any arbitrary function is possible with Hadamard, Pauli, or other standard quantum gates, a method for construction with these would be appreciated.
The oracle is basically just an implementation of the predicate you want to search for a satisfying solution to.
For example, suppose you have a 3-sat problem:
(x1 x3 x4)
(x2 x3 x4)
(x1 x2 x4)
(x1 x3 x4)
(x1 x2 x3)
Or, in table form with each row being a 3-clause, x meaning "this variable false", o meaning "this variable true", and space meaning "not in clause":
1 2 3 4
-------
x x x
o o x
o x o
x o x
Now make a circuit that computes whether the input is a solution, like this:
Now, to turn your circuit into an oracle, hit the output bit with a Z gate and uncompute any garbage you made (i.e. run the compute circuit in reverse order):
That's all there is to it. Compute the predicate, hit the result with a Z, uncompute the predicate. That's an oracle.
Iterate diffusion steps with oracle steps, and you've got yourself a grover search:
... although you should probably pick an example with fewer solutions, so the progress is gradual (instead of rotating along the start-state-solution-state plane by more than 90 degrees per step as my example is).
Z
gate having as target the last but one qubit link — Sep 15, 2020 at 15:12 External links referenced by this document: