herodotus
Lovely. In about 1974 I was paid to write a function, in IBM 360 assembly language, to compute square roots. I was asked to make it as efficient as possible. I was in my last year as an undergraduate student. I used a Chebyshev approximation for the initial guess (after scaling the input to lie between 0 and 1), and then used two (or was it three) unrolled iterations of Newton's method to get the solution. First money I ever received for writing code!
richrichie
Chebyshev polynomials are so powerful and versatile (in approximation) that people think it is a too-good-to-be-true scam and do not use them.

One’s first go to method should be Chebyshev. Neural nets used as a last resort.

jaymzcampbell
This is really nicely done! Great work. I fell in love with just how efficient these can be and it explained a lot about why many of the trig and other mathematical functions implemented in 8-bit computers are they way they are.

Here's a rather wonderful original document from the BBC Research Department (I had no idea that was a thing) back in 1969 going over just what makes them so great (https://downloads.bbc.co.uk/rd/pubs/reports/1969-10.pdf).

If all you've come across are Taylor approximations, these things can seem a little like magic at first.

orlp
I've had good results in the past with sollya: https://www.sollya.org/.

Note: results. The software itself is a bit of a pain to use.

Fredkin
Math.sin(x)/x (the sinc function) for 7 terms over [-3,3] gives coefficients c0...c6 that are all NaNs. Is this a bug?

To work around it, I handled the x near zero case by just forcing to 1.0.

if(Math.abs(x) > 1e-8 ){ Math.sin(x)/x } else { 1.0 }

atum47
I've been wondering about something and I don't know if this is the place to ask it, but here it goes. I saw a video the other day about how the Nintendo 64 did not have the ability to calculate sine, so they used a lookup table from 0 to 2PI (with some clever trick to reduce the size of the table). Would it have been possibly to train a NN and store the weights or even a function and store the coefficients to calculate the sine, cosine?
xioxox
Excellent work. I wanted to do this recently, but it was surprisingly hard to find code to calculate an approximation. I've bookmarked it for when I next need a quick approximation for a function.
Zeetah
Nice!

I'd like to generate a Chebyshev approximation for a set of X, Y sensor values. Any hints on how to modify your code to do that?

ArmedSandwich
This is really nice. Wish I had it back in university, it would have made learning the Chebyshev expansions a lot more interesting than they were.
hggigg
Rather nice that. I like it.

Doesn't handle divide by zero very well though i.e. f(x)=1/x. Should probably consider that as undefined rather than a bad expression.