# Hadamard + Hadamard + Ry: Results in the IBM Q Experience don't match the matrix results

I'm new to the IBM Q Experience. In the Composer, I built a circuit consisting of two Hadamard Gates and an Ry:

OPENQASM 2.0;
include "qelib1.inc";
qreg q;
creg c;

h q;
h q;
ry(pi/2) q;
measure q -> c;


The results returned are 50/50 probability. However, when I apply the matrices in a spreadsheet, I get a $$\frac{28}{72}$$ result. (See image below.) For the Hadamard matrices, I'm using one divided by the square root of two for the corresponding a, b, and c elements and minus one divided by the square root of two for the d element. For the Ry matrix elements a,b c, and d, I have $$\cos\big(\frac{pi/2}{2}\big)$$, $$-\sin\big(\frac{pi/2}{2}\big)$$, $$\sin\big(\frac{pi/2}{2}\big)$$ and $$\cos\big(\frac{pi/2}{2}\big)$$, where $$\pi=180^{\text{o}}$$. The output squared in the spreadsheet gives me 28/72 probability. I hate to be a pest with such a low level question, but where in the matrices am I going wrong?

For $$\pi$$ I used 3.14 instead of 180 degrees, and it came out 50/50. Here are the gates:

$$\begin{equation} H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\1&-1 \end{pmatrix} \qquad R_y(\theta) = \begin{pmatrix} \cos(\theta/2) & -\sin(\theta/2) \\\sin(\theta/2) & \cos(\theta/2) \end{pmatrix} \end{equation}$$

Matrix multiplication (note that $$HH = I$$):

$$U = R_y(\pi/2) H H = R_y(\pi/2) = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & -1 \\ 1 & 1 \end{pmatrix}$$

If we will apply this $$U$$ to the $$|0\rangle$$ state, we will obtain:

$$U |0\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & -1 \\ 1 & 1 \end{pmatrix} \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix} = \frac{1}{\sqrt{2}} (|0\rangle + |1\rangle)$$

So with $$50\%$$ probability we will measure $$|0\rangle$$ (or $$|1\rangle$$) state.

• Cool. Thank you. May 17 '20 at 22:04

For pi I used 3.14 instead of 180 degrees, and it came out 50/50.

Sounds like you answered your own question. Sine and cosine functions would be expecting radians by default, so using $$\pi=3.14 \cdots$$ is correct.

• Thank you, sir. May 17 '20 at 22:02