# 4. Quantum computation

Quantum computation is a new way of doing computation which differs from the classical way. Classical computations can be implemented in several ways, the most successful one today is the circuit model of computation. This is how elements in modern computers are designed. In the circuit model, a computation is made by taking a string of bits as inputs, doing certain operations on them and giving a new string of bits as output. In the current paradigm, these operations are logical operations that follow Boole's logic. It was proved that one needs to be able to carry out a limited set of operation (namely "NOT gate", and "AND gate") in order to implement any operation (addition, multiplication, division, ... ) by a combination of operation from this set. This fundamental set of gates is called an "elementary set of gates" and is all that is required to be able to do any computation. Similarly to classical computation, quantum computation can be done using the circuit model of computation. In this case, bits are replaced by qubits and logic gates must be substituted with quantum gates which can operate on qubits while keeping intact their special quantum properties. Quantum circuits must be reversible due to the reversibility inherent in the laws of quantum mechanics. 
A reversible circuit allows you to run the computation backwards and retrieve the inputs given the outputs. Classical computation can also be implemented using reversible gates but there are disadvantages with regards to the circuit size and complexity. Thus, modern computer are built with "irreversible" logic (which means it's impossible to run the computation backwards, see truth table of the "AND" gate for example) and this is the reason why the generate heat! In order to have reversible quantum gates, one must implement these gates using, what is called a "unitary operation", that is an operation which preserve the sum of the probabilities of seeing each of the measurable values of the qubits. Although, the probability of seeing any single outcome can change, their sum will always add up to one.


## 4.1 The qubit


In quantum computation the objects of the computation are quantum objects called qubits. Similarly to bits, when qubits are measured they can only take two values: $\lvert 0 \rangle$, $\lvert 1 \rangle $.
Where the brackets around the number points to the fact that these are quantum objects (see Dirac's notation). 
In linear algebra representation, the state of a qubit is a vector in a two-dimensional Hilbert space. One of the possible basis for this space is the so-called computational basis which is formed by the eigenvector of the Pauli Z matrix (more details below), the $\lvert 0 \rangle$ and $\lvert 1 \rangle $ states. In matrix form, they can be written as

$$
 \lvert 0 \rangle = 
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} 
$$

$$
 \lvert 1 \rangle = 
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} 
$$

A generic vector $\lvert \psi \rangle $ in the Hilbert space can then be constructed as a linear combination of the basis vectors

$$
 \lvert \psi \rangle =  \alpha \lvert 0 \rangle + \beta \lvert 1 \rangle = 
        \begin{pmatrix}
        \alpha \\
        \beta 
        \end{pmatrix} 
$$

where $\alpha$ and $\beta$ are two complex numbers.


### Superposition

Differently from the regular bits stored in a computer, which can either take the value of $"0"$ or $"1"$, during a computation qubits can be in a state $\lvert \psi \rangle$ which is a superposition of $\lvert 0 \rangle$ and $\lvert 1 \rangle$: 

\begin{equation}
\lvert \psi \rangle = \alpha \lvert 0 \rangle + \beta \lvert 1 \rangle ,
\end{equation}


where $\alpha$ and $\beta$ are related to the probability of obtaining the corresponding outcome $\lvert 0 \rangle$ or $\lvert 1 \rangle$ when the qubit is measured to learn its value.

\begin{eqnarray}
\text{P}(\text{qubit state} = 0) = \lvert \alpha \rvert^{2} \\ \notag
\text{P}(\text{qubit state} = 1) = \lvert \beta \rvert^{2} 
\end{eqnarray}

Which means that the value of the qubit is not determined until it is measured. This is a counter-intuitive property of quantum mechanical objects. A qubit in a superposition of different states will behave as if it possess properties of all the states in the superposition. However, when measured, the qubit will be in one of the states of the superposition, with a probability given by the modulo square of the coefficient of the corresponding state.


### Multi-qubit state

In quantum computation, one is generally interested in doing operations on a qubit register which contains a collection of qubits. To denote the state of an $n$ qubit register, one of the following equivalent notations is used:

\begin{equation}
\lvert 0 \rangle_1 \otimes  \lvert 1 \rangle_2 \otimes ...  \otimes \lvert 0 \rangle_n \equiv \lvert 0, 1, ..., 0 \rangle \equiv \lvert 01...0 \rangle
\end{equation}

Where each of the zeros or ones correspond to the state of one of the qubit in the register and the index counts the qubit's number. The linear algebra meaning of all these notations (although less and less explicit going from left to right) is that the Hilbert space containing the state of the multi-qubit system is a tensor product $\otimes$ of the Hilbert spaces of the single qubits and the state of the system is a Dirac ket vector in this tensor product space. That is, the state of the system is a tensor product of the state of the single qubits. So, if the Hilbert space of one qubit has dimension $2$, the Hilbert space of an $n$-qubit register has dimension $2^n$  

As an example, let us consider the case of $n=2$ qubits. The matrix form of the basis of the 4-dimensional Hilbert space is given by the tensor product of the basis vectors of each of the single qubit spaces.
From the definition of tensor product between vectors given in Chapter 2, we have

$$
 \lvert 00 \rangle = 
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} \otimes
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} = 
        \begin{pmatrix}
        1 \cdot 1 \\
        1 \cdot 0 \\
        0 \cdot 1 \\
        0 \cdot 0 
        \end{pmatrix} = 
        \begin{pmatrix}
        1 \\
        0 \\
        0 \\
        0
        \end{pmatrix}
$$

$$
 \lvert 01 \rangle = 
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} \otimes
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} = 
        \begin{pmatrix}
        1 \cdot 0 \\
        1 \cdot 1 \\
        0 \cdot 0 \\
        0 \cdot 1 
        \end{pmatrix} = 
        \begin{pmatrix}
        0 \\
        1 \\
        0 \\
        0
        \end{pmatrix}
$$

$$
 \lvert 10 \rangle = 
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} \otimes
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} = 
        \begin{pmatrix}
        0 \cdot 1 \\
        0 \cdot 0 \\
        1 \cdot 1 \\
        1 \cdot 0 
        \end{pmatrix} = 
        \begin{pmatrix}
        0 \\
        0 \\
        1 \\
        0
        \end{pmatrix}
$$

$$
 \lvert 11 \rangle = 
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} \otimes
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} = 
        \begin{pmatrix}
        0 \cdot 0 \\
        0 \cdot 1 \\
        1 \cdot 0 \\
        1 \cdot 1
        \end{pmatrix} = 
        \begin{pmatrix}
        0 \\
        0 \\
        0 \\
        1
        \end{pmatrix}
$$

The extension to $n$ qubits is then straightforward, although tedious.

### Entanglement

Another interesting property of qubits, which departs from the classical world, is that they can be entangled. If qubits are entangled with each other, the value taken by each of them is strictly related to the value taken by the other. The correlations between the values of entangled qubits is so strong that it cannot be described by classical probability theory. This is one of the most peculiar features of quantum mechanics.
In a way, entangled qubits lose their identity as individual objects, as their properties now depend on the properties of the other qubits with which they are entangled. It's not possible to separate an entangled system in independent parts and it must be treated as a new unit (in quantum mechanical terms, the state of the whole system is not separable, it cannot be factorized as product state of the state of individual systems).
To see the difference between an entangled state and a non-entangle state, consider the following two possibilities for a two-qubit state:
<ol>
    <li> $\frac{1}{\sqrt{2}} \left( \lvert 0 \rangle_1 \otimes \lvert 0 \rangle_2 \right) +  \frac{1}{\sqrt{2}} \left( \lvert 0 \rangle_1 \otimes \lvert 1 \rangle_2 \right) $ </li>
    
    <li> $\frac{1}{2} \left( \lvert 0 \rangle_1 \otimes \lvert 0 \rangle_2 \right) + \frac{1}{2} \left( \lvert 1 \rangle_1 \otimes \lvert 1 \rangle_2 \right)$ </li> 
</ol>

The state shown in 1. can be manipulated so that it will look like the tensor product of the state of the first qubit and the state of the second qubit. In fact, we can rewrite 1. as: $ \lvert 0 \rangle_1 \otimes \frac{1}{\sqrt{2}} \left( \lvert 0 \rangle_2 + \lvert 1 \rangle_2 \right) $. Thus, we can say that the first qubit is in the state $\lvert 0 \rangle_1$ and the second qubit is in an equal superposition of $\lvert 0 \rangle_2$ and $\lvert 1 \rangle_2$.
The same procedure cannot be done on the two-qubit state shown in 2. which cannot be manipulated so that the two-qubit state looks like a tensor product of the state of the first qubit and the state of the second qubit. Therefore, one cannot say anything about the state of a single qubit in state 2. but one has always to talk about the joint state of the two qubits. If one of them has value $"0"$ the other one will have value $"0"$ as well, and if one qubit has value $"1"$, the other qubit will have value $"1"$ too. This purely quantum correlation between the states of a system is what is called quantum entanglement.   

## 4.2 Quantum gates


Quantum gates implement operations on qubits by keeping intact their quantum properties. They correspond to operators acting on the qubit register. Furthermore, they allow some of those properties to arise, for example by putting qubits in a superposition of states or entangling them with each other.
It was shown that, similarly to the classical case, it is only really necessary to be able to perform a finite set of quantum gates on the qubits to implement any possible operation on them by combining these particular quantum gates. The minimum set of quantum gates needed for computation is then called a "universal set of quantum gates". 

Let's see some quantum gates:

### 4.2.1 One-qubit gates

These gates act on one of the qubits in the qubit register, leaving all other qubits unaffected.

#### Identity gate
The identity gate I leaves the state of a qubit unchanged. In matrix form this is just the identity matrix in a two-dimensional vector space


$$\text{1. Identity gate.}$$

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

and its action on the state of a qubit is

$$
    \hat{I} \lvert 0 \rangle = 
        \begin{pmatrix}
        1 & 0\\
        0 & 1
        \end{pmatrix}
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} =
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} = \lvert 0 \rangle
$$

$$
    \hat{I} \lvert 1 \rangle = 
        \begin{pmatrix}
        1 & 0\\
        0 & 1
        \end{pmatrix}
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} =
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} = \lvert 1 \rangle
$$

#### Pauli X gate
The X gate flips the state of a qubit from $\lvert 0 \rangle \rightarrow \lvert 1 \rangle $ and $\lvert 1 \rangle \rightarrow \lvert 0 \rangle $. It is the quantum analog of the NOT gate and it is sometimes referred to as the "bit-flip gate". When considering the Bloch sphere representation of a qubit, the X gate correspond to a $\pi$ rotation around the y-axis. 


$$\text{2. X gate.}$$


In matrix representation, the X gate is

$$
    \hat{X}  = 
        \begin{pmatrix}
        0 & 1\\
        1 & 0
        \end{pmatrix}
$$

Its action on a qubit is 

$$
    \hat{X} \lvert 0 \rangle = 
        \begin{pmatrix}
        0 & 1\\
        1 & 0
        \end{pmatrix}
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} =
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} = \lvert 1 \rangle
$$

$$
    \hat{X} \lvert 1 \rangle = 
        \begin{pmatrix}
        0 & 1\\
        1 & 0
        \end{pmatrix}
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} =
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} = \lvert 0 \rangle
$$



#### Pauli Z gate
The Z gate flips the phase of a qubit if it is in the $\lvert 1 \rangle$ state. This correspond to a $\pi$ rotation around the z-axis.


$$\text{3. Z gate.}$$

In matrix representation, the Z gate is

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

The effect on the state of a qubit is

$$
    \hat{Z} \lvert 0 \rangle = 
        \begin{pmatrix}
        1 & 0\\
        0 & -1
        \end{pmatrix}
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} =
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} = \lvert 0 \rangle
$$

$$
    \hat{Z} \lvert 1 \rangle = 
        \begin{pmatrix}
        1 & 0\\
        0 & -1
        \end{pmatrix}
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} =
        \begin{pmatrix}
        0 \\
        -1 
        \end{pmatrix} = - \lvert 1 \rangle
$$

#### Pauli Y gate
The Y gate flips the state of a qubit and its phase and is sometimes called the " bit- and phase-flip gate". 


$$\text{4. Y gate.}$$

The definition of the Y gate in matrix form is

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

The effect of the Y gate on the state of a qubit is

$$
    \hat{Y} \lvert 0 \rangle = 
        \begin{pmatrix}
        0 & -i\\
        i & 0
        \end{pmatrix}
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} =
        \begin{pmatrix}
        0 \\
        i 
        \end{pmatrix} = i \lvert 1 \rangle
$$

$$
    \hat{Y} \lvert 1 \rangle = 
        \begin{pmatrix}
        0 & -i\\
        i & 0
        \end{pmatrix}
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} =
        \begin{pmatrix}
        -i \\
        0 
        \end{pmatrix} = -i \lvert 0 \rangle
$$

As the name of the Y gate suggest, the Y gate itself is not an independent gate but it is the combination of the X and Z gate. In particular, let us consider

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



#### Hadamard gate
The Hadamard gate H puts a qubit in an equal superposition of $\lvert 0 \rangle$ and $\lvert 1 \rangle$. 


$$\text{5. Hadamard gate.}$$

Its matrix representation is

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

Acting with the Hadamard gate on a qubit gives

$$
    \hat{H} \lvert 0 \rangle = 
        \frac{1}{\sqrt{2}}
        \begin{pmatrix}
        1 & 1\\
        1 & -1
        \end{pmatrix}
        \begin{pmatrix}
        1 \\
        0 
        \end{pmatrix} =
        \frac{1}{\sqrt{2}} \begin{pmatrix}
        1 \\
        1 
        \end{pmatrix} = \frac{1}{\sqrt{2}} \left( \lvert 0 \rangle + \lvert 1 \rangle \right)
$$

$$
    \hat{H} \lvert 1 \rangle = 
        \frac{1}{\sqrt{2}}
        \begin{pmatrix}
        1 & 1\\
        1 & -1
        \end{pmatrix}
        \begin{pmatrix}
        0 \\
        1 
        \end{pmatrix} =
        \frac{1}{\sqrt{2}} \begin{pmatrix}
        1 \\
        -1 
        \end{pmatrix} = \frac{1}{\sqrt{2}} \left( \lvert 0 \rangle - \lvert 1 \rangle \right)
$$

#### Rotations
Rotations around an axis ($R_x, R_y, R_z$): Rotates qubit state $\lvert \psi \rangle = \alpha \lvert 0 \rangle + \beta \lvert 1 \rangle $, by changing the coefficients $\alpha, \beta$ in a way that depends on the angle of rotation.


$$\text{6. Rotation gate around the $x$, $y$ and $z$ axis.}$$

In matrix form

$$
\hat{R}_x(\theta) = 
\begin{pmatrix}
\cos(\theta/2) & -i\sin(\theta/2)\\
-i\sin(\theta/2) & \cos(\theta/2)
\end{pmatrix}
$$


$$
\hat{R}_y(\theta) = 
\begin{pmatrix}
\cos(\theta/2) & \sin(\theta/2)\\
\sin(\theta/2) & \cos(\theta/2)
\end{pmatrix}
$$


$$
\hat{R}_z(\theta) = 
\begin{pmatrix}
1 & 0 \\
0 & e^{i \theta}
\end{pmatrix}
$$

Their action is

 $$ \hat{R}_x(\theta) \lvert \psi \rangle = 
       \begin{pmatrix}
        \cos(\theta/2) & -i\sin(\theta/2)\\
        -i\sin(\theta/2) & \cos(\theta/2)
        \end{pmatrix}
        \begin{pmatrix}
        \alpha \\
        \beta 
        \end{pmatrix} =
        \begin{pmatrix}
        \cos(\theta/2) \alpha -i\sin(\theta/2) \beta\\
        -i\sin(\theta/2) \alpha + \cos(\theta/2) \beta
        \end{pmatrix} = \left( \cos(\theta/2) \alpha -i\sin(\theta/2) \right) \lvert 0 \rangle + \left( -i\sin(\theta/2) \alpha + \cos(\theta/2) \beta \right)  \lvert 1 \rangle$$
        
$$ \hat{R}_y(\theta) \lvert \psi \rangle = 
       \begin{pmatrix}
        \cos(\theta/2) & \sin(\theta/2)\\
        \sin(\theta/2) & \cos(\theta/2)
        \end{pmatrix}
        \begin{pmatrix}
        \alpha \\
        \beta 
        \end{pmatrix} =
        \begin{pmatrix}
        \cos(\theta/2) \alpha + \sin(\theta/2) \beta\\
        \sin(\theta/2) \alpha + \cos(\theta/2) \beta
        \end{pmatrix} = \left( \cos(\theta/2) \alpha + \sin(\theta/2) \right) \lvert 0 \rangle + \left( \sin(\theta/2) \alpha + \cos(\theta/2) \beta \right)  \lvert 1 \rangle$$
        
        
$$ \hat{R}_z(\theta) \lvert \psi \rangle = 
       \begin{pmatrix}
        1 & 0 \\
        0 & e^{i \theta}
        \end{pmatrix}
        \begin{pmatrix}
        \alpha \\
        \beta 
        \end{pmatrix} =
        \begin{pmatrix}
         \alpha \\
         e^{i \theta} \beta
        \end{pmatrix} = \alpha \lvert 0 \rangle +  e^{i \theta} \beta   \lvert 1 \rangle $$


### 4.2.2 Multi-qubit gates


$$\text{7. Two single-qubit gates. $X$ on the first qubit and $I$ on the second qubit.}$$

If we are dealing with a qubit register that contains more than a single qubit, the operators on the whole register can be obtained by taking the tensor product of the operators acting on each qubit. To avoid lengthy calculations, we work out a few examples for a two-qubit register. We have shown above the form of the basis vector of a two-qubit register. 
As an example, consider the matrix representation of the X gate on the first qubit is

$$
\hat{X} \otimes \hat{I} = 
\begin{pmatrix}
0 & 1 \\
1 & 0 
\end{pmatrix} \otimes
\begin{pmatrix}
1 & 0 \\
0 & 1 
\end{pmatrix} = 
\begin{pmatrix}
0 \cdot 1 & 0 \cdot 0 & 1 \cdot 1 & 1 \cdot 0 \\
0 \cdot 0 & 0 \cdot 1 & 1 \cdot 0 & 1 \cdot 1 \\
1 \cdot 1 & 1 \cdot 0 & 0 \cdot 1 & 0 \cdot 0 \\
1 \cdot 0 & 1 \cdot 1 & 0 \cdot 0 & 0 \cdot 1 
\end{pmatrix} = 
\begin{pmatrix}
0 & 0 & 1 & 0\\
0 & 0 & 0 & 1\\
1 & 0 & 0 & 0\\
0 & 1 & 0 & 0
\end{pmatrix}
$$

The action of this operator on a two-qubit register will be

$$
\left( \hat{X} \otimes \hat{I} \right) \lvert 00 \rangle = 
\begin{pmatrix}
0 & 0 & 1 & 0\\
0 & 0 & 0 & 1\\
1 & 0 & 0 & 0\\
0 & 1 & 0 & 0
\end{pmatrix}
\begin{pmatrix}
1 \\
0\\
0\\
0
\end{pmatrix} = 
\begin{pmatrix}
0 \\
0\\
1\\
0
\end{pmatrix} = 
\lvert 10 \rangle
$$

Exactly as expected. If we now want to combine different type of single qubit gates, acting on the two-qubit register, we only need to calculate the tensor product between these operators to find what is their matrix representation.
 


### 4.2.3 Two-qubit gates

#### Control-NOT gate

The most reknown two-qubit gate is the control-not gate or CNOT (CX) gate. The CX gate flips the state of a qubit (called $target$) conditionally on the state of another qubit (called $control$). 


$$\text{8. CNOT gate. The first qubit is the control and the second is the target.}$$

The matrix representation of the CX gate is the following

$$
\hat{C}X_{12} = 
\begin{pmatrix}
1 & 0 & 0 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 0 & 1\\
0 & 0 & 1 & 0
\end{pmatrix} 
$$

Let us see the effect of acting with the CX gate on a two-qubit register. In the matrix form shown above, the first qubit will be the control qubit and the second qubit will be the target qubit.
If the control qubit is in the state $\lvert 0 \rangle$, nothing is done to the target qubit. If the control qubit is in state $\lvert 1 \rangle$, the X gate (bit-flip) is applied to the target qubit.


$$
\hat{C}X_{12} \lvert 00 \rangle = 
\begin{pmatrix}
1 & 0 & 0 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 0 & 1\\
0 & 0 & 1 & 0
\end{pmatrix}
\begin{pmatrix}
1 \\
0 \\
0 \\
0 
\end{pmatrix} = 
\begin{pmatrix}
1 \\
0 \\
0 \\
0 
\end{pmatrix} = \lvert 00 \rangle
$$

$$
\hat{C}X_{12} \lvert 01 \rangle = 
\begin{pmatrix}
1 & 0 & 0 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 0 & 1\\
0 & 0 & 1 & 0
\end{pmatrix}
\begin{pmatrix}
0 \\
1 \\
0 \\
0 
\end{pmatrix} = 
\begin{pmatrix}
0 \\
1 \\
0 \\
0 
\end{pmatrix} = \lvert 01 \rangle
$$

$$
\hat{C}X_{12} \lvert 10 \rangle = 
\begin{pmatrix}
1 & 0 & 0 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 0 & 1\\
0 & 0 & 1 & 0
\end{pmatrix}
\begin{pmatrix}
0 \\
0 \\
1 \\
0 
\end{pmatrix} = 
\begin{pmatrix}
0 \\
0 \\
0 \\
1 
\end{pmatrix} = \lvert 11 \rangle
$$

$$
\hat{C}X_{12} \lvert 11 \rangle = 
\begin{pmatrix}
1 & 0 & 0 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 0 & 1\\
0 & 0 & 1 & 0
\end{pmatrix}
\begin{pmatrix}
0 \\
0 \\
0 \\
1 
\end{pmatrix} = 
\begin{pmatrix}
0 \\
0 \\
1 \\
0 
\end{pmatrix} = \lvert 10 \rangle
$$

There is also another way to write the action of the CNOT gate in Dirac's notation:

$$\hat{C}X_{12} \lvert x, y \rangle = \lvert x, x \oplus y \rangle  $$

where $x,y= \{ 0,1 \}$. So that:


$$\hat{C}X_{12} \lvert 0, 0 \rangle = \lvert 0, 0 \oplus 0 \rangle = \lvert 0, 0 \rangle  $$

$$\hat{C}X_{12} \lvert 0, 1 \rangle = \lvert 0, 1 \oplus 0 \rangle = \lvert 0, 1 \rangle  $$

$$\hat{C}X_{12} \lvert 1, 0 \rangle = \lvert 0, 0 \oplus 1 \rangle = \lvert 1, 1 \rangle$$

$$\hat{C}X_{12} \lvert 1, 1 \rangle = \lvert 1, 1 \oplus 1 \rangle = \lvert 1, 0 \rangle  $$

## Problems


<ol>

<li>
Consider the generic state of a qubit $\lvert \psi \rangle = \alpha \lvert 0 \rangle + \beta \lvert 1 \rangle  $. Give the values of $\alpha$ and $\beta$ (normalized to $\lvert \alpha \rvert^2 + \lvert \beta \rvert^2 = 1$) to represent the following ket-vectors
<ol>
<li>
$ \lvert 0 \rangle $
</li>

<li>
$ \lvert 1 \rangle $
</li>

<li>
equal superposition of $\lvert 0 \rangle $ and $\lvert 1 \rangle$
</li>
</ol>
</li>


<li>
Find the basis for the Hilbert space of three qubits (it has dimension 8) using the tensor product of the computational basis of the Hilbert space of a qubit. 
</li>


<li>
Given a qubit in the state $\lvert \psi \rangle = \frac{\sqrt{2}}{\sqrt{6}} \lvert 0 \rangle + \frac{\sqrt{4}}{\sqrt{6}} \lvert 1 \rangle$, Calculate:

<ol>
<li>
$ \hat{X} \lvert \psi \rangle $
</li>

<li>
$\hat{Z} \lvert \psi \rangle$
</li>

<li>
$\hat{X} \lvert \psi \rangle$
</li>

<li>
$\hat{Y} \lvert \psi \rangle$
</li>

<li>
$\hat{H} \lvert \psi \rangle$
</li>

</ol>
</li>


<li>
Calculate the following multi-qubit operators in matrix form

<ol>
<li>
$ X \otimes X $
</li>

<li>
$ H \otimes H $
</li>

<li>
$ H \otimes Z $
</li>
</ol>
</li>


<li>
Given a qubit in the state $\lvert \psi \rangle = \frac{\sqrt{2}}{\sqrt{6}} \lvert 00 \rangle + \frac{\sqrt{2}}{\sqrt{6}} \lvert 01 \rangle + \frac{\sqrt{i}}{\sqrt{6}} \lvert 10 \rangle + \frac{\sqrt{1}}{\sqrt{6}} \lvert 11 \rangle$, Calculate $\hat{C}X_{12} \lvert \psi \rangle$, where the first qubit is the control qubit and the second qubit is the target qubit.
</li>


</ol>


## References

[1] R. Feynman, Simulating Physics with Computers, International Journal of Theoretical
Physics, Vol. 21, nos. 6/7, pp. 467{488 (1982).

[2] M. A. Nielsen, and I. L. Chuang, 2000, Quantum Computation
and Quantum Information (Cambridge University Press, Cambridge).

[3] A. Barenco et al., Phys. Rev. A 52, 3457 (1995).

de92bbd45654326d9559fa0df0616f6e61adbaef
ipynb
Jupyter Notebook
4.Quantum computation.ipynb
miamico/IBM-Teach-Me-Quantum
2229f7cccb656aa89ea12be14d8e78ea80115936
Apache-2.0
4.Quantum computation.ipynb
miamico/IBM-Teach-Me-Quantum
2229f7cccb656aa89ea12be14d8e78ea80115936
Apache-2.0
4.Quantum computation.ipynb
miamico/IBM-Teach-Me-Quantum
2229f7cccb656aa89ea12be14d8e78ea80115936
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES