# Introduction

Quantum entanglement is a powerful physical phenomenon where quantum systems interact in a way that they can't be described independently of each other. This anomaly is useful for sending classical information. Superdense coding is a procedure where quantum superposition and entanglement is used to encode two bits of information in one quantum bit. This blog post covers the basics of quantum systems and the mathematical methods used to describe and manipulate them. This post also shows how superdense coding is used to encode and decode bits 01, followed by the execution of a superdense code on a Quantum Virtual Machine (QVM).

## Simple Quantum Systems

The pure state of a two-level quantum system (qubit) is represented by a $2\times1$ matrix \begin{align} \ket{\psi} = \begin{bmatrix} \alpha \\ \beta \\ \end{bmatrix} = \alpha \ket{0} + \beta \ket{1} \end{align} Where $\alpha$ and $\beta$ are complex numbers that represent probability amplitudes and $${|\alpha|}^2 + {|\beta|}^2 =1$$ The spin of an electron is a two-level quantum system where \begin{align} \ket{0} = \begin{bmatrix} 1 \\ 0 \\ \end{bmatrix} \end{align} is spin down and \begin{align} \ket{1} = \begin{bmatrix} 0 \\ 1 \\ \end{bmatrix} \end{align} is spin up.$\\$

## Operators

The state of a quantum system is modfied by applying an operator $\textit{U}$ to it. $\textit{U}$ could be a Pauli-X matrix, \begin{align} X &= \begin{bmatrix} 0 & 1 \\ 1 & 0 \\ \end{bmatrix} \end{align} or a Pauli-Z matrix. \begin{align} Z &= \begin{bmatrix} 1 & 0 \\ 0 & -1 \\ \end{bmatrix} \end{align} It can also be an identity matrix, whose application does not change the system's state. \begin{align} I &= \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ \end{bmatrix} \end{align} Operator application is realized by computing the dot product of the operator and the state. The Pauli-X operator modifies the spin of an electron from up to down and vice versa. \begin{align} \begin{bmatrix} 0 & 1 \\ 1 & 0 \\ \end{bmatrix} . \begin{bmatrix} 1 \\ 0 \\ \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \\ \end{bmatrix} \end{align} The Hadamard operator \begin{align} H &= \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \\ \end{bmatrix} \end{align} puts an electron in an equal superposition of spin up and spin down. \begin{align} \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \\ \end{bmatrix} . \begin{bmatrix} 1 \\ 0 \\ \end{bmatrix} = \begin{bmatrix} \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \\ \end{bmatrix} = \frac{1}{\sqrt{2}} \ket{0} + \frac{1}{\sqrt{2}} \ket{1} \end{align} When this state is measured, there is a ${|\frac{1}{\sqrt{2}}|}^2 = 0.5$ chance that it will be $\ket{0}$ and ${|\frac{1}{\sqrt{2}}|}^2 = 0.5$ chance that it will be $\ket{1}.$

## Quantum Entanglement

The Controlled-NOT operator is applied to entangled systems. It flips the state of the second qubit if the state of the first qubit is 1 and leaves the second qubit unchanged if the first qubit is 0. \begin{align} CNOT &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix} \end{align} The tensor product transforms a 2-level system into a 4-level system before applying the CNOT operator. \begin{align} A \otimes B = \begin{bmatrix} A_{11} \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{bmatrix} & A_{12} \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{bmatrix} \\ A_{21} \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{bmatrix} & A_{22} \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{bmatrix}\\ \end{bmatrix} \end{align} Entangling $\ket{1}$ with $\ket{0}$ and applying CNOT on the resulting state will flip the state of the second qubit. \begin{align} \begin{bmatrix} 0 \\ 1 \\ \end{bmatrix} \otimes \begin{bmatrix} 1 \\ 0 \\ \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ 1 \\ 0\\ \end{bmatrix} = \ket{10} \end{align} \begin{align} CNOT\ket{10} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix}. \begin{bmatrix} 0 \\ 0 \\ 1 \\ 0\\ \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ 0 \\ 1\\ \end{bmatrix} = \ket{11} \end{align}

## Superdense coding

Two bits of information can be encoded into one qubit. Superdense coding is performed by entangling two qubits and encoding two bits by applying an operator on one qubit. Entangled qubits are sent to the receiver who uses a decoder to read the bits that were encoded.
Suppose the sender wants to send bits *01*. He will transform the first qubit into a superposition of states.
\begin{align}
\ket{\psi} = H(\ket{0})= \frac{1}{\sqrt{2}} \ket{0} + \frac{1}{\sqrt{2}} \ket{1} \tag{0}
\end{align}
The sender will entangle this qubit with a second qubit that is spin down.
\begin{align}
\ket{\psi} = CNOT(\frac{1}{\sqrt{2}} \ket{0} + \frac{1}{\sqrt{2}} \ket{1} \otimes \ket{0}) = \frac{1}{\sqrt{2}} \ket{00} + \frac{1}{\sqrt{2}} \ket{11}\tag{1}
\end{align}
The X operator is applied on the first qubit.
\begin{align}
\ket{\psi} = X \otimes I (\frac{1}{\sqrt{2}} \ket{00} + \frac{1}{\sqrt{2}} \ket{11}) = \frac{1}{\sqrt{2}} \ket{01} + \frac{1}{\sqrt{2}} \ket{10}\tag{2}
\end{align}
The reciever will use the first and second qubit to decode *01* that was encoded in the first qubit.
\begin{align}
\ket{\psi} = CNOT(\frac{1}{\sqrt{2}} \ket{01} + \frac{1}{\sqrt{2}} \ket{10}) = \frac{1}{\sqrt{2}} \ket{01} + \frac{1}{\sqrt{2}} \ket{11}\tag{3}
\end{align}
\begin{align}
\ket{\psi} = H \otimes I (\frac{1}{\sqrt{2}} \ket{01} + \frac{1}{\sqrt{2}} \ket{11}\tag{4})= \ket{01}
\end{align}
The X operator is removed to encode *00*. The Z operator is applied in place of X to encode *10*. *11*
is encoded with Z and X.

## Simulation of superdense coding

It's not difficult to write a program simulates superdense coding. A program that consists of instructions we can run on a quantum computer is composed of commands where each line contains an operator and a qubit it's applied to. "H 1" means "Apply the Hadamard operator to qubit 1". A program that encodes and decodes bits *01* could be

` ````
H 0
CNOT 0 1
X 0
CNOT 0 1
H 0
MEASURE 0
MEASURE 1
```

Since we don't have access to a quantum computer, we can run this program on a virtual machine that simulates a quantum computer.
We paste the *01* coding program into a file and execute it on a virtual machine.

` ````
python vm.py python vm.py sd_coding.eg
MEASUREMENT of qubit 0 is 0
MEASUREMENT of qubit 1 is 1
```

## Conclusion

Superdense coding is a glimpse into the possibilities of quantum information. The principle of superposition and entanglement is used to encode two bits of information in one qubit. This technique can be executed on a quantum computer or a QVM.

Discuss on Github

## References

- Wikipedia entry on Superdense coding
- Wikipedia entry on Qubits
- Wikipedia entry on the Tensor product
- Wikipedia entry on Quantum gates