Matrices for Grover’s algorithm
As we saw in the previous sections, each application of the Grover iterate has two parts:
- In the first part, the oracle marks the target amplitude.
- In the second part, the diffuser inverts all amplitudes about the mean.
Each part is a collection of quantum gates, and those gates apply a matrix to the circuit’s qubits. In this section, we’ll describe the matrix representations of the oracle and the diffuser.
A matrix for the oracle
Let’s assume that we have only two qubits. After these qubits go through Hadamard gates, we have a matrix representation of . If we want to mark the |10⟩ amplitude, we must do the following:
In general, the oracle’s matrix is the identity matrix with one of the 1s along the diagonal changed to a -1. Simple as this is, it’s also somewhat disconcerting. To know which diagonal element becomes -1, you have to know which item is...