Curvature.lean

Lean 4 source, lean/DataMiningAsObservation/Curvature.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.

/-
Curvature.lean. Chapter 0 section 0.5, chapter 6 section 6.1, and chapter 7 section 7.2,
the curvature and the Hessian.

The curvature of a consumer is its second derivative, which the finite difference of
equation 0.8 does not read. For a quadratic the second difference recovers it exactly at
every step, the error of the linear model at a step is the curvature times the step
squared, and the gradient at the two ends of a step differs by the curvature times the
step. An affine consumer has second difference zero.
-/
import Mathlib
import DataMiningAsObservation.FiniteDifference

namespace DMO.Curvature

open DMO.FiniteDifference

/-- The second difference. -/
noncomputable def second (f : ℝ → ℝ) (x h : ℝ) : ℝ := (f (x + h) - 2 * f x + f (x - h)) / h ^ 2

/-- **The second difference recovers the curvature of a quadratic exactly.** -/
theorem second_quad (a b c x h : ℝ) (hh : h ≠ 0) : second (quad a b c) x h = 2 * a := by
  unfold second quad
  rw [div_eq_iff (pow_ne_zero 2 hh)]
  ring

/-- **An affine consumer has no curvature.** -/
theorem second_affine (m b x h : ℝ) : second (fun z => m * z + b) x h = 0 := by
  unfold second
  ring

/-- **The linear model's error at a step is the curvature times the step squared.** -/
theorem linear_error (a b c x h : ℝ) :
    quad a b c (x + h) - (quad a b c x + (2 * a * x + b) * h) = a * h ^ 2 := by
  unfold quad
  ring

/-- **The gradient at the two ends of a step differs by the curvature times the step.** -/
theorem gradient_change (a b x h : ℝ) :
    (2 * a * (x + h) + b) - (2 * a * x + b) = 2 * a * h := by
  ring

end DMO.Curvature