Faster asin() Was Hiding In Plain Sight

28 points by knl


Corbin

As a readability suggestion, write approximant polynomials using Horner's rule. The resulting polynomial is mostly just a list of coefficients. That way, it's much easier to compare different polynomials. It also gives the programmer more control over the order of operations, since IEEE-754 arithmetic doesn't associate; if one wants a predictable ladder of FMAs then one has to repeatedly alternate multiplication and addition.

Lolremez (previously, on Lobsters) supports arc sine. Instead of fishing for constants from old codebases and hoping that they work, we can generate fresh coefficients. Arc sine is an odd function, so we can change Remez variables to add a corresponding structural constraint before iterating. For example, I got:

$ lolremez --debug --degree 4 --range 0:1 "asin(sqrt(x))/sqrt(x)" "1/sqrt(x)"
…
[debug] error: 3.0793806583731183e-2
// Approximation of f(x) = asin(sqrt(x))/sqrt(x)
// with weight function g(x) = 1/sqrt(x)
// on interval [ 0, 1 ]
// with a polynomial of degree 4.
// p(x)=(((1.0632192121365258e+1*x-2.2122094756619801e+1)*x+1.5633874881759952e+1)*x-3.8898539851548752)*x+1.285884258668319

I'll leave it to the reader to read the linked tutorial and write the wrapper function that calls this.