In a combination lock, we can represent the oracle as a unitary operator:

where is the right -bit combination for the lock as a basis vector. Applying the oracle is called a query. It tells us when the combination is correct by flipping the sign, so we can try to incorporate it into our lock-breaking circuit. Let's start by creating the oracle operation as a matrix.

The simplest way to do this is to create the identity matrix

and then simply change the entry corresponding to the solution from to .

For this codercise, write a function that returns the oracle in matrix form for a given secret combination.

or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Explain the role of oracles in quantum algorithms.
  • Express the action of an oracle as a unitary matrix applied to computational basis states.