-1
$\begingroup$

I am new to quantum computing and was looking through the jupyter notebook of Variational Quantum Linear Solver by Qiskit. I came across the hadamard test and was not understanding how it works. It is written there,

Circuit: [Hadamard test]1

$$\frac{|0\rangle \ + \ |1\rangle}{\sqrt{2}} \ \otimes \ |\psi\rangle \ = \ \frac{|0\rangle \ \otimes \ |\psi\rangle \ + \ |1\rangle \ \otimes \ |\psi\rangle}{\sqrt{2}}$$


Applying our controlled unitary:


$$\frac{|0\rangle \ \otimes \ |\psi\rangle \ + \ |1\rangle \ \otimes \ |\psi\rangle}{\sqrt{2}} \ \rightarrow \ \frac{|0\rangle \ \otimes \ |\psi\rangle \ + \ |1\rangle \ \otimes \ U|\psi\rangle}{\sqrt{2}}$$


Then applying the Hadamard gate to the first qubit:


$$\frac{|0\rangle \ \otimes \ |\psi\rangle \ + \ |1\rangle \ \otimes \ U|\psi\rangle}{\sqrt{2}} \ \rightarrow \ \frac{1}{2} \ \big[ |0\rangle \ \otimes \ |\psi\rangle \ + \ |1\rangle \ \otimes \ |\psi\rangle \ + \ |0\rangle \ \otimes \ U|\psi\rangle \ - \ |1\rangle \ \otimes \ U|\psi\rangle \big]$$


$$\Rightarrow \ \frac{1}{2} |0\rangle \ \otimes \ (\mathbb{I} \ + \ U)|\psi\rangle \ + \ \frac{1}{2} |1\rangle \ \otimes \ (\mathbb{I} \ - \ U)|\psi\rangle$$


How do we get the equation "applying hadamard gate to the first qubit"? Especially the fourth term which is negative.

Link to the notebook

$\endgroup$

1 Answer 1

2
$\begingroup$

The Hadamard gate $H$ transforms the computational basis as follows: $$\begin{align}H\lvert 0\rangle &= \lvert + \rangle = \frac{\lvert 0\rangle + \lvert 1\rangle}{\sqrt 2} \\ H\lvert 1\rangle &= \lvert - \rangle = \frac{\lvert 0\rangle \color{red}- \lvert 1\rangle}{\sqrt 2}\end{align}$$ So, to elaborate a little bit on the steps involved in the transformation that's confusing you: applying a Hadamard gate to the first qubit equates to applying $H\otimes I$ to the whole system, which gives us the result $$\begin{align*} (H\otimes I)\bigg(\frac{\lvert 0\rangle\otimes\lvert\psi\rangle + \lvert 1\rangle\otimes U\lvert\psi\rangle}{\sqrt 2}\bigg) &= \frac{H\lvert 0\rangle\otimes\lvert\psi\rangle + H\lvert 1\rangle\otimes U\lvert\psi\rangle}{\sqrt 2} \\ &= \frac{\tfrac{\lvert 0\rangle + \lvert 1\rangle}{\sqrt 2}\otimes \lvert\psi\rangle + \tfrac{\lvert 0\rangle \color{red}- \lvert 1\rangle}{\sqrt 2}\otimes U\lvert\psi\rangle}{\sqrt 2} \\ &= \frac{\lvert 0\rangle\otimes\lvert\psi\rangle + \lvert 1\rangle\otimes\lvert\psi\rangle + \lvert 0\rangle\otimes U\lvert\psi\rangle \color{red}- \lvert 1\rangle\otimes U\lvert\psi\rangle}{2} \end{align*}$$ Does this clear up where the sign of the fourth term comes from?

$\endgroup$
1
  • $\begingroup$ Yes, That makes sense. I didn't take into account how Hadamard acts on $|1\rangle$ state. Thank you. $\endgroup$
    – Vaishnav
    Commented Mar 20, 2023 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.