I wonder how to generate the best lookup table (linear interpolation) for a function, for example, $e^{-x}$ or $\sin(x)$
For $f(x)$ $n\in\mathbf{N}$ $a,b\in\mathbf{R}, a<b$, find $$\mathop{\arg\min}\limits_{P = \{(x_i, y_i)|i = 0..n, a=x_0<x_1<...<x_n=b\}}\sum_{i=0}^{n-1}\int_{x_i}^{x_{i+1}}||l_i(x)-f(x)||^2\mathrm{d}x\quad \mathrm{where}\space\space \frac{l_i(x)-y_i}{x-x_i}=\frac{y_{i+1}-y_i}{x_{i+1}-x_i}$$
or is there some useful code/library/software to solve the question?