Skip to main content

The I/O Complexity of Computing Prime Tables

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 9644))

Abstract

We revisit classical sieves for computing primes and analyze their performance in the external-memory model. Most prior sieves are analyzed in the RAM model, where the focus is on minimizing both the total number of operations and the size of the working set. The hope is that if the working set fits in RAM, then the sieve will have good I/O performance, though such an outcome is by no means guaranteed by a small working-set size.

We analyze our algorithms directly in terms of I/Os and operations. In the external-memory model, permutation can be the most expensive aspect of sieving, in contrast to the RAM model, where permutations are trivial. We show how to implement classical sieves so that they have both good I/O performance and good RAM performance, even when the problem size N becomes huge—even superpolynomially larger than RAM. Towards this goal, we give two I/O-efficient priority queues that are optimized for the operations incurred by these sieves.

This research was supported by NSF grants CCF 1217708, IIS 1247726, IIS 1251137, CNS 1408695, CCF 1439084, CNS-1408782, IIS-1247750, and Sandia National Laboratories.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    In our analyses, we model each sieving algorithm as if it writes the list of primes to an append-only output tape (i.e., the algorithm cannot read from this tape). All other memory used by the algorithm counts towards its working set size.

  2. 2.

    Sieves are also less effective at computing P[ab]. For primality-test algorithms, one simply checks the \(b-a+1\) candidate primes, whereas sieves generally require computing many primes smaller than a.

  3. 3.

    It is possible to compress this table using known prime-density theorems, decreasing the space usage further.

  4. 4.

    Here the representation of P[N] matters most, because the I/O complexity depends on the size (and cost to scan) P[N]. For most other sieves in this paper, P[N] is represented as a bit array and the I/O cost to scan P[N] is a lower-order term.

  5. 5.

    Note that the delete-min operations of the priority queue are on the keys, i.e., the composites.

  6. 6.

    These tables are available online. For example, see https://oeis.org/A002189/b002189.txt.

  7. 7.

    Sorenson’s exposition removes multiples of the small primes one by one on each segment in order to retain small working space. From an external memory point of view, building the whole wheel of size \(N^{o(1)}\) is also effective.

References

  1. Aggarwal, A., Vitter, S.: Jeffrey: the input/output complexity of sorting and related problems. Commun. ACM 31(9), 1116–1127 (1988)

    Article  MathSciNet  Google Scholar 

  2. Agrawal, M., Kayal, N., Saxena, N.: Primes is in P. Ann. Math. 50, 781–793 (2004)

    Article  MathSciNet  MATH  Google Scholar 

  3. Arge, L.: The buffer tree: a technique for designing batched external data structures. Algorithmica 37(1), 1–24 (2003)

    Article  MathSciNet  MATH  Google Scholar 

  4. Arge, L., Bender, M.A., Demaine, E.D., Holland-Minkley, B., Munro, J.I.: Cache-oblivious priority queue and graph algorithm applications. In: Proceedings of the 34th Annual Symposium on Theory of Computing, pp. 268–276 (2002)

    Google Scholar 

  5. Arge, L., Thorup, M.: RAM-efficient external memory sorting. In: Cai, L., Cheng, S.-W., Lam, T.-W. (eds.) Algorithms and Computation. LNCS, vol. 8283, pp. 491–501. Springer, Heidelberg (2013)

    Chapter  Google Scholar 

  6. Atkin, A., Bernstein, D.: Prime sieves using binary quadratic forms. Math. Comput. 73(246), 1023–1030 (2004)

    Article  MathSciNet  MATH  Google Scholar 

  7. Bays, C., Hudson, R.H.: The segmented sieve of Eratosthenes and primes in arithmetic progressions to 1012. BIT Numer. Math. 17(2), 121–127 (1977)

    Article  MathSciNet  MATH  Google Scholar 

  8. Bengelloun, S.: An incremental primal sieve. Acta Informatica 23(2), 119–125 (1986)

    Article  MathSciNet  MATH  Google Scholar 

  9. Brent, R.P.: The first occurrence of large gaps between successive primes. Math. Comput. 27(124), 959–963 (1973)

    Article  MathSciNet  MATH  Google Scholar 

  10. Cox, D.A.: Primes of the Form \(x^2+ny^2\): Fermat, Class Field Theory, and Complex Multiplication. Wiley, New York (1989)

    Google Scholar 

  11. Dunten, B., Jones, J., Sorenson, J.: A space-efficient fast prime number sieve. IPL 59(2), 79–84 (1996)

    Article  MathSciNet  MATH  Google Scholar 

  12. Farach-Colton, M., Tsai, M.-T.: On the complexity of computing prime tables. In: Elbassioni, K., Makino, K. (eds.) ISAAC 2015. LNCS, vol. 9472, pp. 677–688. Springer, Heidelberg (2015). doi:10.1007/978-3-662-48971-0_57

    Chapter  Google Scholar 

  13. Gale, R., Pratt, V.: CGOL-an Algebraic Notation for MACLISP Users. MIT Artificial Intelligence Library, Cambridge (1977)

    Google Scholar 

  14. Galway, W.F.: Dissecting a sieve to cut its need for space. In: Bosma, W. (ed.) ANTS-IV. LNCS, vol. 1838, pp. 297–312. Springer, Heidelberg (2000)

    Chapter  Google Scholar 

  15. Gries, D., Misra, J.: A linear sieve algorithm for finding prime numbers. Commun. ACM 21(12), 999–1003 (1978)

    Article  MathSciNet  MATH  Google Scholar 

  16. Hardy, G.H., Wright, E.M.: An Introduction to the Theory of Numbers. Oxford University Press, Oxford (1979)

    MATH  Google Scholar 

  17. Horsley, S.: KO\(\Sigma \)KINON EPATO\(\Sigma \Theta \)ENOY\(\Sigma \). or, the sieve of eratosthenes. being an account of his method of finding all the prime numbers, by the Rev. Samuel Horsley, FRS. Philos. Trans. 62, 327–347 (1772)

    Article  Google Scholar 

  18. Lenstra Jr., H.W.: Primality testing with gaussian periods. In: Agrawal, M., Seth, A.K. (eds.) FSTTCS 2002. LNCS, vol. 2556, pp. 1–1. Springer, Heidelberg (2002)

    Chapter  Google Scholar 

  19. Mairson, H.G.: Some new upper bounds on the generation of prime numbers. Commun. ACM 20(9), 664–669 (1977)

    Article  MathSciNet  MATH  Google Scholar 

  20. Mertens, F.: Ein beitrag zur analytischen zahlentheorie. J. fr die reine und angewandte Mathematik 78, 46–62 (1874)

    MathSciNet  Google Scholar 

  21. News, F.: World’s largest prime number discovered - all 17 million digits, February 2013. https://web.archive.org/web/20130205223234/, http://www.foxnews.com/science/2013/02/05/worlds-largest-prime-number-discovered/

  22. Patrascu, M., Thorup, M., Dynamic integer sets with optimal rank, select, predecessor search. In: FOCS, pp. 166–175 (2014)

    Google Scholar 

  23. Pomerance, C., Selfridge, J.L., Wagstaff, S.S.: The pseudoprimes to \(25 \cdot 10^9\). Math. Comput. 35(151), 1003–1026 (1980)

    MathSciNet  MATH  Google Scholar 

  24. Pomerance, C., Shparlinski, I.E.: On pseudosquares and pseudopowers. Comb. Number Theor., 171–184 (2009)

    Google Scholar 

  25. Pritchard, P.: A sublinear additive sieve for finding prime number. Commun. ACM 24(1), 18–23 (1981)

    Article  MathSciNet  MATH  Google Scholar 

  26. Pritchard, P.: Explaining the wheel sieve. Acta Informatica 17(4), 477–485 (1982)

    Article  MathSciNet  MATH  Google Scholar 

  27. Pritchard, P.: Linear prime-number sieves: a family tree. Sci. Comput. Program. 9(1), 17–35 (1987)

    Article  MathSciNet  MATH  Google Scholar 

  28. Schönhage, A., Grotefeld, A., Vetter, E.: Fast algorithms: a multitape turing machine implementation. Wissenschaftsverlag, B.I (1994)

    Google Scholar 

  29. Singleton, R.C.: Algorithm 357: an efficient prime number generator. Commun. ACM 12, 563–564 (1969)

    Article  Google Scholar 

  30. Sorenson, J.: An introduction to prime number sieves. Technical report 909, Computer Sciences Department, University of Wisconsin-Madison (1990)

    Google Scholar 

  31. Sorenson, J.P.: The pseudosquares prime sieve. In: Hess, F., Pauli, S., Pohst, M. (eds.) ANTS 2006. LNCS, vol. 4076, pp. 193–207. Springer, Heidelberg (2006)

    Chapter  Google Scholar 

  32. Villarino, M.B.: Mertens’ proof of mertens’ theorem. arXiv:math/0504289 (2005)

  33. Vitter, J.S.: External memory algorithms and data structures: dealing with massive data. ACM Comput. Surv. (CsUR) 33(2), 209–271 (2001)

    Article  Google Scholar 

  34. Williams, H.C.: Edouard Lucas and primality testing. Canadian Mathematics Society Series of Monographs and Advanced Texts, 22 (1998)

    Google Scholar 

Download references

Acknowledgments

We thank Oleksii Starov for suggesting this problem to us.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Alexander Conway .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Bender, M.A. et al. (2016). The I/O Complexity of Computing Prime Tables. In: Kranakis, E., Navarro, G., Chávez, E. (eds) LATIN 2016: Theoretical Informatics. LATIN 2016. Lecture Notes in Computer Science(), vol 9644. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-662-49529-2_15

Download citation

  • DOI: https://doi.org/10.1007/978-3-662-49529-2_15

  • Published:

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-662-49528-5

  • Online ISBN: 978-3-662-49529-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics