What is the purpose of Hadamard Test?
Hadamard Test is a subroutine to estimate eigen values of unitary matrix U.
Quantum Circuit
Apply Hadamard Gate to 1st qubit
\ket{0}\mapsto\ket{+}=\frac{1}{\sqrt{2}}(\ket{0}+\ket{1})Apply Ctrl-U with 1st qubit to the other qubits
Ctrl-U Gate is represented by
\ket{0}\bra{0}\otimes I + \ket{1}\bra{1}\otimes Uapply it to Hadamard basis,
\frac{1}{\sqrt{2}}(\ket{0}+\ket{1})\otimes\ket{\psi} \xmapsto{Ctrl-U} \\
\frac{1}{\sqrt{2}}(\ket{0}\otimes\ket{\psi}+\ket{1}\otimes U \ket{\psi})Apply another Hadamard Gate to 1st qubit
\frac{1}{\sqrt{2}}(\ket{0}\otimes\ket{\psi}+\ket{1}\otimes U \ket{\psi}) \xmapsto{Hadamard} \\
\frac{1}{\sqrt{2}}(\frac{1}{\sqrt{2}}(\ket{0}+\ket{1})\otimes\ket{\psi}+\frac{1}{\sqrt{2}}(\ket{0}-\ket{1})\otimes U \ket{\psi})\\
=\ket{0}\otimes(\frac{\ket{\psi}+U\ket{\psi}}{2})+\ket{1}\otimes(\frac{\ket{\psi}-U\ket{\psi}}{2})\\
=\ket{0}\otimes(\frac{I+U}{2})\ket{\psi}+\ket{1}\otimes(\frac{I-U}{2})\ket{\psi}Measurement of 1st qubit
\begin{align}
p_0=\|(\frac{I+U}{2})\ket{\psi}\|^2=\frac{1}{4}(\bra{\psi}+\bra{\psi}U^*)(\ket{\psi}+U\ket{\psi})\\
=\frac{1+Re(\bra{\psi}U\ket{\psi})}{2}\\
p_1=\|(\frac{I-U}{2})\ket{\psi}\|^2=\frac{1-Re(\bra{\psi}U\ket{\psi})}{2}\\
\end{align}Reference
量子コンピューティング〜基本アルゴリズムから量子機械学習まで〜
https://note.com/quantum_note/n/nce36efb1bce3
https://utokyo-icepp.github.io/qc-workbook/quantum_computation.html