Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 1 [7] — the first row and column of the edit matrix

Proved
MasekPaterson.FourRussians.initial_vectors

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, normalized cost function (that is, γ(a→b)=δ(γ,a,b)\gamma(a \to b) = \delta(\gamma, a, b)γ(a→b)=δ(γ,a,b) for every edit operation), and let A,BA, BA,B be strings with edit matrix δi,j=δ(γ,Ai,Bj)\delta_{i,j} = \delta(\gamma, A^i, B^j)δi,j​=δ(γ,Ai,Bj). Then δ0,0=0\delta_{0,0} = 0δ0,0​=0, and

δi,0=∑1≤r≤iDAr(1≤i≤∣A∣),δ0,j=∑1≤r≤jIBr(1≤j≤∣B∣).\delta_{i,0} = \sum_{1 \le r \le i} D_{A_r} \quad (1 \le i \le |A|), \qquad \delta_{0,j} = \sum_{1 \le r \le j} I_{B_r} \quad (1 \le j \le |B|).δi,0​=1≤r≤i∑​DAr​​(1≤i≤∣A∣),δ0,j​=1≤r≤j∑​IBr​​(1≤j≤∣B∣).

This gives the initial vectors (first row and column) of the edit matrix, from which the Wagner–Fischer recurrence (Theorem 2) computes the rest. The paper cites it from Wagner and Fischer [7].

Formalization Note The paper states both formulas under the joint condition "1≤i≤∣A∣,1≤j≤∣B∣1 \le i \le |A|, 1 \le j \le |B|1≤i≤∣A∣,1≤j≤∣B∣"; each formula involves only one of the two indices, so each is stated with its own range, which is the same content and does not become vacuous when the other string is empty. The paper's standing assumption ∣A∣≥∣B∣|A| \ge |B|∣A∣≥∣B∣ (used only for running times) is dropped. ∑1≤r≤iDAr\sum_{1 \le r \le i} D_{A_r}∑1≤r≤i​DAr​​ is written as the sum of DDD over the first iii characters of AAA.

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

/-- Theorem 1 [Wagner–Fischer]: `δ_{0,0} = 0`, `δ_{i,0} = ∑_{1≤r≤i} D_{A_r}` for
`1 ≤ i ≤ |A|`, and `δ_{0,j} = ∑_{1≤r≤j} I_{B_r}` for `1 ≤ j ≤ |B|`, for a nonnegative
normalized cost function. -/
theorem initial_vectors {α : Type*} (γ : EditOp α → ℝ) (hγ : ∀ o, 0 ≤ γ o)
    (hN : IsNormalized γ) (A B : List α) :
    dmat γ A B 0 0 = 0 ∧
    (∀ i : ℕ, 1 ≤ i → i ≤ A.length → dmat γ A B i 0 = ((A.take i).map (delCost γ)).sum) ∧
    (∀ j : ℕ, 1 ≤ j → j ≤ B.length → dmat γ A B 0 j = ((B.take j).map (insCost γ)).sum) := by sorry

end MasekPaterson.FourRussians
Source
Masek, Paterson, A Faster Algorithm Computing String Edit Distances, J. Comput. System Sci. 20, 1980, p. 20, Theorem 1 [7]
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α. The type of edit operations is defined in the imported shared file. There are two assumptions:

  • γ(o)≥0\gamma(o)\ge0γ(o)≥0 for every edit operation ooo;
  • γ\gammaγ satisfies the predicate IsNormalized. This predicate is imported and not shown, so its content (and whether it is compatible with nonnegativity) cannot be read off this code.

Let A=(A1,…,A∣A∣)A=(A_1,\dots,A_{|A|})A=(A1​,…,A∣A∣​) and B=(B1,…,B∣B∣)B=(B_1,\dots,B_{|B|})B=(B1​,…,B∣B∣​) be finite lists over α\alphaα. Write δi,j\delta_{i,j}δi,j​ for dmat γ A B i j. This is an imported function of i,j∈Ni,j\in\mathbb Ni,j∈N whose definition is not reproduced here; the docstring calls it the edit matrix. Likewise del(a)\mathrm{del}(a)del(a) and ins(b)\mathrm{ins}(b)ins(b) are the imported deletion and insertion costs under γ\gammaγ. The statement asserts three facts together:

δ0,0=0,\delta_{0,0}=0,δ0,0​=0, δi,0=∑r=1idel(Ar)for every i with 1≤i≤∣A∣,\delta_{i,0}=\sum_{r=1}^{i}\mathrm{del}(A_r)\quad\text{for every } i \text{ with } 1\le i\le|A|,δi,0​=r=1∑i​del(Ar​)for every i with 1≤i≤∣A∣, δ0,j=∑r=1jins(Br)for every j with 1≤j≤∣B∣.\delta_{0,j}=\sum_{r=1}^{j}\mathrm{ins}(B_r)\quad\text{for every } j \text{ with } 1\le j\le|B|.δ0,j​=r=1∑j​ins(Br​)for every j with 1≤j≤∣B∣.

In the degenerate cases:

  • If AAA is empty, the second claim is vacuous; if BBB is empty, the third is vacuous. For two empty lists only δ0,0=0\delta_{0,0}=0δ0,0​=0 is asserted.
  • If α\alphaα is empty, every list is empty and only δ0,0=0\delta_{0,0}=0δ0,0​=0 remains.
  • Nothing is asserted about δi,0\delta_{i,0}δi,0​ for i>∣A∣i>|A|i>∣A∣ or δ0,j\delta_{0,j}δ0,j​ for j>∣B∣j>|B|j>∣B∣.
  • If IsNormalized together with nonnegativity were unsatisfiable, the whole statement would be vacuous. That cannot be decided from the code shown.
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