Documentation

CslibFrontier.Algorithms.WordRAM.EditDistance

Word-RAM edit distance and longest common subsequence #

Checked Word-RAM implementations and O((|x| + 1)(|y| + 1)) running-time bounds for the dynamic programs of CslibFrontier.Algorithms.Lean.EditDistance:

All three instantiate a shared private GridDP execution engine that fills the suffix table D.value (x.drop (|x| - s)) (y.drop (|y| - k)) in place across one (n + 1)-word row using an explicit diagonal register. Every address calculation, table read/write, comparison, arithmetic instruction, loop branch/jump, and final halt is charged by the Word-RAM semantics.

Main definitions #

Main results #

References #

Shared register layout and GridDP row engine #

Shared three-way minimum tail #

Word-encoded sequence pairs: LCS length and unit-cost edit distance #

A pair of word-encoded sequences src, tgt : List ℕ for longest-common-subsequence length and unit-cost Levenshtein edit distance on the Word-RAM. Letters may be arbitrary w-bit words.

Word-RAM input layout [|src|, |tgt|] ++ src ++ tgt of length 2 + |src| + |tgt|.

@[reducible, inline]

Word-width condition for WordSeqPair: one-past-end working-row addresses and all DP entries fit in w bits.

Longest common subsequence on the Word-RAM #

Fixed standard-basis Word-RAM program computing lcsLength I.src I.tgt on I : WordSeqPair.

Word-RAM running time of longest common subsequence. The fixed standard-basis program lcsLengthProgram computes lcsLength I.src I.tgt in at most 20 (|x| + 1)(|y| + 1) instructions (including input header reads and halt) at every fitting word width w.

Uniform Word-RAM computability of longest-common-subsequence length in 20 (|x| + 1)(|y| + 1) instructions, bundling width admissibility (WordSeqPair.inputAdmissible).

Unit-cost Levenshtein edit distance on the Word-RAM #

Fixed standard-basis Word-RAM program computing editDist Costs.unit I.src I.tgt on I : WordSeqPair.

Word-RAM running time of unit-cost edit distance (Levenshtein). The fixed standard-basis program unitEditDistProgram computes editDist Costs.unit I.src I.tgt in at most 26 (|x| + 1)(|y| + 1) instructions at every fitting word width w.

Uniform Word-RAM computability of unit-cost Levenshtein edit distance in 26 (|x| + 1)(|y| + 1) instructions, bundling width admissibility (WordSeqPair.inputAdmissible).

General-cost Wagner–Fischer edit distance on the Word-RAM #

An edit-distance instance over a finite integer alphabet Fin sigma with arbitrary natural-number letter costs (Costs (Fin sigma)).

Flattened row-major σ × σ substitution-cost table [costs.sub a b | a, b < σ].

All 2σ + σ² letter-operation cost entries of I.

Word-RAM input layout [σ, |src|, |tgt|] ++ src ++ tgt ++ del ++ ins ++ sub of length 3 + |src| + |tgt| + 2σ + σ².

Largest single letter-operation cost entry in I.

Upper bound on all DP entries and candidate sums during Wagner–Fischer execution on I: deleting all of src plus inserting all of tgt, plus maxOpCost.

@[reducible, inline]

Word-width condition for WeightedInstance: working-row addresses and all candidate DP sums fit in w bits.

FitsWidth already bounds the length, header words, < σ symbols, and ≤ maxOpCost cost entries of I.encode, so callers need not discharge InputFits separately.

Word-RAM running time of Wagner–Fischer edit distance under arbitrary letter costs. The fixed standard-basis program weightedEditDistProgram computes editDist I.costs I.src I.tgt in at most 28 (|x| + 1)(|y| + 1) instructions (including input header reads and halt) at every fitting word width w.

Uniform Word-RAM computability of general-cost Wagner–Fischer edit distance in 28 (|x| + 1)(|y| + 1) instructions, bundling width admissibility (WeightedInstance.inputAdmissible).