Mixed-state Hadamard-test quadratures (source code)

= Mixed-state Hadamard-test quadratures
{title2=$m=\operatorname{Tr}(\rho U)$}

For the <Hadamard test> with a <density operator> $\rho$ in the auxiliary register, the output control <qubit> has <Pauli Z gate> expectation $\operatorname{Re}m$ and <Pauli Y gate> expectation $-\operatorname{Im}m$, where $m=\operatorname{Tr}(\rho U)$. The minus sign comes from the final <Hadamard gate>, since $HYH=-Y$. Measuring in $(|0\rangle\pm i|1\rangle)/\sqrt2$ therefore estimates the imaginary part using the minus-outcome frequency minus the plus-outcome frequency.