Theorem 2 [7] — the Wagner–Fischer recurrence for
ProvedMasekPaterson.FourRussians.wagner_fischer_recurrenceLet be a nonnegative, normalized cost function and strings with edit matrix . For all with and ,
Each internal entry of the edit matrix is thus determined by its three neighbours above and to the left; this is Wagner and Fischer's matrix-filling algorithm [7], and it is the basis of every step of the Masek–Paterson algorithm.
Formalization Note is the minimum over all edit sequences (Section 1.1), not the recurrence, so this is a genuine theorem. Normalization is needed: with , and all insertions and deletions costing , while the right-hand side is . Characters are 1-based as in the paper ( is A[i-1]).
import Mathlib import Definitions.Def_MasekPaterson_Shared_editDist open MasekPaterson.Shared
namespace MasekPaterson.FourRussians
/-- Theorem 2 [Wagner–Fischer]: for `1 ≤ i ≤ |A|`, `1 ≤ j ≤ |B|`,
`δ_{i,j} = min(δ_{i−1,j−1} + R_{A_i,B_j}, δ_{i−1,j} + D_{A_i}, δ_{i,j−1} + I_{B_j})`,
for a nonnegative normalized cost function. `A_i` (1-based) is `A[i-1]`. -/
theorem wagner_fischer_recurrence {α : Type*} (γ : EditOp α → ℝ) (hγ : ∀ o, 0 ≤ γ o)
(hN : IsNormalized γ) (A B : List α) (i j : ℕ)
(hi : 1 ≤ i) (hiA : i ≤ A.length) (hj : 1 ≤ j) (hjB : j ≤ B.length) :
dmat γ A B i j =
min (min (dmat γ A B (i - 1) (j - 1) + replCost γ A[i - 1] B[j - 1])
(dmat γ A B (i - 1) j + delCost γ A[i - 1]))
(dmat γ A B i (j - 1) + insCost γ B[j - 1]) := by sorry
end MasekPaterson.FourRussians
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Let be any type and a real-valued cost function on edit operations over (a type defined in the imported shared file). There are two assumptions:
- for all ;
- satisfies the imported predicate
IsNormalized, whose content is not shown.
Let be finite lists over with 1-based entries and . Write for the imported quantity dmat γ A B i j, which the docstring calls the edit matrix and whose definition is not reproduced here. Write , and for the imported replacement, deletion and insertion costs under .
For all natural numbers with and , the statement asserts the exact equality
Because , the indices and are ordinary predecessors; natural-number truncation at never occurs. The index or may equal , so boundary entries of can appear on the right.
In the degenerate cases:
- If or is empty (in particular if is empty), no satisfies the hypotheses and the statement is vacuous.
- If
IsNormalizedwere unsatisfiable together with nonnegativity, it would be vacuous too. This cannot be judged from the code shown.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.