MDS codes

An MDS (Maximum Distance Separable) code is a linear code of dimension and length over a finite field (a vector subspace of dimension of ), which reaches the Singleton bound (the minimal Hamming distance between any two codewords is ), and so provides the maximum erasure-correcting capability possible (as a linear code cannot verify , again by the Singleton bound). So we can correct up to erasures by finding the closest codeword under the Hamming distance. A generating matrix of a linear code is defined by . The property that any coefficients of a codeword determine it, comes from the fact that any set of rows of its generating matrix forms a full rank matrix (the equation where is the unknown has a unique solution, as is invertible).

Reed-Solomon codes

Let be a prime field of order . Let such that . Let be a primitive -th root of unity. Aside: how do we find such primitive roots of unity in practice?

We consider the Reed-Solomon code of parameters and evaluation points, the subgroup of the -th roots of unity. We denote it .

RS has rate . To a vector we associate the polynomial , and reciprocally. RS is a linear code, whose generating matrix is the following Vandermonde matrix, for which every square submatrix is invertible, so RS is indeed MDS:

Encoding

Encoding a message amounts to evaluate its associated polynomial at the evaluation points . This can be done with an -points discrete Fourier transform supported by in time :

Input:

Output:

Return

Decoding from erasures

As we saw earlier, we can decode a codeword with at most erasures, i.e. from at least components of .

Without loss of generality, let be the received codeword with erasures, the first components of a codeword. We can retrieve the original message with any components of thanks to the Lagrange interpolation polynomial, where the are the evaluation points of

As detailed in https://arxiv.org/pdf/0907.1788v1.pdf, the idea is to rewrite as a product of two polynomials and so that the convolution theorem allows us to recover using FFTs in . (The authors consider sums to while we can consider sums to since has degree .)

To do so, let

Let .

The interpolation polynomial becomes:

Note that by definition, so it is invertible in .

In order to replace the costly product in this expression, we use the fact that the formal derivative of satisfies for all : . So we can compute by evaluating at the points with an FFT.

Indeed: So as the other polynomials have as root.

The resulting expression corresponds to the barycentric formula.

Writing the fraction as a formal power series, we obtain

But if we let then

is thus given by the first components of .

So the product is given by the convolution theorem, and by linearity of the DFT and pairwise product:

The total cost is : the first term accounts for the computation of the product for with a divide and conquer approach for the multiplication of its factors with FFT multiplication, and the second one for the other steps.

Sharding

In some applications, such as database sharding, it can be advantageous to split the codewords into chunks (aka shards). For this purpose, let be the number of shards, the length of a shard, and a primitive -th root of unity.

The domain of evaluation is then split into cosets: , for and .

For a set of shard indices , we reorganize the product into We notice that (as its roots are the elements of a group of order dividing ) entails (multiplying all terms by a constant in an integral domain), which is as sparse as it can be. More formally: every element of is of the form for . Thus So every element of is a root of . Moreover, is a degree polynomial so has at most roots: ’s only roots are .

With this little observation, we’ve reduced the number of leaves of the recursion tree for the divide-and-conquer multiplication of the factors of from to .