Background
Unique Low Degree Extensions
- Lagrange interpolation and Reed-Solomon both give us techniques to create unique low-degree extension polynomials for a message. The unique low degree extensions will always have degree or lower where is the length of the message. The extension polynomials are then evaluated at points where to create a low degree extension encoding which is much longer than the original message. The algorithms only differ in how the message is represented as a polynomial.
- Low degree extension encodings are valuable because of their distance amplifying properties - if two messages differ even at one entry, almost every entry in their extension encodings will be different, allowing for fast comparison of messages via random sampling of entries in the encoding.
- In both Lagrange interpolation and Reed-Solomon, the symbols of the message are mapped to elements of a finite field and the entries of the message are applied as the weights in a linear combination over a polynomial basis.
- With Reed-Solomon, we use the standard monomial basis resulting in the polynomial
- In univariate Lagrange interpolation, the Lagrange basis is used , resulting in a polynomial with the form
- With Reed-Solomon, we use the standard monomial basis resulting in the polynomial
- With Reed-Solomon, the symbols of the message uniquely determine a polynomial by specifying the coefficients. The degree is clearly because the sum spans standard monomial basis polynomials .
- Univariate Lagrange interpolation obtains an or lower degree polynomial for the message by interpreting its entries as a set of points and defining the polynomial that passes through them. Because two distinct polynomials of degree or lower can intersect at no more than points, we know that there is no other polynomial of degree or lower that interpolates the points. Thus, the Lagrange interpolating polynomial is unique.
Univariate Lagrange Interpolation
High Level
Specifying the low degree extension for a message with Lagrange interpolation is less intuitive than with Reed-Solomon, so we'll begin with a high level summary of steps.
- Our goal is to uniquely represent an -length message with a univariate polynomial of degree such that evaluating for produces the character of the message. We define over a finite field where .
- We'll create the interpolating polynomial by pairing the characters of the message with their corresponding zero-based indices to obtain a set of coordinate pairs .
- The x-values in the set of coordinates being interpolated are the nodes over which we can define a set of Lagrange basis polynomials.
- Lagrange basis polynomials are polynomials that evaluate to 1 for their corresponding node, and 0 for all other nodes in the set.
- For example, the second Lagrange basis polynomial will return 0 for all nodes other than the node at index two:
- For example, the second Lagrange basis polynomial will return 0 for all nodes other than the node at index two:
- We create the interpolating polynomial by multiplying the entries in the message by Lagrange basis polynomials.
- For an input to , each Lagrange basis polynomial will evaluate to 0, except which will evaluate to 1.
- As a result, the evaluation of of will be
- For example, we can see that evaluates to the third character in the message
- For example, we can see that evaluates to the third character in the message
- We define , the Lagrange interpolating polynomial, as mapping .
- The x-values in the coordinate pairs are the nodes over which we define our Lagrange basis polynomials, or the interpolating set.
- We create the interpolating polynomial by using entries in the message as the weights in a linear combination of the Lagrange basis polynomials
The Details
Lagrange Basis Polynomials
- Let be an -dimensional vector where is a prime number larger than . There exists a unique univariate Lagrange interpolating polynomial over with degree such that
- We'll interpolate the set of points , so our nodes are .
- Given a set of distinct nodes, we define the Lagrange basis for polynomials of degree to be the set of degree polynomials over where and if and .
- In other words, the th Lagrange basis polynomial evaluates to for the th node and 0 for all other nodes in the set.
- Note that this is only true for inputs in the domain over which the set of Lagrange basis polynomials was defined. Evaluating a Lagrange basis polynomial at a value outside of that domain will not return even if the value does not equal .
- Another way you may see this written written is . The refers to the Kronecker delta function which returns 1 if and 0 if , for example and .
- We're intentionally creating a polynomial for every node index such that there will be a zero at every element in the domain that isn't , and that the evaluation of the polynomial at the node is 1.
- We set the numerator so that for every except , there will be a zero at .
- We set the denominator so that in the one case where , terms in the numerator and denominator will all cancel, leaving us with 1.
- The set is a Lagrange basis for polynomials of degree because
- The Lagrange basis polynomials are linearly independent so no polynomial in the set can be written as a linear combination of the others.
- Any other polynomial of degree can be expressed as a linear combination of the Lagrange basis polynomials.
Lagrange Interpolating Polynomial
- Using the Lagrange basis polynomials that we defined for the set of coordinates being interpolated, we can create the Lagrange interpolating polynomial, . Our goal is that for the vector
- We must create a sum where all terms evaluate to 0 except the one multiplied by the th entry of the message. $$
q_m(x) = \sum_{i=0}^{n-1}m_{i+1}\cdot L_i(x) - Expanded, we have
- When evaluating for only the basis polynomial evaluates to 1 and that all other basis polynomials in evaluate to zero. Since we use the entries as coefficients of the Lagrange basis polynomials, this has the effect of causing the interpolating polynomial to return .
Lagrange Interpolating Polynomials are Unique Low Degree Extensions
- The Lagrange interpolating polynomial is unique - it's the only polynomial of degree that represents the -length message .
- Each Lagrange basis polynomial has degree .
In the th Lagrange basis polynomial, has degree 1 and and are constant values such that . Thus, the Lagrange basis polynomial is a product of linear terms and the interpolating polynomial is a linear combination of Lagrange basis polynomials, so its degree is .
- Since the Lagrange interpolating polynomial has degree , and interpolates points, it must be unique.
- Proof: Suppose there were another polynomial of degree which interpolated the same points. Then is a polynomial of degree with roots at all nodes, which would mean that is the constant zero function, so .
- We call the Lagrange interpolating polynomial the unique low degree extension of , and the set of all evaluations of for a low degree extension encoding of .
Low Degree Extensions and Distance Amplification
- For an -dimensional vector , the low degree extension encoding is a -dimensional vector of the evaluations .
- A message that differs from at even one entry will have a Lagrange polynomial that interpolates a different set of values for the same set of nodes , so will have a different low degree extension, still of degree .
- Since and are distinct polynomials of degree , they agree at points. The low degree extension encodings of and are of length , so an entry at a random has
- As long as , the extension is distance amplifying. If an encoding is distance amplifying, the distance between the codewords (number of entries at which they are different) is greater than the distance between the original messages.
- As long as the order of the field is sufficiently large, the probability of two random entries in an extension code being the same for different messages is near zero.
- Both Reed-Solomon and Lagrange interpolation result in a unique or lower degree extension polynomial with distance amplification properties.
- In the case of Lagrange interpolation, the extension encoding contains the original vector. For an -dimensional vector , the first evaluations of the Lagrange interpolating polynomial on elements of will result in the entries . We say that this encoding is systemic.
Lagrange Interpolation Worked Example
- Given a message , the length of the message is 5 so the Lagrange polynomial will be of degree
- The points being interpolated are and our nodes are .
- As an example, we'll evaluate the fourth Lagrange basis polynomial, , so , and for
- if and
- The expanded Lagrange basis polynomial looks like this:
- Plugging in node values we have
- Evaluated at , the terms in the numerator and the terms in the denominator all cancel out, leaving us with 1
- Evaluated at any other node, one of the numerator terms evaluates to zero, leaving us with 0
- The full Lagrange interpolating polynomial for can be calculated as follows
Implementation
function getUnivariateLagrange(message: string, r: Field): Field {
const n = message.length;
if (n === 0) {
throw Error("Message cannot be empty.");
}
// r value is an element in the interpolating set, return the corresponding message entry
if (r.lessThan(n).toBoolean()) {
const index = Number(r.toBigInt());
return Field(asciiToNumber(message[index]));
}
// accumulator for summation over interpolation points
let result = Field(0);
// interpolation points ({0...n-1})
const interpolatingSet = Array.from({ length: n }, (_, index) =>
Field(index),
);
// sum over interpolation points
for (let i = 0; i < interpolatingSet.length; i++) {
// coefficient
const coeff = Field(asciiToNumber(message[i]));
// lagrange basis evaluated at r
const lagrangeBasis = getLagrangeBasis(i, interpolatingSet, r);
result = result.add(coeff.mul(lagrangeBasis));
}
return result;
}
// returns the index-th lagrange basis polynomial for the interpolating set evaluated at x
function getLagrangeBasis(
index: number,
interpolatingSet: Field[],
x: Field,
): Field {
// accumulator for product over interpolating set indices
let accumulator = Field(1);
for (let j = 0; j < interpolatingSet.length; j++) {
// skip term where j = index
if (j === index) continue;
// jth term = (x-interpolatingSet[j]) / (interpolatingSet[index] - interpolatingSet[j])
const term = (x.sub(interpolatingSet[j]))
.div(
(interpolatingSet[index].sub(interpolatingSet[j]))
);
accumulator = accumulator.mul(term);
}
return accumulator;
}