I'm just starting of on quantum computing, specifically following the IBM Q Experience documentation [1]. In here, they are explaining the following experiment:


The expected outcomes according to the document:

  • Phase angle: $\pi/4$
  • Gates: $T$
  • Prob 0: 0.8535533
  • Prob 1: 0.1464466
  • X-length: 0.7071067

I'm trying to deduce this with math.

$T |+\rangle = \begin{bmatrix}1 & 0 \\ 0 & e^{i\pi/4}\end{bmatrix} {1\over\sqrt 2} \begin{bmatrix} 1 \\ 1 \end{bmatrix} = {1\over\sqrt 2} \begin{bmatrix}1\\e^{i\pi/4}\end{bmatrix}$

I think I now need to split this out in $|0\rangle$ and $|1\rangle$ so that I get the quantum amplitudes:

$ = {1\over\sqrt 2} \begin{bmatrix}1\\0\end{bmatrix} + {1\over\sqrt 2} e^{i\pi/4} \begin{bmatrix}0 \\1 \end{bmatrix}$

Here things are falling apart, as

$ P(0) = |{1\over\sqrt 2}|^2 = 0.5 $
$ P(1) = |{1\over\sqrt 2} e^{i\pi/4}|^2 = 0.5 $

So my question: How do I correctly calculate the probabilities and the X-length?

[1]: IBM Q: User Guide / The Weird and Wonderful World of the Qubit / Introducing Qubit Phase

  • $\begingroup$ You're Measuring in the wrong basis. you’ve done it in the z basis when you should be using the x basis. $\endgroup$
    – DaftWullie
    Jun 28, 2018 at 21:08

2 Answers 2


You are correct with your calculation that $$ T\left(\begin{array}{c} 1 \\ 1 \end{array}\right)/\sqrt{2}=\left(\begin{array}{c} 1 \\ e^{i\pi/4} \end{array}\right)/\sqrt{2}, $$ and you are correct that if you want to calculate the probability of getting a "0"$\equiv\left(\begin{array}{c} 1 \\ 0 \end{array}\right)$ measurement result, you evaluate $$ P(0)=\left|\left(\begin{array}{cc} 1 & 0 \end{array}\right)\cdot\left(\begin{array}{c} 1 \\ e^{i\pi/4} \end{array}\right)/\sqrt{2}\right|^2=\frac{1}{2}, $$ so you get both answers with probability 1/2. However, this is not what the referenced page is trying to calculate. It says

If we start with a system initially in the |+⟩ (which is done using the Hadamard), then apply multiples of the T gate and measure in the x-basis...

The X-basis is not the question of 0 or 1 that you have already calculated. Instead, it's the probability of being in $|\pm\rangle=\frac{1}{\sqrt{2}}\left(\begin{array}{c} 1 \\ \pm 1\end{array}\right)$. I think the confusion has arisen because while people often refer to 0 and 1 as being the computational basis (as I have, and you have), when you're talking about measurements where there are two possible results, you can always label the outcomes as 0 and 1, no matter what basis was used. This is what they've done.

So, $$ P(+)=\left|\frac{1}{\sqrt{2}}\left(\begin{array}{cc} 1 & 1 \end{array}\right)\cdot\left(\begin{array}{c} 1 \\ e^{i\pi/4} \end{array}\right)/\sqrt{2}\right|^2=\frac{1}{4}|1+e^{i\pi/4}|^2 $$ Expanding this gives $$ P(+)=\frac{1}{4}\left((1+\cos\frac{\pi}{4})^2+\sin^2\frac{\pi}{4}\right)=\frac{1}{4}\left((1+\frac{1}{\sqrt{2}})^2+\frac{1}{2}\right)=\frac{2+\sqrt{2}}{4} $$ If you numerically evaluate this, you'll get the required result, 0.8535533. You could repeat the calculation for $P(-)$, or just use the fact that $P(+)+P(-)=1$.

The x-length, as they call it, is $$ P(+)-P(-)=2P(+)-1=\frac{2+\sqrt{2}}{2}-1=\frac{1}{\sqrt{2}}. $$ Again, that's exactly what's claimed.

  • $\begingroup$ Your math appears to work out, and thereby answer my question, so thank you for that. Still, I have some concerns/unclear parts. According to inst.eecs.berkeley.edu/~cs191/fa14/lectures/lecture89.pdf: $|\phi\rangle = A_0 \times |0 \rangle + A_1 \times |1 \rangle$; $P(0)=|A_o|^2$ instead of $P(0)=||0 \rangle \times A_o|^2$; Without the $|0 \rangle$, $P(+) = |(\alpha + \beta)/sqrt(2))|^2$ (as discussed in the link) works out. My remaining question: how could you add $(\begin{bmatrix} 1 & 0 \end{bmatrix}$, aka $|0 \rangle$ into the $P(0)=|A_0|^2$? $\endgroup$ Jun 30, 2018 at 11:57
  • 1
    $\begingroup$ This seems a bit jumbled/muddled. Can I suggest expanding into a separate question, then i’ve got a better chance of understanding what you're asking, and giving a decent answer? $\endgroup$
    – DaftWullie
    Jun 30, 2018 at 12:00
  • $\begingroup$ You use $P(0)=|A_o \times |0 \rangle |^2$. Should it not be $P(0)=|A_o |^2$ based on inst.eecs.berkeley.edu/~cs191/fa14/lectures/lecture89.pdf $\endgroup$ Jun 30, 2018 at 12:03
  • $\begingroup$ I believe you turned the use of $|+\rangle$ and $T|+\rangle$ around, taking the complex conjugate transpose of $|+\rangle$ instead of $T|+\rangle$, which eventually did not change the outcome thanks to taking the absolute value? $\endgroup$ Jul 22, 2018 at 16:30
  • $\begingroup$ I believe I've done it correctly for the question as specified. The state produced was $T|+\rangle$, so the probability of being found in the + state is $|\langle +|T|+\rangle|^2$, which is exactly what I've calculated. $\endgroup$
    – DaftWullie
    Jul 23, 2018 at 7:20

The other answers were (almost?*) correct, and pointed me in the right direction for computing any probability for a measurement(especially the notion that I was measuring in the wrong basis), but I missed the definition.

Assuming you are in state $|\psi\rangle$, and you want to know the probability of measuring outcome $|\phi\rangle$:
$P=|\langle\psi|\phi\rangle|^2$ (https://ocw.tudelft.nl/course-lectures/0-3-1-measuring-qubits-standard-basis/ @1:48)
where $\langle\psi|$ is the complex conjugate transpose of the $|\psi\rangle$

More, concrete, if we are in $T |+\rangle$ ($\equiv{1\over\sqrt 2} \begin{bmatrix}1\\e^{i\pi/4}\end{bmatrix}$), and want to know the probability of measuring $|+\rangle$ ($\equiv{1\over\sqrt 2}\begin{bmatrix} 1 \\ 1 \end{bmatrix})$, we calculate:
$P=|{1\over\sqrt 2} \begin{bmatrix}1 & e^{-i\pi/4}\end{bmatrix}{1\over\sqrt 2}\begin{bmatrix} 1 \\ 1 \end{bmatrix}|^2$
$P={1\over4}|1+e^{-i\pi/4}|^2 \approx 0.853553$ (or use Euler's formula for the exact outcome)

P.S. I hope I took the right complex conjugate.
* I also have the $\psi$ and $\phi$ the other way around compared to DaftWullie his/her answer.

  • $\begingroup$ I would recommend putting this in a separate question, or editing your main question with this additional piece. Since I think people will probably miss that you had a followup and assume that @DaftWullie took care of it! But you are correct, and the order of $|\psi\rangle$ and $|\phi\rangle$ doesn't matter since that only changes the conjugation, which doesn't matter when you are taking the norm. $\endgroup$ Jul 23, 2018 at 3:13
  • $\begingroup$ Well, this is a matter of practicality. I do the calculation by saying "I have state $|\psi\rangle$, so the amplitude for being in state $|\phi\rangle$ is $\langle\phi|\psi\rangle$, and hence the probability is $|\langle\phi|\psi\rangle|^2$ but you don't have to think about it like that. The point is simply that $|\langle\phi|\psi\rangle|^2=\langle\phi|\psi\rangle\langle\psi|\phi\rangle=\langle\psi|\phi\rangle\langle\phi|\psi\rangle$, so once you take the mod-square, ordering is irrelevant. You're taking a marginally less conventional ordering from that lecture, but it makes no difference. $\endgroup$
    – DaftWullie
    Jul 23, 2018 at 7:26

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.