Preprint
Article

This version is not peer-reviewed.

Six Exact Formulations of the Sieve of Eratosthenes and Their Algebraic Equivalence

Submitted:

26 June 2025

Posted:

27 June 2025

You are already at the latest version

Abstract
We present and compare six mathematically exact formulations of the Sieve of Eratosthenes, ranging from arithmetic expressions with the floor function to elegant algebraic products using roots of unity, primorials, and factorials. We demonstrate their algebraic equivalence as primality indica- tors and exact prime-counting formulas. Examples, computational remarks, and a complexity comparison are provided to clarify their pedagogical and mathematical value.
Keywords: 
;  ;  

1. Introduction

The Sieve of Eratosthenes is a foundational method in number theory for generating all prime numbers up to a given limit. Over the centuries, it has inspired efficient algorithms and beautiful algebraic identities. This article synthesizes six exact formulations of the sieve—both classical and less well-known—and reveals their algebraic equivalence. These formulations serve as didactic bridges between arithmetic, algebra, and complex analysis.

2. Six Exact Formulations

2.1. Floor-Function Indicator

For n N :
I floor ( n ) = k = 2 n 1 n k + n 1 k
I floor ( n ) = 1 if n is prime, 0 otherwise [1,2,3].

2.2. Roots-of-Unity (Complex Exponential) Indicator

Let
δ ( k , n ) = 1 k m = 0 k 1 exp 2 π i m n k
Then
I unity ( n ) = k = 2 n 1 δ ( k , n )
Again, I unity ( n ) = 1 iff n is prime [4,5,6].

2.3. Primorial and GCD Model

Let P n denote the product of all primes p n :
I primorial ( n ) = 1 if gcd ( n , P n ) = 1 0 otherwise
A number is prime if it is coprime to its local primorial [2,3].

2.4. Wilson’s Theorem (Roots of Unity)

Using Wilson’s theorem, ( n 1 ) ! 1 ( mod n ) :
I Wilson ( n ) = 1 n k = 0 n 1 exp 2 π i ( ( n 1 ) ! + 1 ) k n
I Wilson ( n ) = 1 if n is prime, 0 otherwise [3,7].

2.5. Aggregated Fermat Test

Define:
S ( n ) = a = 1 n 1 a n 1 mod n
n is prime iff S ( n ) n 1 ( mod n ) [8,9].

2.6. Discrete Derivative (Prime Counting)

The exact prime counting function:
π ( n ) = k = 2 n I ( k )
where I ( k ) can be any of the above indicators. The difference
P I D N ( n ) = π ( n ) π ( n 1 )
is a primality indicator [2,10].

3. Numerical Examples

For illustration, we compute the indicator for n = 7 (prime) and n = 8 (composite) for each formulation:
  • Floor-Function:
    I floor ( 7 ) = ( 1 7 / 2 + 6 / 2 ) ( 1 7 / 3 + 6 / 3 ) = ( 1 3 + 3 ) ( 1 2 + 2 ) = ( 1 ) ( 1 ) = 1 I floor ( 8 ) = ( 1 4 + 3 ) ( 1 2 + 2 ) = ( 0 ) ( 1 ) = 0
  • Roots-of-Unity:  I unity ( 7 ) = 1 , I unity ( 8 ) = 0 (by evaluation of the exponential sums).
  • Primorial GCD:  P 7 = 2 × 3 = 6 ; gcd ( 7 , 6 ) = 1 1 , gcd ( 8 , 6 ) = 2 0 .
  • Wilson:  ( 6 ! + 1 ) mod 7 = 720 + 1 = 721 mod 7 = 0 1 , ( 7 ! + 1 ) mod 8 = 5041 mod 8 = 1 0 0 .
  • Aggregated Fermat:  S ( 7 ) = 6 ( mod 7 ) = 6 , S ( 8 ) 7 .
  • Discrete Derivative:  P I D N ( 7 ) = π ( 7 ) π ( 6 ) = 4 3 = 1 , P I D N ( 8 ) = π ( 8 ) π ( 7 ) = 4 4 = 0 .

4. Complexity Comparison Table

Table 1. Comparison of dominant operation and efficiency. All are exact, but vary widely in practical utility.
Table 1. Comparison of dominant operation and efficiency. All are exact, but vary widely in practical utility.
Formulation Dominant Operation Practical Efficiency
Floor-function Division, floor O ( n )
Roots of unity Exponential sum O ( n ) (slower constants)
Primorial GCD List of primes up to n , GCD O ( n )
Wilson Factorial, sum O ( n ) (factorial cost)
Aggregated Fermat Exponentiation O ( n ) (not efficient)
Discrete Derivative As above As above

5. Discussion

These six formulas are mathematically equivalent: all encode, in their own language, the principle that a number is prime if it is not divisible by any smaller prime (or, for Wilson/Fermat, if certain congruences hold). Their main value is didactic and conceptual, not computational: while the floor-function and GCD versions are moderately efficient, the Wilson and Fermat types are beautiful but slow for large n.
This synthesis aims to unify classic results under a common pedagogical roof, making the structure of primality visible from multiple angles.

6. Conclusions

The Sieve of Eratosthenes can be expressed in multiple algebraic and arithmetic forms, all exact and fundamentally equivalent. Presenting these side by side deepens both the theoretical and educational understanding of primality.

References

  1. C. P. Willans, “On formulae for the nth prime number,” Mathematical Gazette, 48(363), 1964.
  2. G. H. Hardy, E. M. Wright, An Introduction to the Theory of Numbers, Oxford, 1979.
  3. R. Crandall, C. Pomerance, Prime Numbers: A Computational Perspective, Springer, 2001.
  4. Math StackExchange, “Proof for a relation between prime numbers and roots of unity.” https://math.stackexchange.com/questions/1723456/proof-for-a-relation-between-prime-numbers-and-roots-of-unity.
  5. C. F. Gauss, Disquisitiones Arithmeticae, 1801.
  6. P. G. L. Dirichlet, “Über die Bestimmung der mittleren Werthe in der Zahlentheorie,” Abhandlungen der Königlichen Akademie der Wissenschaften zu Berlin, 1849.
  7. Wilson indicator and algebraic sum, see also OEIS A007635.
  8. K. Giuga, “Su una presumibile proprietà caratteristica dei numeri primi,” Ist. Lombardo Sci. Lett. Rend. A, 83, 511-528, 1949.
  9. See also: https://en.wikipedia.org/wiki/Giuga_number.
  10. For variants and discussion, see OEIS A000720, Wikipedia “Sieve of Eratosthenes,” and “Formula for primes.”.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.
Prerpints.org logo

Preprints.org is a free preprint server supported by MDPI in Basel, Switzerland.

Subscribe

Disclaimer

Terms of Use

Privacy Policy

Privacy Settings

© 2025 MDPI (Basel, Switzerland) unless otherwise stated