Skip to content

A Machine-Checked Theory of Dynamic Time Warping in Lean 4

Srihari Maruthachalam

eess.SP

Abstract

Dynamic time warping (DTW) is a standard dissimilarity measure for time series. In practice, large-scale DTW search depends on two ingredients whose correctness is usually argued on paper: global path constraints such as the Sakoe-Chiba band, and cheap lower bounds such as LBKim and LBKeogh that prune candidates without false dismissals. We present a formalization of DTW in Lean 4 with mathlib, covering: warping paths and DTW as a minimum over them; correctness of the dynamic-programming recurrence; nonnegativity, symmetry and DTW(x,x)=0, with a machine-checked witness of the known failure of the triangle inequality; constrained and Sakoe-Chiba banded DTW; the LBKim, LBKimFL, LBYi and LBKeogh lower bounds, the last restated for an arbitrary global constraint; and an executable row-by-row implementation proved equal to the specification. The recurrence is proved once, for cell costs in an arbitrary linearly ordered additive commutative monoid. Instantiating it at the reals extended with a top element yields constrained DTW with no separate optimality proof. The development has no sorry, and every main theorem uses only Lean's standard axioms. To our knowledge it is the first formalization of DTW itself in a proof assistant. The mathematics is classical; the contribution is a checked, reusable development and the precision it forces.

Create a lesson

Metadata

Categories
eess.SP, cs.LO
Comments
9 pages. Lean 4 + mathlib formalization; source code at https://github.com/harimaruthachalam/dtw-lean