Pure divide-and-conquer correctness step for Hirschberg alignment #
This module establishes only the pure functional divide-and-conquer correctness step toward
Hirschberg's O(mn)-time, O(m + n)-space alignment and longest-common-subsequence theorem
(after Hirschberg, Algorithm C, p. 342, and minimum-trace-cost variant, p. 343
and Kleinberg–Tardos, §§6.6–6.7, (6.19)–(6.20)), not the cited machine
time and space theorem (#9553).
Here recursive calls slice List α inputs with List.take, List.drop and List.reverse with
no machine time or space model; certifying O(mn) time and O(m + n) space on the Word-RAM is
tracked in #9553.
hirschbergAlign splits the longer input in half, uses the forward and reverse score rows
(bestSplit) to find a target column where some optimal alignment crosses the split, solves the
two smaller problems recursively, and joins their scripts without re-traversing them. When it
exchanges the inputs to place the shorter word across the score row, it transposes the costs and
emits operations in the original direction, supporting arbitrary natural-number insertion,
deletion and substitution costs. hirschbergLCS keeps the matched letters of an optimal
insertion–deletion alignment.
Main definitions #
Cslib.Algorithms.Lean.EditDistance.Costs.transpose,Cslib.Algorithms.Lean.EditDistance.EditOp.transpose: reversed-direction letter costs and edit operations.Cslib.Algorithms.Lean.EditDistance.hirschbergAlign: pure divide-and-conquer edit-script reconstruction overList α.Cslib.Algorithms.Lean.EditDistance.hirschbergLCS: pure divide-and-conquer longest common subsequence reconstruction overList α.
Main results #
Cslib.Algorithms.Lean.EditDistance.EditScript.transpose_spec,Cslib.Algorithms.Lean.EditDistance.editDist_transpose: transposing operations swaps source and target under transposed costs and preserves edit distance.Cslib.Algorithms.Lean.EditDistance.hirschbergAlign_spec: pure functional correctness step showinghirschbergAlign C x yis a valid script fromxtoyof costeditDist C x y.Cslib.Algorithms.Lean.EditDistance.hirschbergLCS_spec: pure functional correctness step showinghirschbergLCS x yis a common subsequence of lengthlcsLength x y.
References #
Costs of running an alignment in the opposite direction.
Reverse the direction of a single edit operation.
Swapping the sides of each operation exchanges the words consumed and produced and charges the transposed costs. Operations stay in their original order.
Pure functional divide-and-conquer edit-script reconstruction over List α (after
Hirschberg, p. 343 and Kleinberg–Tardos, §6.7), slicing
sublists without a machine time or space bound
(#9553).
Pure functional divide-and-conquer correctness step toward Hirschberg's O(mn)-time,
O(m + n)-space alignment theorem (after Hirschberg, p. 343 and
Kleinberg–Tardos, §6.7, (6.19)–(6.20)), not the cited machine time and
space result (#9553):
hirschbergAlign C x y consumes x, produces y, and attains editDist C x y for arbitrary
natural-number letter costs.
Pure functional divide-and-conquer longest-common-subsequence reconstruction over List α
(after Hirschberg, Algorithm C, p. 342), keeping the matched letters of
hirschbergAlign Costs.indel x y without a machine time or space bound
(#9553).
Pure functional divide-and-conquer correctness step toward Hirschberg's O(mn)-time,
O(m + n)-space longest-common-subsequence theorem (after
Hirschberg, Algorithm C, p. 342), not the cited machine time and space result
(#9553): hirschbergLCS x y is a
sublist of both inputs and attains lcsLength x y.