The discrete calculus of variations