You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

339 lines
12 KiB

  1. \documentclass[a4paper]{article}
  2. \setlength{\parindent}{0em}
  3. \setlength{\parskip}{0.4em}
  4. \usepackage{amsmath}
  5. \usepackage{amsfonts}
  6. \usepackage{amsthm}
  7. \usepackage{enumerate}
  8. \usepackage[bookmarksopen=true,bookmarks=true]{hyperref}
  9. \usepackage{bookmark}
  10. \hypersetup{
  11. pdfborder = {0.1 0.1 0.1},
  12. % colorlinks,
  13. % citecolor=black,
  14. % filecolor=black,
  15. % linkcolor=black,
  16. % urlcolor=blue
  17. }
  18. \usepackage{multicol}
  19. \usepackage{graphicx}
  20. \usepackage{float}
  21. \graphicspath{ {./imgs} }
  22. \usepackage{pgf-umlsd} % diagrams
  23. \usepackage[UKenglish]{datetime}
  24. \newdateformat{DATEMonthYear}{\monthname[\THEMONTH] \THEYEAR}
  25. \newdateformat{DATEYearMonthDay}{\THEYEAR-\THEMONTH-\THEDAY}
  26. \usepackage{booktabs} % \toprule \midrule ...
  27. \theoremstyle{definition}
  28. \newtheorem{definition}{Def}[section]
  29. \newtheorem{theorem}[definition]{Thm}
  30. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  31. \title{Notes on Reed-Solomon codes}
  32. \author{arnaucube}
  33. \date{January 2023}
  34. \begin{document}
  35. \maketitle
  36. \begin{abstract}
  37. Notes taken while reading about Reed-Solomon codes. Usually while reading papers I take handwritten notes, this document contains some of them re-written to $LaTeX$.
  38. The notes are not complete, don't include all the steps neither all the proofs.
  39. \end{abstract}
  40. \tableofcontents
  41. \section{Reed-Solomon Codes overview}
  42. In this section we overview the main ideas presented in the Reed-Solomon paper \cite{reedsolomon} and in Bruce Maggs notes \cite{reedsolomon-bruce}.
  43. Reed-Solomon codes appeared in parallel to the BCH codes, and can be described as nonbinary BCH codes. In this section we will focus only in the Reed-Solomon codes, particularly in the encoding and error detection (not correction).
  44. \emph{tmp-note}: I feel like it is worth to check Galois theory \& BCH codes before going to Reed-Solomon codes, but due time constraints and our main goal being FRI, probably we should skip it.
  45. \subsection{Idea}
  46. Let $p(x) = m_0 + m_1 x + \ldots + m_{k-1} x^{k-1}$, where $m_i \in K$ and $k < 2^n$.
  47. We map $k$-tuples of $K$ into $2^n$-tuples of $K$, where $K=GF(p^r)$.
  48. % Code E maps $k$-tuples of $K$ into $2^n$-tuples of $K$, where $K$ is a field of degree $n$ over the field of two elements $\mathbb{Z}_2$.
  49. $$
  50. k
  51. \begin{cases}
  52. m_0\\
  53. m_1\\
  54. \vdots\\
  55. m_{k-1}
  56. \end{cases}
  57. \in K~~~~
  58. % \stackrel{E}{ \xrightarrow{\hspace*{1cm}} }
  59. \xrightarrow{\hspace*{1cm}}
  60. 2^n
  61. \begin{cases}
  62. p(0)\\
  63. p(\alpha)\\
  64. p(\alpha^2)\\
  65. \vdots\\
  66. p(1)
  67. \end{cases}
  68. \in K
  69. $$
  70. The receiver then, can decode the messages by solving simultaneously any $k$ of the $2^n$ equations
  71. \begin{align*}
  72. p(0) &= m_0\\
  73. p(\alpha) &= m_0 + m_1 \alpha + m_2 \alpha^2 + \ldots + m_{k-1} \alpha^{k-1}\\
  74. p(\alpha^2) &= m_0 + m_1 \alpha^2 + m_2 \alpha^4 + \ldots + m_{k-1} \alpha^{2k-2}\\
  75. &~~~\vdots\\
  76. p(1) &= m_0 + m_1 + m_2 + \ldots + m_{k-1}\\
  77. \end{align*}
  78. This system of equations can be solved, as we can see that any $k$ of the $p(\alpha^j)$ equations are linearly independent since they form a Vandermonde matrix
  79. $$
  80. V =
  81. \begin{pmatrix}
  82. 1 & x_1 & x_1^2 & \ldots & x_1^{k-1} \\
  83. 1 & x_2 & x_2^2 & \ldots & x_2^{k-1} \\
  84. 1 & x_3 & x_3^2 & \ldots & x_3^{k-1} \\
  85. \vdots & \vdots & \vdots & & \vdots\\
  86. 1 & x_n & x_n^2 & \ldots & x_n^{k-1} \\
  87. \end{pmatrix}
  88. $$
  89. and $\det V$ is a Vandermonde determinant and $\det V \neq 0$ as
  90. $$
  91. \det~V = \prod_{j < i} (x_i - x_j)
  92. $$
  93. See Annex \ref{sec:vandermondedet} for a proof of the Vandermonde determinant.
  94. % The number of combinations of taking $k$ elements from $2^n$ elements (without regard of order) can be expressed by $C_k^{2^n} = \binom{2^n}{k} = \frac{(2^n)!}{k!~(2^n - k)!}$.
  95. % This is the number of determinations of $(m_0, \ldots, m_{m-1})$ in case of no errors.
  96. % TODO this part needs to be continued & finished.
  97. \subsection{Real world approach}
  98. In the practical side, instead of transmitting $k+2s$ polynomial evaluations, we send $k$ coefficients + $2s$ evaluations.
  99. This is because we are interested in efficiency in the \emph{common} case, where in most of cases there are no errors and we care more about having a fast check that there are no errors than of the error recovering phase.
  100. Furthermore, in our use case in the context of FRI IOP, we are not interested into decoding but only into detecting errors.
  101. % \subsubsection{The setup}
  102. % We work on $GF(p^r)$. For $\alpha$ being a primitive element of $GF(p^r)$, we set the generator polynomial
  103. %
  104. % $$
  105. % g(x) = (x-\alpha) (x-\alpha^2) \cdots (x-\alpha^{2s-1})
  106. % $$
  107. %
  108. %
  109. % THIS part is not coherent with the 'Encoding' section
  110. % We define
  111. % $$b(x) = x^{2s} \cdot m(x) \pmod{g(x)}$$
  112. %
  113. % thus, for some $q(x)$,
  114. % $$x^{2s} m(x) = q(x) g(x) + b(x)$$
  115. %
  116. % Define the codeword $c(x)$ as
  117. % $$c(x) = x^{2s} \cdot m(x) - b(x)$$
  118. % UNTIL HERE.
  119. % notice that $c(x)=q(x)g(x)$, thus $c(x)$ is a multiple of $g(x)$.
  120. %
  121. % In order to check if a received codeword $c'(x)$ is correct, we'll check its divisibility by $g(x)$. If the check passes, we extract the first $k$ elements of $c'(x)$.
  122. \subsubsection{Encoding}
  123. Let $g(x)$ be the generator polynomial
  124. $$g(x) = (x-\alpha) (x-\alpha^2) \cdots (x-\alpha^{2s-1})$$
  125. with $\alpha$ being a primitive element of $GF(p^r)$.
  126. The \emph{encoder} wants to map the message $\{ m_0, m_1, \ldots, m_{k-1} \}$ into a polynomial $p(x)$ of degree $<k$ such that
  127. $$p(\alpha_i) = m_i ~~ \forall i\in{0, k-1}$$
  128. so we interpolate taking $\{ m_0, m_1, \ldots, m_{k-1} \}$ as the coefficients of $p(x)$ in order to obtain
  129. $$p(x) = m_0 + m_1 \cdot x + \cdots + m_{k-1} x^{k-1}$$
  130. Then the encoder computes $c(x) = p(x) \cdot g(x)$, and will output the coefficients of $c(x)$, $\{ c_i \}^k$.
  131. Notice that $c(x)=q(x)g(x)$, thus $c(x)$ is a multiple of $g(x)$.
  132. \subsubsection{Error checking}
  133. The \emph{receiver} starts from the received coefficients $\{c_i'\}^k$ of $c'(x)$. $c'(x)$ may contain errors, which we represent by $e(x) = e_0 + e_1 x + e_2 x^2 + \ldots + e_{k-1} x^{k-1}$, so $c'(x) = c(x) + e(x)$.
  134. In order to check $c(x)\stackrel{?}{=} c'(x)$ (thus, that there are no errors ($e(x) = 0$)), we will do the divisibility check $g(x) | c'(x)$, which if there are no errors the check should pass. This comes from the fact that we've chosen $c(x)$ to be a multiple of $g(x)$.
  135. If the check passes, we'll extract the first $k$ elements of $c'(x)$.
  136. If $c'(x) / g(x) = 0$, it means that $c'(x)$ is a multiple of $g(x)$, thus $c(x)=c'(x)$, which means that there are no errors.
  137. In practice, checking divisibility by dividing $c'(x)$ by $g(x)$ could be computationally expensive, that's why we do the following approach.
  138. % so we multiply $c(x)$ by some polynomial $d(x)$, and then we check if $g(x)d(x)$ divides the result.
  139. %
  140. % In this way, instead of checking that $c'(x)/g(x) = 0$, we check that
  141. % $$c'(x) = d(x) \cdot g(x) = 0 \pmod{x^n - 1}$$
  142. %
  143. % If $c'(x) / g(x) \neq 0$, means that there are errors, such that
  144. % $$c'(x) = p(x) \cdot g(x) + e(x)$$
  145. \textbf{The check polynomial}
  146. From $g(x) = (x-\alpha) (x-\alpha^2) \cdots (x-\alpha^{2s-1})$, we know that
  147. $$g(x) = \prod_{i=0}^{2s-1} (x - \alpha^i) = x^{2s} - 1$$
  148. a proof for $\prod_{i=0}^{n-1} (x - \alpha^i) = x^n - 1$ can be found in \cite{cyclotomicpolyroots}.
  149. Now, let $g'(x)=\prod_{i=0}^{n-1} (x-\alpha^i)$, which for $n=k +2s$, is equivalent to
  150. $$g'(x) = \prod_{i=0}^{n-1} (x-\alpha^i) = \prod_{i=0}^{2s-1} (x-\alpha^i) ~\cdot \prod_{i=2s-1}^{n-1} (x-\alpha^i)$$
  151. % \begin{align*}
  152. % g'(x) = \prod_{i=0}^{n-1} (x-\alpha^i) =& \prod_{i=0}^{2s-1} (x-\alpha^i) ~\cdot \prod_{i=2s-1}^{n-1} (x-\alpha^i)\\
  153. % =& ~g(x) ~\cdot \prod_{i=2s-1}^{n-1} (x-\alpha^i)
  154. % \end{align*}
  155. where we see clearly that $g'(x)$ is a multiple of $g(x)$, so, we have that $g(x) | g'(x)$, which is the same than saying that
  156. $$g(x) | (x^n-1),~for~2s<n$$
  157. From here, as we know that $c(x)$ is a multiple of $g(x)$, we can see that there is a unique polynomial $h(x)$ of degree $n-2s$ such that
  158. $$g(x) h(x) = x^n - 1$$
  159. So, $h(x) = (x^n -1) / g(x)$, and we can see that
  160. $$h(x) = (x^n -1)/g(x)= \prod_{2s-1}^{n-1} (x - \alpha^i)$$
  161. % $$h(x) = (x^n -1)/g(x)=\frac{x^n -1}{x^{2s} -1} = \frac{\prod_0^{n-1} (x-\alpha^i)}{\prod_0^{2s-1} (x-\alpha^i)}$$
  162. % $$= \frac{\prod_0^{2s-1} (x-\alpha^i) \cdot \prod_{2s-1}^{n-1} (x - \alpha^i)}{\prod_0^{2s-1} (x-\alpha^i)}
  163. % = \prod_{2s-1}^{n-1} (x - \alpha^i)
  164. % $$
  165. The degree of $h(x)$ being $n-2s$ can be seen from the fact that $deg(g(x))=2s$ and $deg(x^n -1)=n$, thus
  166. $$deg(h(x)) = deg((x^n -1)/g(x))=n-2s$$
  167. which is equal to $k$.
  168. The polynomial $h(x)$ receives the \emph{check polynomial} name.
  169. From here, to determine if $c'(x)$ is a valid codeword we check:
  170. $$c'(x) \cdot h(x) = 0 \pmod{x^n - 1}$$
  171. It is common to choose $n = p^r -1$ such as $n=2^8 - 1$, and $k=223$ (\emph{RS(255, 223)}), over $GF(2^8)$.
  172. \newpage
  173. %%%%%% APPENDIX
  174. \appendix
  175. \section{Vandermonde determinant}
  176. \label{sec:vandermondedet}
  177. This section contains a simple proof of the Vandermonde matrix determinant. The proof was found in \cite{vanddetproof}, here it is written with small modifications and expanded. A different proof can be found in \cite{vanddetproof2}.
  178. $$
  179. \det~V(x_1, ..., x_n) = \det
  180. \begin{pmatrix}
  181. 1 & x_1 & x_1^2 & \ldots & x_1^{n-1} \\
  182. 1 & x_2 & x_2^2 & \ldots & x_2^{n-1} \\
  183. 1 & x_3 & x_3^2 & \ldots & x_3^{n-1} \\
  184. \vdots & \vdots & \vdots & & \vdots\\
  185. 1 & x_n & x_n^2 & \ldots & x_n^{n-1} \\
  186. \end{pmatrix}
  187. = \prod_{j < i} (x_i - x_j)
  188. $$
  189. \emph{Proof}
  190. The equation is true for $n = 2$, as we have:
  191. $$
  192. \det~V(x_1, x_2) = \det
  193. \begin{pmatrix}
  194. 1 & x_1\\
  195. 1 & x_2
  196. \end{pmatrix}
  197. = x_2 - x_1
  198. $$
  199. We now assume that $n \ge 3$. Starting with column $n$ and ending at column $2$, we successively apply the following operation: subtract $x_1$ times column $i-1$ from column $i$. The determinant remains the same and the resulting matrix is:
  200. $$
  201. = \det
  202. \begin{pmatrix}
  203. 1 & x_1-(x_1 \cdot 1) & x_1^2 - (x_1 \cdot x_1) & \ldots & x_1^{n-1} - (x_1 \cdot x_1^{n-2}) \\
  204. 1 & x_2-(x_1 \cdot 1) & x_2^2 - (x_1 \cdot x_2) & \ldots & x_2^{n-1} - (x_1 \cdot x_2^{n-2}) \\
  205. 1 & x_3-(x_1 \cdot 1) & x_3^2 - (x_1 \cdot x_3) & \ldots & x_3^{n-1} - (x_1 \cdot x_3^{n-2}) \\
  206. \vdots & \vdots & \vdots & & \vdots\\
  207. 1 & x_n-(x_1 \cdot 1) & x_n^2 - (x_1 \cdot x_n) & \ldots & x_n^{n-1} - (x_1 \cdot x_n^{n-2}) \\
  208. \end{pmatrix}
  209. $$
  210. $$
  211. = \det
  212. \begin{pmatrix}
  213. 1 & 0 & 0 & \ldots & 0 \\
  214. 1 & (x_2 - x_1) & x_2(x_2 - x_1) & \ldots & x_2^{n-2}(x_2 - x_1) \\
  215. 1 & (x_3 - x_1) & x_3(x_3 - x_1) & \ldots & x_3^{n-2}(x_3 - x_1) \\
  216. \vdots & \vdots & \vdots & & \vdots \\
  217. 1 & (x_n - x_1) & x_n(x_n - x_1) & \ldots & x_n^{n-2}(x_n - x_1) \\
  218. \end{pmatrix}
  219. $$
  220. Applying the Laplace expansion along the first row and factoring out the scalar multiples $(x_i - x_1)$ in each column, we obtain:
  221. $$
  222. = \det
  223. \begin{pmatrix}
  224. x_2-x_1 & x_2^2 - x_1 x_2 & x_2^3 - x_1 x_2^2 & \ldots & x_2^{n-1} - x_1 x_2^{n-2} \\
  225. x_3-x_1 & x_3^2 - x_1 x_3 & x_3^3 - x_1 x_3^2 & \ldots & x_3^{n-1} - x_1 x_3^{n-2} \\
  226. \vdots & \vdots & \vdots & & \vdots\\
  227. x_n-x_1 & x_n^2 - x_1 x_n & x_n^3 - x_1 x_n^2 & \ldots & x_n^{n-1} - x_1 x_n^{n-2} \\
  228. \end{pmatrix}
  229. $$
  230. in each row, factor out $(x_i - x_1)$
  231. $$
  232. = \det
  233. \begin{pmatrix}
  234. 1(x_2-x_1) & x_2(x_2 - x_1) & x_2^2(x_2 - x_1) & \ldots & x_2^{n-2}(x_2 - x_1) \\
  235. 1(x_3-x_1) & x_3(x_3 - x_1) & x_3^2(x_3 - x_1) & \ldots & x_3^{n-2}(x_3 - x_1) \\
  236. \vdots & \vdots & \vdots & & \vdots\\
  237. 1(x_n-x_1) & x_n(x_n - x_1) & x_n^2(x_n - x_1) & \ldots & x_n^{n-2}(x_n - x_1) \\
  238. \end{pmatrix}
  239. $$
  240. $$
  241. = \prod_{2 \leq i \leq n} (x_i - x_1) ~~\det
  242. \begin{pmatrix}
  243. 1 & x_2 & x_2^2 & \ldots & x_2^{n-2} \\
  244. 1 & x_3 & x_3^2 & \ldots & x_3^{n-2} \\
  245. \vdots & \vdots & \vdots & & \vdots\\
  246. 1 & x_n & x_n^2 & \ldots & x_n^{n-2} \\
  247. \end{pmatrix}
  248. $$
  249. now, by induction
  250. $$
  251. = \prod_{i=2}^n (x_i - x_1) ~~\cdot \prod_{2 \leq j < i \leq n} (x_i - x_j) ~~= \prod_{1 \leq j < i \leq n} (x_i - x_j)
  252. $$
  253. \qed
  254. % Bibliography
  255. \addcontentsline{toc}{section}{References}
  256. \bibliography{notes_reed-solomon.bib}
  257. \bibliographystyle{unsrt}
  258. \end{document}