Dynamic programs over pairs of suffixes #
The common skeleton of the Wagner–Fischer edit-distance program
Wagner and Fischer and the longest-common-subsequence program
CLRS, Section 15.4. Both fill a table indexed by pairs of suffixes of two words x and
y. The entry for two empty suffixes is a constant. An entry with one empty suffix depends on its
neighbour along that border. Every other entry depends on three neighbours: the entry dropping the
first letter of both suffixes, the entry dropping only the first letter of the suffix of x, and
the entry dropping only the first letter of the suffix of y. (The textbook tables are indexed by
prefixes; indexing by suffixes is the same program run on the reversed words, and it lets the
recursion follow the list structure.)
A GridDP records the four rules. GridDP.value D x y is the entry for the whole words, computed
row by row: GridDP.row D y x lists the entries for x against every suffix of y, longest
first, and the row for a :: x is computed from the row for x alone (GridDP.stepRow). This is
the usual two-row scheme, in which only the previous row is kept. Checked Word-RAM running-time
bounds for the concrete edit-distance and longest-common-subsequence instances live in
CslibFrontier.Algorithms.WordRAM.EditDistance.
Main definitions #
Cslib.Algorithms.Lean.EditDistance.GridDP: the four rules of a table over pairs of suffixes.Cslib.Algorithms.Lean.EditDistance.GridDP.value: the entry for the whole words.
Main results #
Cslib.Algorithms.Lean.EditDistance.GridDP.value_nil_nil,value_cons_nil,value_nil_cons,value_cons_cons:valuesatisfies the four rules.
References #
The rules of a dynamic program over pairs of suffixes of two words over α, with entries in
β. The entry for (a :: x, b :: y) is consCons a b d u l, where d, u and l are the
entries for (x, y), (x, b :: y) and (a :: x, y).
- nilNil : β
The entry for two empty words.
- consNil : α → β → β
The entry for
(a :: x, [])from the entry for(x, []). - nilCons : α → β → β
The entry for
([], b :: y)from the entry for([], y). - consCons : α → α → β → β → β → β
The entry for
(a :: x, b :: y)from the entries for(x, y),(x, b :: y)and(a :: x, y).