# The binary field#

On computer systems, information is typically represented, stored and processed in the form of 0s and 1s. Which is why, when we were studying the repetition code, we assumed that the information Alice meant to send was in the form of a string of bits.

At one point, we said that the corrupted codeword $\vec{\tilde{c}} = \vec{m} + \vec{e}$. What does it mean to add two strings of bits? In the following, we will discuss this in more detail, as a precursor to our study of both classical and quantum error-correcting codes. We will also figure out how to do this sort of mathematics in python.

## What is the binary field?#

In the binary field, there are only two numbers $\set{0,1}$. To do anything useful with them, we need to define their addition and multiplication. The rules for addition are summarized in the following table.

+ 0 1
0 0 1
1 1 0

Out of the four rules, the one in the bottom right corner is the most interesting one, $1+1 = 0$.

Similarly, the rules of multiplication are as follows. They are pretty straightforward and not different from the rules we use to multiply real numbers or integers.

$\times$ 0 1
0 0 0
1 0 1

What is important about the two sets of rules is that they always ensure that the addition or multiplication of two numbers never yields anything besides $\set{0,1}$.

The binary field is labelled $\mathbb{F}_2$.

## Linear algebra over $\mathbb{F}_2$#

Classical error-correcting codes are defined using vector fields over the binary field. This means that any vectors and matrices we will encounter will have their elements coming from the binary field. When we do any matrix algebra, we will have to apply the addition and multiplication rules of binary field.

For example, let us take the two-dimensional vector space over the binary field. Define $$\vec{v} = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \quad \vec{w} = \begin{pmatrix} 1 \\ 1 \end{pmatrix}.$$ Then $$\vec{v} + \vec{w} = \begin{pmatrix} 0 \\ 1 \end{pmatrix}$$

Now, also define $$M = \begin{pmatrix} 1 & 0 \\ 1 & 1 \end{pmatrix}.$$ Then, $$M\vec{w} = \begin{pmatrix} 1\times 1 + 0 \times 1 \\ 1 \times 1 + 1 \times 1\end{pmatrix} = \begin{pmatrix} 1 \\ 0\end{pmatrix}.$$

Finally, we will use the following notation.

A $m$-dimensional vector space over the binary field is labelled as $\mathbb{F}^m_2$.

Question: Let $\vec{m} = \begin{pmatrix} 1 & 1 & 1 & 0 & 0 & 0 \end{pmatrix}$ and $\vec{e} = \begin{pmatrix} 0 & 0 & 1 & 0 & 0 & 1 \end{pmatrix}$. What is the corrupted codeword $\vec{\tilde{c}}$?

## Working with $\mathbb{F}_2^m$ in python#

The following is some example code that will help you understand how to work with binary vectors and matrices in python. There are only two things you have to do.

• Specify dtype=int for any numpy arrays you use.
• For every operation, use modulus 2. This is done via % 2 in python.
import numpy as np

print('(1 + 1) % 2 = ', (1 + 1) % 2)
print('')

# declare your vectors and matrices as numpy.array
# with a data-type of int, rather than the default
# type of float
M = np.array([[1, 0], [1,1]], dtype=int)
v = np.array([1, 1], dtype=int)
print('M = \n', M)
print('')

# if you add things as
print('M + M =\n', M+M, 'incorrect! 2 is not part of our number system.')
# you will get the wrong answer. '2' is not part of our number system.

print('')
# Instead mod everything 2. This is done with '% 2' in python
print('(M + M) % 2 =\n', (M+M) % 2, 'correct')
# The parenthesis in (M+M) % 2 are important

print('')
print('v = ', v)
# Remember that in numpy matrix multiplication is done using the @ symbol
print('M@v = ', M@v, 'incorrect')
print('M@v % 2 = ', M@v % 2, 'correct')
(1 + 1) % 2 =  0

M =
[[1 0]
[1 1]]

M + M =
[[2 0]
[2 2]] incorrect! 2 is not part of our number system.

(M + M) % 2 =
[[0 0]
[0 0]] correct

v =  [1 1]
M@v =  [1 2] incorrect
M@v % 2 =  [1 0] correct