\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{relsize}
\newcounter{lecnum}
\usepackage{graphicx}
\graphicspath{./}
\usepackage{caption}
\usepackage{subcaption}
\newcommand{\abs}[1]{\lvert #1 \rvert}
\newcommand{\lecture}[4]{
   \newpage
   \setcounter{lecnum}{#1}
   \noindent

   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 16cm { {\bf CS761 Derandomization and Pseudorandomness
                        \hfill 2022-23 Sem I} }
       \vspace{4mm}
       \hbox to 16cm { {\Large \hfill Lecture #1: #2  \hfill} }
       \vspace{2mm}
       \hbox to 16cm { {\it Scribe: #4  \hfill  Lecturer: #3} }
      \vspace{2mm}}
   }
   \end{center}
   \vspace*{4mm}
}

\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}

\renewcommand{\b}{\textbf}
\renewcommand{\i}{\textit}
\renewcommand{\t}{\text}
\newcommand{\m}{\mathbb}
\renewcommand{\c}{\mathcal}
\newcommand{\bm}{\boldsymbol}
\newcommand\norm[1]{\left\lVert#1\right\rVert}

\DeclareMathOperator{\Enc}{Enc}


\setlength{\parindent}{0cm}

\begin{document}

\lecture{11}{12/9/22}{Mrinal Kumar}{Amit Kumar Mallik}

\section{Reed Solomon Codes}

A code where codewords are picked at random turns out to be a good with high probability. 
However, for applications, we need explicit constructions. Reed Solomon codes is one such construction. 

We denote Reed Solomon codes as $RS(k,n)$ for some integers $k\leq n$, defined as follows. 

Let $\m{F}$ be a field with $ \abs{\m{F}} \geqslant n$.  We view the messages as coming from the set
\[Msg := \{g(x)\in \m{F}[x] \mid  deg(g)\leqslant k-1\}\]
%
Thus, $\abs{Msg}= \abs{\m{F}}^k$.

Pick some distinct $\alpha_1,\alpha_2,\dots,\alpha_n \in \m{F}$.
Encoding of a message is given as 
\[\Enc(g)=(g(\alpha_1),g(\alpha_2),\dots g(\alpha_n))\in \m{F}^n.\]
The encodings are called codewords of the code. 

Let $g(x)=g_0+g_1x+g_2x^2+\dots g_{k-1}x^{k-1}$. Observe that $\Enc(g)$  can also be written as a matrix-vector product as follows
\[\Enc(g)=\begin{bmatrix}1 & \alpha_1 & \alpha_1^2 & \dots & \alpha_1^{k-1}\\
                        1 & \alpha_2 & \alpha_2^2 & \dots & \alpha_1^{k-1}\\
                        \vdots & \vdots & \vdots & \ddots & \vdots \\
                        1 & \alpha_n & \alpha_n^2 & \dots & \alpha_n^{k-1}
\end{bmatrix}
\begin{bmatrix} g_0 \\ g_1 \\ \vdots \\ g_{k-1}
\end{bmatrix}\]

\textbf{Notation.} For any two codewords $r, s \in \m{F}^n$ in the code the distance between them $\Delta(r,s)$ is the number of positions in which they differ, i.e.,
\[\Delta(r,s) = \abs{\{i : r_i \neq s_i\}}.\]
The normalized distance $\delta$ of a code is the minimum distance between any two codewords divided by $n$. 

We now discuss some properties of $RS(k,n)$.

\subsection{Properties}

\begin{enumerate}
    \item \b{Linear Code}\\
    Observe that $\Enc(g+h)=\Enc(g)+\Enc(h)$.
    \item \b{Rate}\\
    $Rate=\dfrac{\log_{|\m{F}|} |Msg|}{n}=\dfrac{k}{n}$
    \item \b{Minimum Distance}
    Observe that $g(\alpha_i)=h(\alpha_i) \iff  (g-h)(\alpha_i)=0$. But, $g-h$ is a polynomial of degree at most $k-1$ and thus has at most $k-1$ roots. So, $\Enc(g)$ and $\Enc(h)$ can match at at most $k-1$ position. Thus, for all $g,h$ $\Delta(\Enc(g),\Enc(h))\geqslant n-k+1 \implies \delta \geqslant \dfrac{n-k+1}{n}$
\end{enumerate}
% 1. Linear code
% 2. Rate = k/n
% 3. Distance >= (n-k+1)/n
% if g(alpha1)=h(alpha1) then (g-h)(alpha1)=0

% For all fields, a deg d polynomial with coeffcients in F can have at most d distinct roots.

Thus, RS codes match the Singleton bound, which implies that 
 $\delta\leqslant \dfrac{n-k+1}{n}$.

Note that all the above properties do not depend on the choice of $\alpha_i's$.

\subsection{Decoding algortithms}
Let $r=(r_1,r_2,\dots ,r_n)\in \m{F}^n$ be the received message. 
We want to find an RS codeword $c$ s.t. $\Delta(c,r)<(n-k+1)/2$ if it exists or say no. We will discuss the Welch Berlekamp algorithm. This algortihm is described in two steps.

% Input (alphai,ri)
\b{Step 1} :  Find a non-zero polynomial $Q(x,y)=A(x)+yB(x)$  s.t. \begin{enumerate}
    \item $\deg(A)<(n+k)/2:=D$
    \item $\deg(B)<(n-k+2)/2:=d$
    \item $Q(\alpha_i,r_i)=0$ for all $1\leq i \leq n$
\end{enumerate}
% 1.  2.  3. 

\b{Step 2} : Set $g(x)=-\dfrac{A(x)}{B(x)}$. If $h$ is a polynomial of degree at most $k-1$ and the $\Delta(\Enc(g),r)<(n-k+1)/2$ then output $g$ else say no.

Let's first discuss how to do step 1. Observe that $Q$ can be written as 

\[Q(x,y)=A_0+A_1x+A_2x^2+\dots +A_{D-1}x^{D-1}+B_0y+B_1xy+B_2x^2y+\dots +B_{d-1}x^{d-1}\]
% How to do step1
% A=A0+A1x+... Ad-1x^D-1
% B=.... Bd-1x^D-1

Observe that $D+d>n$. Now, $Q(\alpha_i,r_i)=0$ for all $i$ gives $n$ equations in $D+d>n$ variables.
 Thus, it has a non-trivial solution which can be found  using Gaussian Elimination. 
% n equations in D+d variables.
% If D+d>n then we will have a non-zero solution.
Then we check if $-A(x)/B(x)$ is a polynomial satisfying the above conditions and output accordingly.
We will now argue the algorithm's correctness.

\subsection{Correctness}

Observe that if the algorithm outputs something, it is correct! This is true as we are checking for all the desired conditions in the final step. We thus want to argue that if there is a polynomial $h$ satisfying the desired conditions, then the algorithm outputs it.
\begin{claim}
If there exists a polynomial $h(x)$ with $\deg(h)\leqslant k-1$ such that $\Delta(\Enc(h),r)<(n-k+1)/2$, then the algorithm outputs it.
\end{claim}
\begin{proof}
Let $Q$ be a poly satisfying the constraints be some output of step 1. 
Consider 
\[U(x)=Q(x,h(x))=A(x)+h(x)B(x).\]
%with $\deg(h)\leqslant k-1$.

Observe that 
\begin{enumerate}
    \item $\deg(U)\leqslant\max(D-1,(k-1)+(d-1))=\dfrac{n+k-2}{2}$ and
    \item for any $1\leq i \leq n$,  $ \left( h(\alpha_i)=r_i\implies U(\alpha_i)=0 \right)$.
\end{enumerate}

Thus, the number of zeros of $U$ is at least the number of agreements between $r$ and $\Enc(h)$. So, if the number of agreements of $\Enc(h)$ and $r$ is at least $\deg(U)$ then $U\equiv 0$.
We know that $\Delta(\Enc(h),r)<(n-k+1)/2$, and hence, the number of agreements between $r$ and $\Enc(h)$ is more than $(n+k-1)/2$, which is more than $\deg(U)$.
%But the number of errors we want to tolerate is $\dfrac{(n-k+1)}{2}$.
 %That gives at least $\dfrac{(n+k-1)}{2}>deg(U)$ agreements between $g$ and $r$. 
 Thus, $U\equiv 0$ and hence $g(x)=-\dfrac{A(x)}{B(x)}=h(x)$ is a polynomial of degree at most $k-1$ and will be output.
\end{proof}
\subsection{Going beyond minimum distance}

In the next class, we will look at decoding RS codes beyond the half distance limit. Unfortunately, in this scenario, uniqueness of such a codeword is not guaranteed. So, we need to define precisely as to what do we want the algorithm to do. One way is to ask the algorithm to output any code that satisfies the constraints. Other possibility is to ask the algorithm to output every codeword that satisfies the constraints. This, is called ``List Decoding" (as opposed to Unique Decoding). We must ensure that the output list is of polynomial size. That is guaranteed by Johnson's theorem.

\b{Johnson's Theorem :}\\
Let $C\subseteq \m{F}^n$ be a code with minimum distance $\Delta$, then for all $r \in \m{F}^n$, all the words in $C$ within distance $n-\sqrt{n(n-\Delta)}$ is at most $poly(n)$.

Observe that for RS codes, $\Delta=n-k+1$. Take $k\approx 0.01n$. We then get, $n-\sqrt{n(n-\Delta)}\approx n-\sqrt{nk}\approx 0.9n$.




\end{document}
