mathstodon.xyz is one of the many independent Mastodon servers you can use to participate in the fediverse.
A Mastodon instance for maths people. We have LaTeX rendering in the web interface!

Server stats:

2.9K
active users

The context is finding a polynomial of degree at most n that passes through n+1 points (x0,y0),,(xn,yn). The classical Lagrange interpolation formula is what you'd write down if you "just did it."

f(x)=i=0nyijixxjxixj

I put practical application in quotes because the classical formula is numerically unstable. I acutally didn't know this at the time I wrote PIM, but for the application of secret sharing it doesn't really matter because you do the math over a finite field and numerical accuracy is irrelevant.

But now that I'm in my polynomial approximation era, I actually do care about numerical precision and stability. And for that purpose, the barycentric formula is much better.

The main observation here is that the terms of the classical formula can be thought of as divisors of a single polynomial

ℓ(𝑥)=∏ᵢ₌₀ⁿ(𝑥−𝑥ᵢ)

Then each term is j(x)=(x)/(xxj), multiplied by the term-specific weight wj=ij1(xixj). Then you can factor out (x), precompute the wj, and get

f(x)=(x)i=0nyiwixxi

This is more efficient, but you can also avoid computing (x) entirely by using the mathematician's favorite trick of dividing by a cleverly-disguised 1. In this case, the 1 is represented by its interpolation formula (including (x)), which is achieved by just setting all yi to 1.

When you divide, the (x) cancels out and you get

f(x)=[i=0nyiwixxi]/[i=0nwixxi]

This is the barycentric formula. It is numerically stable for well-chosen point sets xi (see section 7 of the paper of Trefethen linked below). I have to admit, I have no idea what this has to do with barycentric coordinates (en.wikipedia.org/wiki/Barycent) as I originally learned about them. I guess the lagrange terms j(x) are supposed to be the vertices of a simplex, and the wj the barycentric weights, but the calling this a simplex seems weird to me.

en.wikipedia.orgBarycentric coordinate system - Wikipedia

The other nice thing about this formula is that the weights are trivial to compute for certain point sets. For uniform spaced points on [1,1], wj=(1)j(nj), and for Chebyshev points on the same domain it's wj=(1)j with values halved at j=0,j=n.

I wrote some Python code to implement this here (github.com/j2kun/remez/blob/ma), along with one extra tweak to improve numerical stability, which boils down to multiplying the numerator and denominator of each term in the sum by 2 to avoid underflow. The test includes an interpolation of degree 100,000 that runs in about a second in vanilla Python.

GitHubremez/lagrange.py at main · j2kun/remezAn implementation of the remez algorithm and variants - j2kun/remez

Popularizing barycentric Lagrange interpolation seems to be something of a passion project for Lloyd N. Trefethen (en.wikipedia.org/wiki/Nick_Tre). Trefethen, head of the numerical analysis group at Oxford, is an author on basically every paper I can find on this topic, in addition to the applications of this to Remez-like algorithms. In this paper (people.maths.ox.ac.uk/trefethe), section 10 gives a history, of the curious obscurity of this formula. Among other interesting facts, Trefethen states that Richard Hamming included it in the first edition of Numerical Methods for Scientists and Engineers, and then dropped it in the second edition with no explanation.

en.wikipedia.orgNick Trefethen - Wikipedia

@j2kun I assume you've read his ATAP book? It's excellent. Oh, and another of his popularization efforts: people.maths.ox.ac.uk/trefethe

@j2kun Oh wow, I can almost guarantee you'll love it based on your interests.

@j2kun

Nick was not 'head' of the numerical analysis group at Oxford. Rather, he was a member of the group.

Nick moved to Harvard starting in the fall 2023 academic year after retiring from Oxford (given UK rules on retirement).

@masonporter I pulled that word from Wikipedia, heh, should probably be updated

@j2kun Well, Wikipedia has its quality issues, of course.

In the case of these specific facts about Nick, I can readily just use my personal knowledge.

At least it didn't list a totally wrong institution. (A couple of times, I scrubbed my Wikipedia page to remove errors of commission that listed me with totally incorrect institutions. That is the only type of situation in which I am willing to edit my own page.)