\section{Error Correction}

Error detection is helpful, but we'd also like to fix errors when we find them. One example of such a system is the QR code, which remains readable even if a significant amount of it is removed. QR codes with icons inside aren't special--they're just missing their central elements. The error-correcting codes in the QR specification allow us to recover the lost data.
\begin{figure}[h]
	\centering
	\includegraphics[width = 3cm]{qr}
\end{figure}

\definition{Repeating codes}
The simplest possible error-correcting code is a \say{repeating code}. It works just as you'd expect: \\
Instead of sending data once, it sends multiple copies. If a few bits are damaged, they can be both detected and repaired. \\

For example, consider the following three-repeat code encoding the binary string $101$:

$$
 111~000~111
$$

If we flip any one bit, we can easily find and fix the error.

\definition{Code Efficiency}
The efficiency of an error-correcting code is calculated as follows:
$$
\frac{\text{number of data bits}}{\text{total bits sent}}
$$

For example, the efficiency of the three-repeat code above is $\frac{3}{9} = \frac{1}{3} \approx 0.33$

\problem{}
What is the efficiency of an $k$-repeat code?

\vfill

\problem{}
How many repeated digits do you need to...
\begin{itemize}
	\item[-] detect a transposition error?
	\item[-] correct a transposition error?
\end{itemize}

\vfill
\pagebreak

\definition{Hamming's Square Code}

A more effective coding scheme comes in the form of Hamming's square code.
Take a four-bit message and arrange it in a $2 \times 2$ square. \\

Compute the pairity of each row and write it at the right. \\
Compute the pairity of each column and write it at the bottom. \\
Finally, compute the pairity of the entire message write it in the lower right corner.

\vspace{3mm}

Reading the result row by row to get the encoded message. \\
For example, the message 1011 generates the sequence 101110011:

$$
1011
\longrightarrow
\begin{array}{cc|}
	1 & 0 \\
	1 & 1 \\
	\hline
\end{array}
\longrightarrow
\begin{array}{cc|c}
	1 & 0 & 1 \\
	1 & 1 & 0 \\ \hline
	0 & 1 &
\end{array}
\longrightarrow
\begin{array}{cc|c}
	1 & 0 & 1 \\
	1 & 1 & 0 \\ \hline
	0 & 1 & 1
\end{array}
\longrightarrow
101110011
$$

\problem{}
The following message are encoded using the method above.
Find and correct any single-digit or transposition errors.
\begin{enumerate}
	\item \texttt{110 110 011} %101110011
	\item \texttt{100 101 011} %110101011
	\item \texttt{001 010 110} %000110110
\end{enumerate}

\begin{solution}
	\begin{enumerate}
		\item \texttt{101 110 011} or \texttt{110 101 011}
		\item \texttt{110 101 011}
		\item \texttt{000 110 110}
	\end{enumerate}
\end{solution}

\vfill

\problem{}
What is the efficiency of this coding scheme?

\vfill

\problem{}
Can we correct a single-digit error in the encoded message? \\
Can we correct a transposition error in the encoded message?

\vfill

\problem{}
Let's generalize this coding scheme to a non-square table: \\
Given a message of length $ab$, construct a rectangle with dimensions $a \times b$ as described above.
\begin{itemize}
	\item What is the efficiency of a $a \times b$ rectangle code?
	\item Can the $a \times b$ rectangle code detect and fix single-bit errors?
	\item Can the $a \times b$ rectangle code detect and fix two-bit errors?
\end{itemize}

\vfill
\pagebreak
