Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 3 — steps of an edit matrix lie in [−I,D][-I, D][−I,D] and [−D,I][-D, I][−D,I]

Proved
MasekPaterson.FourRussians.step_bounds

by mikedeng1 · Sep 26, 2026 · Mathlib 0df444a (Lean v4.33.1)

dynamic-programmingedit-distancep2o-batch-p100ap2o-gran-per-chapterp2o-plan-paperp2o-v1

Let γ\gammaγ be a nonnegative cost function, and let I,DI, DI,D be real numbers with Ia≤II_a \le IIa​≤I and Da≤DD_a \le DDa​≤D for every character aaa (for a finite alphabet, the paper's I=max⁡{Ia∣a∈Σ}I = \max\{I_a \mid a \in \Sigma\}I=max{Ia​∣a∈Σ} and D=max⁡{Da∣a∈Σ}D = \max\{D_a \mid a \in \Sigma\}D=max{Da​∣a∈Σ}). Then for all strings A,BA, BA,B and all i,ji, ji,j with 1≤i≤∣A∣1 \le i \le |A|1≤i≤∣A∣, 1≤j≤∣B∣1 \le j \le |B|1≤j≤∣B∣,

  1. −I≤δi,j−δi−1,j≤D-I \le \delta_{i,j} - \delta_{i-1,j} \le D−I≤δi,j​−δi−1,j​≤D, and
  2. −D≤δi,j−δi,j−1≤I-D \le \delta_{i,j} - \delta_{i,j-1} \le I−D≤δi,j​−δi,j−1​≤I.

The size of a step is therefore bounded independently of the strings involved, which is the first half of the finiteness of the set of steps (Lemma 4).

Formalization Note The paper's III and DDD are maxima over a finite alphabet; the statement is given for arbitrary upper bounds I,DI, DI,D, which implies the paper's version (take the maxima) and needs neither finiteness nor nonemptiness of the alphabet. Normalization of γ\gammaγ is not assumed: the lemma holds for every nonnegative cost function.

Preamble
import Mathlib
import Definitions.Def_MasekPaterson_Shared_editDist
open MasekPaterson.Shared
Formal statement
namespace MasekPaterson.FourRussians

/-- Lemma 3: if every insertion cost is at most `I` and every deletion cost at most `D`
(in particular for `I = max_a I_a`, `D = max_a D_a` over a finite alphabet), then for all
strings `A, B` and `1 ≤ i ≤ |A|`, `1 ≤ j ≤ |B|`:
(i) `−I ≤ δ_{i,j} − δ_{i−1,j} ≤ D`, and (ii) `−D ≤ δ_{i,j} − δ_{i,j−1} ≤ I`. -/
theorem step_bounds {α : Type*} (γ : EditOp α → ℝ) (hγ : ∀ o, 0 ≤ γ o)
    (I D : ℝ) (hI : ∀ a : α, insCost γ a ≤ I) (hD : ∀ a : α, delCost γ a ≤ D)
    (A B : List α) (i j : ℕ)
    (hi : 1 ≤ i) (hiA : i ≤ A.length) (hj : 1 ≤ j) (hjB : j ≤ B.length) :
    (-I ≤ dmat γ A B i j - dmat γ A B (i - 1) j ∧ dmat γ A B i j - dmat γ A B (i - 1) j ≤ D) ∧
    (-D ≤ dmat γ A B i j - dmat γ A B i (j - 1) ∧ dmat γ A B i j - dmat γ A B i (j - 1) ≤ I) := by sorry

end MasekPaterson.FourRussians
Source
Masek, Paterson, A Faster Algorithm Computing String Edit Distances, J. Comput. System Sci. 20, 1980, p. 23, Lemma 3
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Let α\alphaα be any type and γ\gammaγ a real-valued cost function on edit operations over α\alphaα (a type defined in the imported shared file). Assume γ(o)≥0\gamma(o)\ge0γ(o)≥0 for all ooo. No normalisation hypothesis appears in this statement, and α\alphaα is not assumed finite.

Let I,DI,DI,D be real numbers such that, for every symbol a∈αa\in\alphaa∈α:

  • ins(a)≤I\mathrm{ins}(a)\le Iins(a)≤I;
  • del(a)≤D\mathrm{del}(a)\le Ddel(a)≤D.

Here ins\mathrm{ins}ins and del\mathrm{del}del are the imported insertion and deletion costs under γ\gammaγ. Let A,BA,BA,B be finite lists over α\alphaα, and write δr,s\delta_{r,s}δr,s​ for the imported dmat γ A B r s (the edit matrix per the docstring; its definition is not shown).

For all natural numbers i,ji,ji,j with 1≤i≤∣A∣1\le i\le|A|1≤i≤∣A∣ and 1≤j≤∣B∣1\le j\le|B|1≤j≤∣B∣, the statement asserts both chains of inequalities:

−I≤δi,j−δi−1,j≤D,-I\le\delta_{i,j}-\delta_{i-1,j}\le D,−I≤δi,j​−δi−1,j​≤D, −D≤δi,j−δi,j−1≤I.-D\le\delta_{i,j}-\delta_{i,j-1}\le I.−D≤δi,j​−δi,j−1​≤I.

In the degenerate cases:

  • If AAA or BBB is empty, the statement is vacuous.
  • If α\alphaα is empty, every list is empty, so the statement is again vacuous, and the bound hypotheses hold for every choice of I,DI,DI,D.
  • If α\alphaα is nonempty but the insertion or deletion costs are unbounded above, no real III or DDD satisfies the hypotheses, so the statement is vacuous for such γ\gammaγ.
Human review
  • Endorsed by Shuze Chen · Sep 27, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Sep 27, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me