I have a function defined with a series of arbitrary points $(P_1,P_2,...,P_n); P_k(x_k, y_k)$ such that $x_k<x_{k+1}$, and $$f(x) = y_k\frac{x_{k+1}-x}{x_{k+1}-x_k}+y_{k+1}\frac{x-x_k}{x_{k+1}-x_k}; x_k\le x<x_{k+1}$$
It is not defined for $x\in\langle-\infty, x_1\rangle\cup[x_n,+\infty\rangle$.
Given some arbitrary threshold $\lambda$, I'm looking for a series of points $(P'_1, P'_2,...P'_m), P'_k(x'_k,y'_k)$ with minimal $m$, such that $g(x)=y'_k\frac{x'_{k+1}-x}{x'_{k+1}-x'_k}+y'_{k+1}\frac{x-x'_k}{x'_{k+1}-x'_k}$ and $$\frac{\sum_{i=\lceil x_1\rceil}^{\lceil x_n\rceil-1}(f(i)-g(i))^2}{\lceil x_n\rceil-\lceil x_1\rceil} < \lambda$$
How would I efficiently find points $(P'_1,P'_2,...,P'_m)$?
I would post some of my attempts at solving this problem, but it got me completely stumped, the best I could think of was iteratively removing a single point $P_k$ selected by checking which removed point introduces smallest error, and then using hill climbing to shift other points around until it best approximated the original function. That is both highly inefficient and I believe quite suboptimal. Is there a better way?