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?