# Single Qubit Gates

Over the course of this tutorial, we won't be able to go through all possible quantum gates. We will however take time to go through the most important ones, especially ones that we'll use when learning to code later on.

## The Identity Gate

A very simple gate, which doesn't change anything at all. It preserves the state of the system as it is - it gives us the identity of the qubit.

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

![Symbol for the Identity gate](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M3MNdoE_wShT2bKV4JW%2F-M3MPTPDZh8Fv03GMyv9%2Fimage.png?alt=media\&token=e9a4154c-8d0d-479d-af30-bdb4098c982a)

## Pauli Gates

These gates work by changing the direction of the vector $$|\psi\rangle$$ in either the $$x$$, $$y$$ or $$z$$ direction.

{% hint style="info" %}
[More about the Pauli matrices and where they come from](https://en.wikiversity.org/wiki/Pauli_matrices)
{% endhint %}

### Pauli X

The Pauli X gate is exactly the classical NOT gate as we described earlier:

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

$$
|0\rangle \rightarrow |1\rangle, |1\rangle \rightarrow|0\rangle
$$

And here is how the X gate will be represented on our circuit diagram:

![Symbol for the X gate](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M34hcGDwLAYNrS63zTo%2F-M34hnExi68OLDFCopvw%2Fimage.png?alt=media\&token=e41fd18a-7a53-4f1d-a5dd-0208789feee0)

We can track the result on the Bloch sphere:

![An animation showing the rotation of the X gate on the Bloch sphere](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M33cn8HVb6ZP1E1G5mX%2F-M33daV0Dm0lNaE-Vdk2%2F5d908427a5654129b4cf14f53a2f8f26X_Bloch.gif?alt=media\&token=3e21f595-7618-4e1d-b4f8-d4c568cf8420)

### Pauli Y

The Pauli Y gate is an interesting machine - we get the same result as the Pauli X gate, but instead of moving through real space we move through imaginary space instead.

$$
Y=\begin{bmatrix}0&-i\i&0\end{bmatrix}
$$

<div align="center"><img src="https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M34hu1uQCyDQJ29pBEg%2F-M34i3bW6LdYjK17WKsv%2Fimage.png?alt=media&#x26;token=4aee95ef-2d52-48e5-8e0f-7dee14928598" alt="Symbol for the y gate"></div>

<div align="center"><img src="https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M33gQGUjX81CCizBR7Y%2F-M34akVIVSJI_BSWiM2m%2Fbc3a4d2390564bc09fe4dab0e6475561Y_Bloch.gif?alt=media&#x26;token=10f4411e-3ff7-4501-b7f3-789fd78ddfe2" alt="An animation showing the rotation of the Y gate on the Bloch sphere"></div>

### Pauli Z

The Pauli Z gate changes the state of our qubit along the plane formed by the vectors represented by our two states. This means that no change will occur if we're fully in one state or the other - only if we're somewhere between the two.

$$
Z=\begin{bmatrix}1&0\0&-1\end{bmatrix}
$$

![Symbol for the Z gate](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M34hu1uQCyDQJ29pBEg%2F-M34iBwQR1cS8m5XdLIs%2Fimage.png?alt=media\&token=5eb843db-3a97-49ff-8ad8-8bd916b6c166)

![An animation showing the rotation of the Z gate on the Bloch sphere](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M33gQGUjX81CCizBR7Y%2F-M34ajRssiOWT_WOlEXF%2F80823b8202d44bfcbc0ee29058a20929Z_Bloch.gif?alt=media\&token=cad0782d-8378-417b-a20d-125360c4c02f)

## Hadamard Gate

The Hadamard gate imposes the *uniform superposition* on our system. This gate is very important, because often we need to scramble our initial state before we can start computation. The Hadamard gate does this for us in a predictable way.

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

![Symbol for the Hadamard gate](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M34hu1uQCyDQJ29pBEg%2F-M34iQ1bpu565f7jDOzQ%2Fimage.png?alt=media\&token=a2c0c149-ff14-4fd0-a2cb-e9a0a7825ca8)

![An animation showing the rotation of the Hadamard gate on the Bloch sphere](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M33gQGUjX81CCizBR7Y%2F-M34ai_JVjY8HfPISxUO%2Fffbc26fc17d7425e80209112134951ffH_Bloch.gif?alt=media\&token=80485666-18a1-4610-bc72-cc3c8dbf8c77)

## Phase Gate

The Phase gate is often referred to as the "Z90" gate or the "S" gate. We can see that it's half of our Z gate - instead of going half way around the Bloch sphere, we only go a quarter (a 90 degree turn).

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

![Symbol for the phase gate](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M34iTcp6qRHOVjMuf1P%2F-M34kgzBwP1TdlkAcQfn%2Fimage.png?alt=media\&token=a223f24d-0f70-4886-ae87-7e3948a4f61f)

![An animation showing the rotation of the phase gate on the Bloch sphere](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M34iTcp6qRHOVjMuf1P%2F-M34klA2xPz-CdOkifNu%2F29cf0d32dc724cf8bc4cd3a6f2a1866bS_Bloch.gif?alt=media\&token=20ecbe13-e575-486f-8b42-ee121a3c7107)

## The T Gate

The T gate preforms a $$\frac{1}{8}$$ turn on the sphere. It's a quarter of our Z gate, and half of our S gate. You might think that there's a relationship between the T gate and the S gate, and you'd be right - one S gate amounts two the T gate squared: $$S=T^2$$

$$
T=\begin{bmatrix}1&0\0\&exp(\frac{i\pi}{4})\end{bmatrix}
$$

{% hint style="success" %}
This $$exp(a)$$ notation just means to take the constant $$e$$to the power of whatever is in the brackets - i.e. $$e^a$$. You'll see this notation used often, so I've left it unconverted here for you.
{% endhint %}

![Symbol for the T gate](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M4G8JP58KbZP9_fbQRb%2F-M4G9vST0uRmXM48znw1%2FT%20gate.png?alt=media\&token=f2e0297b-af40-4102-8f8b-06e6575974de)

![An animation showing the rotation of the T gate on the Bloch sphere](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M4G8JP58KbZP9_fbQRb%2F-M4G9xlwMbktJMZCW3pX%2Fafcdc4368d684cedb2279c2de11d76b2T_Bloch.gif?alt=media\&token=5af03197-496a-4d14-9192-2d87daa6a1c1)

## Reversibility

We said before that all of our quantum gates need to be [*reversible*](https://lewisla.gitbook.io/learning-quantum/quantum-information#reversibility). For most of these gates (in fact all of them except the *phase gate* and *T gate*) they reverse themselves.

That is to say that if you apply the *Pauli X* gate twice, for example, it undoes what it did. This makes intuitive sense when we look at the diagram. If we make a 180 degree turn the first time, we would make the same turn when we go the second time, resulting in ending up where we started.

### Reverse Phase Gate

The *phase gate* requires an extra step - we need to do some math to it to find the matrix that reverses it's operations. We denote reverse matrices using the $$\dagger$$ symbol, so this would be the $$S^\dagger$$ gate.

$$
S^\dagger = \begin{bmatrix}1&0\0&-i\end{bmatrix}
$$

![Symbol for the reverse phase gate](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M40SRQTMWU0jlOIbLGW%2F-M40ShSruh7JjRfZeKQN%2Fimage.png?alt=media\&token=5ae95a2b-a053-44db-9c69-2a9bd14af71b)

![An animation showing the rotation of the reverse phase gate on the Bloch sphere](https://3199855145-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-Qqv_c34aARaXqqlB7%2F-M40SrjQ1qEmFHL0hNxH%2F-M40T555XrBicc4atOJP%2F0c695aa2283e45df9d64a79770246485S_D_Bloch.gif?alt=media\&token=19ca5256-8484-498a-9d8b-8754ec5fa668)
