In Chapter 6 of "Quantum Computation and Quantum Information" Textbook by Nielsen and Chuang, Box 6.1 gives a circuit example of Quantum Search Algorithm done on a two-bit sized search space.

The Quantum Search Algorithm consists of an initial Hadamard Transformation on the two-bit input(2 wires), followed by iterations of the Grover Algorithm which itself contains a conditional phase-shift circuit.

The phase shift operation, lets call it $S$, when written in matrix form is given by:

$$S= 2|00\rangle \langle 00|-I$$ so that $S|00\rangle=|00\rangle$, and $S|x\rangle=-|x\rangle$ for $x \neq 00$

The sequence of gate operation on the input qubits are as such:
(1) Apply $X$ gate on both the 1st and 2nd bit.
(2) Apply $H$ gate on the 1st bit.
(3) Apply C-NOT gate on the 1st bit with the 2nd bit as the control bit.
(4) Do (2).
(5) Do (1).

I tried to use $|00\rangle$ as the input state for the phase shift hoping to get back $|00\rangle$.
However I got -$|00\rangle$ after the phase shift if I work out the math for such a gate sequence. These are my steps:

(1) $X_2|0\rangle_2 \otimes X_1|0\rangle_1 =|1\rangle_2|1\rangle_1$

(2) $|1\rangle_2 \otimes H_1|1\rangle_1 = |1\rangle_2 \otimes (\frac{1}{\sqrt {2}} |0\rangle_1 - \frac{1}{\sqrt{2}}|1\rangle_1)$

(3) $|1\rangle_2 \otimes X_1(\frac{1}{\sqrt{2}} |0\rangle_1 - \frac{1}{\sqrt {2}}|1\rangle_1) =|1\rangle_2 \otimes (\frac{1}{\sqrt{2}} |1\rangle_1 - \frac{1}{\sqrt {2}}|0\rangle_1) $

(4) $|1\rangle_2 \otimes H_1(\frac{1}{\sqrt{2}} |1\rangle_1 - \frac{1}{\sqrt {2}}|0\rangle_1)$ $= |1\rangle_2 \otimes \left[\frac{1}{\sqrt{2}} (\frac{1}{\sqrt{2}} |0\rangle_1 - \frac{1}{\sqrt {2}}|1\rangle_1) - \frac{1}{\sqrt {2}}(\frac{1}{\sqrt{2}} |0\rangle_1 + \frac{1}{\sqrt {2}}|1\rangle_1)\right] = |1\rangle_2\otimes -|1\rangle_1 $

(5) $-X_2|1\rangle_2 \otimes X_1|1\rangle_1 =-|0\rangle_2|0\rangle_1$

Can someone find out whats my mistake?

  • 1
    $\begingroup$ You're probably right. But it makes no difference whether you apply $S$ or $-S$. $\endgroup$
    – DaftWullie
    Jun 17, 2019 at 10:01
  • $\begingroup$ @DaftWullie I don't get it. You mean if the sequence of gates is as such, then the other three states in this two-qubit search space will have their signs unchanged after the phase shift? $\endgroup$
    – C.C.
    Jun 17, 2019 at 10:05
  • $\begingroup$ Yes, exactly. Basically steps 2-4 produce the controlled-phase gate which gives a - sign on 11, and leaves other states unchanged. So 1,5 just switch that from 11 to 00. $\endgroup$
    – DaftWullie
    Jun 17, 2019 at 10:07
  • $\begingroup$ @DaftWullie Haha ok. I need to rethink this through. $\endgroup$
    – C.C.
    Jun 17, 2019 at 10:10

1 Answer 1


You're right! Maybe this answer is still helpful / interesting for you.

There are several sources for the Grover algorithm and the phase shift. In Nielsen and Chuang, you'll find that the circuit does something different than what the authors actually say on the previous page. Nevertheless, that does not change the final result. I would like to clarify this a bit.

Before I start a big calculation, let's summarize what the Grover algorithm is all about. In the Grover algorithm, two elements are important. This is the oracle on the one hand and the conditional phase shift on the other hand.

I try to reduce the mathematical calculations to the minimum. Suppose we are looking for an element of four elements. The searched element is $|11\rangle$.

We start with a equal superposition over all states:


The oracle negates the amplitude of the searched element. Important the oracle recognizes a solution for the search problem, so the oracle does the following:


Next, the Hadamard transform is used, as can be seen quite well on the circuit shown in Nielsen & Chuang.

$$|\psi_2\rangle=\frac{1}{2}(H|00\rangle+H|01\rangle+H|10\rangle-H|11\rangle)$$ $$=\frac{1}{4}(|00\rangle + |01\rangle + |10\rangle +|11\rangle \\ + |00\rangle - |01\rangle+|10\rangle-|11\rangle \\ +|00\rangle+|01\rangle-|10\rangle-|11\rangle \\ -|00\rangle+|01\rangle+|10\rangle-|11\rangle)$$ $$=\frac{1}{2}(|00\rangle+|01\rangle+|10\rangle-|11\rangle)$$

Now the conditional phase shift is applied, which means: $|00\rangle\rightarrow|00\rangle, |x\rangle\rightarrow -|x\rangle$ therefore:


The Hadamard-Transformation is to apply: $$H|\psi_3\rangle=\frac{1}{2}(H|00\rangle-H|01\rangle-H|10\rangle+H|11\rangle)$$

Now results in a calculation, which is very similar to the previous one, I abbreviate the times something and write only the result:


If you measure the register at this point you will see state $|11\rangle$ with 100% probability!

But lets get back to the circuit that you have analyzed. The quantum circuit does the following: $|00\rangle \rightarrow -|00\rangle, |x\rangle \rightarrow |x\rangle$ Now I apply this rule to this: $$|\psi_2\rangle=\frac{1}{2}(|00\rangle+|01\rangle+|10\rangle-|11\rangle)$$ I get: $$|\psi_3\rangle=\frac{1}{2}(-|00\rangle+|01\rangle+|10\rangle-|11\rangle)$$ Now the Hadamard transformation has to be executed again: $$H|\psi_3\rangle=\frac{1}{2}(-H|00\rangle+H|01\rangle+H|10\rangle-H|11\rangle)$$ If one calculates this now, one gets the following: $$\frac{1}{4}(-4|11\rangle)=-|11\rangle$$

In summary, this means that the difference between the regulations is really just another sign. However, this does not matter in the measurement, since only the magnitude square of the amplitude plays a role.

In fact, this is a bit strange in Nielsen and Chuang. Since the circuit shown there actually implements the last rule. You have also recognized that correctly.

So in a nutshell: Whether this $|0\rangle\rightarrow|0\rangle, |x\rangle\rightarrow-|x\rangle$ or $|0\rangle\rightarrow-|0\rangle, |x\rangle\rightarrow|x\rangle$ (at the phase shift operator) here is used is "no matter". The difference is only the sign. Granted, if you look at Nielsen and Chuang's first pages on the Grover algorithm, then the real implementation is a bit confusing to the reader. But you analyzed the circuit absolutely correctly.

  • $\begingroup$ Thank you for the showing the thorough analysis. $\endgroup$
    – C.C.
    Jun 17, 2019 at 13:10
  • $\begingroup$ As a side note, this difference becomes significant when you apply the Grover iteration in quantum counting algorithm (estimating its eigenvalues) - at that point the extra global phase starts to matter. $\endgroup$ Jun 17, 2019 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.