Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / quantum-computing

Quantum Computing for Everyone - Part II: Quantum Gates

5.00/5 (2 votes)
16 Jun 2018CPOL27 min read 22.6K  
An introduction to what quantum computer gates are, how they are used, and their effect on qubits.
Part I: Classical vs. Quantum Computing Part III: Quantum Circuits and OpenQASM

Table of Contents

 

Introduction

In Part I of this series we saw the difference between a quantum and classical computer, learned what a qubit was, and how it can be represented. If you have not read Part I yet, I strongly recommend doing so before beginning this article. Everything that follows builds upon the concepts that were presented in Part I.

In this part we will see how qubits can be manipulated using various quantum gates. These gates are the quantum computing equivalent of logic gates in classical computers. Quantum gates change the states of one or more qubits which allows calculations to be performed. The quantum gates will be presented starting with the simpler, more common gates working up to less common, more general gates. The most important gates to learn when starting are the Identity gate, Pauli-X/-Y/-Z, Hadamard, CNOT, SWAP, Toffoli, \(S\), \(S^\dagger\), \(T\), and \(T^\dagger\). I recommend working on learning these gates first as they are the most common and are the gates that the QX service provides by default (excluding the SWAP and Toffoli gates).

 

Matrix Review

Before we can talk about the different quantum gates (also know as operations) and what they do, we will first need to go over some matrix algebra. This is necessary because to determine the state of the qubits after a gate operates on them, you need to multiply the matrix for the qubits starting states by the gate's matrix.

A gate that operates on a single qubit is represented by a \(2 \times 2\) unitary matrix. A unitary matrix means that if you multiple the matrix by its (complex) conjugate transpose you end up with an identity matrix. What does this mean? Lets break it down into individual steps to make it clear.

Lets start with a matrix of the following form:

$\begin{aligned} \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} \end{aligned}$

The conjugate of a complex number simply means to change the sign of the imaginary part. So if you have complex number \(a + ib\) the conjugagte is \(a - ib\). It also applies the other way. If you have a number \(a - ib\) the conjugate is \(a + ib\).

The transpose of a matrix is another matrix formed by interchanging the rows and columns. For our matrix:

$\begin{aligned} \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} \end{aligned}$

The transpose would be:

$\begin{aligned} \begin{pmatrix} 0 & i \\ -i & 0 \end{pmatrix} \end{aligned}$

Now if we take the conjugate of this matrix (by switching the sign of the imaginary numbers) we end up with the following matrix:

$\begin{aligned} \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} \end{aligned}$

In this case, it turns out that it is the same as the original matrix.

Now, the identity matrix is a matrix with \(1\)'s down its main diagonal (top left to bottom right) and \(0\)'s everywhere else. So a \(2 \times 2\) identity matrix would be:

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

Putting this all together, if our original matrix is a unitary matrix then multiply it by it conjugate transpose should result in the above identity matrix:

$\begin{aligned} \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} \end{aligned}$

The resulting matrix is:

$\begin{aligned} \begin{pmatrix} 0 * 0 + -i * i & 0 * i + -i * 0 \\ i * 0 + 0 * i & i * -i + 0 * 0 \end{pmatrix} = \begin{pmatrix} -i * i & 0 \\ 0 & i * -i \end{pmatrix} = \begin{pmatrix} -(-1) & 0 \\ 0 & -(-1) \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \end{aligned}$

Matrix Multiplication

If two square matrices, \(A\) and \(B\), where each matrix is defined as

$\begin{aligned} A = \begin{pmatrix} a & b \\ c & d \end{pmatrix} B = \begin{pmatrix} e & f \\ g & h \end{pmatrix} \end{aligned}$

are multiplied together, the resulting matrix \(C\) (that is where \(C = AB\)) equals

$\begin{aligned} C = AB = \begin{pmatrix} ae + bg & af + bh \\ ce + dg & cf + dh \end{pmatrix} \end{aligned}$

Since the resulting matrix is an identity matrix, we have proven that the original matrix was indeed a unitary matrix. Actually, this is a special matrix called the Pauli-Y Gate. We will talk about this gate, and others, in the next section, but first some quick notes on notation.

  • If a matrix is written as \(U\) then the conjugate transpose is written as \(U^\dagger\).
  • An identity matrix is usually written as \(I\).
  • To show the above matrix multiplication of a unitary matrix we could write \(U^{\dagger}U=I\).
  • To show a gate operating on a qubit, which causes the qubit to be in a new state, we can write \(|\psi^{\prime}\rangle = U|\psi\rangle\) where \(|\psi^{\prime}\rangle\) is the state of the qubit after the gate has finished manipulating the qubit.

As writting out matrix multiplication can be long, especially when you start using 3 qubit gates, like the Toffoli gate, which are represented by an \(8 \times 8\) matrix, I have provided a link to an online matrix calculator. Further information on this resource, and a link to the page, can be found in the References section.

 

Quantum Gates

Quantum gates are the basic building blocks of quantum circuits and are the quantum analog of logic gates used in classical computers. There are two important features of quantum gates that should be remembered:

  1. Quantum gates are reversible, unlike many classical logic gates. For example, you cannot determine what the inputs to a classic AND gate were based solely the output of the gate. However, with quantum gates, the input(s) can be reconstructed from the output.
  2. Most quantum gates operate on one or two qubits at a time, but all quantum gates are represented by unitary matrices. If the gate operates on \(n\) qubits, then the gate's matrix is a \(2^n \times 2^n\) unitary matrix.

In this section, when describing how a quantum gate changes the state of a qubit, the qubit will assumed to be starting in the ground state (i.e. \(|0\rangle\)) unless otherwise noted. To determine how a qubit's state changes after being operated on by a gate, the matrix of the qubit's current state is multiplied by the matrix of the gate operating on the qubit. A specific example of this is shown under the description of the Pauli-X Gate, but it works the same way for all the gates, just the matrix being multiplied changes

 

Single Qubit Gates

Identity Gate

The simplest gate is known as the Identity gate:

$\begin{aligned} I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \end{aligned}$

This gate does not change the state of a qubit and outputs whatever was inputted. For example, the identity gate maps \(|0\rangle\) to \(|0\rangle\) and \(|1\rangle\) to \(|1\rangle\). It is the equivalent of a NOP.

Pauli Gates

Three of the most common gates are known as the Pauli Gates. These include the Pauli-X Gate, the Pauli-Y Gate, and the Pauli-Z gate. These gates have the following matrices:

$\begin{aligned} X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \end{aligned}$

We will see later on that all three of these gates are special cases of the more generaal Rotation Gates.

Pauli-X Gate (NOT Gate)

We will start with a description of the Pauli-X Gate. To see how this gate changes a qubit's state, and why it is sometimes called the NOT gate, we will multiple the starting qubit's matrix by the Pauli-X Gate matrix (as specified above):

$\begin{aligned} X|0\rangle = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\begin{pmatrix} 1 \\ 0 \end{pmatrix} = \begin{pmatrix} 0 * 1 + 1 * 0 \\ 1 * 1 + 0 * 0 \end{pmatrix} = \begin{pmatrix} 0 \\ 1 \end{pmatrix} \end{aligned}$

The result of apply the Pauli-X gate changes the state of a \(|0\rangle\), \(\begin{pmatrix} 1 \\ 0 \end{pmatrix}\), qubit to \(|1\rangle\), \(\begin{pmatrix} 0 \\ 1 \end{pmatrix}\). That is, it changes a qubit in the ground state into a qubit in the excited state. If the gate was applied to a qubit in the excited state, \(|1\rangle\), instead, the resulting state would be the ground state \(|0\rangle\). This is why the gate is also known as the NOT gate (or the bit-flip gate) because it acts in the same way as the classical NOT gate, by changing the qubit to its opposite. If we recall the Bloch Sphere:

Bloch Sphere.svg
By Glosser.ca - Own work, CC BY-SA 3.0, Link

The X gate performs a rotation around the X-axis of the sphere by \(\pi\) radians and has the property that \(X \longrightarrow X\) and \(Z \longrightarrow -Z\).

Pauli-Y Gate

The Pauli-Y gate, as the name suggests, performs a rotation around the Y-axis of the Bloch Sphere by \(\pi\) radians and has the property that \(X \longrightarrow -X\) and \(Z \longrightarrow -Z\). The gate maps \(|0\rangle\) to \(i|1\rangle\) and \(|1\rangle\) to \(-i|0\rangle\). This can be easily proven by multiplying the qubit matrix by Pauli-Y gate matrix given above.

 

 

 

Pauli-Z Gate (Phase Flip Gate)

Again, like the Pauli-X and Pauli-Y gate, the Pauli-Z gate acts on a single qubit and rotates the qubit around teh Z-axis of the Bloch Sphere by \(\pi\) radians and has the property that \(X \longrightarrow -X\) and \(Z \longrightarrow Z\).

This gate is a special case of the phase shift gate, where \(\theta = \pi\), and is sometimes called the phase-flip gate. It does not change the \(|0\rangle\) state (i.e. \(Z|0\rangle = |0\rangle\)) but it maps \(|1\rangle\) to \(-|1\rangle\).

 

Hadamard Gate

Another common, and important, gate is knownn as the Hadamard Gate. This gate is important because it is used to put a qubit into a superposition (i.e. a mixture of \(|0\rangle\) and \(|1\rangle\)) which we learned in Part I of this series is part of what gives quantum computers their power. The matrix of the Hadamard gate is:

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

This gate is the equivalent of two rotations; a rotation of \(\pi\) radians around the X-axis followed by a rotation of \(\frac{\pi}{2}\) radians around the Y-axis. These two rotations are also equivalent to a rotation of \(\pi\) radians around the axis \((\hat{x} + \hat{z}{)}/\sqrt{2}\).

To see how a Hadamard gate changes a qubits state, we can multiple the \(|0\rangle\)'s matrix by the Hadamard gate matrix given above. The result of this operation is \(\frac{|0\rangle + |1\rangle}{\sqrt{2}}\). This can also be written as \(\frac{1}{\sqrt{2}}|0\rangle + \frac{1}{\sqrt{2}}|1\rangle\) which in matrix form is:

$\begin{aligned} \begin{pmatrix} \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \end{pmatrix} \end{aligned}$

and means that the probability of measuring a \(|0\rangle\) state or a \(|1\rangle\) state is \(50%\). We saw why this is \(50/50\) in Part I under The Qubit section. Also, if you reviewed the Five Key Laws of Quantum Mechanics sidebar in Part I, you will notice that the above matrix is also known as the \(|+\rangle\) state.

If the Hadamard gate is instead applied to a qubit in the \(|1\rangle\) state, the result will be \(\frac{|0\rangle - |1\rangle}{\sqrt{2}}\) instead. This is also known as the \(|-\rangle\) state. The difference in the sign, a \(-\) instead of a \(+\), indicates a difference in phase. However, as we mentioned in Part I under Visualizing a Qubit, the phase factor does not have any physical meaning in of itself. Therefore, a Hadarmard gate applied to a qubit in the \(|1\rangle\) state, results in a qubit state that has an equal probability of being a \(|0\rangle\) or \(|1\rangle\), the same as when the gate is applied to a qubit in the \(|0\rangle\) state.

Applying a Hadamard gate to either a \(|0\rangle\) or \(|1\rangle\) qubit puts the qubit in a state that has an equal probability of being measured as either a \(|0\rangle\) or \(|1\rangle\) (i.e. superposition). However, applying the gate twice in a row puts the qubit into a definite state, which is the state the qubit was in before the first Hadamard gate was applied. That is:

$\begin{aligned} HH|0\rangle = |0\rangle \\ HH|1\rangle = |1\rangle \end{aligned}$

Even though in both cases, after the first gate is applied, the qubit is in a superposition. This can easily be confirmed by multipling the qubit's matrix by the Hadamard matrix and then multiplying the resulting matrix by the Hadamard matrix. This is because multiplying a quantum gate's matrix by itself results in the identity matrix, and any matrix multiplied by the identity matrix is itself (i.e. multiplying a matrix by an identity matrix is similar to multiplying a number by ond). This gate also has the property that \(X \longrightarrow Z\) and \(Z \longrightarrow X\).

Multi-Qubit Gates

Gates that act on single qubits alone, although necessary, are not enough to perform calculations. For that, gates that operate on multiple qubits at the same time are necessary. This section will go over the three most common, multi-qubit gates.

CNOT Gate

The CNOT gate is a controlled NOT gate. This gate operates on two qubits and performs the NOT operation on the second qubit if, and only if, the first qubit is \(|1\rangle\). The control qubit is represented by the dot and the target qubit is represented by circle with the cross inside. In the image to the left, the control qubit is the top line and the target qubit is the bottom line.

As mentioned in the introduction to the quantum gates section of this article, a gate operating on \(n\) qubits is represented by a matrix with a size of \(2^n \times 2^n\). For the CNOT gate, this matrix is:

$\begin{aligned} CNOT = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix} \end{aligned}$

The truth table for the CNOT gate is:

 

Before After
Control Target Control Target
\(|0\rangle\) \(|0\rangle\) \(|0\rangle\) \(|0\rangle\)
\(|0\rangle\) \(|1\rangle\) \(|0\rangle\) \(|1\rangle\)
\(|1\rangle\) \(|0\rangle\) \(|1\rangle\) \(|1\rangle\)
\(|1\rangle\) \(|1\rangle\) \(|1\rangle\) \(|0\rangle\)

 

From this truth table, you can see that the resulting state of the target qubit is the analog of the classical XOR gate. When both inputs are the same the target qubit is \(|0\rangle\), but when the inputs are different the target qubit is \(|1\rangle\). In the case where the control qubit is fixed, either as \(|0\rangle\) or \(|1\rangle\), then the resulting state of the target qubit is the same as applying either the identity gate or the Pauli-X (NOT) gate, respectively.

As we know, qubits can also be in a superposition instead of a definite \(|0\rangle\) or \(|1\rangle\) state. If we have a quantum state which is in a superposition represented by \(a|00\rangle + b|01\rangle + c|10\rangle + d|11\rangle\), then applying the CNOT gate would result in the superposition state represented by \(a|00\rangle + b|01\rangle + c|11\rangle + d|10\rangle\).

SWAP Gate

The SWAP gate does exactly what it sounds like it should do. It swaps two qubits. That means when applying a SWAP gate to two qubits the resulting state is:

$\begin{aligned} |00\rangle \mapsto |00\rangle \\ |01\rangle \mapsto |10\rangle \\ |10\rangle \mapsto |01\rangle \\ |11\rangle \mapsto |00\rangle \\ \end{aligned}$

The matrix for the SWAP gate is:

$\begin{aligned} CNOT = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \end{aligned}$

To apply this gate to the two qubits we need expand the qubit matrix to accommodate two qubits. For example, for a single quibt in the \(|0\rangle\) state, the matrix is \(\begin{pmatrix} 1 \\ 0 \end{pmatrix}\). However two qubits that both in the ground state, \(|00\rangle\), the matrix is:

$\begin{aligned} |00\rangle = \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \end{pmatrix} \end{aligned}$

The three other combinations of possible states for two qubits are also represented by a \(4 \times 1\) matrix. These matrices are:

$\begin{aligned} |00\rangle = \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \end{pmatrix} |01\rangle = \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix} |10\rangle = \begin{pmatrix} 0 \\ 0 \\ 1 \\ 0 \end{pmatrix} |11\rangle = \begin{pmatrix} 0 \\ 0 \\ 0 \\ 1 \end{pmatrix} \end{aligned}$

Using these matrices we can now work out the multiplication to see how the matrix, and therefore the state of the qubit, is changed. Below are two examples, one where the SWAP gate is operates on the \(|11\rangle\) state and one where it operates on the \(|01\rangle\) state.

We will start with the \(|11\rangle\) state, which should end up in the same state after the SWAP gate operates on it:

$\begin{aligned} SWAP|11\rangle = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} 0 \\ 0 \\ 0 \\ 1 \end{pmatrix} = \begin{pmatrix} 1*0+0*0+0*0+0*1 \\ 0*0+0*0+1*0+0*1 \\ 0*0+1*0+0*0+0*1 \\ 0*0+0*0+0*0+1*1 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ 0 \\ 1 \end{pmatrix} = |11\rangle \end{aligned}$

As you can see, the result of the SWAP gate operating on the \(|11\rangle\) state is \(|11\rangle\) which is what we expected. Now lets see what happens when the SWAP gate operates on the \(|01\rangle\) state. The final state should be the matrix representing the \(|10\rangle\)state:

$\begin{aligned} SWAP|01\rangle = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix} = \begin{pmatrix} 1*0+0*1+0*0+0*0 \\ 0*0+0*1+1*0+0*0 \\ 0*0+1*1+0*0+0*0 \\ 0*0+0*1+0*0+1*0 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ 1 \\ 0 \end{pmatrix} = |10\rangle \end{aligned}$

Again we ended up with the results we expected; the two qubit states have been swapped.

Toffoli Gate (CCNOT)

The Toffoli gate is also known as the CCNOT and it is the first gate we are seeing that operates on three qubits. This gate is similar to the CNOT gate; the gate applies the Pauli-X (NOT) gate to the third qubit if both of the first two quibits are in the \(|1\rangle\) state. The matrix for this gate is:

$\begin{aligned} CNOT = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix} \end{aligned}$

The truth table for the Tofolli (CCNOT) gate is:

 

Before After
Control 1 Control 2 Target Control 1 Control 2 Target
\(|0\rangle\) \(|0\rangle\) \(|0\rangle\) \(|0\rangle\) \(|0\rangle\) \(|0\rangle\)
\(|0\rangle\) \(|0\rangle\) \(|1\rangle\) \(|0\rangle\) \(|0\rangle\) \(|1\rangle\)
\(|0\rangle\) \(|1\rangle\) \(|0\rangle\) \(|0\rangle\) \(|1\rangle\) \(|0\rangle\)
\(|0\rangle\) \(|1\rangle\) \(|1\rangle\) \(|0\rangle\) \(|1\rangle\) \(|1\rangle\)
\(|1\rangle\) \(|0\rangle\) \(|0\rangle\) \(|1\rangle\) \(|0\rangle\) \(|0\rangle\)
\(|1\rangle\) \(|0\rangle\) \(|1\rangle\) \(|1\rangle\) \(|0\rangle\) \(|1\rangle\)
\(|1\rangle\) \(|1\rangle\) \(|0\rangle\) \(|1\rangle\) \(|1\rangle\) \(|1\rangle\)
\(|1\rangle\) \(|1\rangle\) \(|1\rangle\) \(|1\rangle\) \(|1\rangle\) \(|0\rangle\)

Other Gates

All the gates in this section are more advanced that the gates already presented. This is because these gates perform more complicated rotations (as visualized on the Bloch Sphere) and some of them (e.g. the Rotation Gates) perform rotations through arbitrary angles. The QX service only provides the \(S\), \(S^\dagger\), \(T\), and \(T^\dagger\) gates from this section. The other gates (e.g. the Fredkin gate, the \(\sqrt{SWAP}\) gate, etc.) are provided here for reference. However, you do not have to know/understand all these gates to be able to use the QX service or build simple quantum circuits. That can be done using the gates that have already been discussed. Therefore, much less detail about these gates will be given, compared to the gates we have already seen, but there are links under the References section in case you would like to research these gates further.

Phase Gates

The four gates presented in this section are all phase gates, meaning that they perform a rotation around the Z-axis. When the qubit is in the \(|0\rangle\) or \(|1\rangle\) state, rotations around the Z-axis don't do much. However, when a qubit is in the \(|+\rangle\) state, a rotation around the Z-axis will flip the state from \(|+\rangle\) to \(|-\rangle\). We will quickly go over the four gates by presenting their individual matrices and how much of a rotation around the Z-axis each gate performs.

\(S\) Gate - \(\sqrt{Z}\)

The \(S\) gate performs a rotation of \(\frac{\pi}{2}\) around the Z-axis. This gate extends the \(H\) gate to make complex superpositions and has the property that \(X \longrightarrow Y\) and \(Z \longrightarrow Z\). The matrix for this gate is:

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

We can see from this matrix why the gate is also known as the \(\sqrt{Z}\). If we multiply the matrix for the \(S\) byitself, we end up the matrix for the \(Z\) gate (\(S^2 = Z\)):

$\begin{aligned} S^2 = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} = \begin{pmatrix} 1*1+0*0 & 1*0+0*i \\ 0*1+i*0 & 0*0+i*i \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & \sqrt{-1}^2 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \end{aligned}$
\(S^\dagger\) Gate - \(\sqrt{Z}^\dagger\)

This gate is the transposed complex conjugate of the \(S\) gate and has the property that \(X \longrightarrow -Y\) and \(Z \longrightarrow Z\). The rotation peformed is the opposite of the \(S\) gate and is \(-\frac{\pi}{2}\) around the Z-axis. The matrix is the same as the \(S\) gate with the opposite sign of the complex numbers (since it is the complex conjugate of the \(S\) gate:

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

Also, since these gates are opposite, apply them one after the other results in the original state. That is:

$\begin{aligned} SS^\dagger|0\rangle = |0\rangle \\ SS^\dagger|1\rangle = |1\rangle \\ \end{aligned}$
\(T\) Gate - \(\sqrt{S}\)

The \(T\) gate performs a rotation of \(\frac{\pi}{4}\) around the Z-axis. The matrix for this gate is:

$\begin{aligned} T = \begin{pmatrix} 1 & 0 \\ 0 & \frac{1+i}{\sqrt{2}} \end{pmatrix} \end{aligned}$

Similar to the \(S\) gate, the \(T\) gate is the same as \(\sqrt{S}\). We can check this by multiplying the matrix for the \(T\) gate by itself:

$\begin{aligned} T^2 = \begin{pmatrix} 1 & 0 \\ 0 & \frac{1+i}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 0 & \frac{1+i}{\sqrt{2}} \end{pmatrix} = \begin{pmatrix} 1*1+0*0 & 1*0+0*\frac{1+i}{\sqrt{2}} \\ 0*1+\frac{1+i}{\sqrt{2}}*0 & 0*0+\frac{1+i}{\sqrt{2}}*\frac{1+i}{\sqrt{2}} \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & (\frac{1+i}{\sqrt{2}})^2 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} \end{aligned}$

Algebra Review

$\begin{aligned} (\frac{1+i}{\sqrt{2}})^2 = \frac{(1+i)(1+i)}{\sqrt{2}\sqrt{2}} = \frac{2i}{2} = i \end{aligned}$

The numerator of the fraction can be simplified using the FOIL method (First, Outer, Inner, Last):

$\begin{aligned} (1+i)(1+i) = 1*1 + 1*i + i*1 + i*i = 1 + 2i +i^2 = 1 + 2i + \sqrt(-1)^2 = 1 + 2i - 1 = 2i \end{aligned}$
\(T^\dagger\) Gate - \(\sqrt{S}^\dagger\)

This gate is the transposed complex conjugate of the \(T\) gate and the rotation performed around the Z-axis is the opposite of the \(T\) gate - \(-\frac{\pi}{4}\). Also like the \(S^\dagger\) gate, applying the \(T\) and \(T^\dagger\) gate one after another, results in the qubit being operated on ending up in the same state that it started in:

$\begin{aligned} TT^\dagger|0\rangle = |0\rangle \\ TT^\dagger|1\rangle = |1\rangle \\ \end{aligned}$

Fredkin Gate (CSWAP)

The Fredkin gate is a three qubit gate which is similar to the CNOT gate, however instead of apply the NOT operation on the target qubit when both control qubit is in the \(|1\rangle\) state, it applys the SWAP operation to the target qubits. This is why you will sometimes see this gate referred to as the CSWAP (Controlled SWAP) gate. The matrix for this gate is:

$\begin{aligned} Fredkin = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix} \end{aligned}$

The truth table for the Fredkin (CSWAP) gate is:

 

Before After
Control Target 1 Target 2 Control Target 1 Target 2
\(|0\rangle\) \(|0\rangle\) \(|0\rangle\) \(|0\rangle\) \(|0\rangle\) \(|0\rangle\)
\(|0\rangle\) \(|0\rangle\) \(|1\rangle\) \(|0\rangle\) \(|0\rangle\) \(|1\rangle\)
\(|0\rangle\) \(|1\rangle\) \(|0\rangle\) \(|0\rangle\) \(|1\rangle\) \(|0\rangle\)
\(|0\rangle\) \(|1\rangle\) \(|1\rangle\) \(|0\rangle\) \(|1\rangle\) \(|1\rangle\)
\(|1\rangle\) \(|0\rangle\) \(|0\rangle\) \(|1\rangle\) \(|0\rangle\) \(|0\rangle\)
\(|1\rangle\) \(|0\rangle\) \(|1\rangle\) \(|1\rangle\) \(|1\rangle\) \(|0\rangle\)
\(|1\rangle\) \(|1\rangle\) \(|0\rangle\) \(|1\rangle\) \(|0\rangle\) \(|1\rangle\)
\(|1\rangle\) \(|1\rangle\) \(|1\rangle\) \(|1\rangle\) \(|1\rangle\) \(|1\rangle\)

\(\sqrt{NOT}\) Gate

This gate acts on a single qubit and is represented by the matrix:

$\begin{aligned} \sqrt{NOT} = \frac{1}{2}\begin{pmatrix} 1+i & 1-i \\ 1-i & 1+i \end{pmatrix} \end{aligned}$

As the name suggests, applying the \(\sqrt{NOT}\) gate twice in a row on a qubit is the same as apply the \(NOT\) gate (i.e. the Pauli-X) gate once - \(\sqrt{NOT}\sqrt{NOT}=NOT\).

This can be proven by multiplying the \(\sqrt{NOT}\) gate matrix by itself.

 

$\begin{aligned} \sqrt{NOT}\sqrt{NOT} = \begin{pmatrix} \frac{1+i}{2} & \frac{1-i}{2} \\ \frac{1-i}{2} & \frac{1+i}{2} \end{pmatrix} \begin{pmatrix} \frac{1+i}{2} & \frac{1-i}{2} \\ \frac{1-i}{2} & \frac{1+i}{2} \end{pmatrix} = \begin{pmatrix} \frac{1+i}{2}*\frac{1+i}{2} + \frac{1-i}{2}*\frac{1-i}{2} & \frac{1+i}{2}*\frac{1-i}{2} + \frac{1-i}{2}*\frac{1+i}{2} \\ \frac{1-i}{2}*\frac{1+i}{2} + \frac{1+i}{2}*\frac{1-i}{2} & \frac{1-i}{2}*\frac{1-i}{2} + \frac{1+i}{2}*\frac{1+i}{2} \end{pmatrix} = \begin{pmatrix} \frac{i}{2}-\frac{i}{2} & \frac{1}{2}+\frac{1}{2} \\ \frac{1}{2}+\frac{1}{2} & -\frac{i}{2}+\frac{i}{2} \end{pmatrix} = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \end{aligned}$

The final matrix is indeed the same as the Pauli-X (NOT) gate.

\(\sqrt{SWAP}\) Gate

This gate acts on two qubits and is represented by the matrix:

$\begin{aligned} \sqrt{SWAP} = \frac{1}{2}\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \frac{1}{2}(1+i) & \frac{1}{2}(1-i) & 0 \\ 0 & \frac{1}{2}(1-i) & \frac{1}{2}(1+i) & 0 \\ 0 & 0 & 0 & 1\end{pmatrix} \end{aligned}$

Similar to the \(\sqrt{NOT}\) gate, if we multiply the matrix for the \(\sqrt{SWAP}\) gate by itself, we will end up with the matrix for the \(SWAP\) gate (i.e. \(\sqrt{SWAP}\sqrt{SWAP}=SWAP\)). Working out this problem to prove that the result is the same matrix as the \(SWAP\) gate isn't difficult, but would take up a lot of space so we won't show it here. However, you can work this out yourself following the same steps as was shown for the \(\sqrt{NOT}\) gate, but using the \(\sqrt{SWAP}\) gate matrix instead.

Rotation Gates

Rotation gates are that do exactly what the name says - they rotate a qubit around a specific axix by a specific angle.

X Rotation Gate

The X Rotation Gate is a combination of rotations around the Y and Z axes. The gate in terms of Y & Z rotations is:

$\begin{aligned} R_x(\theta) = R_z\left(\frac{\pi}{2}\right) \cdot R_y(\theta) \cdot R_z\left(-\frac{\pi}{2}\right) \end{aligned}$

The X Rotation Gate can also be represented by the following gate matrix:

$\begin{aligned} R_x(\theta) = \begin{pmatrix} \cos\left(\frac{\theta}{2}\right) & i\sin\left(\frac{\theta}{2}\right) \\ -i\sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right)\end{pmatrix} \end{aligned}$
Y Rotation Gate

The matrix for the Y Rotation Gate is:

$\begin{aligned} R_y(\theta) = \begin{pmatrix} \cos\left(\frac{\theta}{2}\right) & \sin\left(\frac{\theta}{2}\right) \\ -\sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right)\end{pmatrix} \end{aligned}$
Z Rotation Gate

The matrix for the Z Rotation Gate is:

$\begin{aligned} R_z(\alpha) = \begin{pmatrix} e^{i\alpha/2} & 0 \\ 0 & e^{-i\alpha/2}\end{pmatrix} \end{aligned}$

 

Conclusion

This part presented details regarding the most common, and some uncommon, quantum gates along with their matrix representations and how qubits are affected when the gate is applied to them. With this information, we can begin to construct quantum circuits which can be used to work out problem such as integer factorization. The next part, Part III - Quantum Circuits and OpenQASM, will introduce quantum circuits along with a programming language specifically designed to describe them.

 

References

The following are a list of links for further information. Most, if not all, are contained within the article but are included here for easy reference.

 

History

June 26, 2017: First version

 

Part I: Classical vs. Quantum Computing Part III: Quantum Circuits and OpenQASM

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)