The Euler's Sieve refines the Sieve of Eratosthenes to compute prime numbers, by crossing off each non prime number just once. Euler's Sieve is considered hard to be faithfully and efficiently coded as a purely functional stream based program. We propose three Haskell programs implementing the Euler's Sieve, all based on the idea of generating just once each composite to be crossed off. Their faithfulness with respect to the Euler's Sieve is up to costly stream unions imposed by the sequential nature of streams. Our programs outperform classical naive stream based prime generators such as trial division, but they are asymptotically worse than the O'Neill `faithful' Sieve of Eratosthenes. To circumvent the bottleneck of union of streams, we integrate our techniques inside the O'Neill program, thus obtaining a fast prime generator based on the Euler's Sieve and priority queues.

Three Euler's Sieves and a Fast Prime Generator (Functional Pearl) / Salvo, I.; Pacifico, A.. - (2018).

Three Euler's Sieves and a Fast Prime Generator (Functional Pearl)

Salvo I.
;
Pacifico A.
2018

Abstract

The Euler's Sieve refines the Sieve of Eratosthenes to compute prime numbers, by crossing off each non prime number just once. Euler's Sieve is considered hard to be faithfully and efficiently coded as a purely functional stream based program. We propose three Haskell programs implementing the Euler's Sieve, all based on the idea of generating just once each composite to be crossed off. Their faithfulness with respect to the Euler's Sieve is up to costly stream unions imposed by the sequential nature of streams. Our programs outperform classical naive stream based prime generators such as trial division, but they are asymptotically worse than the O'Neill `faithful' Sieve of Eratosthenes. To circumvent the bottleneck of union of streams, we integrate our techniques inside the O'Neill program, thus obtaining a fast prime generator based on the Euler's Sieve and priority queues.
2018
File allegati a questo prodotto
Non ci sono file associati a questo prodotto.

I documenti in IRIS sono protetti da copyright e tutti i diritti sono riservati, salvo diversa indicazione.

Utilizza questo identificativo per citare o creare un link a questo documento: https://hdl.handle.net/11573/1211643
 Attenzione

Attenzione! I dati visualizzati non sono stati sottoposti a validazione da parte dell'ateneo

Citazioni
  • ???jsp.display-item.citation.pmc??? ND
  • Scopus ND
  • ???jsp.display-item.citation.isi??? ND
social impact