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:
- General-cost Wagner–Fischer edit distance (
weightedEditDistProgram) over a finite alphabetFin σwith arbitrary natural-number letter costs (Costs (Fin σ)), laid out in input memory as[σ, |x|, |y|], the wordsxandy, theσ-entrydelandinstables, and theσ²-entry row-majorsubtable. The program computeseditDist I.costs I.src I.tgtusing a single working row of|y| + 1words in at most28 (|x| + 1)(|y| + 1)standard-basis instructions. - Unit-cost Levenshtein edit distance (
unitEditDistProgram) over arbitraryw-bit word sequencesx, y : List ℕ(WordSeqPair), laid out as[|x|, |y|] ++ x ++ ywith no alphabet table. The program computeseditDist Costs.unit I.src I.tgtin at most26 (|x| + 1)(|y| + 1)instructions. - Longest-common-subsequence length (
lcsLengthProgram) over arbitraryw-bit word sequencesx, y : List ℕ(WordSeqPair), computinglcsLength I.src I.tgtin at most20 (|x| + 1)(|y| + 1)instructions.
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 #
Cslib.Algorithms.WordRAM.EditDistance.WeightedInstance: edit-distance instance overFin σwith general letter costs, its word layoutWeightedInstance.encode, and word-width conditionWeightedInstance.FitsWidth.Cslib.Algorithms.WordRAM.EditDistance.WordSeqPair: pair of word-encoded sequencesList ℕ, its word layoutWordSeqPair.encode, and word-width conditionWordSeqPair.FitsWidth.Cslib.Algorithms.WordRAM.EditDistance.weightedEditDistProgram,unitEditDistProgram,lcsLengthProgram: fixedProgram .standard 22programs.
Main results #
Cslib.Algorithms.WordRAM.EditDistance.WeightedInstance.FitsWidth.inputFits:FitsWidthimpliesInputFits w I.encode.Cslib.Algorithms.WordRAM.EditDistance.computesInTime_weightedEditDist,uniformComputableInTime_weightedEditDist: general-cost Wagner–Fischer edit distance runs in at most28 (|x| + 1)(|y| + 1)Word-RAM instructions at fitting widths.Cslib.Algorithms.WordRAM.EditDistance.computesInTime_unitEditDist,uniformComputableInTime_unitEditDist: unit-cost Levenshtein edit distance on word sequences runs in at most26 (|x| + 1)(|y| + 1)Word-RAM instructions at fitting widths.Cslib.Algorithms.WordRAM.EditDistance.computesInTime_lcsLength,uniformComputableInTime_lcsLength: longest-common-subsequence length on word sequences runs in at most20 (|x| + 1)(|y| + 1)Word-RAM instructions at fitting widths.
References #
Shared register layout and GridDP row engine #
Shared three-way minimum tail #
Word-encoded sequence pairs: LCS length and unit-cost edit distance #
Word-width condition for WordSeqPair: one-past-end working-row addresses and all DP entries
fit in w bits.
Every WordSeqPair admits a fitting word width.
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 #
Flattened row-major σ × σ substitution-cost table [costs.sub a b | a, b < σ].
All 2σ + σ² letter-operation cost entries of I.
Largest single letter-operation cost entry in I.
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.
Every WeightedInstance admits a fitting word width.
Fixed standard-basis Word-RAM program computing editDist I.costs I.src I.tgt on
I : WeightedInstance.
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).