Back on the breadboard, I'd factored 5,283,065,753,709,209 with three ATtiny moduli. It took 25 minutes, about as long as Lehmer's 1932 gear machine, even though the breadboard sieve can run ten times faster. Having only three moduli let through 740,000 survivors, which the Pico has to check. This left the sieve idle over 90% of the time waiting on the Pico.
With 30 moduli the same problem now finishes in under two minutes, about ten times faster than the gear machine, as expected. Only two candidates survive, and both are real solutions. Two of Lehmer's gears accept every value on this problem and do no filtering at all, so those two cards stay dark for the whole run. He couldn't swap in different moduli because they were fixed by the gears he had, but the remaining 28 still filtered enough. My current sieve is also ten times faster than the breadboard version, so at its full rate of 500,000 numbers per second the same run takes 11 seconds.
With the machine now fully working, over several hours I ran published problems from three of Lehmer's sieves. The 1928 bicycle chain machine, the 1932 gear machine, and the 1965 delay line electronic sieve.
1928 and 1932: bicycle chains and gears
In 1928, Lehmer published [LF28] with results from the bicycle chain machine, and [PS33] and [NF33] in 1933 with results from the gear machine. Each result gives how fast the machine ran, where it stopped, and how long that took.
I set my REQ clock, the shared line that steps every card, to each machine's own rate. That is 50 numbers/sec for the bicycle chain machine, and 5,000/sec for the gear machine. The chain machine had 19 chains, so those runs use 19 cards. The gear machine had 30 gears, so those use all 30.
| Problem | Paper | Rate | Published notes | My sieve | Stops |
|---|---|---|---|---|---|
| 9,999,000,099,990,001 | LF28 | 50/s | "about 2 hours" | 2 h 14 min 09 s | 2 |
| a factor of 3^111 + 1 | LF28 | 50/s | "only 4 seconds" | 2.96s | 1 |
| 4,500,383,424,373 as a sum of two squares, run1 | LF28 | 50/s | "one stop, not a solution" | 1 h 05 min 42 s | 1 |
| same problem, run2 | LF28 | 50/s | "stopped only once" | 52 min 37 s | 2 |
| 2^79 - 1 | PS33 | 5,000/s | "12 s" | 11.31 s | 1 |
| 2^93 + 1 | NF33 | 5,000/s | "a few seconds" | 1.41 s | 1 |
Every solution matched the published one as expected. Run 1 of the sum of two squares has no solution in its range, so it ran to the end. My measured times agree as well. My sieving rate comes out about 0.5% below the REQ clock rate, from the periodic self-test checkpoints and OLED updates.
Interestingly, I found some minor discrepancies from the published results.
The 1928 paper does not note two of the stops
The bicycle chain machine [LF28] stops when a survivor is found, and a person then checks it by hand. The paper says how many times that happened. On two of the four runs, my sieve stopped one more time than was noted in the paper.
- Sum of two squares, run 2. Paper: "stopped only once", at x = 157,044. Mine stopped first at x = 102,151, a = 510,758, N minus a^2 = 4,239,509,689,809, not a square, 18 minutes earlier.
- N = 9,999,000,099,990,001. Paper: "stopped at x = 400,453". Mine first stopped at x = 257,749, a = 1,955,793,401, a^2 minus N = 3,815,128,827,295,156,800, not a square, 48 minutes earlier.
Neither could have been rejected by that machine. Both are quadratic residues of every prime up to 67, its largest chain, and the smallest prime that rejects them is 73. So the machine would have stopped. I'm assuming these were just left out of the final write-up.
Two smaller items
[PS33] gives the wrong period for the gear machine (the number of steps before the initial gear positions repeat) as 2497194316592991015263471297031949336968700272210.
- That number is actually the product of the first 30 primes, with 79 multiplied in twice
- The first 4 gears actually have prime power tooth counts, 64, 27, 25, 49. (The rest were the remaining primes 11 to 113)
- These are all coprime, so the true period is the product of the gear teeth counts 318629350775409486504503679418760117932208844859200. That's about 128 times higher than the reported number.
Not every gear or chain helps on every problem.
- On 2^79 - 1, moduli 64, 27 and 79 accept every candidate, so those three gears played no part in the sieving.
- The same happens on the chain machine. On N = 9,999,000,099,990,001, chains 64 and 25 accept everything, so Lehmer would have pinned every link on both these chains.
- With fixed teeth or fixed chain lengths there was nothing to be done about it. On my sieve the affected cards are visible as dark cards during the run.
- Lehmer talks about this in his 1982 lecture, describing thebenefits of an adjustable sieve design mine recreates: "...we don't have to commit ourselves hardware wise to the set of modulus that we use..."
1965: the delay line sieve
The DLS-127 electronic sieve used surplus Navy delay lines, one per modulus, and stepped 1,000,000 candidates per second, twice my board's 500,000. The ring patterns were generated on a CDC 6400 and punched onto a 25 foot paper tape of 2,877 characters, which was read into the machine through a photoelectric tape reader [DHL82]. It was then left to run, printing surviving numbers on a Clary printer for a separate step where each number could be verified.
The Lehmers published six problems solved on it [LLS70], but no running times anywhere. I've shown the running times on my board instead.
| Problem | published value at p=127 | My sieve's running time |
|---|---|---|
| I | 196,265,095,009 | 4 h 33 min |
| II | 328,878,692,999 | 7 h 39 min |
| III | 71,837,718,283 | 1 h 40 min |
| IV | 8,133,814,327 | 11 min 21 s |
| V | 60,664,576,541 | 1 h 24 min |
| VI | 9,447,241,877 | 13 min 11 s |
Many of these are multi-hour runs, running at the full-speed my sieve is capable of - but every one of these runs worked without errors. All checkpoints passed, and the sieve successfully found the same published results.
There was one oddball problem which was interesting to realize.
Problem I produces 50,000 survivors, and the rest produce one
Problem I asks for a pseudosquare, the smallest number above 1 that is 1 modulo 8 and a quadratic residue of every odd prime up to 127. It is unique among the six, producing over 50,000 survivors over its run, while the others all stop once, on the solution.
The reason is simply that every odd perfect square also passes the modulus checks, so they show up as survivors, and have to be checked and discarded.
DLS-127 had no way to test a survivor as it arrived, and it would have been impossible to check 50,000 numbers printed on paper. Instead Lehmer used a second capability of the machine. It could count survivors without printing them, and the number of perfect squares could be calculated from a second, much simpler sieve run. By running both problems alternately and doing a binary search on the range, Lehmer isolated the single survivor that was not a square.
My sieve follows the later designs, where a controlling computer checks survivors as they arrive. The Pico discards the squares as they come out, without ever holding up the sieve so my run was very straightforward.
Why these machines lasted so long
A sieve is fast because rejecting is cheap. It does no arithmetic, so it picks up every improvement in hardware without having to implement complex instruction and memory stages. So electromechanical chains at 50 numbers per second became VLSI at 6.4 billion over 70 years, and why the machines were still winning on some problems into the 1990s.
What ended them was a better algorithm, not faster hardware. A sieve is still brute-forcing its way through every integer in its range. In 2001 Bernstein showed how to take the same moduli and generate the survivors directly via an algorithm that was fast to run on a general purpose computer. This removed any reason to build such hardware from then on.
kbsriram
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.