Dividing In Lagrange basis when one of the points is zero - Generalised
Problem
We restate the problem, however we do not assume that the elements in the domain are roots of unity.
We have
Lagrange polynomial
We briefly restate the formula for a lagrange polynomial:
The i'th lagrange polynomial evaluated at is 1 and 0 everywhere else on the domain
First form of the barycentric interpolation formula
We introduce the polynomial .
We also introduce the derivative of .
You can derive this yourself by generalising the product rule: https://en.wikipedia.org/wiki/Product_rule#Product_of_more_than_two_factors
In general this derivative does not have a succint/sparse form. We do have a succint form if the domain is the roots of unity!
Now note that
If we plug in into all the terms with will vanish, this is why the sum disappears into a single product.
We can use and to re-define our lagrange polynomial as :
Looking at the original lagrange formula, is the denominator and is the numerator.
The first barycentric form for a polynomial can now be defined as :
Remarks
- is not dependent on the values of and so can be brought out of the summation.
- is only dependent on the domain, so it can be precomputed, along with
Re-defining the quotient
Note that our original problem was that:
Had a term in the denominator. We will use the first form as a way to get rid of this.
First we rewrite using the first form:
We then note that:
I just re-arranged the formula for the first form to equal for
We can hence plug this into our previous equation:
Simplifying since we have a in the numerator and denominator:
This is the exact same formula that we had in Dankrad's post, but generalised! To see this, we note that when the elements in the domain are roots of unity;
The nice simplifcation here is due to two reasons: roots of unity form a cyclic group, and we can succintly represent the d'th roots of unity in a sparse equation which is nice to derivate.
We have now re-defined to not include !
We now summarise and state that:
Explicit formulas for each case
Computing
when dealing with the point which vanishes on zero, the above formula becomes:
Note:
Computing
For the case that the evaluation does not vanish on the domain, we can use the original formula.
For all
We note that the terms of the sum are zero, except for when , hence we can simplify this to be:
Optimisations
If we use the formulas as shown above, will take steps due to the sum, and will take steps. We describe a way to reduce this complexity in the code.
1. Rewrite in terms of
Note that if we multiply by we get:
We can now substite in
2. Removing field inversions in
Note that has a division which is many times more expensive than a field multiplication. We now show a way to precompute in such a way that we do not need to invert elements.
With the roots of unity, we were able to use the fact that they formed a group.
Again note that:
(Dankrad):
For our case where the domain is the discrete interval
We only need to precompute for . This is 510 values, so we would store 510 * 32 = 16Kb.
How would I lookup these values?
First we imagine that we have stored the values in an array:
We first note that we can easily get from to in the array by jumping forward 255 indices. Our strategy will be to find then jump to if we need to.
Example
We want to compute .
- Compute the
In practice, we can use an if statement to check whether 255 or 0 is larger, and subtract accordingly.
- Note that is at index
- Since our original computation was which is negative, we need to get the element at index
3. Precompute
With the roots of unity, we did not need this optimisation as equaled which was trivial to fetch from the domain.
For this, we will need to store precomputed values, if we want to efficiently compute in steps, and to also avoid inversions.
(Dankrad): We precompute and . Given that we have 256 points in the domain. This will cost us 256 2 32 bytes = 16kB.
How would I lookup these values?
Similar to the previous optimisation, we store in an array.
Example
We want to compute
- We can fetch by looking up the element at index in the array.
- We can fetch by looking up the element at index 5, then jumping forward 256 positions.
In general:
- To fetch we need to fetch the element at index
- To fetch we need to fetch the element at index
Evaluate polynomial in evaluation form on a point outside of the domain
Suppose is a point outside of the domain.
- We already store precomputations for
- We should compute separately, then batch invert using the montgomery trick, so that we only pay for one inversion.