Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

§2.3 — for a normalized cost function, δ_{i,j} is the minimum cost of an edit path from (0, 0) to (i, j)

Proved
MasekPaterson.Necessity.editDist_eq_pathMin

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

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

Let γ\gammaγ be a cost function assigning a nonnegative real number to every edit operation, normalized as in §1.1: γ(a→b)=δ(γ,a,b)\gamma(a \to b) = \delta(\gamma, a, b)γ(a→b)=δ(γ,a,b) for every edit operation a→ba \to ba→b. Let A=A1A2⋯A = A_1 A_2 \cdotsA=A1​A2​⋯ and B=B1B2⋯B = B_1 B_2 \cdotsB=B1​B2​⋯ be strings over the alphabet, with prefixes Ai=A1⋯AiA^i = A_1 \cdots A_iAi=A1​⋯Ai​, Bj=B1⋯BjB^j = B_1 \cdots B_jBj=B1​⋯Bj​ and edit matrix δi,j=δ(γ,Ai,Bj)\delta_{i,j} = \delta(\gamma, A^i, B^j)δi,j​=δ(γ,Ai,Bj). An edit path from (0,0)(0,0)(0,0) to (i,j)(i,j)(i,j) is a sequence of moves through the matrix, each increasing iii, jjj, or both by 111: the move (p,q)→(p+1,q)(p,q) \to (p+1,q)(p,q)→(p+1,q) deletes Ap+1A_{p+1}Ap+1​ at cost DAp+1D_{A_{p+1}}DAp+1​​, the move (p,q)→(p,q+1)(p,q) \to (p,q+1)(p,q)→(p,q+1) inserts Bq+1B_{q+1}Bq+1​ at cost IBq+1I_{B_{q+1}}IBq+1​​, and the move (p,q)→(p+1,q+1)(p,q) \to (p+1,q+1)(p,q)→(p+1,q+1) replaces Ap+1A_{p+1}Ap+1​ by Bq+1B_{q+1}Bq+1​ at cost RAp+1,Bq+1R_{A_{p+1},B_{q+1}}RAp+1​,Bq+1​​. Then for all i,j≥0i, j \ge 0i,j≥0,

δi,j=min⁡{cost of an edit path from (0,0) to (i,j)}.\delta_{i,j} = \min\{\text{cost of an edit path from } (0, 0) \text{ to } (i, j)\}.δi,j​=min{cost of an edit path from (0,0) to (i,j)}.

In words: to transform AiA^iAi into BjB^jBj it is enough to consider edit sequences that proceed left to right through the two strings, which are exactly the edit paths through the matrix. This identifies the edit distance, defined as a minimum over arbitrary edit sequences, with the path costs that §4 compares.

Formalization Note The strings are given as 1-based infinite sequences N→α\mathbb N \to \alphaN→α whose prefixes are AiA^iAi, BjB^jBj (every finite string over a nonempty alphabet is such a prefix). The nonnegativity of γ\gammaγ and the normalization γ(a→b)=δ(γ,a,b)\gamma(a \to b) = \delta(\gamma, a, b)γ(a→b)=δ(γ,a,b) are the standing assumptions of §1.1 (p. 19), stated as hypotheses. The paper's assumption ∣A∣≥∣B∣|A| \ge |B|∣A∣≥∣B∣ is not used.

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

/-- §2.3: for a nonnegative normalized cost function `γ` (`γ(a → b) = δ(γ, a, b)`, §1.1) and
any strings `A, B` (given as 1-based sequences, `A^i = A_1 ⋯ A_i`), every edit matrix entry
`δ_{i,j} = δ(γ, A^i, B^j)` is the minimum cost of an edit path from `(0, 0)` to `(i, j)`. -/
theorem editDist_eq_pathMin {α : Type*} (γ : EditOp α → ℝ) (hγ : ∀ o, 0 ≤ γ o)
    (hnorm : IsNormalized γ) (A B : ℕ → α) (i j : ℕ) :
    editDist γ (List.ofFn fun t : Fin i => A (t.val + 1))
        (List.ofFn fun t : Fin j => B (t.val + 1)) =
      pathMin γ A B (0, 0) (i, j) := by sorry

end MasekPaterson.Necessity
Source
Masek, Paterson, A Faster Algorithm Computing String Edit Distances, J. Comput. System Sci. 20, 1980, p. 24, Section 2.3 (Edit Paths); standing assumptions p. 19, Section 1.1
Read-back

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

Setting. Let α\alphaα be an arbitrary type, the alphabet, in any universe. It has no finiteness, decidability or ordering assumptions.

  • EditOp(α)\mathrm{EditOp}(\alpha)EditOp(α) is a type of edit operations over α\alphaα, defined in an imported file. Its definition is not shown here.
  • γ:EditOp(α)→R\gamma : \mathrm{EditOp}(\alpha) \to \mathbb{R}γ:EditOp(α)→R is a real-valued cost function on edit operations.
  • A,B:N→αA, B : \mathbb{N} \to \alphaA,B:N→α are infinite sequences of letters.
  • i,j∈Ni, j \in \mathbb{N}i,j∈N are natural numbers.

Hypotheses.

  1. Nonnegativity: every edit operation has nonnegative cost:
γ(o)≥0for every o∈EditOp(α).\gamma(o) \ge 0 \quad \text{for every } o \in \mathrm{EditOp}(\alpha).γ(o)≥0for every o∈EditOp(α).
  1. Normalization: γ\gammaγ satisfies a predicate called IsNormalized\mathrm{IsNormalized}IsNormalized. It is defined in an imported file whose body is not shown here, so this read-back cannot say what it requires. The attached doc comment describes the intent as γ(a→b)=δ(γ,a,b)\gamma(a \to b) = \delta(\gamma, a, b)γ(a→b)=δ(γ,a,b), but the code as shown does not confirm this.

Conclusion. Form the finite words

Ai=(A1,A2,…,Ai),Bj=(B1,B2,…,Bj),A^{i} = (A_1, A_2, \dots, A_i), \qquad B^{j} = (B_1, B_2, \dots, B_j),Ai=(A1​,A2​,…,Ai​),Bj=(B1​,B2​,…,Bj​),

which are the entries of AAA at positions 111 through iii and of BBB at positions 111 through jjj. The entries A0A_0A0​ and B0B_0B0​ are never used. The statement asserts

editDistγ(Ai,Bj)  =  pathMinγ(A,B; (0,0), (i,j)).\mathrm{editDist}_\gamma\big(A^{i}, B^{j}\big) \;=\; \mathrm{pathMin}_\gamma(A, B;\ (0,0),\ (i,j)).editDistγ​(Ai,Bj)=pathMinγ​(A,B; (0,0), (i,j)).
  • editDistγ\mathrm{editDist}_\gammaeditDistγ​ is a real-valued function of γ\gammaγ and two finite lists, imported from a shared definitions file.
  • pathMinγ(A,B;(0,0),(i,j))\mathrm{pathMin}_\gamma(A, B; (0,0), (i,j))pathMinγ​(A,B;(0,0),(i,j)) is a real-valued quantity imported from an "edit paths" definitions file. It depends on γ\gammaγ, on the whole sequences AAA and BBB (not just their first iii and jjj entries), on the start point (0,0)(0,0)(0,0) and on the end point (i,j)(i,j)(i,j) in N×N\mathbb{N}\times\mathbb{N}N×N.

Neither definition is shown here, so this read-back cannot spell out either side. The names and the doc comment say that the left side is the edit distance between the prefixes and the right side is the minimum cost of an edit path from (0,0)(0,0)(0,0) to (i,j)(i,j)(i,j). Whether the code actually means this depends entirely on the two imported definitions. In particular, whether pathMin\mathrm{pathMin}pathMin can look at A0A_0A0​, B0B_0B0​ or at entries beyond positions iii and jjj cannot be seen from this code.

The equation is claimed for every α\alphaα, every γ\gammaγ meeting both hypotheses, every AAA and BBB, and every pair (i,j)(i, j)(i,j).

Degenerate cases.

  • i=0i = 0i=0 or j=0j = 0j=0: the corresponding word is empty. The claim is then that the edit distance involving an empty word equals pathMin\mathrm{pathMin}pathMin from (0,0)(0,0)(0,0) to (0,j)(0,j)(0,j), (i,0)(i,0)(i,0) or (0,0)(0,0)(0,0). For i=j=0i = j = 0i=j=0, the edit distance between two empty words equals pathMin\mathrm{pathMin}pathMin from (0,0)(0,0)(0,0) to itself.
  • Empty alphabet: if α\alphaα is empty, no sequences A,B:N→αA, B : \mathbb{N} \to \alphaA,B:N→α exist, so the statement holds vacuously.
  • One-letter alphabet: if α\alphaα has one element, both words are constant and only their lengths iii and jjj differ.
  • Arbitrary costs: γ\gammaγ may assign cost 000 to every operation, as far as the nonnegativity hypothesis goes. Whether that γ\gammaγ passes IsNormalized\mathrm{IsNormalized}IsNormalized is not visible.
  • Can the hypotheses be met? That depends on the hidden definitions of IsNormalized\mathrm{IsNormalized}IsNormalized and EditOp\mathrm{EditOp}EditOp. If no nonnegative γ\gammaγ can satisfy IsNormalized\mathrm{IsNormalized}IsNormalized, the theorem is vacuous; this read-back cannot rule that out.
  • Junk values: no division, natural-number subtraction, integral or supremum appears in the statement itself. Any such default values inside editDist\mathrm{editDist}editDist or pathMin\mathrm{pathMin}pathMin, such as a minimum or infimum over an empty set of paths, are not visible here.
Human review
  • Endorsed by Shuze Chen · Sep 28, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Sep 28, 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