# Measuring Probability of Mixed States

I am a little stuck on understanding the measurement probabilities of a 3 qubit system (QCQI q 4.41).

1)H gates are applied to both $$q_1$$ and $$q_2$$

2) $$C^{(1,2)}_3(X)$$, a Toffoli, controlled by $$q_1$$ and $$q_2$$ is then applied to $$q_3$$

3) A Unitary (S gate) is then applied to $$q_3$$

4) $$C^{(1,2)}_3(X)$$, a Toffoli, controlled by $$q_1$$ and $$q_2$$ is then applied to $$q_3$$

5) H gates are applied to both $$q_1$$ and $$q_2$$

The probability of measuring $$|q_1\rangle = |q_2\rangle = 0$$ should be $$\frac{5}{8}$$, however I can only seem to derive $$\frac{4}{8}$$, by expanding out the tensors and then cancelling.

After step 4 the state I think is:

$$(|00\rangle + |01\rangle + |10\rangle)\otimes S|q_3\rangle + |11\rangle \otimes XSX|q_3\rangle$$

Then after applying step 5, expanding out and cancelling I am left with:

$$(|00\rangle + |00\rangle + |00\rangle - |11\rangle)\otimes S|q_3\rangle + (|00\rangle - |01\rangle - |10\rangle + |11\rangle)\otimes XSX|q_3\rangle$$

however I can't seem to find the missing $$|00\rangle$$, and also in this result the measurement of $$|00\rangle$$ corresponds to two different states of $$q_3$$. I think the error in my understanding is somewhere here:

Applying Hs (step 5) and expanding $$|11\rangle \otimes XSX|q_3\rangle$$

$$(H|1\rangle \otimes H|1\rangle) \otimes IXSX|q_3\rangle$$ = $$(|00\rangle - |01\rangle - |10\rangle + |11\rangle)\otimes XSX|q_3\rangle$$

Could it also be my misunderstanding that the state of $$|q_1q_2\rangle$$ going into both Toffoli gates can be different for step 2 & 4? I was assuming that if that state was $$|11\rangle$$ in the first Toffoli then it must be $$|11\rangle$$ into the second as well.

I'm not sure that I agree with all of your calculation. I agree up to step 4 (but let's be careful and keep normalisation factors in there), $$\frac{1}{2}(|00\rangle+|01\rangle+|10\rangle)\otimes S|q_3\rangle+|11\rangle\otimes XSX|q_3\rangle,$$ which I would even simplify to $$\frac{1}{2}(|00\rangle+|01\rangle+|10\rangle)\otimes S|q_3\rangle+|11\rangle\otimes iS^\dagger|q_3\rangle.$$ Now we need to apply the Hadamards $$\rightarrow\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)\otimes S|q_3\rangle+i\frac{1}{4}(|00\rangle-|01\rangle-|10\rangle+|11\rangle)\otimes S^\dagger|q_3\rangle.$$ Let's simplify the first bracket $$=\frac{1}{4}(3|00\rangle+|01\rangle+|10\rangle-|11\rangle)\otimes S|q_3\rangle+i\frac{1}{4}(|00\rangle-|01\rangle-|10\rangle+|11\rangle)\otimes S^\dagger|q_3\rangle.$$ So, we can now regroup terms as $$\frac{1}{4}|00\rangle\otimes(3S+iS^\dagger)|q_3\rangle+\frac{1}{4}(|01\rangle+|10\rangle-|11\rangle)\otimes(S-iS^\dagger)|q_3\rangle.$$ At this point, you might get ahead of yourself and try to read off the amplitude for the $$|00\rangle$$ term, and determine the measurement probability from that. However, you need to be careful to take into account the normalisation of the state of the third qubit. For example, $$(S-iS^\dagger)=(1-i)Z=\sqrt{2}e^{-i\pi/4}Z.$$ From this, we conclude that each of the other terms appears with probability $$|\sqrt{2}e^{-i\pi/4}/4|^2=1/8$$, and applies $$Z$$ on qubit 3. So, it is clear that the $$|00\rangle$$ answer must arise with probability 5/8. We just need to check what the rotation is. Let's maipulate it a bit $$3S+iS^\dagger=\left(\begin{array}{cc} 3+i & 0 \\ 0 & 3i+1 \end{array}\right).$$ If we write $$3+i=\sqrt{10}e^{i\phi}$$, then this is $$\sqrt{10}\left(\begin{array}{cc} e^{i\phi} & 0 \\ 0 & ie^{-i\phi}\end{array}\right)=\sqrt{10}e^{i\pi/4}\left(\begin{array}{cc} e^{i(\phi-\pi/4)} & 0 \\ 0 & ie^{-i(\phi-\pi/4)}\end{array}\right).$$ The $$\sqrt{10}$$ contributes to the amplitude of the overall state, so we get $$|00\rangle$$ with probability $$|\sqrt{10}e^{i\pi/4}/4|^2$$, as required. The unitary is of the form $$R_z(\theta)$$ with $$\theta/2=\pi/4-\phi$$. Hence, $$\cos\theta=\cos\left(\frac{\pi}{2}-2\phi\right)=\sin(2\phi)=\frac{3}{5}.$$