# How to create the state $\vert 0 \rangle+i \vert 1 \rangle$ using elementary gates?

I am trying to write $$|0\rangle+i|1\rangle$$ in terms of elementary gates like H, CNOT, Pauli Y, using the IBM QE circuit composer.

I was thinking some kind of combination of H and Y since $$Y|0\rangle=i|1\rangle$$, so it is close but not quite.

Starting with the state $$|\psi_0 \rangle = |0\rangle$$, and we want to get to the state $$|\psi_f \rangle = \dfrac{|0\rangle + i|1\rangle}{\sqrt{2}}$$ then we must realize that we need to create some sort of a superposition between the state $$|0\rangle$$ and the state $$|1\rangle$$. This is where the Hadamard gate will come into play. The Hadamard gate which defined in the computational basis $$\bigg\{ |0\rangle = \begin{pmatrix} 1\\ 0 \\ \end{pmatrix} , |1\rangle = \begin{pmatrix} 0 \\ 1 \\ \end{pmatrix} \bigg\}$$ as: $$H = \dfrac{1}{\sqrt{2}} \begin{pmatrix} 1& 1\\ 1 & -1 \\ \end{pmatrix}$$ and it takes the state $$|0\rangle$$ to the state $$\dfrac{|0\rangle + |1\rangle}{\sqrt{2}}$$. This can be workout explicitly as through Matrix algebra as follow:

$$H|0\rangle = \dfrac{1}{\sqrt{2}} \begin{pmatrix} 1& 1\\ 1 & -1 \\ \end{pmatrix}\begin{pmatrix} 1\\ 0 \\ \end{pmatrix} = \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1\\ 1 \\ \end{pmatrix} = \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}$$

Now, we need to change the relative phase from of the above state. That is we want to change the state from $$\dfrac{|0\rangle + |1\rangle}{\sqrt{2}}$$ to the state $$\dfrac{|0\rangle + i|1\rangle}{\sqrt{2}} = \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1\\ i \\ \end{pmatrix}$$. If you look at it closely, you will see that the unitary matrix (quantum gate) you want to apply should take the form as:

$$\begin{pmatrix} 1& 0\\ 0 & i \\ \end{pmatrix}$$

since

$$\begin{pmatrix} 1& 0\\ 0 & i \\ \end{pmatrix}\dfrac{1}{\sqrt{2}}\begin{pmatrix} 1\\ 1 \\ \end{pmatrix} = \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1\\ i \\ \end{pmatrix} = \dfrac{|0\rangle + i|1\rangle}{\sqrt{2}}$$

The matrix $$\begin{pmatrix} 1& 0\\ 0 & i \\ \end{pmatrix}$$ has a special name, it is called the Phase gate (or S gate) in quantum computing.

So to summarize, we first apply the Hadamard gate follows by the Phase gate (As Lena pointed out in her answer as well) to get from the state $$|\psi_0 \rangle = |0\rangle$$ to the state $$|\psi_f \rangle = \dfrac{|0\rangle + i|1\rangle}{\sqrt{2}}$$.

The quantum circuit looks like: H then S do the trick, it gives me this : • Okay, I'm not sure how you can apply S to a superposition like H|0> though. Since S is a 2x2 matrix, I;m not sure how to write 1/sqrt(2)(|0>+|1>) so that you can apply S to it Jan 18, 2021 at 16:34
• As you can see in the other responses, S can be applied to a superposed state, it will just apply to |0> and |1> easy thanks to the linearity of the operations in quantum computation ;)
– Lena
Jan 18, 2021 at 16:50

It helps to know the action of various gates on the computational basis states. For example, the S gate

$$S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}$$

keeps $$|0\rangle$$ fixed while phasing $$|1\rangle$$ by $$i$$. This means that if we had the state $$|0\rangle+|1\rangle$$ then $$S(|0\rangle+|1\rangle)$$ is $$|0\rangle+ i|1\rangle$$, i.e. the state we need. We can obtain $$|0\rangle+|1\rangle$$ by applying Hadamard

$$H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}$$

to the $$|0\rangle$$ state.

In summary, you can apply Hadamard and the S gate to the $$|0\rangle$$ state

$$SH|0\rangle = S\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) = \frac{1}{\sqrt{2}}(S|0\rangle + S|1\rangle) = \frac{1}{\sqrt{2}}(|0\rangle + i|1\rangle)\tag1$$

where we included normalization factors.

Note that $$(1)$$ is not the only way to obtain $$|0\rangle + i|1\rangle$$. For example, the $$\frac{\pi}{2}$$ Y rotation

$$R_y\left(\frac{\pi}{2}\right) = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & -1 \\ 1 & 1 \end{pmatrix}$$

can be used in place of the Hadamard. This is useful on hardware platforms that may not implement Hadamard natively.

• Hi, thanks for your explanation! For the purpose of implementing quantum algorithms (I'm trying to implement phase estimation), does the normalisation constant not make much of a difference? It was trying to "get rid" of this that was confusing me. Jan 18, 2021 at 16:47
• It only matters at the end if/when you compute output probabilities. However, you can still keep ignoring the normalization factors as long as you remember to renormalize before measurement. Jan 18, 2021 at 16:52
• Ah okay, thank you! Jan 18, 2021 at 17:03