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?

• |00> = [1 0 1 0] not [0 0 0 0]. – alanf Jun 11 '16 at 12:49
• I thought |00> = [1 0 0 0] |01>= [0 1 0 0] |10>= [0 0 1 0] and |11>= [0 0 0 1] – Tinniam V. Ganesh Jun 11 '16 at 13:55
• 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. – Peter Shor Jun 11 '16 at 16:58
• Your 4x4 matrix has an error: it should be -0.707 in the bottom right corner, not +0.707. – Craig Gidney Sep 18 '16 at 22:49

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}$$

• 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 – Tinniam V. Ganesh Jun 11 '16 at 14:14
• 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? – Tinniam V. Ganesh Jun 11 '16 at 14:32
• Very sorry, first answer was botched. Your understanding of the states is correct after all and in this case your conclusion is correct too. – udrv Jun 11 '16 at 17:30
• 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 – Tinniam V. Ganesh Jun 12 '16 at 2:49
• Yeah, unfortunately these do not check out. Just curious, where did you get the output table anyway? – udrv Jun 12 '16 at 4:09

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

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:

When I enter your circuit I get this result:

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?

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.

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.