A Faster Algorithm Computing String Edit Distances 2: Discrete Edit Costs Are NecessaryResearch Paper
Motivation
The edit distance between two strings is the least total cost of a sequence of single-character insertions, deletions and replacements that turns one string into the other. It underlies spelling correction, sequence alignment in computational biology, and file comparison. Wagner and Fischer (J. ACM 21, 1974) computed it for strings of length in time by filling an matrix. Masek and Paterson (J. Comput. System Sci. 20, 1980) lowered this to with a "Four Russians" block method: the matrix is cut into blocks, and the effect of every possible block is tabulated in advance.
The tabulation only pays off if the number of possible blocks is small. The paper guarantees this under two hypotheses: the alphabet is finite, and the edit costs are discrete, that is, all integer multiples of one constant. Its §4 asks whether discreteness can be dropped, and answers no with an explicit example whose costs are , , and . This mission formalizes that example.
Timeline:
- 1974, Wagner and Fischer: the matrix algorithm and its recurrence, for nonnegative costs.
- 1980, Masek and Paterson: the algorithm for a finite alphabet and discrete costs (§2, Lemma 4), and the example of §4 showing the discreteness hypothesis cannot simply be removed (Theorem 5).
- 2015, Backurs and Indyk (STOC 2015): no strongly subquadratic algorithm under the Strong Exponential Time Hypothesis, which places the gap the paper left open in context.
Setting
Let be an alphabet and the null string. An edit operation is a pair of strings of length at most one other than : a replacement when both are symbols, a deletion when , an insertion when . results from by if and . A cost function assigns a nonnegative real to each edit operation; , , . The edit distance is the minimum of over sequences of edit operations taking to . For fixed strings, , where ; this is the edit matrix. A step is the difference of two horizontally or vertically adjacent entries, or , and the possible steps of are the steps of all edit matrices of all pairs of strings. The cost set is discrete if some has every element of as an integer multiple.
An edit path is a sequence of matrix cells in which each cell increases , or both by one: a deletion of (cost ), an insertion of (cost ), or a replacement of by (cost ). The eccentricity of is .
The example. with
Let . The infinite strings and are and with a written into both, at each even position where , so that and each contain exactly letters . The first is at position . is the minimum cost of an edit path from to through points all of eccentricity at least .
Formalization targets
Goal (Theorem 5, as its proof establishes it)
For the example's , and ,
The first part gives at least distinct steps in the edit matrix of and ; the second is the negation of the conclusion of the paper's Lemma 4. The goal fixes no constants and no growth rate beyond "at least one new step per diagonal position".
Milestones
- §2.3: for every nonnegative normalized cost function and all strings, equals the minimum cost of an edit path from to .
- Lemma 5: if is even, and if is odd.
- Lemma 6: for , .
- Lemma 7: and .
A further item records that the example satisfies every other condition of the paper: its costs are nonnegative and normalized (), but is not discrete.
Significance
The block algorithm precomputes one table entry per block and per pair of initial step vectors, so its preprocessing is polynomial in only when the number of possible steps is bounded independently of the strings. The example shows that without discreteness the steps can grow with even over a three-letter alphabet with nonnegative normalized costs, so the table size becomes of order and the method gives no speedup. It explains why the finite-alphabet, non-discrete case is left open in the paper's conclusion.
The paper's result is proved on paper; no machine-checked version is known to exist, and Mathlib has no edit distance at the pinned revision. The formalization produces exact closed forms for three diagonals of a nontrivial edit matrix with irrational entries, a formal link between edit distance over arbitrary edit sequences and minimum-cost paths, and a verified counterexample to the naive generalization of the algorithm. The sibling mission of the series formalizes the algorithm and Lemma 4.
Difficulty
The central difficulty is Lemma 5: a lower bound on the cost of every path confined to a band of eccentricity, not only the straight diagonal. A path may leave its diagonal, pay for a deletion and an insertion, and travel along another diagonal whose 's may or may not line up. The bound must hold uniformly in , and , and it depends on the floor function and on precise inequalities between and . Checking that the straight diagonals are optimal for small does not suffice: the -densities are chosen so that even and odd diagonals cost almost exactly the same per step, and a periodic placement of 's would let one diagonal eventually undercut another.
Formalization scope
Strings are Lists; the infinite strings , are functions read from index , and is the list of their first symbols. An edit operation is a pair of Option values other than . The edit distance and are real infima (sInf) of nonempty sets of nonnegative reals, so they coincide with the paper's minima. has indexing and indexing (the paper's Figure 4 prints across the columns). is . The constraint of applies to every point of the path, endpoints included. Costs use Real.pi itself.
Pinned statements: the paper states Theorem 5 about the running time of Algorithm Y ("Discreteness is a necessary condition for Algorithm Y to run in time on length strings and step sequences"); its proof establishes that the number of distinct steps grows linearly with the string length, which is what the goal states. Running time is not formalized. The §2.3 milestone is stated, as in the paper, for all strings and every nonnegative cost function satisfying the §1.1 normalization ; both standing assumptions are hypotheses. The paper's standing assumption is used only for running times and is omitted.
The example must be the paper's: replacing by a rational, or quantifying over "some" cost function or "some" strings, makes the goal false or empty, and the edit distance must be the minimum over edit sequences, not a recurrence.
Needed infrastructure: edit sequences and their costs, the reduction of edit sequences to edit paths, and bounds on with (Mathlib's irrational_pi and Real.pi_gt_d2). The edit-distance definitions are shared in shape with the sibling mission and are reusable. Proofs of any milestone are welcome.
Selected references
- W. J. Masek, M. S. Paterson, A Faster Algorithm Computing String Edit Distances, J. Comput. System Sci. 20 (1980), 18–31. https://doi.org/10.1016/0022-0000(80)90002-1
- R. A. Wagner, M. J. Fischer, The String-to-String Correction Problem, J. ACM 21 (1974), 168–173. https://doi.org/10.1145/321796.321811
- A. Backurs, P. Indyk, Edit Distance Cannot Be Computed in Strongly Subquadratic Time (unless SETH is false), STOC 2015, 51–58. https://doi.org/10.1145/2746539.2746612