more efficient calculation of Lagrange polynomial