When the algorithm is a table

A checker that stops at two edits

A nearest-word search that must always answer pays most of its price on the queries whose answer is useless: misspellings of words the vocabulary does not have, whose nearest vocabulary word can be twenty edits away. Capping the answer at two edits keeps every suggestion a misspelt vocabulary word could get and costs 42% of the uncapped search. What it does not do is stop the false suggestions. It declines 95% of unfamiliar words of eleven letters or more and 1% of those of three or four, because two edits is most of a short word, and 72% of what it still says to an unfamiliar word is wrong — against 77% with no cap at all.

A second try before any feature searched a trie of 2,424 vocabulary words for the word nearest a misspelt query. It measured the cost in cells of the edit-distance table and charged every attempt. The best fixed schedule was a walk that gives up past one edit, then one that gives up past two, then the discovering walk, which finds the nearest word however far away it is. On a stream where a fifth of the queries were misspellings of words the vocabulary lacks, that schedule cost 10,327 cells a query, well under the discovering walk alone. (It costs 10,398 below, where all 600 unfamiliar queries are weighted into the fifth rather than the first 500 interleaved.)

Its closing section pointed at where the rest of the price goes. The queries still unfound after the walk at two were 11% of the stream and paid 52,737 cells each to discover. For those queries the answer found is almost never the one wanted. Every misspelt vocabulary word in the stream is one or two edits from its source, so a query that fails the walk at two is a query whose intended word is not in the vocabulary. The nearest vocabulary word to instrumnted is not what its writer meant, however carefully it is found.

So the section proposed a checker that declines: after the walk at two, report “no suggestion within two edits” and stop, or pay for one walk at a larger cap and stop there. It predicted that a cap at two would keep every useful suggestion and cost about a third of discovering, and that the false suggestions of the uncapped search would be almost all at three edits or more. It named one way the prediction could fail. A large share of unfamiliar words might have a vocabulary word within two edits that is a plausible suggestion — a plural, a tense.

Scoring a suggestion against the word that was meant

Measuring what a suggestion is worth needs something the earlier pages never kept: the word each query was made from. The streams are 2,000 misspellings of vocabulary words and 600 of words from a second corpus that the vocabulary lacks, each word given one or two random insertions, deletions or substitutions from a seeded generator. Replaying the generator’s own arithmetic with the same seed gives each query’s source beside it. Every one of the 2,600 replayed queries is checked against the stream’s own, so the sources belong to exactly these queries.

A checker returns every vocabulary word at the nearest distance, since ties are what a list of suggestions would show; a misspelt vocabulary word gets 1.9 on average. For a misspelt vocabulary word, a suggestion list is a hit if it contains the source. For a word the vocabulary lacks, the right answer is none. A suggestion list is scored a variant if it contains a vocabulary word that differs from the writer’s word only in its ending: time for timed, adjacent for adjacency, continues for continue. The rule is stated once — a shared prefix of at least three letters and, after it, an ending from a list of thirty English ones on each side — and it refuses floor for flow and the for theory. Anything else is a false suggestion.

A cap CC runs the earlier page’s schedule and stops: a walk at one, a walk at two, and if CC is larger, one walk at CC. Every walk is charged. A query whose nearest word is further than CC gets no suggestion.

What a cap saves: with a fifth of the queries unfamiliar, stopping after a walk at two costs 4,368 cells a query against 10,398 for finding the nearest word however far — 42% of the price, all of it saved on words the vocabulary lacks (6,938 against 37,086)Mean cells of the edit-distance table a query, against the cap on the answer's distance, for a schedule of walks at one, then two, then one walk at the cap, stopping there (none: the discovering walk). Words it lacks: 1 1,091, 2 6,938, 3 17,718, 4 24,696, 5 29,492, 6 32,136, none 37,086. A fifth unfamiliar: 1 1,085, 2 4,368, 3 6,524, 4 7,920, 5 8,879, 6 9,408, none 10,398. Misspelt vocabulary words: 1 1,083, 2 3,726, 3 3,726, 4 3,726, 5 3,726, 6 3,726, none 3,726. Misspelt vocabulary words are all answered by the walk at two, so no cap above two changes their cost.010203040the cap on an answer's distance, in editsthousands of cells a query123456nonewords it lacksa fifth unfamiliarmisspelt vocabulary wordsevery attempt charged2,000 + 600 queries
Fig. 1 Mean cells a query against the cap. With a fifth of the queries unfamiliar: 1,085 at a cap of one, 4,368 at two, 6,524 at three, 10,398 with no cap. Misspelt vocabulary words cost 3,726 at every cap from two, since the walk at two answers all of them. Words the vocabulary lacks: 6,938 at two, 37,086 with no cap.

With a fifth of the queries unfamiliar, a cap of two costs 4,368 cells a query against 10,398 with no cap — 42% of the price. The prediction said about a third, and it is a little more. The misspelt vocabulary words cost 3,726 cells whatever the cap, because every one of them is answered by the walk at one or the walk at two. So the whole saving comes from the other fifth. Each unfamiliar query costs 6,938 cells at a cap of two against 37,086 uncapped. Of the 600, 336 have no vocabulary word within two edits, and discovering theirs cost 53,835 cells each. Those 336 queries are 85% of everything the uncapped search spends on unfamiliar words, because the discovering walk’s bound starts at infinity. The bound the search finds for itself found that a search’s price is set by how soon it finds a good bound, and a query with no near word finds one late. The columns the candidates share priced the trie walk that gives one column to each prefix. A walk bounded at two abandons a prefix as soon as every cell of its column exceeds two, and for a query unlike any vocabulary word that happens within a few letters of the root, down every branch.

What the uncapped search finds for those queries is what the proposal expected. The median declined query’s nearest word is four edits away. For pprimitives, a misspelling of primitives, it offers pyrimidine, positives and priorities. For receatable it offers reachable, predictable and recomputable, and for a misspelt growthtradeoff, ten edits away, trades. A few of the far suggestions are close relatives — substantially for substantfal at three edits, condition for conditinal — which is why the cap declines some variants as well.

A cap of one would save far more, 1,085 cells a query, but the walk at one answers only 59% of misspelt vocabulary words. The other 41% have been given two edits and need the walk at two. So two is the smallest cap that keeps the misspelt vocabulary words, and it keeps all of them. From a cap of two upwards, 93.9% of their suggestion lists contain the word that was meant, the same share as with no cap at all. The other 6.1% are misspellings that landed nearer to some other word — ecent from descent is one edit from event — and no cap, large or small, gets those right.

What the checker says to a word it lacks

The price is half the case. The other half is the part the cap was meant to change: what the checker says to a word it does not have.

What a cap says to a word the vocabulary lacks: uncapped, every such query gets a suggestion and 77% get only words that are not a form of what was meant; a cap of two declines 56% of them and still offers a false suggestion to 32% — while every cap from two answers every misspelt vocabulary word, finding its source 93.9% of the timeFor each cap, the 600 misspellings of words the vocabulary lacks sorted by what the checker returns: no suggestion; suggestions including a vocabulary word that differs from the writer's word only in its ending (time for timed, adjacent for adjacency); or suggestions that include no such word. Cap 1: 89.3% none, 3.3% variant, 7.3% false. Cap 2: 56.0% none, 12.3% variant, 31.7% false. Cap 3: 31.5% none, 20.3% variant, 48.2% false. Cap 4: 17.2% none, 22.3% variant, 60.5% false. Cap 5: 10.2% none, 22.7% variant, 67.2% false. Cap 6: 6.7% none, 22.7% variant, 70.7% false. Cap none: 0.0% none, 22.7% variant, 77.3% false. Misspelt vocabulary words: a cap of one declines 40.8%; from two up every one is answered and 93.9% of the suggestion lists contain the source, the rest having a nearer word.0%25%50%75%100%no suggestiona variant of the worda false suggestioncap 17% false, 3% variantcap 232% false, 12% variantcap 348% false, 20% variantcap 461% false, 22% variantcap 567% false, 23% variantcap 671% false, 23% variantcap none77% false, 23% variantshare of 600 misspelt words the vocabulary lacksvariant: differs only in its endingties: every word at the nearest distance
Fig. 2 The 600 misspellings of words the vocabulary lacks, by what each cap returns: no suggestion, a variant of the writer’s word, or only false suggestions. Cap of one: 89.3% none. Cap of two: 56.0% none, 12.3% variant, 31.7% false. Cap of three: 31.5% none, 20.3% variant, 48.2% false. No cap: 22.7% variant, 77.3% false.

Uncapped, every unfamiliar word gets a suggestion and 77% get only false ones. A cap of two declines 56% of them — and still gives a false suggestion to 32%. The prediction that the false suggestions would be almost all at three edits or more fails. Of the 600 unfamiliar queries, 264 have a vocabulary word within two edits, and 190 of those are offered only words that are not a form of what was meant: has for bzs, a misspelling of bfs; deploy for destoy, a misspelling of destroy; spell for sohell, a misspelling of shell.

The failure mode the section named is real but small. Variants of the writer’s word — the plural or tense that makes a false suggestion almost useful — are 12.3% of unfamiliar queries at a cap of two and 22.7% uncapped. The cap removes some of them along with the false suggestions, and it removes them in about the proportion they occur. Of the 336 queries it declines, 18% would have been offered a variant and 82% only false suggestions. Among what a cap of two still says to an unfamiliar word, 72% is false. Uncapped it was 77%. The cap makes the checker say less without making what it says much better.

Where the nearest word to an unfamiliar query lies: 264 of 600 have one within two edits and 336 further; within two, 190 would get only false suggestions, and past two a suggestion is a variant of the writer's word 18% of the timeThe 600 misspellings of words the vocabulary lacks, counted by the edit distance to their nearest vocabulary word (7 or more pooled), each bar split by whether the words at that distance include one differing from the writer's word only in its ending. 0: 2 variant, 3 false. 1: 18 variant, 41 false. 2: 54 variant, 146 false. 3: 48 variant, 99 false. 4: 12 variant, 74 false. 5: 2 variant, 40 false. 6: 0 variant, 21 false. 7+: 0 variant, 40 false. A cap of two answers the first three bars and declines the rest.050100150200a variant of the worda false suggestion5059120021473864425216407+edits to the nearest vocabulary wordqueries600 misspelt words the vocabulary lacksdashed: a cap of two
Fig. 3 The 600 unfamiliar queries by the edit distance to their nearest vocabulary word, each bar split by whether the words at that distance include a variant of the writer’s word. Within two edits: 264 queries, 74 with a variant and 190 without. At three: 147 (48 with a variant); at four: 86 (12); five and beyond: 103 (2). The dashed line is a cap of two.

The distribution says why. An unfamiliar query is its source plus one or two edits, so its nearest vocabulary word is roughly as far away as the source’s nearest, give or take what the edits did. The vocabulary is full of short common words, and a short source is close to many of them. The variants concentrate at two and three edits, the distances of a suffix plus a typo. Past four edits there are almost none, because a source that far from every vocabulary word has no form in the vocabulary at all. The prediction pictured false suggestions as far-away words and variants as near ones. In fact both are spread over the same few edits, and the cap cuts through the middle of both.

Two edits is most of a short word

One property of the query decides, far more than any other, whether a cap of two declines it: the length of the word that was meant.

A cap of two edits is a cap on long words only: it declines 1% of unfamiliar words of three or four letters and offers a false suggestion to 87% of them, and declines 95% of those of eleven letters or moreThe misspellings of words the vocabulary lacks, grouped by the length of the writer's word, sorted by what a checker capped at two edits returns. 3–4 letters (87 queries): 1.1% none, 11.5% variant, 87.4% false. 5–6 letters (147 queries): 32.0% none, 19.0% variant, 49.0% false. 7–8 letters (145 queries): 64.1% none, 15.2% variant, 20.7% false. 9–10 letters (120 queries): 81.7% none, 9.2% variant, 9.2% false. 11+ letters (83 queries): 95.2% none, 3.6% variant, 1.2% false.0%25%50%75%100%no suggestiona variant of the worda false suggestion3–4 letters87 words, 1% declined5–6 letters147 words, 32% declined7–8 letters145 words, 64% declined9–10 letters120 words, 82% declined11+ letters83 words, 95% declinedshare of misspelt words the vocabulary lacks, at a cap of twocap of twolength of the writer's word
Fig. 4 Unfamiliar queries at a cap of two, by the length of the writer’s word. Three or four letters (87 queries): 1.1% declined, 87.4% false. Five or six (147): 32.0% declined. Seven or eight (145): 64.1%. Nine or ten (120): 81.7%. Eleven or more (83): 95.2% declined, 1.2% false.

A cap of two declines 95% of unfamiliar words of eleven letters or more and 1% of those of three or four, and gives a false suggestion to 87% of the short ones. Two edits is a different distance for different words. For an eleven-letter word it is a fifth of the word, and for most such words nothing in the vocabulary is that close. For a three-letter word it is two thirds of the word. bfs with one substitution becomes bzs, which is two edits from sixteen vocabulary words, has, was and best among them. A short unfamiliar query has a median of eleven vocabulary words within two edits of it, and as many as 46. The cap is a fixed number of edits, and a fixed number of edits is a lenient cap on short words and a strict one on long ones.

The filter that feeds the table refused candidates before they reached a table, on a cheap exact test: cut the pattern into pieces, and a match within kk edits must contain one piece exactly. Its refusal was sound, since no match it refused could have been within the bound. The cap’s decline is sound in the same sense for misspelt vocabulary words at every length, since all of them are within two edits. As a test of whether a word is in the vocabulary at all, though, it has no such guarantee. It works on long words and hardly at all on short ones.

The misspelt vocabulary words show what any repair would cost. Their sources have the same short words in them, and their misspellings are also two edits away. A cap tightened to one edit for words of four letters or fewer is the obvious repair, and the streams already contain its whole account. Of the 87 short unfamiliar queries, 59 are exactly two edits from their nearest vocabulary word, and the tightened cap would stop answering them. Of the 2,000 misspelt vocabulary words, 298 come from words of four letters or fewer, and 92 of those are two edits from the nearest vocabulary word. Every one of the 92 gets its source among the suggestions at a cap of two. The tightened cap would refuse 92 right answers to silence 59 wrong ones. On short words, distance cannot tell the two kinds of query apart, because a short word two edits from the vocabulary is exactly what a two-edit typo of a short vocabulary word looks like.

A saving that grows with the unfamiliar share

The saving grows with the share of unfamiliar queries: at none, every cap costs 3,726 cells a query; at half, a cap of two costs 5,332, a cap of three 10,722, and no cap 20,406 — the uncapped search pays 3.8 times as muchMean cells a query on streams mixing misspelt vocabulary words with misspelt words the vocabulary lacks, against the share of the second kind. No cap: 0% 3,726, 10% 7,062, 20% 10,398, 30% 13,734, 50% 20,406. Cap of three: 0% 3,726, 10% 5,125, 20% 6,524, 30% 7,923, 50% 10,722. Cap of two: 0% 3,726, 10% 4,047, 20% 4,368, 30% 4,689, 50% 5,332.05101520share of queries for words the vocabulary lacksthousands of cells a query0%10%20%30%50%no capcap of threecap of twoevery attempt chargedlinear in the share
Fig. 5 Mean cells a query against the share of unfamiliar queries. With none, every cap costs 3,726. With half the stream unfamiliar: a cap of two 5,332, a cap of three 10,722, no cap 20,406.

The saving is linear in the share of unfamiliar queries, and at half the stream the uncapped search costs 3.8 times a cap of two. With no unfamiliar queries the caps are identical, since every query is answered at two. Each unfamiliar query costs 6,938 cells at a cap of two, 17,718 at a cap of three and 37,086 uncapped, against 3,726 for a misspelt vocabulary word. A checker facing technical writing, where a larger share of words are identifiers and jargon the vocabulary lacks, gains more from the cap. That is the same stream on which the cap’s suggestions are least useful. A trie fitted to its queries found the unfamiliar queries to be the expensive ones for every policy it tried, and the cap is the first policy here that makes them cheap. It does so by not answering them.

A cap of three is the obvious compromise, and the measurements put a price on it. It costs 2,156 more cells a query than a cap of two at a fifth unfamiliar. It raises the unfamiliar queries offered a variant from 12.3% to 20.3%, and those offered only false suggestions from 31.7% to 48.2%. Two variants are bought for every four false suggestions added. Whether that is worth it depends on what a false suggestion costs the person reading it, which no cell count can say. The cost is the number of subproblems first counted this table’s work in cells, and a count of cells has no second axis to weigh against. This page has one, and the two axes do not share a unit.

Where these measurements come from

One vocabulary, one second corpus, one typo model. The vocabulary is the prose corpus’s 2,424 distinct words, and the unfamiliar words are those of a corpus of program text that the prose lacks. Many of them are identifiers — bfs, cmp, nan — shorter than typical English words, which weights the unfamiliar stream towards the short words the cap handles worst. Typos are uniform insertions, deletions and substitutions. Real typing errors favour adjacent keys and transposed letters, and would move some misspellings closer to their sources and some into other words.

The variant rule is a rule, not a reader. It counts note for not and proved for proven as variants. It refuses instance for instanceof and every suggestion that shares a stem but changes the middle of a word. Its verdicts were read against the queries they scored, and on the ones read it agrees with what a person would call the same word in another form more often than not. It is not a judgement of usefulness, only of whether a suggestion is plausibly the word that was meant.

Ties are listed, not ranked. A suggestion list holds every word at the nearest distance, 1.9 on average. A checker that ranked ties by word frequency, as real ones do, would show one word. It would be right more often on misspelt vocabulary words and would give the same number of false suggestions to unfamiliar ones, since none of those can be right.

Cells are the cost. Every walk is charged in cells of the table. Cells are not the cost found tables whose cells each hide many transitions. An edit-distance cell reads three neighbours and nothing more, so here a cell is a fair unit, and a cap that stops early also saves the stack of trie nodes the skipped walks would have held.

Still open: a decline that reads the query’s letters

The cap failed as a test of whether a word is in the vocabulary because distance is the only thing it looks at, and on short words distance does not separate the two kinds of query. A two-edit typo of hop and a one-edit typo of bfs look the same to any rule about edits. Something else about the query has to do the separating.

The candidate is the query’s letters. A second try before any feature found that the number of letter-triples in a query that no vocabulary word contains predicts how far its answer is. That is a property of the query’s spelling, not of its distance, and a typo of a vocabulary word breaks at most a few of its triples, while a word from another corpus may have triples the vocabulary has never seen. The measurement that follows declines a query when its unseen triples pass a threshold, before any walk, and combines that with the cap of two. It counts the same things: cells a query, hits kept, variants and false suggestions given. The prediction is that on long words the triples add nothing the cap has not already done, and on short words they do what distance cannot. A three-letter query has only one triple, so the test there is a single yes or no — whether bzs is a string the vocabulary could contain. The question is whether one triple is enough evidence to decline a word, or whether short words are simply where a checker has to answer and be wrong.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

The objects this essay names

Each one links to every other essay that touches it.

Cost modelEdit distanceExpected costMeasured countPruningThresholdTrieWorkload