A Lean proof of the forward difference algorithm

I have formalised the correctness proof of the polynomial evaluation algorithm from an earlier post in Lean 4. The proof verifies the central invariant, namely that after preprocessing the y_j‘s the iteration maintains y_j = \Delta^j P(x + ih) at each step where \Delta P(x) = P(x+h) - P(x) which ensures y_0 = P(x + ih) using only d additions per evaluation. The theorem proved in Lean is as follows

theorem eval_range_correct (P : Poly V) (x h : R) (i : ℕ) :
    State.iterate^[i] (State.init P x h) 0 = P.eval (x + i * h)

Here, P is the polynomial with coefficients in an additive commutative group V that forms a module over the commutative ring R, State.init is the preprocessing of the y_j‘s and iterate is the iteration operator.

The Lean code is available in the PolyEval repository, and the original Rust implementation can be found in a separate repo.