Optimize linear interpolation function