Corollary 1 (of Theorem 2) — the recurrence in terms of steps
ProvedMasekPaterson.FourRussians.step_recurrenceLet be a nonnegative, normalized cost function and strings with edit matrix . For all with and , the vertical step and the horizontal step satisfy
The steps leaving a cell are determined by the steps entering it and the two characters , without reference to the absolute values of . Algorithm Y is exactly this recurrence.
Formalization Note The corollary prints no range for ; it inherits Theorem 2's range , and its hypotheses (nonnegative, normalized ).
import Mathlib import Definitions.Def_MasekPaterson_Shared_editDist open MasekPaterson.Shared
namespace MasekPaterson.FourRussians
/-- Corollary 1 (of Theorem 2): the Wagner–Fischer recurrence in terms of steps. For
`1 ≤ i ≤ |A|`, `1 ≤ j ≤ |B|` and a nonnegative normalized cost function,
`δ_{i,j} − δ_{i−1,j} = min{R_{A_i,B_j} − (δ_{i−1,j} − δ_{i−1,j−1}), D_{A_i},
I_{B_j} + (δ_{i,j−1} − δ_{i−1,j−1}) − (δ_{i−1,j} − δ_{i−1,j−1})}` and
`δ_{i,j} − δ_{i,j−1} = min{R_{A_i,B_j} − (δ_{i,j−1} − δ_{i−1,j−1}),
D_{A_i} + (δ_{i−1,j} − δ_{i−1,j−1}) − (δ_{i,j−1} − δ_{i−1,j−1}), I_{B_j}}`. -/
theorem step_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 - dmat γ A B (i - 1) j =
min (min (replCost γ A[i - 1] B[j - 1]
- (dmat γ A B (i - 1) j - dmat γ A B (i - 1) (j - 1)))
(delCost γ A[i - 1]))
(insCost γ B[j - 1] + (dmat γ A B i (j - 1) - dmat γ A B (i - 1) (j - 1))
- (dmat γ A B (i - 1) j - dmat γ A B (i - 1) (j - 1))) ∧
dmat γ A B i j - dmat γ A B i (j - 1) =
min (min (replCost γ A[i - 1] B[j - 1]
- (dmat γ A B i (j - 1) - dmat γ A B (i - 1) (j - 1)))
(delCost γ A[i - 1] + (dmat γ A B (i - 1) j - dmat γ A B (i - 1) (j - 1))
- (dmat γ A B i (j - 1) - dmat γ A B (i - 1) (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, unshown predicate
IsNormalized.
Let be finite lists over with 1-based entries. Write for the imported dmat γ A B i j, which the docstring calls the edit matrix. Write , and for the imported replacement, deletion and insertion costs.
Fix natural numbers with and , and set
The statement asserts that both of the following equalities hold:
All subtractions are subtractions of real numbers. The index subtractions and are exact because .
In the degenerate cases:
- If or is empty (including whenever is empty), the hypotheses on cannot be met and the statement is vacuous.
- It would also be vacuous if
IsNormalizedwere incompatible with nonnegativity. This is not determinable from the code shown.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.