0
$\begingroup$

Ctrl hadamard

Output cHadamard

I am unable to explain the output of a controlled Hadamard gate. If U is a single qubit gate $$U= \begin{pmatrix}u11 & u12\\ u21 & u22\end{pmatrix},$$ then the controlled gate is

$$\mathrm{controlled-}U=\begin{pmatrix}1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\0 & 0 & u11 & u12\\ 0 & 0 & u21 & u22\end{pmatrix}. \tag A$$

By this logic the unitary 4 x 4 matrix for controlled Hadamard would be $\begin{pmatrix}1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\0 & 0 & .707 & .707\\ 0 & 0 & .707 & .707\end{pmatrix}$

If I apply the controlled hadamard on q00 = $\begin{pmatrix}1\\ 0\\ 0\\ 0\end{pmatrix}$ gives back $\begin{pmatrix}1\\ 0\\ 0\\ 0\end{pmatrix}$. However, I find that the controlled Hadamard is supposed to give the following output

       00   01   10   11
00     .5       .25   .25
01          .5  .25   .25
10     .5       .25   .25
11          .5  .25   .25

How can this result be explained? Is there a derivation that proves this? Also why is the generic form the controlled gate as represented by (A) not applicable?

$\endgroup$
4
  • 1
    $\begingroup$ |00> = [1 0 1 0] not [0 0 0 0]. $\endgroup$
    – alanf
    Jun 11, 2016 at 12:49
  • 2
    $\begingroup$ I thought |00> = [1 0 0 0] |01>= [0 1 0 0] |10>= [0 0 1 0] and |11>= [0 0 0 1] $\endgroup$ Jun 11, 2016 at 13:55
  • 1
    $\begingroup$ Where did you get that probability table? I don't think it applies to a controlled Hadamard gate. Maybe a controlled Hadamard followed by a Hadamard on qubit 1. $\endgroup$ Jun 11, 2016 at 16:58
  • 2
    $\begingroup$ Your 4x4 matrix has an error: it should be -0.707 in the bottom right corner, not +0.707. $\endgroup$ Sep 18, 2016 at 22:49

4 Answers 4

3
$\begingroup$

There should be a negative in the bottom right corner of your matrix. Otherwise you are correct. There is something wrong with the output table.

In qubit notation a general controlled_U gate is defined as $$ CU = |0\rangle\langle 0| \otimes {\hat I} + |1\rangle\langle 1| \otimes {\hat U} $$ This gives $$ CU|00\rangle = |00\rangle \equiv \left(\begin{array}{c}1 \\0 \end{array}\right)\otimes \left(\begin{array}{c}1 \\0 \end{array}\right) = \left(\begin{array}{c}1 \\0 \\0 \\0\end{array}\right)\\ CU|01\rangle = |01\rangle \equiv \left(\begin{array}{c}1 \\0 \end{array}\right)\otimes \left(\begin{array}{c}0 \\1 \end{array}\right) = \left(\begin{array}{c}0 \\1 \\0 \\0\end{array}\right) \\ CU|10\rangle = |1\rangle \otimes U|0\rangle \equiv \left(\begin{array}{c}0 \\1 \end{array}\right)\otimes \left(\begin{array}{c}u_{11} \\u_{21} \end{array}\right) = \left(\begin{array}{c}0 \\0 \\u_{11} \\u_{21}\end{array}\right)\\ CU|01\rangle = |1\rangle \otimes U|1\rangle \equiv \left(\begin{array}{c}0 \\1 \end{array}\right)\otimes \left(\begin{array}{c}u_{12} \\u_{22} \end{array}\right) = \left(\begin{array}{c}0 \\0 \\u_{12} \\u_{22}\end{array}\right)\\ $$ So the truth table should read $$ \begin{array}{ccccc} & & Output & \\& 00 & 01 & 10 & 11 \\00 & 1 & 0 & 0 & 0 \\01 & 0 & 1 & 0 & 0 \\10 & 0 & 0 & u_{11} & u_{21} \\11 & 0 & 0 & u_{12} & u_{22}\end{array} $$ which for the controlled-Hadamard becomes $$ \begin{array}{ccccc} & 00 & 01 & 10 & 11 \\00 & 1 & 0 & 0 & 0 \\01 & 0 & 1 & 0 & 0 \\10 & 0 & 0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\11 & 0 & 0 & \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}}\end{array} $$

$\endgroup$
8
  • $\begingroup$ Thanks. I am little confused. When we consider the CNOT gate |00> = [1 0 0 0] |01>= [0 1 0 0] |10>= [0 0 1 0] and |11>= [0 0 0 1] was used to verify the result of applying CNOT. Should it not be the same values? I see that you have substituted the value of |0> = (1 0)T and |1> = (0 1)T. I think I see now but still am puzzled why the former was used while verifying the CNOT gate $\endgroup$ Jun 11, 2016 at 14:14
  • $\begingroup$ This is what I get if I use the above basis for 2 qubit CNOT(q00) => q01 CNOT(q01) => q00 CNOT(q10) =>q11 and CNOT(q11) => q10. Clearly the result for q00 and q01 is wrong. Am I missing anything here? $\endgroup$ Jun 11, 2016 at 14:32
  • $\begingroup$ Very sorry, first answer was botched. Your understanding of the states is correct after all and in this case your conclusion is correct too. $\endgroup$
    – udrv
    Jun 11, 2016 at 17:30
  • $\begingroup$ Thanks. But with this if we multiply CHadamard x (1 0 0 0) we will not get the values below 00 .5 .25 .25 01 .5 .25 .25 10 .5 .25 .25 11 .5 .25 .25 $\endgroup$ Jun 12, 2016 at 2:49
  • $\begingroup$ Yeah, unfortunately these do not check out. Just curious, where did you get the output table anyway? $\endgroup$
    – udrv
    Jun 12, 2016 at 4:09
3
$\begingroup$

You're having problems because you have an extra Hadamard gate. Also your circuit might be upside down.

The Problem


I used Quirk to inspect your circuit.

By setting up an entangled state, operating on one half, and using an amplitude display, I can make a circuit that shows a scaled version of the matrix for an operation:

Controlled hadamard circuit

When I enter your circuit I get this result:

Your circuit

Well that explains why you're getting strange results; you didn't implement a controlled-hadamard!

The source of the problem is the very first Hadamard gate you apply. It's hiding at the far left of your circuit, on the second qubit. You may have added it when checking how the gate affects superpositions, but then forgotten about it?

Remove that gate and you get this circuit:

Controlled hadamard 2

At first this looks wrong, but it's actually fine.

First thing that looks wrong is that all the phase lines are slanted. But it's always the same slant, so it's just an extra global phase factor. Global phase factors are unobservable, so this is fine.

Second thing is that the 2x2 clump of stuff we expected at the bottom-right has ended up more spread out. It's over col/row 2-and-4 instead of over 3-and-4. That's also fine: it just means this circuit is upside down w.r.t. the other one. We swapped the control and the Hadamard. The first qubit is controlling the second qubit's Hadamard, instead of vice versa.

$\endgroup$
0
$\begingroup$

I believe that your Eq. (A) is correct, and in your numerical $ 4\times 4 $ matrix, only the element $ CH_{33} $ is wrong as alredy mentioned by Craig Gidney. The answer given by udrv is also correct. I think the issue probably is related to joint state ordering if you use IBM Q. Yours and almost all online resources on multi-qubit gates use standard ordering(Wiki QFT), that is:$|01\rangle = |0\rangle \otimes |1\rangle$. But in QisKit doc, it is said that:

Qiskit uses a slightly different ordering of the qubits, in which the qubits are represented from the most significant bit (MSB) on the left to the least significant bit (LSB) on the right (big-endian).

This means: $|01\rangle = |1\rangle \otimes |0\rangle$. Hence the CU matrix is changed to the following form: $$ \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & u_{00} & 0 &u_{01}\\ 0 & 0 & 1 & 0\\ 0 & u_{10} & 0 &u_{11}\\ \end{pmatrix} $$ By the way, I don't know where did you get your output matrix.

$\endgroup$
0
$\begingroup$

I agree with the answer given by Craig Gidney and with his individuation of the problem.

But I saw the solution and I noticed that the obtained state is the right one except for a global phase factor, as mentioned in his answer. I then show again the circuit:

Controlled hadamard 2

To obtain your exact matrix, you can change the circuit a little, particularly swapping the two bits and adding two T gates, as shown in this new circuit

New circuit

Where I recall the fact that $T^4 = S^2 = Z$. In this way the matrix that you associate to the circuit is the right one, even according to the global phase factor. In this way you can clearly see the wrong sign in the element $A_{4,4}$ of your matrix.

$\endgroup$

Your Answer

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

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