Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The block algorithm (Algorithms Y and Z) computes δ(γ,A,B)\delta(\gamma, A, B)δ(γ,A,B) from a string-independent finite table

Proved
MasekPaterson.FourRussians.algZ_correct_finite_table

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

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

Let Σ\SigmaΣ be a finite alphabet and γ\gammaγ a nonnegative, normalized cost function whose cost set Ω\OmegaΩ is discrete. Then there is a finite set T⊂RT \subset \mathbb{R}T⊂R such that for every block size m≥1m \ge 1m≥1 and all strings A,BA, BA,B with m∣∣A∣m \mid |A|m∣∣A∣ and m∣∣B∣m \mid |B|m∣∣B∣:

  1. Algorithm Z, with Fetch\mathrm{Fetch}Fetch given by Algorithm Y, returns
cost=δ(γ,A,B);\mathrm{cost} = \delta(\gamma, A, B);cost=δ(γ,A,B);
  1. every entry of every step vector P(i,j)P(i, j)P(i,j) (1≤i≤∣A∣/m1 \le i \le |A|/m1≤i≤∣A∣/m, 0≤j≤∣B∣/m0 \le j \le |B|/m0≤j≤∣B∣/m) and Q(i,j)Q(i, j)Q(i,j) (0≤i≤∣A∣/m0 \le i \le |A|/m0≤i≤∣A∣/m, 1≤j≤∣B∣/m1 \le j \le |B|/m1≤j≤∣B∣/m) computed by Algorithm Z lies in TTT.

The set TTT is chosen before mmm, AAA and BBB. Consequently every call Fetch(P(i,j−1),Q(i−1,j),… )\mathrm{Fetch}(P(i,j-1), Q(i-1,j), \dots)Fetch(P(i,j−1),Q(i−1,j),…) made by Algorithm Z is answered from the table of Algorithm Y over Σm×Σm×Tm×Tm\Sigma^m \times \Sigma^m \times T^m \times T^mΣm×Σm×Tm×Tm, a table whose size depends only on mmm, Σ\SigmaΣ and γ\gammaγ and not on the strings. These are the two facts on which the paper's running time O(∣A∣⋅∣B∣/max⁡(1,∣B∣/log⁡∣A∣))O(|A| \cdot |B| / \max(1, |B|/\log|A|))O(∣A∣⋅∣B∣/max(1,∣B∣/log∣A∣)) rests.

Formalization Note The paper states a running time O(∣A∣⋅∣B∣/max⁡(1,∣B∣/log⁡∣A∣))O(|A|\cdot|B|/\max(1, |B|/\log |A|))O(∣A∣⋅∣B∣/max(1,∣B∣/log∣A∣)) on a logarithmic-cost RAM; this statement formalizes the two facts the bound rests on, correctness and a string-independent finite table domain. The RAM cost model, the operation counts and the choice m=⌊log⁡k∣A∣⌋m = \lfloor \log_k |A| \rfloorm=⌊logk​∣A∣⌋ are not formalized, nor is the padding reduction for m∤∣A∣m \nmid |A|m∤∣A∣. The standing assumption ∣A∣≥∣B∣|A| \ge |B|∣A∣≥∣B∣ is dropped. Algorithms Y and Z are transcribed from the pseudo-code and do not refer to δ\deltaδ.

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

/-- Correctness of the Masek–Paterson block algorithm with a string-independent finite table
(§2.2, Algorithm Z with Fetch = Algorithm Y). Over a finite alphabet, for a nonnegative
normalized cost function whose cost set `Ω` is discrete, there is one finite set `T` of
reals such that for every block size `m ≥ 1` and all strings `A, B` with `m ∣ |A|` and
`m ∣ |B|`: Algorithm Z returns `δ(γ, A, B)`, and every entry of every step vector
`P(i, j)` (`1 ≤ i ≤ |A|/m`, `0 ≤ j ≤ |B|/m`) and `Q(i, j)` (`0 ≤ i ≤ |A|/m`,
`1 ≤ j ≤ |B|/m`) that Algorithm Z computes lies in `T`. -/
theorem algZ_correct_finite_table {α : Type*} [Fintype α] (γ : EditOp α → ℝ)
    (hγ : ∀ o, 0 ≤ γ o) (hN : IsNormalized γ) (hΩ : IsDiscrete γ) :
    ∃ T : Finset ℝ, ∀ m : ℕ, 0 < m → ∀ A B : List α, m ∣ A.length → m ∣ B.length →
      algZ γ m A B = editDist γ A B ∧
      (∀ i j : ℕ, 1 ≤ i → i ≤ A.length / m → j ≤ B.length / m →
        ∀ k : Fin m, algZ_P γ m A B i j k ∈ T) ∧
      (∀ i j : ℕ, i ≤ A.length / m → 1 ≤ j → j ≤ B.length / m →
        ∀ k : Fin m, algZ_Q γ m A B i j k ∈ T) := by sorry

end MasekPaterson.FourRussians
Source
Masek, Paterson, A Faster Algorithm Computing String Edit Distances, J. Comput. System Sci. 20, 1980, p. 24, Section 2.2, Algorithm Z (with Algorithm Y, p. 22, and Lemma 4, p. 23)
Read-back

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

Let α\alphaα be any type with finitely many elements (an alphabet, possibly empty or with a single letter). Let γ\gammaγ be a real-valued function on EditOp(α)\mathrm{EditOp}(\alpha)EditOp(α), a type defined in the imported bundle whose construction is not shown here. Presumably it describes edit operations over α\alphaα, and γ\gammaγ assigns each one a real cost. The statement assumes three things about γ\gammaγ:

  • γ(o)≥0\gamma(o) \ge 0γ(o)≥0 for every o∈EditOp(α)o \in \mathrm{EditOp}(\alpha)o∈EditOp(α);
  • γ\gammaγ satisfies the bundle predicate IsNormalized\mathrm{IsNormalized}IsNormalized;
  • γ\gammaγ satisfies the bundle predicate IsDiscrete\mathrm{IsDiscrete}IsDiscrete.

The definitions of IsNormalized\mathrm{IsNormalized}IsNormalized and IsDiscrete\mathrm{IsDiscrete}IsDiscrete are not included in the code provided. Their exact content, and whether they can be satisfied together with nonnegativity, cannot be read off from this declaration. If no γ\gammaγ satisfies all three, the statement holds vacuously.

The statement uses the following objects from the imported bundle, none of whose definitions are shown:

  • δγ(A,B)\delta_\gamma(A,B)δγ​(A,B) (editDist) is a value computed from γ\gammaγ and two finite lists A,BA, BA,B of letters from α\alphaα.
  • Zγ,m(A,B)Z_{\gamma,m}(A,B)Zγ,m​(A,B) (algZ) is a value computed from γ\gammaγ, a natural number mmm, and A,BA, BA,B.
  • Pγ,m,A,B(i,j)P_{\gamma,m,A,B}(i,j)Pγ,m,A,B​(i,j) and Qγ,m,A,B(i,j)Q_{\gamma,m,A,B}(i,j)Qγ,m,A,B​(i,j) (algZ_P, algZ_Q) are defined for all natural numbers i,ji, ji,j. Each is a vector of mmm real entries, indexed by k∈{0,1,…,m−1}k \in \{0, 1, \dots, m-1\}k∈{0,1,…,m−1}.

Conclusion. Under these hypotheses there exists a single finite set T⊂RT \subset \mathbb{R}T⊂R with the following property. TTT depends only on α\alphaα and γ\gammaγ; it is chosen before, and independently of, mmm, AAA and BBB. For every natural number m≥1m \ge 1m≥1 and all lists A,BA, BA,B over α\alphaα whose lengths ∣A∣|A|∣A∣ and ∣B∣|B|∣B∣ are both divisible by mmm, three things hold.

  1. The two values are exactly equal:
Zγ,m(A,B)=δγ(A,B).Z_{\gamma,m}(A,B) = \delta_\gamma(A,B).Zγ,m​(A,B)=δγ​(A,B).
  1. For all natural numbers i,ji, ji,j with 1≤i≤∣A∣/m1 \le i \le |A|/m1≤i≤∣A∣/m and 0≤j≤∣B∣/m0 \le j \le |B|/m0≤j≤∣B∣/m, and every k∈{0,…,m−1}k \in \{0,\dots,m-1\}k∈{0,…,m−1}:
Pγ,m,A,B(i,j)k∈T.P_{\gamma,m,A,B}(i,j)_k \in T.Pγ,m,A,B​(i,j)k​∈T.
  1. For all natural numbers i,ji, ji,j with 0≤i≤∣A∣/m0 \le i \le |A|/m0≤i≤∣A∣/m and 1≤j≤∣B∣/m1 \le j \le |B|/m1≤j≤∣B∣/m, and every k∈{0,…,m−1}k \in \{0,\dots,m-1\}k∈{0,…,m−1}:
Qγ,m,A,B(i,j)k∈T.Q_{\gamma,m,A,B}(i,j)_k \in T.Qγ,m,A,B​(i,j)k​∈T.

The divisions ∣A∣/m|A|/m∣A∣/m and ∣B∣/m|B|/m∣B∣/m are natural-number (floor) divisions. Because divisibility is assumed, they are exact quotients here. The statement says nothing about PPP or QQQ at index pairs outside these ranges. It also says nothing about how large TTT is, how TTT is built, or whether it is minimal: it only claims that some finite TTT exists. The substance of the membership claims is that one finite TTT works for every block size mmm and every pair of lists at once. For any single fixed input, only finitely many entries are involved, so a finite set containing them exists trivially.

Degenerate cases. The value m=0m = 0m=0 is excluded, and m=1m = 1m=1 is allowed. In that case every length is divisible by mmm, and the vectors have one entry each.

  • AAA empty. Length 000 is divisible by every mmm. The PPP clause is vacuous, because no iii satisfies 1≤i≤01 \le i \le 01≤i≤0. The QQQ clause concerns only i=0i = 0i=0 and 1≤j≤∣B∣/m1 \le j \le |B|/m1≤j≤∣B∣/m.
  • BBB empty. Symmetrically, the QQQ clause is vacuous, and the PPP clause concerns only j=0j = 0j=0.
  • Both AAA and BBB empty. Both membership clauses are vacuous. The statement then asserts only Zγ,m(∅,∅)=δγ(∅,∅)Z_{\gamma,m}(\varnothing,\varnothing) = \delta_\gamma(\varnothing,\varnothing)Zγ,m​(∅,∅)=δγ​(∅,∅) for every m≥1m \ge 1m≥1.
  • α\alphaα empty. The only list is the empty one, so the whole statement reduces to that last equality, with TTT allowed to be any finite set, including ∅\varnothing∅. What EditOp(α)\mathrm{EditOp}(\alpha)EditOp(α), and hence γ\gammaγ and the three hypotheses, amount to in this case depends on definitions not shown.
  • Single-letter α\alphaα. No special treatment: the statement applies to all lists over that letter.
  • Default values. Apart from the floor divisions, which are exact here, the statement itself contains no division, natural-number subtraction, integral or supremum that could produce a default value. Whether editDist, algZ, algZ_P or algZ_Q rely internally on such default values cannot be determined from the code provided.
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