# Quantum Computing #02: Single-qubit gates

## Introduction to Quantum Computing series

Classical example: NOT gate: 0 → 1 ; 1 → 0Quantum examples: as quantum theory isunitary,i.e., quantum gates are represented by unitary matrices: \(U^\dagger U = \mathbb{I}\)(identity matrix)

# The Pauli Gates

\(\sigma_X, \sigma_Y, \sigma_Z\) are called **Pauli matrices** and \(\sigma_i^2 = \mathbb{I} = \begin{bmatrix}1 & 0 \ 0&1\end{bmatrix}\). Apply a same gates 2 times = do nothing!
→ together with identity \(\mathbb{I}\), they form a basis of 2x2 matrices

## Pauli-X gate

X-Gate (like classical NOT gate):

$$\sigma_X = X = \begin{bmatrix} 0 & 1 \ 1 & 0 \end{bmatrix} = |0\rangle\langle1| + |1\rangle\langle0|$$

X-gate switches the amplitudes of \(|0\rangle\) and \(|1\rangle\)

$$X|0\rangle = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix} = |1\rangle$$

$$X|1\rangle = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 0 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} = |0\rangle$$

\(\Rightarrow\) **a bit flip** ~ classical NOT gate (but not only flip bit 0 and 1, but also **superposition**)
→ We can think of this as **a rotation by \(\pi\) radians around the x-axis of the Bloch sphere.**

*(→ X-gate would*

**not**have any effect on \(|+\rangle\) and \(|-\rangle\) state)## Pauli-Z gate

$$\sigma_Z = Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} = |0\rangle\langle0| - |1\rangle\langle1|$$

Apply \(\sigma_Z\) to \(|+\rangle\) and \(|-\rangle\):

$$\sigma_Z|+\rangle = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}.\frac{1}{\sqrt2}\begin{bmatrix}1 \\1 \end{bmatrix} = \frac{1}{\sqrt2}\begin{bmatrix}1 \\-1 \end{bmatrix} = |-\rangle$$

$$\sigma_Z|-\rangle = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}.\frac{1}{\sqrt2}\begin{bmatrix}1 \\-1 \end{bmatrix} = \frac{1}{\sqrt2}\begin{bmatrix}1 \\1 \end{bmatrix} = |+\rangle$$

or \(\sigma_X|-\rangle = (|0\rangle\langle0| - |1\rangle\langle1|).\frac{1}{\sqrt2}(|0\rangle - |1\rangle) = \frac{1}{\sqrt2}(|0\rangle + |1\rangle) = |+\rangle\)

\(\Rightarrow\) **a phase flip** (rotation around the z-axis by \(\pi\))

## Pauli-Y gate

$$\sigma_Y = Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} = -i|0\rangle\langle1| + i|1\rangle\langle0| = i.\sigma_X.\sigma_Z$$

→ rotations by \(\pi\) around the y-axis of the Bloch sphere
\(\Rightarrow\) **bit and phase flip**

## Hadamard Gate

It allows us to move away from the poles of the Bloch sphere and **create a superposition of \(|0\rangle\) and \(|1\rangle\):**

$$H = \tfrac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} = \tfrac{1}{\sqrt{2}}(|0\rangle\langle0|+|0\rangle\langle1| + |1\rangle\langle0| - |1\rangle\langle1|)$$

$$H|0\rangle = |+\rangle \Rightarrow H|+\rangle = |0\rangle$$

$$H|1\rangle = |-\rangle \Rightarrow H|-\rangle = |1\rangle$$

*→ Going back and forth → used to change between X and Z basis.*

This can be thought of as a rotation around the Bloch vector [1,0,1] (the line between the x & z-axis), or as transforming the state of the qubit between the X and Z bases.

## The R\(_\phi\)-gate

- The \(R_\phi\) gate is
*parametrized,*that is, it needs a number \(\phi\) to tell it exactly what to do. The \(R_\phi\) gate performs a rotation of ϕ around the Z-axis direction (and as such is sometimes also known as the \(R_z\) gate

\(R_\phi = \begin{bmatrix} 1 & 0 \ 0 & e^{i\phi} \end{bmatrix}\) where \(\phi\) is a real number

## The I, S and T-gates

The I, Z, S & T-gates were all special cases of the more general Rϕ-gate

### The I-gate

The I-gate (aka ‘Id-gate’ or ‘Identity gate’). This is simply a gate that does nothing. Its matrix is the identity matrix:

$$I = \begin{bmatrix} 1 & 0 \\ 0 & 1\end{bmatrix}$$

Applying the identity gate anywhere in your circuit should have no effect on the qubit state, so it’s interesting this is even considered a gate, because:

- It is often used in calculations. For example: proving the X-gate is its own inverse: \(I = XX\)
- it is often useful when considering real hardware to specify a ‘do-nothing’ or ‘none’ operation.

### The S-gate

S-gate (sometimes known as the \(\sqrt{Z}\) -gate), this is an \(R_\phi\) gate with \(\phi = \pi/2\)

\(S = \begin{bmatrix} 1 & 0 \\ 0 & i\end{bmatrix}\) adds \(\pi/2\) to the phase \(\phi\)

\(S|+\rangle = |+i\rangle\) and \(S|-\rangle = |-i\rangle\)

\(\Rightarrow S.H\) is applied to change from \(Z\) to \(Y\) basis

It does a

**quarter-turn**around the Bloch sphere.- It is important to note that unlike every gate introduced in this chapter so far,
**the S-gate is not its own inverse!**

\(S^\dagger\) gate, (also “S-dagger”, “Sdg” or \(\sqrt{Z}^\dagger\) gate) is \(R_\phi\) gate with \(\phi = -\pi/2\)

$$S = \begin{bmatrix} 1 & 0 \\ 0 & e^{\frac{i\pi}{2}} \end{bmatrix}, \quad S^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & e^{-\frac{i\pi}{2}} \end{bmatrix}$$

- The name "\(\sqrt{Z}\)-gate" is due to the fact that two successively applied S-gates has the same effect as one Z-gate:

$$SS|q\rangle = Z|q\rangle$$

### The T-gate

- The T-gate is a very commonly used gate, this is an \(R_\phi\) gate with \(\phi = \pi/4\):

\(T = \begin{bmatrix} 1 & 0 \\ 0 & e^{\frac{i\pi}{4}} \end{bmatrix}, \quad T^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & e^{-\frac{i\pi}{4}} \end{bmatrix}\)

As with the S-gate, the T-gate is sometimes also known as the \(\sqrt[4]{Z}\)-gate.

## General U-gates

The U_3\)-gate is the most general of all single-qubit quantum gates. It is a parametrized gate of the form

$$U_3(\theta, \phi, \lambda) = \begin{bmatrix} \cos(\theta/2) & -e^{i\lambda}\sin(\theta/2) \\ e^{i\phi}\sin(\theta/2) & e^{i\lambda+i\phi}\cos(\theta/2) \end{bmatrix}$$

Every gate in this chapter could be specified as \(U_3(\theta,\phi,\lambda)\), but it is unusual to see this in a circuit diagram, possibly due to the difficulty in reading this.

Qiskit provides \(U_2\) and \(U_1\) gates, which are specific cases of the \(U_3\) gate in which \(\theta=\pi/2\), and \(\theta = \phi = 0\) respectively.

- U1-gate is equivalent to the Rϕ-gate

$$\begin{aligned} U_3(\tfrac{\pi}{2}, \phi, \lambda) = U_2 = \tfrac{1}{\sqrt{2}}\begin{bmatrix} 1 & -e^{i\lambda} \\ e^{i\phi} & e^{i\lambda+i\phi} \end{bmatrix} & \quad & U_3(0, 0, \lambda) = U_1 = \begin{bmatrix} 1 & 0 \ 0 & e^{i\lambda}\\ \end{bmatrix} \end{aligned}$$

### Reference

- IBM Qiskit Textbook: https://qiskit.org/textbook