Suppose that you know a function, f, for each of several values of its argument, but you need to know its value for some other argument. Let S be the set of arguments where the value is known.
This arises when we are interpolating in a large table for some mathematical function and indeed this is the original context of Lagrange’s invention. The table gives some logarithms thus:
2.3567 0.372304301812888 2.3568 0.372322729498556 2.3569 0.372341156402345 2.3570 0.372359582524324 2.3571 0.372378007864557but you need to know log(2.356940377234422). Linear interpolation uses the logs of 2.3569 and 2.3570 but since the log function is not actually linear this is a poor estimate. If LC is the Scheme function
p(x) = sum[i in S] (p(i) * (product[j in S but not i] (x - j))/ (product[j in S but not i] (i - j)))The coefficients are the quotient of products in the above.
It is not necessary that the arg values be spread uniformly but it is necessary that they be distinct. (LC args x) is a polynomial in x whose degree is one less than the length of args. It is in fact the unique polynomial that takes on all the tabulated values. That the polynomial is the correct sort of function to invoke here is related to the fact that interesting functions tend to have small higher derivatives and also the reason that Taylor series work.
Another application is Reed-Soloman erasure coding where a polynomial of degree q is fit thru q+1 portions of data to be stored in less than perfectly reliable places. The polynomial is evaluated and stored for several other arguments as well and if some of either set are lost then the polynomial is still determined by the surviving values, if at least q+1 of them survive.