Anyone of you can explain (with mathematical steps) me this circuit:

I do not understand why the first qubit phase (as show on IBM composer) is influenced by the second. More precisely: In circuit with single qubit set to zero, the two Hadamard gates at the end, return a quantum state with prob of $|1\rangle$ equal to 0% and phase 0. On circuit like that in the figure, the first qubit (q[0]), return a quantum state with prob of $|1\rangle$ equal to 0% but phase is $\pi$.

Thanks enter image description hereenter image description here

  • $\begingroup$ What is it that the IBM composer is showing you? It seems to me this circuit should not change any phases, since the two Hadamards cancel each other out. $\endgroup$
    – jecado
    Nov 1, 2021 at 18:22
  • 2
    $\begingroup$ You're going to have to show us that result, if we're to have any hope of knowing what's happening! Can you edit your question to include the numbers you're seeing? Include both before and after adding the second qubit, if you can. $\endgroup$
    – jecado
    Nov 1, 2021 at 19:02
  • 1
    $\begingroup$ @KAJ226 That question neatly addresses that two Hadamards together make identity, but I think the OP is asking why his circuit doesn't appear to be identity. I suspect the answer is related to internal implementation of global phases, but of course we'll need a more-thoroughly documented version of the question to be sure. $\endgroup$
    – jecado
    Nov 2, 2021 at 14:15
  • 1
    $\begingroup$ I have posted the circuits and I do not know the mathematical steps that lead the first bit to the π phase and it is precisely for this reason that I have been asking for help. I also take this opportunity to ask the kindness of some of you to explain to me how do you write characters like Bra and Ket. Thank you in advance. $\endgroup$
    – Curiosity
    Nov 4, 2021 at 19:58
  • 1
    $\begingroup$ Yes, the screenshots are helpful. Ideally, circuit composer would say "phase: undefined" when the amplitude is zero. It's like trying to determine the longitude of someone standing at the North pole. It is a coordinate singularity and hence meaningless. And since the phase has no meaning for the zero amplitude, I suggest not to worry about it and just ignore it as if it said "undefined". $\endgroup$ Nov 4, 2021 at 20:43

1 Answer 1


You have a circuit with 2 qubits. But you only apply Hadamard gates on one of them. So q1 remains unchanged (think of it as if you apply identity to it), as for the q0, at the end it is also unchanged since the two Hadamard gates cancel each other.

First note that

$H|0\rangle = \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}$ and $H|1\rangle = \dfrac{|0\rangle - |1\rangle}{\sqrt{2}}$

The math behind it:

Let is assume your initial state is $|0\rangle $

Apply Hadamard once, it $H|0\rangle$ becomes $$\frac{1}{\sqrt2}(|0\rangle+|1\rangle)= \frac{1}{\sqrt2}|0\rangle + \frac{1}{\sqrt2}|1\rangle $$

Now we apply Hadamard again to the result $H (\frac{1}{\sqrt2}|0\rangle + \frac{1}{\sqrt2}|1\rangle) $, I am gonna split it in 2 steps.

First, apply Hadamard to the first part, So $ H\frac{1}{\sqrt2}|0\rangle$ becomes $$ \frac{1}{\sqrt2}( \frac{1}{\sqrt2}|0\rangle + \frac{1}{\sqrt2}|1\rangle)=\frac{1}{2}|0\rangle + \frac{1}{2}|1\rangle $$

With the second part, $ H\frac{1}{\sqrt2}|1\rangle$ becomes $$ \frac{1}{\sqrt2}( \frac{1}{\sqrt2}|0\rangle - \frac{1}{\sqrt2}|1\rangle)=\frac{1}{2}|0\rangle - \frac{1}{2}|1\rangle $$

Put them back together:

$$ \frac{1}{2}|0\rangle + \frac{1}{2}|1\rangle + \frac{1}{2}|0\rangle - \frac{1}{2}|1\rangle\\ = (\frac{1}{2}+\frac{1}{2}) |0\rangle + (\frac{1}{2}- \frac{1}{2}) |1\rangle \\ = |0\rangle $$

You can do the same calculation if your initial state was $|1\rangle$ and you will similarly $|1\rangle$ .

Another way to think about it is in terms of matrices, you can see that HH=Identity matrix:

$H = \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} $ H applied twice is
$HH = \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} \times \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} $ Now, I leave the remaining math to OP since it is an easy one. But by computing $HH$ you will find $\dfrac{1}{2}\begin{pmatrix} 2 & 0\\ 0 & 2 \end{pmatrix}$ which is the identity matrix

  • 1
    $\begingroup$ This is a good breakdown, although the OP seems to be asking why his circuit doesn't appear to act as identity when a second qubit is included in the circuit. $\endgroup$
    – jecado
    Nov 2, 2021 at 14:11
  • 1
    $\begingroup$ @jecado, oh... is that the case? it is not so clear from his post and he did not complain about this answer not being fine for him... Since he is asking for "mathematical steps", I thought of it as seeking clarification more than a "debugging" issue. He does not show us an (weird) outcome of his circuit... if he modifies his question, I will gladly adapt my answer $\endgroup$
    – user206904
    Nov 2, 2021 at 15:45
  • $\begingroup$ I am sorry for confusion and I try to explain me better. On single qubit set to zero, two hadamard gates at the end return a quantistic status with prob of |1> equal to 0% and phase 0. On circuit like image, the first qubit q[0] become with phase "π". $\endgroup$
    – Curiosity
    Nov 2, 2021 at 18:50

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.