Proofs: Edit distance hardness under SETH
These are the human proofs of Edit distance hardness under SETH, at full length.
Proof of the edit distance hardness theorem full
This proof shows: statement.
Positions in strings are numbered from 1 in this proof, and coordinates of vectors also from 1. For a symbol and an integer , is the string of copies of . The distance is the Levenshtein distance with unit costs.
Alignments and gain
An alignment of strings and is a set of pairs with and , such that no two pairs share an or a , and for any two pairs and , holds if and only if . A pair is equal when and unequal otherwise. A symbol in no pair is unpaired. The cost of the alignment is the number of unpaired symbols of and plus the number of unequal pairs. Each unpaired symbol and each unequal pair is one unit of cost.
Lemma 1. is the least cost of an alignment of and . If an alignment has pairs, of which are equal, its cost is .
Proof. Given an alignment, delete the unpaired symbols of , substitute for in each unequal pair, and insert the unpaired symbols of . Because the pairs are in the same order in both strings, this turns into with as many operations as the cost. Conversely, take a sequence of operations that turns into , and follow each symbol of through it. Pair with when the symbol at position of is never deleted and ends at position of . Insertions, deletions and substitutions keep the order of the symbols that they do not remove, so this is an alignment. Each unpaired symbol of was deleted, each unpaired symbol of comes from an insertion, and the symbol of each unequal pair was substituted at least once. These are distinct operations, so the cost of the alignment is at most . For the formula: there are unpaired symbols in , in and unequal pairs, and the sum is .
Call the gain of the alignment: each pair gains 1, and 2 when it is equal. Let , the largest gain of an alignment of and . Lemma 1 turns each lower bound on into an upper bound on the gain. Reversing both strings maps alignments to alignments with the same pairs read backwards, so and do not change under the reversal of both arguments.
The next fact is used many times. Let and be pairs of an alignment with , so .
(B) A symbol of at a position strictly between and is unpaired or paired with a position of strictly between and . The same holds with the roles of and exchanged.
This follows from the definition: a pair with needs .
From SETH to orthogonal vectors
Lemma 2. If there are constants and and an algorithm that solves OV with vectors of dimension on each side in time , then SETH is false.
Proof. A smaller gives a weaker assumption, so we may assume . Let and let be any integer. Take a -CNF formula with variables. Add one unused variable if is odd, and remove repeated clauses. A clause is a set of at most literals out of , so there are clauses. Split the variables into two halves and of size . For each assignment of , let have coordinate equal to 0 when some literal of clause on a variable of is true under , and 1 otherwise. Define in the same way for each assignment of . Then if and only if each clause has a literal that is true under or under , that is, if and only if the joint assignment satisfies . So is satisfiable if and only if the OV instance with the vectors and the vectors has an orthogonal pair. Building the instance takes time, and the algorithm takes . For fixed , for all large , so the total time is . This holds for every , which contradicts SETH for this .
Coordinate gadgets
Fix . The alphabet has distinct symbols , and for . For let
where the block and . So and .
Lemma 3. .
Proof. The symbol at position of occurs in only in block , and it occurs there exactly when or , that is, when . So an alignment has at most equal pairs, and at most pairs, because . Its gain is at most , and by Lemma 1 its cost is at least . For the upper bound, pair position of with the copy of in block when there is one, and with the first symbol of block otherwise. The pairs are in increasing order in both strings, there are of them, and are equal, so the gain is and the cost is .
A gadget with two options
Lemma 4. Let and be two symbols, and let , and be strings that contain neither of them, with and . Let , and
Then .
Proof. Name the parts and , with and . Then and .
Upper bound. Pair with symbol by symbol ( unequal pairs), align with at cost , pair with ( equal pairs), and leave and unpaired ( units). The cost is . In the same way, leaving and unpaired, pairing with , with and with costs .
Lower bound. By Lemma 1 it suffices to show that each alignment has gain at most , since then the cost is at least . Fix an alignment. Each pair has its end in or in . Let be the gain of the pairs with their end in , and the gain of the pairs with their end in . The only symbols of are in , so an equal pair with its end in has its end in . There are three cases.
Case 1: has a partner in and a partner in . All of lies strictly between these two partners, so by (B) each symbol of is unpaired or paired with a symbol of . So no pair with its end in is equal, and . Each symbol of gains at most 2, so . The gain is at most .
Case 2: has no partner in . The partners of lie in , and . Let and be the numbers of pairs between and , and between and . Each of these pairs is unequal and gains 1. The pairs between and form an alignment of and , so they gain at most . So . Now bound . The number of equal pairs that it counts is at most , because only symbols of can be their ends and symbols of are paired with . The number of pairs that it counts is , where is the number of unpaired symbols of . If , let be the smallest position in of a symbol paired with . All of comes before in , so a symbol of can only be paired with one of the symbols of before position . So at least symbols of are unpaired, while . So , which also holds when . Hence , and the gain is .
Case 3: has no partner in . Reverse both strings. The reversed is and the reversed is , where denotes reversal. The reversed alignment is in Case 2 for these strings, with in the place of . So its gain, which is the same as before, is at most .
Each alignment is in at least one of the three cases, because an alignment that is not in Case 1 has no partner of in or none in . Since , each case gives a gain of at most .
Vector gadgets
Let , and . For let , for let , and let and . Define
So and . Let and .
Lemma 5. For all : if and otherwise, and if is the zero vector and otherwise.
Proof. Apply Lemma 4 with , , , and . These strings contain no or , and . With Lemma 3, . For : and . For : is the number of ones of , and .
The pattern distance
For strings and , let be the least value of over all substrings of , the empty one included.
Let and be an OV instance in dimension . Let be a new symbol and . Let for . Let be the vectors ( times), , then ( times), so , and let . Define
The strings and are the cores. The runs of in are (before ), between and , and (after ). Each has at least symbols, and have . Between and the text has a run of symbols . No core contains .
Lemma 6. If for some and , then . If for all and , then .
Proof of the first claim. Let . Then and , because . Let be the substring of . It has the same runs of as , with in the place of . Pair the runs of symbol by symbol, at no cost, and align each with optimally. The cost is . By Lemma 5 each term is at most , and the term for is , since .
Proof of the second claim. No is the zero vector, since otherwise . So by Lemma 5, for all and . Fix a substring of and an alignment of with . A core touches when a symbol of is paired with a symbol of . For each , let be the set of such that touches .
Order. If , touches and touches , then , because the pairs are in the same order in both strings. Hence, if and are nonempty and , then .
Sort each core into one class:
- (C0) touches no core.
- (C2) touches at least two cores.
- (C1) touches exactly one core . It is clean if and all of lies inside , cut if and some symbol of is outside , and shared if .
We now give sets of units, pairwise disjoint, that together contain at least units.
(C0). Let hold the unpaired symbols of and the pairs with an end in . Such a pair has its other end in a of , because touches no core, so it is unequal. So .
(C2). Let touch and with . The run of symbols between and lies strictly between a partner of in and a partner of in , so it lies inside . By (B), each of its symbols is unpaired or paired with a symbol of , which is not . Let hold these units. So .
Clean (C1). Let hold the unpaired symbols of and of , and the unequal pairs with an end in or in . A pair with an end in has its other end in or in a , since touches only . A pair with an end in has its other end in or in a of , since . Drop the pairs with an end in a . The pairs between and that remain form an alignment of with , which is whole inside . Its cost counts the unpaired symbols of and , the symbols of and that were paired with a , and the unequal pairs between and . Each of these is one unit of , counted once. So .
Shared (C1). For each with , let . The runs lie strictly between a symbol of and a symbol of whose partners are in . By (B), each of their symbols is unpaired or paired with a symbol of , which is not . Let hold these units. Each shared core whose touched core is has its index in , so there are at most of them. So times the number of these cores.
Cut (C1). Here , contains a symbol of and misses another one, so starts or ends strictly inside . Suppose that it starts inside . Let be the first symbol of that has a partner, and its partner. Some symbol of has a partner in , and that partner is at or after , so lies in the part of up to that partner, which is inside . Each symbol of comes before in , so its partner, if any, comes before in and is a symbol of . Let hold the units of the symbols of . If does not start inside , it ends inside , and the same argument with the last symbol of that has a partner gives units from ; let hold those.
Disjointness. Unpaired core symbols appear only in the sets of (C0) and clean cores, each for its own core, and the core of a clean is touched by no other core, so no other set holds it. Unpaired symbols of appear only in (C2) sets. A run of in the set of lies strictly between two partners of . If it also lay strictly between two partners of with , then a partner of after the run would come before a partner of before the run, against the order of the pairs. So two (C2) sets use different runs. Unpaired symbols of appear only in shared and cut sets. By the order property, the index ranges of two shared sets are disjoint. A cut core with uses or . If one of these were in the range of a shared set for , then for and . If or , then touches . If , then by (B) every partner of lies strictly between two symbols of , so it is in and again touches . Either way , which is impossible because . At most one cut core uses the run before it, since starts inside only one core, and at most one uses the run after it. If the first one is and the second is , they would use the same run . But starts inside the core touched by and ends inside the core touched by , so , and the order property gives . Then is touched by both cores, against . Now the unequal pairs. A pair between a core and a of appears only in the set of . A pair between a core and a of appears only in a clean set with this , in , or in a cut set with this , and exactly one of these kinds can exist for a given . A pair between two cores appears only in a clean set. So the sets are pairwise disjoint.
Every core is in one class, and each class gives at least units for each of its cores, so the cost of the alignment is at least . This holds for every and every alignment, so .
Padding
Lemma 7. Let and be strings, let be a symbol that occurs in neither, and let . Then .
Proof. Upper bound. Let with . Pair the last symbols of the first run of with and the first symbols of the second run with , align with optimally, and leave the other symbols unpaired. Each of the symbols is one unit, and nothing else costs more than the alignment of with .
Lower bound. Fix an alignment. Each symbol is unpaired or in an unequal pair, so the symbols give units. If no symbol of is paired, the symbols of give more units. Otherwise, let be the substring of from the first to the last partner of a symbol of . By (B), the symbols of are unpaired or paired with symbols of , and the symbols of are unpaired or paired with symbols of . So the pairs between and form an alignment of with , and its units are units of the whole alignment that do not involve . Its cost is at least .
Proof of the theorem
Part 1. Given the OV instance, build and as in Lemma 6, and let , and . By Lemmas 6 and 7, when there is an orthogonal pair, and otherwise. The lengths are and with and , so and are , and the strings are written in time. The symbols are for , and , , and : in all.
Part 2. Suppose that an algorithm computes the edit distance of two strings of length at most over at most symbols in time . Given an OV instance, build , and by part 1 and compare with . Here and , so for , which we may assume, the time is . By Lemma 2 with , SETH is false.