# How to compute the measurement probability in the Hadamard test?

In the Hadamard test (e.g., page 40 of these lecture notes) we have:

But if you look at standard textbook reference, like Nielsen and Chuang, there's an example for how to compute the measurement probability of a single qubit in a multi-qubit system:

For the two qubit state: $$\alpha_{00} |00\rangle + \alpha_{01} |01\rangle + \alpha_{10} |10\rangle + \alpha_{11} |11\rangle$$ the measurement probability for the first qubit to be zero is $$p(0) = |\alpha_{00}|^2 + |\alpha_{01}|^2.$$

Essentially, you take the amplitudes in front of the terms with $$|0\rangle$$ in the first qubit and sum their measurement probabilities.

So, back to the Hadamard test, we have the state: $$\frac{1}{2} (|0\rangle \otimes (|\psi\rangle + U|\psi\rangle)) + \frac{1}{2} (|1\rangle \otimes (|\psi\rangle - U|\psi\rangle)) \\ = \frac{1}{2}|0\rangle|\psi\rangle + \frac{1}{2} |0\rangle U |\psi\rangle + \frac{1}{2}|1\rangle|\psi\rangle - \frac{1}{2}|1\rangle U |\psi\rangle$$

Generalizing from the textbook example, why is it not the case that the measurement probability for the first qubit to be zero is: $$p(0) = \bigg|\frac{1}{2}\bigg|^2 + \bigg|\frac{1}{2}\bigg|^2 = \frac{1}{2},$$ but instead is $$p(0) = \frac{1}{2} (1 + \text{Re} \langle\psi| U |\psi\rangle)$$?

In the first example, you can rewrite your state as $$|0\rangle(\alpha_{00}|0\rangle+\alpha_{01}|1\rangle)+ \cdots$$ Thus correspondingly to the first qubit being $$|0\rangle$$ the second qubit is in the state $$(\alpha_{00}|0\rangle+\alpha_{01}|1\rangle)$$. Being $$|0\rangle$$ and $$|1\rangle$$ orthonormal, the norm of this vector is just the sum of the squared moduli of the coefficients: $$\| (\alpha_{00}|0\rangle+\alpha_{01}|1\rangle) \|^2 = |\alpha_{00}|^2+|\alpha_{01}|^2.$$ Same identical reasoning goes for the Hadamard test. The state of the second register conditional to the first one being $$|0\rangle$$ is, $$\frac12(|\psi\rangle + U|\psi\rangle).$$ The squared norm of this object gives the probability you're looking for. Though in this case the expression is not written as a sum over orthonormal basis states, hence the norm isn't just the sum of the square moduli of the coefficients. In this case you can write the norm observing that $$\||\psi\rangle+U|\psi\rangle\|^2 = \| (U+I)|\psi\rangle\|^2 \equiv \langle\psi|(U+I)^\dagger(U+I)|\psi\rangle \\ = 2 + \langle \psi|U^\dagger+U|\psi\rangle,$$ from which you get the standard expression.
In summary, the rule you mention only works when the coefficients are attached to orthonormal states, and $$|\psi\rangle$$ and $$U|\psi\rangle$$ aren't generally orthogonal.
• Thanks for your answer! I can now see how the math works out. Conceptually though, I still feel a little confused. If I measure the state $\frac{1}{2}|0\rangle|\psi\rangle + \frac{1}{2} |0\rangle U |\psi\rangle + \frac{1}{2}|1\rangle|\psi\rangle - \frac{1}{2}|1\rangle U |\psi\rangle$ and I get the first qubit to be |0>, then the second qubit is either in state $| \psi \rangle$ or $U | \psi \rangle$, which are both normalized. Why is it that the possibility for the 2nd qubit to be in one of two non-orthonormal states affects the measurement probability of the 1st qubit? Mar 30 at 17:18
• @CountAbly it's not in either of those states. It's in their superposition, that is, $|\psi\rangle+U|\psi\rangle$ (properly renormalised)