Documentation

CslibFrontier.Algorithms.Lean.EditDistance.HirschbergSplit

Choosing a split column for edit-script reconstruction #

Split the source into left ++ right. A forward row gives the distance from the left half to every target prefix, and a backward row gives the distance from the right half to every target suffix. Adding corresponding entries and selecting the first minimum finds a target column where two independently optimal alignments concatenate to a whole optimal alignment.

The suffix-indexed grid computes the prefix scores on reversed words. Reversing the order of a script leaves the cost of each operation unchanged, so asymmetric letter costs are allowed.

Reversing both words preserves their weighted edit distance. Each reversed script has the same operations in reverse order, with the same individual costs.

def Cslib.Algorithms.Lean.EditDistance.splitCosts {α : Type u_1} (C : Costs α) (left right y : List α) :

The sum of the forward and backward scores at every possible split column, in order.

@[simp]
theorem Cslib.Algorithms.Lean.EditDistance.length_splitCosts {α : Type u_1} (C : Costs α) (left right y : List α) :
(splitCosts C left right y).length = y.length + 1
theorem Cslib.Algorithms.Lean.EditDistance.getElem_splitCosts {α : Type u_1} (C : Costs α) (left right y : List α) (k : ℕ) (hk : k < (splitCosts C left right y).length) :
(splitCosts C left right y)[k] = editDist C left (List.take k y) + editDist C right (List.drop k y)

Column k records the cost of cutting the target just before index k.

def Cslib.Algorithms.Lean.EditDistance.bestSplit {α : Type u_1} (C : Costs α) (left right y : List α) :

The least-cost split column for left ++ right against y, taking the first minimum. Each half contributes one score row, and the final scan compares their pointwise sums.

theorem Cslib.Algorithms.Lean.EditDistance.bestSplit_le_length {α : Type u_1} (C : Costs α) (left right y : List α) :
bestSplit C left right y ≤ y.length

The selected split column lies between the two ends of the target, inclusive.

theorem Cslib.Algorithms.Lean.EditDistance.bestSplit_spec {α : Type u_1} (C : Costs α) (left right y : List α) :
have k := bestSplit C left right y; editDist C left (List.take k y) + editDist C right (List.drop k y) = editDist C (left ++ right) y

An optimal alignment through the selected column has the whole edit distance as its cost.