Close

The modulus chorus plays for us

A project log for A Tiny Sieve | Lehmer's Math Machine in ATtinys

Until the late 1990s, this device outperformed general purpose computers at certain number theory problems.

kbsriramkbsriram • 09/21/2026 at 00:55•0 Comments

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.

ProblemPaperRatePublished notesMy sieveStops
9,999,000,099,990,001LF2850/s"about 2 hours"2 h 14 min 09 s2
a factor of 3^111 + 1LF2850/s"only 4 seconds"2.96s1
4,500,383,424,373
as a sum of two squares, run1
LF2850/s"one stop, not
a solution"
1 h 05 min 42 s1
same problem, run2LF2850/s"stopped only once"52 min 37 s2
2^79 - 1PS335,000/s"12 s"11.31 s1
2^93 + 1NF335,000/s"a few seconds"1.41 s1

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.

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.

Not every gear or chain helps on every problem.

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.

Problempublished value at p=127My sieve's running time
I 196,265,095,0094 h 33 min
II328,878,692,9997 h 39 min
III71,837,718,2831 h 40 min
IV8,133,814,32711 min 21 s
V60,664,576,5411 h 24 min
VI9,447,241,87713 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.

GitHub source for all the material here.

Discussions