Documentation

CslibFrontier.Algorithms.Lean.EditDistance.Hirschberg

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 #

Main results #

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.

Swapping the input words preserves edit distance when the costs are transposed as well.

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.