Metric properties of Levenshtein edit distance and pattern matching distance #
Establishes the metric properties and structural monotonicity laws of unit-cost Levenshtein edit
distance (Cslib.Algorithms.Lean.EditDistance.editDist Costs.unit), its characterization via
deletion-substitution scripts to a common target word, and the exact guard-padding reduction from
substring pattern matching distance to global edit distance:
- Symbol-count and filter bounds: symbol-count lower bounds (
count_sub_le_editDist_unit) and 1-Lipschitz stability underList.filter(editDist_unit_filter_le), building on the shared metric and concatenation laws inEditDistance.BasicandEditDistance.Unit. - Common-target deletion-substitution characterization (
IsDelSubScript,isLeast_delSub_common_target):editDist Costs.unit x yequals the least total cost over all common target wordszof transformingxtozandytozusing only deletions and substitutions (no insertions). - Pattern matching distance and fresh-guard reduction (
patternDist,isLeast_patternDist,editDist_unit_guard_pad_eq_patternDist): defines the minimum edit distance from a patternpto all contiguous substrings (List.IsInfix) of a textt, and proves that flankingpon both sides with|t|copies of a fresh symbolg ∉ tsatisfieseditDist Costs.unit (g^{|t|} ++ p ++ g^{|t|}) t = 2 * |t| + patternDist p t.
Main definitions #
Cslib.Algorithms.Lean.EditDistance.IsDelSubScript: predicate onEditScript αforbidding insertions.Cslib.Algorithms.Lean.EditDistance.patternDist: minimum unit-cost edit distance from a pattern word to all contiguous substrings of a text word.
Main results #
Cslib.Algorithms.Lean.EditDistance.count_sub_le_editDist_unitCslib.Algorithms.Lean.EditDistance.editDist_unit_filter_leCslib.Algorithms.Lean.EditDistance.isLeast_delSub_common_targetCslib.Algorithms.Lean.EditDistance.isLeast_patternDistCslib.Algorithms.Lean.EditDistance.editDist_unit_guard_pad_eq_patternDist
1. Metric and Lipschitz properties of unit-cost edit distance #
Difference in letter multiplicity is bounded by unit-cost edit distance.
Filtering by any Boolean predicate p does not increase unit-cost edit distance.
2. Common-target deletion-substitution characterization #
An edit script uses only deletions and substitutions (no insertions).
Unit-cost edit distance equals the minimum over all common target words z of the combined cost
of deletion-substitution scripts transforming x to z and y to z.
3. Pattern matching distance and fresh-guard reduction to edit distance #
Pattern matching distance from a pattern p to a text t: the minimum unit-cost edit distance
editDist Costs.unit p x over all contiguous substrings x <:+: t.
patternDist p t is the least value of editDist Costs.unit p x over x <:+: t.
Fresh-guard reduction from pattern matching distance to edit distance: if a guard symbol g
does not occur in t, then flanking p on both sides with |t| copies of g shifts unit-cost
edit distance by 2 * |t| above patternDist p t:
editDist Costs.unit (g^{|t|} ++ p ++ g^{|t|}) t = 2 * |t| + patternDist p t.