Levenshtein distance on words #
A SingleEdit inserts, deletes, or changes one letter anywhere in the current word.
isLeast_editDist_unit identifies the Wagner–Fischer table entry with the minimum length of
a sequence of such edits through arbitrary intermediate words. This is the unit-cost case of
Wagner and Fischer, §3, Theorem 1, p. 171.
Each alignment gives a sequence of the same cost, and every sequence bounds the distance.
Reversing and joining sequences gives symmetry and the triangle inequality.
One insertion, deletion, or replacement by a different letter in the current word.
The cons constructor skips a common first letter and permits edits at any later position.
- ins {α : Type u_1} (b : α) (xs : List α) : SingleEdit xs (b :: xs)
Insert a letter at the front.
- del {α : Type u_1} (a : α) (xs : List α) : SingleEdit (a :: xs) xs
Delete the front letter.
- sub {α : Type u_1} {a b : α} (h : a ≠ b) (xs : List α) : SingleEdit (a :: xs) (b :: xs)
Change the front letter, keeping the tail.
- cons {α : Type u_1} (a : α) {xs ys : List α} (h : SingleEdit xs ys) : SingleEdit (a :: xs) (a :: ys)
Perform the edit after a common first letter.
Realize any alignment by exactly one edit per charged operation.
The Levenshtein distance from a word to itself is zero.
The Levenshtein distance is the minimum number of single-letter edits at arbitrary positions in successive words (Wagner and Fischer, §3, Theorem 1, p. 171, unit costs).
Levenshtein distance is symmetric because an edit sequence can be reversed.
Joining two shortest sequences gives the triangle inequality for Levenshtein distance.
Two words have Levenshtein distance zero exactly when they agree.