0

If I want to write a program to simulate Grover's algorithm, how could I write the oracle for it? If I already know the result, why should I use the search?

Mariia Mykhailova
  • 1,987
  • 1
  • 9
  • 18
David Chan
  • 641
  • 1
  • 7
  • 10

1 Answers1

4

A lot of examples of Grover search implementation use an oracle with a hardcoded answer, which is indeed not very enlightening. In general case the point of Grover search is, of course, to perform search if you don't know the answer. To write an oracle for this, you need not an oracle which checks whether the input equals some hardcoded value, but an oracle which checks a certain property of the input. Implementing the oracle is the hardest part of solving the problem.

The easiest example of such a problem is SAT problem. You can map the variables in the formula to the qubits of the input and write an oracle which computes f(x) with relative ease, and you can apply Grover search to find the interpretation which satisfies the given formula, but you don't know the answer from just glancing at the oracle. You can see an example of implementing the oracle for solving SAT problem in the SolveSATWithGrover tutorial.

P.S. There are a lot of great answers regarding Grover search algorithm at the Quantum Computing StackExchange.

Mariia Mykhailova
  • 1,987
  • 1
  • 9
  • 18