Polyhedral methods for piecewise-linear functions I: the lambda method