Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Algorithm Y returns the final step vectors of every m×mm \times mm×m submatrix

Proved
MasekPaterson.FourRussians.blockY_final_steps

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

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

Let γ\gammaγ be a nonnegative, normalized cost function and A,BA, BA,B strings with edit matrix δi,j\delta_{i,j}δi,j​. Consider the (i,j,m)(i, j, m)(i,j,m) submatrix, whose upper-left entry is δi,j\delta_{i,j}δi,j​, with i+m≤∣A∣i + m \le |A|i+m≤∣A∣ and j+m≤∣B∣j + m \le |B|j+m≤∣B∣. Run Algorithm Y on the strings C=Ai+1,i+mC = A^{i+1, i+m}C=Ai+1,i+m and D=Bj+1,j+mD = B^{j+1, j+m}D=Bj+1,j+m and the submatrix's actual initial step vectors

R=⟨δi+k,j−δi+k−1,j⟩k=1m (left column),S=⟨δi,j+k−δi,j+k−1⟩k=1m (top row).R = \langle \delta_{i+k,j} - \delta_{i+k-1,j} \rangle_{k=1}^{m} \ \text{(left column)}, \qquad S = \langle \delta_{i,j+k} - \delta_{i,j+k-1} \rangle_{k=1}^{m} \ \text{(top row)}.R=⟨δi+k,j​−δi+k−1,j​⟩k=1m​ (left column),S=⟨δi,j+k​−δi,j+k−1​⟩k=1m​ (top row).

Then its output (R′,S′)(R', S')(R′,S′) is the submatrix's actual pair of final step vectors:

R′=⟨δi+k,j+m−δi+k−1,j+m⟩k=1m (right column),S′=⟨δi+m,j+k−δi+m,j+k−1⟩k=1m (bottom row).R' = \langle \delta_{i+k,j+m} - \delta_{i+k-1,j+m} \rangle_{k=1}^{m} \ \text{(right column)}, \qquad S' = \langle \delta_{i+m,j+k} - \delta_{i+m,j+k-1} \rangle_{k=1}^{m} \ \text{(bottom row)}.R′=⟨δi+k,j+m​−δi+k−1,j+m​⟩k=1m​ (right column),S′=⟨δi+m,j+k​−δi+m,j+k−1​⟩k=1m​ (bottom row).

This is the statement, made in Section 2.1, that each submatrix is determined by its two initial step vectors and its two strings, and that Algorithm Y computes its final step vectors; Algorithm Z relies on it for every block.

Formalization Note The paper states this in prose ("each (i,j,k)(i, j, k)(i,j,k) submatrix may be determined by a starting value δ(i,j)\delta(i,j)δ(i,j), two initial step vectors … along with the two strings", and "Algorithm Y calculates a submatrix of steps according to Corollary 1"); it is not a numbered result. Vectors are 0-based in Lean: entry k : Fin m is the paper's entry k+1k+1k+1. For m=0m = 0m=0 the statement is trivially true.

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

/-- Algorithm Y computes a submatrix's final step vectors (§2.1): for the `(i, j, m)`
submatrix of the edit matrix of `A, B` (upper-left entry `δ_{i,j}`, with `i + m ≤ |A|`,
`j + m ≤ |B|`), Algorithm Y applied to the strings `C = A^{i+1,i+m}`, `D = B^{j+1,j+m}` and
the actual initial step vectors `R = ⟨δ_{i+k,j} − δ_{i+k−1,j}⟩_{k=1..m}` (left column) and
`S = ⟨δ_{i,j+k} − δ_{i,j+k−1}⟩_{k=1..m}` (top row) returns the actual final step vectors
`R' = ⟨δ_{i+k,j+m} − δ_{i+k−1,j+m}⟩_{k=1..m}` (right column) and
`S' = ⟨δ_{i+m,j+k} − δ_{i+m,j+k−1}⟩_{k=1..m}` (bottom row). Vectors are 0-based in Lean:
entry `k : Fin m` is the paper's entry `k + 1`. -/
theorem blockY_final_steps {α : Type*} (γ : EditOp α → ℝ) (hγ : ∀ o, 0 ≤ γ o)
    (hN : IsNormalized γ) (A B : List α) (i j m : ℕ)
    (hiA : i + m ≤ A.length) (hjB : j + m ≤ B.length) :
    blockY γ m
        (fun k => A[i + k.val]) (fun k => B[j + k.val])
        (fun k => dmat γ A B (i + k.val + 1) j - dmat γ A B (i + k.val) j)
        (fun k => dmat γ A B i (j + k.val + 1) - dmat γ A B i (j + k.val)) =
      (fun k => dmat γ A B (i + k.val + 1) (j + m) - dmat γ A B (i + k.val) (j + m),
       fun k => dmat γ A B (i + m) (j + k.val + 1) - dmat γ A B (i + m) (j + k.val)) := by sorry

end MasekPaterson.FourRussians
Source
Masek, Paterson, A Faster Algorithm Computing String Edit Distances, J. Comput. System Sci. 20, 1980, p. 22, Section 2.1 (paragraph before Algorithm Y, and Algorithm Y)
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). There are two assumptions:

  • γ(o)≥0\gamma(o)\ge0γ(o)≥0 for all ooo;
  • γ\gammaγ satisfies the imported, unshown predicate IsNormalized.

Let A,BA,BA,B be finite lists over α\alphaα with 1-based entries. Write δr,s\delta_{r,s}δr,s​ for the imported dmat γ A B r s, which the docstring calls the edit matrix. Let i,j,m∈Ni,j,m\in\mathbb Ni,j,m∈N with i+m≤∣A∣i+m\le|A|i+m≤∣A∣ and j+m≤∣B∣j+m\le|B|j+m≤∣B∣. Both i=0i=0i=0 and j=0j=0j=0 are allowed.

Form the following length-mmm inputs, indexed k=1,…,mk=1,\dots,mk=1,…,m:

  • the strings Ck=Ai+kC_k=A_{i+k}Ck​=Ai+k​ and Dk=Bj+kD_k=B_{j+k}Dk​=Bj+k​;
  • the real vectors
Rk=δi+k, j−δi+k−1, j,Sk=δi, j+k−δi, j+k−1.R_k=\delta_{i+k,\,j}-\delta_{i+k-1,\,j},\qquad S_k=\delta_{i,\,j+k}-\delta_{i,\,j+k-1}.Rk​=δi+k,j​−δi+k−1,j​,Sk​=δi,j+k​−δi,j+k−1​.

blockY(C,D,R,S)\mathrm{blockY}(C,D,R,S)blockY(C,D,R,S) is the imported block routine. It fills a table (T(r,s),U(r,s))(T(r,s),U(r,s))(T(r,s),U(r,s)) as follows:

  • boundary values T(r,0)=RrT(r,0)=R_rT(r,0)=Rr​ and U(0,s)=SsU(0,s)=S_sU(0,s)=Ss​;
  • for 1≤r,s≤m1\le r,s\le m1≤r,s≤m:
T(r,s)=min⁡{rep(Cr,Ds)−U(r−1,s), del(Cr), ins(Ds)+T(r,s−1)−U(r−1,s)},T(r,s)=\min\{\mathrm{rep}(C_r,D_s)-U(r-1,s),\ \mathrm{del}(C_r),\ \mathrm{ins}(D_s)+T(r,s-1)-U(r-1,s)\},T(r,s)=min{rep(Cr​,Ds​)−U(r−1,s), del(Cr​), ins(Ds​)+T(r,s−1)−U(r−1,s)}, U(r,s)=min⁡{rep(Cr,Ds)−T(r,s−1), del(Cr)+U(r−1,s)−T(r,s−1), ins(Ds)}.U(r,s)=\min\{\mathrm{rep}(C_r,D_s)-T(r,s-1),\ \mathrm{del}(C_r)+U(r-1,s)-T(r,s-1),\ \mathrm{ins}(D_s)\}.U(r,s)=min{rep(Cr​,Ds​)−T(r,s−1), del(Cr​)+U(r−1,s)−T(r,s−1), ins(Ds​)}.

It returns the pair of vectors ((T(k,m))k,(U(m,k))k)\bigl((T(k,m))_{k},(U(m,k))_{k}\bigr)((T(k,m))k​,(U(m,k))k​). Here rep\mathrm{rep}rep, del\mathrm{del}del and ins\mathrm{ins}ins are the imported replacement, deletion and insertion costs under γ\gammaγ.

The theorem asserts the equality of pairs of vectors

blockY(C,D,R,S)=((δi+k, j+m−δi+k−1, j+m)k=1m, (δi+m, j+k−δi+m, j+k−1)k=1m).\mathrm{blockY}(C,D,R,S)=\Bigl(\bigl(\delta_{i+k,\,j+m}-\delta_{i+k-1,\,j+m}\bigr)_{k=1}^{m},\ \bigl(\delta_{i+m,\,j+k}-\delta_{i+m,\,j+k-1}\bigr)_{k=1}^{m}\Bigr).blockY(C,D,R,S)=((δi+k,j+m​−δi+k−1,j+m​)k=1m​, (δi+m,j+k​−δi+m,j+k−1​)k=1m​).

In the degenerate cases:

  • When m=0m=0m=0, both sides are pairs of empty vectors and the claim is trivially true for all i≤∣A∣i\le|A|i≤∣A∣ and j≤∣B∣j\le|B|j≤∣B∣.
  • When i=0i=0i=0 or j=0j=0j=0, the block touches the boundary row or column of δ\deltaδ, and the input steps are differences of those boundary entries.
  • If IsNormalized were incompatible with nonnegativity, the statement would be vacuous. This cannot be judged 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