Skip to content

Latest commit

 

History

History
9 lines (5 loc) · 3.65 KB

review.md

File metadata and controls

9 lines (5 loc) · 3.65 KB

Review of the specification

Two fresh agents reviewed the specification and the case inputs against the request, from the files alone, each with an independent Python model of the program at 64-bit words. Both found that expected agrees with the request on every input, including the empty array, one word, repeated words, and words at or above 2^63, which compare as unsigned numbers, and both models returned Python's sorted on every case input. The second compared the program with a literal Algorithm D, indexed from 1, pass by pass on the case inputs and on 3,000 random arrays of up to 199 words, and found the same array after every pass. The first checked firstIncrement against Knuth's rule for every N up to 300,000 and for every N within 3 of each increment below 2^64, taking the rule from the request and Niemann's summary without the book, and the second showed that for n > 4 the test h ≤ (n - 5) / 9 is equivalent to 9h + 4 < n.

Both found that the docstring of insertBy_perm had a false reading, a permutation of xs that holds v at i, and it now states a permutation of xs.set! i v. The first found that the program's comment applied pass to every increment, where the program uses straightInsertion for the increment 1, and that the docstring of firstIncrement stated that the division test prevents a wrap that the guard 4 < n prevents. The comment now names the increments above 1 and states that an array of fewer than 14 words has only the increment 1, and the docstring states both tests. Both found that the docstring of the case inputs described arrays of 10,000 words where quicksort's inputs hold one.

Both found that the theorems read "in place" only as a call that does not raise top. The allocator serves a request from a free block below top without raising it, so no theorem states that the result occupies the input's block, and the specification's comment now states that its reading is weaker than the request's. The second found the same claim in the comment of straight insertion's specification, which stated that straightInsertion_bound gives a module that allocates nothing and returns the words in the array's own block, and that comment now states what the theorem states.

Both ran wrong programs on their models. The cases detect each of those with a defect of the final straight insertion, each with a pass above 1 that does not permute the array, and a copy of the array, through the allocation count. No case detects a wrong increment, a missing pass above 1, or a pass that keeps the permutation, such as one with a signed comparison or a wrong stride, since straight insertion sorts every array and the sorted result is unique, and the proof of shellsort_eq likewise uses only the permutation. Both found that no case had a length from 3,281 to 9,841, where the first increment is 1,093, that the passes with 1,093 and 3,280 compared no equal words and no word at or above 2^63, and that the passes with 4 and 13 compared equal words only in arrays of 255 words or more. The cases now hold arrays of 3,280, 3,281, 9,841, and 9,842 words, and for each length at a threshold or one below it, an array that draws its words from eleven arbitrary words, four to six of them at or above 2^63, by the SplitMix64 output of the position. The arrays of 9,841 and 9,842 words draw only every eighth word that way and hold words below 100 elsewhere, since an argument of the host program holds at most 128 KiB, and a Python model of the program shows that every pass with an increment above 1 then compares equal words and words with the high bit set.