and primes enumeration using odd numbers indexation

WOLF Marc, https://orcid.org/0000-0002-6518-9882

WOLF François, https://orcid.org/0000-0002-3330-6087 Independent researchers; [email protected] ; [email protected] April 5th, 2020

ABSTRACT

Odd numbers can be indexed by the map 푘(푛) = (푛 − 3)⁄2 , 푛 ∈ 2ℕ + 3. We first propose a basic primality test using this index function that was first introduced in [8]. Input size of operations is reduced which improves computational time by a constant. We then apply similar techniques to Atkin’s prime-numbers sieve which uses modulus operations and finally to Pritchard’s wheel sieve, in both case yielding similar results.

Keywords: odd number index, primality test, primes enumeration, Atkin sieve, composite odd numbers, wheel sieve. CONTENTS

1 INTRODUCTION ...... 2

1.1 PRIMALITY TEST AND PRIME ENUMERATION ...... 2 1.2 NOTATION ...... 2 2 BASIC PRIMALITY TEST AND PRIMES ENUMERATION ...... 3

2.1 TWO FAMILIES OF INFINITE SEQUENCES WITH ARITHMETIC DIFFERENCE ...... 3 2.2 BASIC PRIMALITY TEST ...... 4 2.3 PRIMALITY TEST WITH INDICES ...... 5 2.4 FIRST OF PRIME ENUMERATION ...... 5 2.4.1 Primality test using numbers ...... 5 2.4.2 Primality test using infinite sequences and indices ...... 8 2.5 PERFOMANCE OF THE ALGORITHMS ...... 11 3 THE SIEVE OF ATKIN ...... 13

3.1 ATKIN ...... 13 3.2 ATKIN ALGORITHM WITH INDICES ...... 16 3.3 PERFORMANCE OF ALGORITHMS ...... 19 4 WHEEL SIEVE WITH INDICES ...... 20

4.1 DESCRIPTION OF PRITCHARD’S WHEEL SIEVE ...... 20 4.2 INDEX WHEEL SIEVE ...... 21

1

4.3 WHEEL SIEVE ALGORITHMS ...... 24 4.4 PERFORMANCE OF ALGORITHMS ...... 25 5 CONCLUSION ...... 26 6 REFERENCES ...... 26 7 APPENDIX: ALGORITHM OF THE INDEX WHEEL SIEVE ...... 27 8 APPENDIXES: MAPLE REGRESSIONS ...... 31

1 Introduction

1.1 Primality test and prime enumeration An odd number 푛 is prime when it is not divisble by any prime 푝 lower than or equal to √푛. This basic primality test requires too much computational time for large integers. Faster and more efficient deterministic and probabilistic primality tests have been designed for large numbers [1]. A deterministic polynomial primality test was proposed by M. Agrawal, N. Kayal and N. Saxena in 2002 [2]. Enumeration of primes up to a given limit can be done by using a primality test but sieves are preferred from a performance point of view. A sieve is a type of fast algorithm to find all primes up to a given number. There exists many such algorithms, from the simple Erastosthenes’ sieve (invented more than 2000 years ago), to the wheel sieves of Paul Pritchard ([3], [4], [5]) and the sieve of Atkin [6]. In [7], Gabriel Paillard, Felipe Franca and Christian Lavault present another version of the wheel sieve and give an overview of all the existing prime-numbers sieves. In theory, indices are a way to represent odd numbers. By adapting results from [8], we show how odd number indices may be used in applied mathematics. In the last part, we apply [8] to Pritchard’s wheel sieve, which leads to a 푑푦푛푎푚푖푐푎푙 wheel sieve. Using the linear diophantine equation resolution method first introduced in [9], we introduce an original way of “turning the wheel”.

1.2 Notation

We will use the following notations: 1. 퐼 designates the set of odd integers greater than 1, i.e.:

퐼 = {푁푘 = 2푘 + 3|푘 ∈ ℕ};

2. 푃 the set of prime numbers, 푃푛 the set of prime numbers not greater than 푛; 3. 퐶 the set of composite odd integers, i.e.:

퐶 = 퐼\푃 = {푁푘 ∈ 퐼|∃(푎, 푏) ∈ 퐼, 푁푘 = 푎푏} 푁 −3 The function 푓: 푘 ∈ ℕ ⟼ 푁 ∈ 퐼 is bijective. The inverse function is 푓−1: 푁 ∈ 퐼 ⟼ 푘 = 푘 . 푘 = 푘 푘 2 −1 푓 (푁푘) is the index of 푁푘. The preimage of 퐶 is denoted by 푊:

2

−1 푊 = 푓 (퐶) = {푘 ∈ ℕ| 푁푘 ∈ 퐶} 4. For 푥 and 푦 two integers, we denote by 푥 mod 푦 the of the of 푥 by 푦, which belongs to ⟦0, 푦 − 1⟧.

5. 푁1 and 푁2 are the subsets of 퐼 given by:

푁1 = {푁푘 ∈ 퐼|푁푘 mod 4 = 1}

푁2 = {푁푘 ∈ 퐼|푁푘 mod 4 = 3} Similarly:

퐶1 = 푁1 ∩ 퐶

퐶2 = 푁2 ∩ 퐶

Finally, 푆1 and 푆2 designate the set of indices corresponding to elements of 퐶1 and 퐶2 respectively, i.e. −1 −1 푆1 = 푓 (퐶1) and 푆2 = 푓 (퐶2).

2 Basic primality test and primes enumeration

2.1 Two families of infinite sequences with arithmetic difference [8] shows that 푊 is the union of two families of finite sequences with arithmetic difference.

Actually proposition 2-5 says that any composite odd number 푁푘 ∈ 퐶 can be written as a difference of two squares, and more precisely that there exists 푗 ∈ ℕ and 푥 ∈ ⟦0, 푗⟧ such that:

2 2 (ퟏ) 푁푘 ∈ 퐶1 ⇒ 푁푘 = (2푗 + 3) − (2푥) , { 2 2 (ퟐ) 푁푘 ∈ 퐶2 ⇒ 푁푘 = (2푗 + 4) − (2푥 + 1)

Corollary 2-1: Let 푘푗(푛) = (2푗 + 3)푛 + 푗. One has:

푊 = 푆1 ∪ 푆2 and: 푆 = {푘 (푥) = 푘 (푖 + 1) + 2(2푖 + 3)푥; 푖 ∈ ℕ, 푥 ∈ ℕ} 1 푖 푖 푆2 = {푘푖(푥) = 푘푖(푖 + 2) + 2(2푖 + 3)푥; 푖 ∈ ℕ, 푥 ∈ ℕ}

Thus 푊 is the union of two families of infinite arithmetic sequences. The indices 푘푖(푖 + 1) of first type reference points (or remarkable points, see[8]) are the initial terms of sequences ranging in 푆1. Similarly, the indices 푘푖(푖 + 2) of second type reference points are the initial terms of sequences ranging in 푆2. Proof: We substitute 푗 by 푖 + 푥 in relations (1) and (2): (2푗 + 3)2 − (2푥)2 = (2푖 + 2푥 + 3)2 − (2푥)2 = (2푖 + 3)(2푖 + 4푥 + 3)

= 2[푘푖(푖 + 1) + 2(2푖 + 3)푥] + 3 and similarly:

3

(2푗 + 4)2 − (2푥 + 1)2 = (2푖 + 2푥 + 4)2 − (2푥 + 1)2 = (2푖 + 3)(2푖 + 4푥 + 5)

= 2(2푖 + 3)(푖 + 2푥 + 2) + 2푖 + 3 = 2[푘푖(푖 + 2) + 2(2푖 + 3)푥] + 3

Proposition 2-1: For any 푁푘 ∈ 퐶 there exists 푋 ∈ 푃, 푋 ≤ √푁푘 and 푥 ∈ ℕ such that:

푁푘 ∈ 퐶1 ⇒ 푁푘 = 푋(푋 + 4푥)

푁푘 ∈ 퐶2 ⇒ 푁푘 = 푋(푋 + 4푥 + 2) Thus, writing 푋 = 2푖 + 3, we get:

′ ′ 푊 = 푆1 ∪ 푆2 where: ′ 푆1 = {푘푖(푥) = 푘푖(푖 + 1) + 2(2푖 + 3)푥; 푖 ∈ ℕ ∖ 푊, 푥 ∈ ℕ} ′ 푆2 = {푘푖(푥) = 푘푖(푖 + 2) + 2(2푖 + 3)푥; 푖 ∈ ℕ ∖ 푊, 푥 ∈ ℕ} 푁 Proof: Take 푋 the smallest prime dividing 푁 ∈ 퐶. Thus 푋 ∈ 푃 and if 푌 = 푘 then 푌 ≥ 푋 and 푌 − 푋 푘 √푁푘 푋 is even, and we can write it either 4푥 or 4푥 + 2. These two cases clearly correspond respectively to

푁푘 ∈ 퐶1 and 푁푘 ∈ 퐶2. Thus the index 푘 can be decomposed as in corollary 2-1, but with 푖 the index of a prime number, hence in ℕ ∖ 푊.

2.2 Basic primality test In this section, we describe a basic primality test using the previous infinite sequences. Definition 2-2: For any 푝 = 2푖 + 3 ∈ 푃 and 푁 ∈ 퐼 we let:

2 2 1- 퐴(푁, 푝) = 푁 − 푝 and 푓퐴(푝) = 푝 .

2- 퐵(푁, 푝) = 푁 − 푝(푝 + 2) and 푓퐵(푝) = 푝(푝 + 2).

Proposition 2-2: 푁 ∈ 푁1 is a prime number when: 퐴(푁, 푝) ∀푝 = 2푖 + 3 ∈ 푃 , mod 푝 ≠ 0 √푁 4

푁 ∈ 푁2 is a prime number when: 퐵(푁, 푝) ∀푝 = 2푖 + 3 ∈ 푃 , mod 푝 ≠ 0 √푁 4 Proof: This follows from the fact that 퐴(푁, 푝) mod 푝 = 푁 mod 푝 and likewise for 퐵(푁, 푝).

Remark 2-2: In order to reduce computation of 퐴(푁, 푝) and 퐵(푁, 푝) for two consecutive prime numbers, we only decrement the value. More precisely, if 푝 < 푝′ are two primes, we let 훼(푝, 푝′) = 푝′ − 푝 and we compute: 훥퐴(푁, 푝, 푝′) = 퐴(푁, 푝) − 퐴(푁, 푝′) = 훼(훼 + 2푝) { 훥퐵(푁, 푝, 푝′) = 퐵(푁, 푝) − 퐵(푁, 푝′) = Δ퐴(푁, 푝, 푝′) + 2훼

4

These two expressions are independent of 푁.

2.3 Primality test with indices We adapt here the results of the previous section with indices. Definition 2-3: For any 푖 index of a prime number 푝 ∈ 푃 and 푘 ∈ ℕ, we let:

′ ′ ′ 1- 퐴 (푘, 푖) = (푘 − 3)⁄2 − 푖(푖 + 3), 푓퐴(푖) = 푖(푖 + 3), 푔퐴(푘) = (푘 − 3)⁄2

′ ′ ′ 2- 퐵 (푘, 푖) = (푘 − 6)⁄2 − 푖(푖 + 4) and 푓퐵(푖) = 푖(푖 + 4), 푔퐵(푘) = (푘 − 6)⁄2

Proposition 2-3: 푘 ∈ 푆1 is a prime number index when: ′ ∀푝 = 2푖 + 3 ∈ 푃√2푘+3 , 퐴 (푘, 푖) mod 푝 ≠ 0

푘 ∈ 푆2 is a prime number index when: ′ ∀푝 = 2푖 + 3 ∈ 푃√2푘+3 , 퐵 (푘, 푖) mod 푝 ≠ 0 Proof: This follows from proposition 2-2 and definition 2-2 because if we let 푁 = 2푘 + 3 then 퐴(푁,푝) 퐵(푁,푝) 퐴′(푘, 푖) = and 퐵′(푘, 푖) = . 4 4

Remark 2-3: In order to reduce computation of 퐴′(푘, 푖) and 퐵′(푘, 푖) for two consecutive prime number indices, we only decrement their values. More precisely, if 푖 < 푖′ are two prime indices we let 훼′(푖, 푖′) = 푖′ − 푖 and we compute: Δ퐴′(푘, 푖, 푖′) = 퐴′(푘, 푖) − 퐴′(푘, 푖′) = 훼′(훼′ + 2푖 + 3) Δ퐵′(푘, 푖, 푖′) = 퐵′(푘, 푖) − 퐵′(푘, 푖′) = Δ퐴′(푘, 푖, 푖′) + 훼′ These two expressions are independent of 푘.

2.4 First algorithms of prime enumeration In this section, we present prime enumeration algorithms based on propostion 2-2 and 2-3. The first one manipulates numbers and the second one indices.

2.4.1 Primality test using numbers This first algorithm named PrimeEnumeration consists in two functions:

➢ The main function which determines primes in up to 푁푀푎푥 and returns them in a list, along with its size. ➢ An auxiliary function which returns whether a number 푁 is prime, based on precomputed list of primes and values of Δ퐴 and Δ퐵. It is called LocalTest. It is also in charge of updating the lists Δ퐴 and Δ퐵 if needed.

5

Three zero-based lists are used and built recursively in this algorithm: the list of primes itself 퐿푝, and the lists of values for Δ퐴 and Δ퐵 respective to 퐿푝 (remember it is independent from 푁). Only numbers which are not multiples of 2 and 3 are tested. Thus we restrict to 푁 = 6푚 + 1 and 푁 = 6푚 + 5. The congruence of 푁 modulo 4 depends on the parity of 푚, i.e. when 푚 is even, 푁 mod 4 = 1 and when 푚 is odd, 푁 mod 4 = 3.

Algorithm 2-4-1a Function PrimeEnumeration(푁푀푎푥): 푁푀푎푥 is an odd integer such that 푁푀푎푥 ≥ 7. This function returns the list of primes up to 푁푀푎푥 and its size.

First step : intialisation of variables

퐿푝 ← {5} → List of primes from 5, initialized with one element

푖푙 ← 1 → Size of the list 퐿푝 → About the next two lists, see the remark 2-2 Δ퐴 ← {16} → Δ퐴(푁, 3,5) = 2 × (2 + 6) = 16 Δ퐵 ← {20} → Δ퐵(푁, 3,5) = Δ퐴(푁, 3,5) + 2 × 2 = 20

푖푟1 → 0 퐶푎푝1 ← 25

푖푟2 → 0 퐶푎푝2 ← 35

Second step : iteration (푚, 푁) ← (1,7) 푀표푑퐸푞푂푛푒 ← False → 푚 = 1 so (6푚 + 1) mod 4 = 3

While 푁 ≤ 푁푀푎푥 Do → Loop to get odd primes in range ⟦5, 푁푀푎푥⟧

If LocalTest(푁, 퐿푝, Δ퐴, Δ퐵, 푖푟1, 퐶푎푝1, 푖푟2, 퐶푎푝2, 푀표푑퐸푞푂푛푒) Do

퐿푝(푖푙) ← 푁

푖푙 ← 푖푙 + 1 End If 푁 ← 6푚 + 5

If 푁 ≤ 푁푀푎푥 And LocalTest(푁, 퐿푝, Δ퐴, Δ퐵, 푖푟1, 퐶푎푝1, 푖푟2, 퐶푎푝2, 푀표푑퐸푞푂푛푒) Do

퐿푝(푖푙) ← 푁

푖푙 ← 푖푙 + 1 End If 푚 ← 푚 + 1

6

푁 ← 6푚 + 1 푀표푑퐸푞푂푛푒 ← ! 푀표푑퐸푞푂푛푒 → Switch the boolean value End While

Return ({2,3} + 퐿푝, 푖푙 + 2) → Return the list of primes and the number of primes.

Algorithm 2-4-1b Function LocalTest (푁, 퐿푝, Δ퐴, Δ퐵, 푖푟1, 퐶푎푝1, 푖푟2, 퐶푎푝2, 푀표푑퐸푞푂푛푒): 푁 is an odd integer. 푖푟표표푡 stands for 푖푟1 or 푖푟2 depending on 푀표푑퐸푞푂푛푒. This function decides whether for all 푝 ∈ 퐿푝[0 … 푖푟표표푡], 퐴(푁, 푝)/4 or 퐵(푁, 푝)/4 is not divisible by 푝. It will also potentially update Δ퐴, Δ퐵, 푖푟1,

푖푟2, 퐶푎푝1 and 퐶푎푝2 which must be passed by reference.

First step : intialisation of variables

2 퐴 ← 9 → stands for 푓퐴(3) = 3

퐵 ← 15 → stands for 푓퐵(3) = 3 × 5 If 푀표푑퐸푞푂푛푒 Do → initiate references that might be updated

푖푟표표푡 ← 푖푟1 퐶푎푝 ← 퐶푎푝1 Δ ← Δ퐴 Else

푖푟표표푡 ← 푖푟2 퐶푎푝 ← 퐶푎푝2 Δ = Δ퐵 End If If 푁 = 퐶푎푝 Do Return False → The cap is a composite number End If If 푁 > 퐶푎푝 Do → update references because we always want 푁 ≤ 퐶푎푝

푖푟표표푡 ← 푖푟표표푡 + 1

훼 ← (퐿푝(푖푟표표푡) − 퐿푝(푖푟표표푡 − 1))

If 푀표푑퐸푞푂푛푒 Do

Δ(푖푟표표푡) ← 훼(훼 + 2퐿푝(푖푟표표푡 − 1)) → Δ퐴 Else

Δ(푖푟표표푡) ← Δ퐴(푖푟표표푡) + 2훼 → Δ퐵, using Δ퐴 which must already be updated

7

End If

퐶푎푝 ← 퐶푎푝 + Δ(푖푟표표푡) End If

Second step : iteration If 푀표푑퐸푞푂푛푒 Do 푁 ← 푁 − 퐴 Else 푁 ← 푁 − 퐵 End If 푖 ← 0

While 푖 ≤ 푖푟표표푡 Do → Iteration at most up to 푖 = 푖푟표표푡 푁 ← 푁 − Δ(푖)

If (푁⁄4) mod 퐿푝(푖) = 0 Do → 푁 is a multiple of 4, division by 4 can be done bitwise Return False → Test is negative End If 푖 ← 푖 + 1 End While Return True → Test is positive

2.4.2 Primality test using infinite sequences and indices

This second algorithm IndexPrimeEnumeration also consists in two functions, mirroring the previous algorithm:

➢ The main function which determines primes up to 푁푀푎푥 and returns them in a list along with its size. ➢ An auxiliary function which returns whether a number 푁 is prime based on precomputed list of primes and values of Δ퐴′ and Δ퐵′. It is called LocalTest. Four zero-based lists are used and built recursively: the list of primes 퐿푝, the corresponding indices ′ ′ 퐼퐿푝 (indices of primes), and the lists Δ퐴 and Δ퐵 respective to 퐿푝. Only numbers which are not multiple of 2 and 3 are tested, i.e. indices of the form 푘 = 3푚 − 1 and 푘 = 3푚 + 1.

8

Remark 2-4-2: To avoid any division in the computation of 퐴′ and 퐵′ we will write 푚 = 2푡 + 1 or 2푡 + 2.

Algorithm 2-4-2a Function IndexPrimeEnumeration(푁푀푎푥): 푁푀푎푥 is an odd integer such that 푁푀푎푥 ≥ 7. This function returns the list of primes up to 푁푀푎푥 and its size.

First step : intialisation of variables

퐿푝 ← {5} → List of primes from 5, initialized with one element

퐼퐿푝 ← {1} → List of index of primes

푖푙 ← 1 → Size of the two lists 퐿푝 and 퐼퐿푝 → About the next two lists, see the remark 2-3 Δ퐴′ ← {4} → Δ퐴′(푘, 0,1) = 1 × (1 + 3) = 4 Δ퐵′ ← {5} → Δ퐵′(푘, 0,1) = Δ퐴′(푘, 0,1) + 1 = 5

푘푀푎푥 ← (푁푀푎푥 − 3)⁄2

푖푟1 → 0 퐶푎푝1 ← 11

푖푟2 → 0 퐶푎푝2 ← 16

Second step : iteration

′ ′ ′ ′ (푡, 푘, 푔 ) ← (0, 2, −2) → 푘 starts at 3(2푡 + 1) − 1, 푔 stands for 푔퐴(푘) or 푔퐵(푘)

While 푘 ≤ 푘푀푎푥 Do → Loop to get odd prime indices in range ⟦1, 푘푀푎푥⟧ ′ ′ ′ If LocalTest(푔 , 푘, 퐿푝, 퐼퐿푝, Δ퐴 , Δ퐵 , 푖푟2, 퐶푎푝2,False) Do

퐼퐿푝(푖푙) ← 푘

퐿푝(푖푙) ← 2푘 + 3

푖푙 ← 푖푙 + 1 End If 푘 ← 푘 + 2 → 푘 = 3(2푡 + 1) + 1 푔′ ← 푔′ + 1 ′ ′ ′ If 푘 ≤ 푘푀푎푥 And LocalTest(푔 , 푘, 퐿푝, 퐼퐿푝, Δ퐴 , Δ퐵 , 푖푟2, 퐶푎푝2,False) Do

퐼퐿푝(푖푙) ← 푘

퐿푝(푖푙) ← 2푘 + 3

9

푖푙 ← 푖푙 + 1 End If 푘 ← 푘 + 1 → 푘 = 3(2푡 + 2) − 1 푔′ ← 푔′ + 2 ′ ′ ′ If 푘 ≤ 푘푀푎푥 And LocalTest(푔 , 푘, 퐿푝, 퐼퐿푝, Δ퐴 , Δ퐵 , 푖푟1, 퐶푎푝1,True) Do

퐼퐿푝(푖푙) ← 푘

퐿푝(푖푙) ← 2푘 + 3

푖푙 ← 푖푙 + 1 End If 푘 ← 푘 + 2 → 푘 = 3(2푡 + 2) + 1 푔′ ← 푔′ + 1 ′ ′ ′ If 푘 ≤ 푘푀푎푥 And LocalTest(푔 , 푘, 퐿푝, 퐼퐿푝, Δ퐴 , Δ퐵 , 푖푟1, 퐶푎푝1,True) Do

퐼퐿푝(푖푙) ← 푘

퐿푝(푖푙) ← 2푘 + 3

푖푙 ← 푖푙 + 1 End If 푡 ← 푡 + 1 → We do not use 푡 but keep it for the sake of readability 푘 ← 푘 + 1 → 푘 = 3(2푡 + 1) − 1 푔′ ← 푔′ − 1 End While

Return ({2,3} + 퐿푝, 푖푙 + 2) → Return the list of primes and the number of primes.

′ ′ ′ ′ Algorithm 2-4-2b Function LocalTest(푔 , 푘, 퐿푝, 퐼퐿푝, Δ퐴 , Δ퐵 , 푖푟표표푡, 퐶푎푝, 푀표푑퐸푞푂푛푒): 푔 stands for ′ ′ 푔퐴(푘) or 푔퐵(푘) depending on 푀표푑퐸푞푂푛푒. This function decides whether for all 푝 ∈ 퐿푝[0 … 푖푟표표푡], 퐴′(푘, 푖) or 퐵′(푘, 푖) is coprime with 푝.

First step : intialisation of variables If 푀표푑퐸푞푂푛푒 Do → initiate references that might be updated Δ ← Δ퐴′ Else Δ = Δ퐵′ End If

10

If 푘 = 퐶푎푝 Do Return False → The cap is the index of a composite number End If If 푘 > 퐶푎푝 Do → update references because we always want 푘 ≤ 퐶푎푝

푖푟표표푡 ← 푖푟표표푡 + 1

훼 ← (퐼퐿푝(푖푟표표푡) − 퐼퐿푝(푖푟표표푡 − 1))

If 푀표푑퐸푞푂푛푒 Do

′ Δ(푖푟표표푡) ← 훼(훼 + 퐿푝(푖푟표표푡 − 1)) → Δ퐴 Else

′ ′ ′ Δ(푖푟표표푡) ← Δ퐴 (푖푟표표푡) + 훼 → Δ퐵 , using Δ퐴 which must already be updated End If

퐶푎푝 ← 퐶푎푝 + Δ(푖푟표표푡) End If

Second step : iteration 푅 ← 푔′ 푖 ← 0

While 푖 ≤ 푖푟표표푡 Do → Iteration at most up to 푖 = 푖푟표표푡 푅 ← 푅 − Δ(푖)

If 푅 mod 퐿푝(푖) = 0 Do Return False → Test is negative End If 푖 ← 푖 + 1 End While Return True → Test is positive

2.5 Perfomance of the algorithms

In this section, we present the performance of the previous two algorithms of prime enumeration. We first give a theoretical complexity, followed by empirical results. Proposition 2-5: Time complexity (in terms of number of arithmetic operations) and space complexity are the same for both PrimeEnumeration and IndexPrimeEnumeration algorithms.

11

Time complexity is: 3 (푁푀푎푥)2 푂 ( ). ln(푁푀푎푥)

Space complexity is:

√푁푀푎푥 푂 ( ) ln(푁푀푎푥)

Proof: Any number 푛’s primality is tested with primes in ⟦5, √푛⟧, in 푂(1) operations. There are √푛 √푛 휋(√푛) − 2 ∼ = 푂 ( ) such primes. We loop over range ⟦7, 푁 ⟧, time complexity is thus ln(√푛) ln(푛) 푀푎푥 3 푁푀푎푥 √푡 (푁푀푎푥)2 ∑푡=7 푂 ( ) = 푂 ( ) (actually we skip two thirds of the terms in this sum by not testing ln(푡) ln(푁푀푎푥) 3 (푁 )2 multiples of 2 and 3, but complexity remains 푂 ( 푀푎푥 ) albeit with smaller constant. ln(푁푀푎푥)

The space complexity is related to the lists we keep in memory, which are at most of size 휋(푁푀푎푥). √푁 This space complexity is 푂 ( 푀푎푥 ). ln(푁푀푎푥)

Both algorithms have been implemented in Visual Studio C++ 2012. We measured execution time for various values of 푁푀푎푥 and produced a regression using Maple 2017.3. Details of the Maple options used to get the regression are given in appendix 8.1.

On the graph 2-5 below, we represent the computation time in seconds for both algorithms. Curve 푇1 corresponds to the algorithm PrimeEnumeration and curve 푇2 to IndexPrimeEnumeration. The correlation coefficient R of each curve is given on the graph. We observe that computation time of both algorithms is consistent with theoretical complexity, although exponent is a bit smaller than 1.5.

Graph 2-5: computation time 푻 (푵푴풂풙) in seconds for both algorithms (Prime enumeration)

−9 1.410 5.79 × 10 × 푁푀푎푥 푇1(푁푀푎푥) ≃ ln(푁푀푎푥) R =0.9996 −9 1.406 6.11 × 10 × 푁푀푎푥 푇2(푁푀푎푥) ≃ ln(푁푀푎푥) R =0.9996

12

Both algorithms PrimeEnumeration and IndexPrimeEnumeration have the same number of modulo operations. But the computation of the input of modulus operations is done with larger inputs for the former than for the latter, which allows to marginally save time for large values of 푁푀푎푥.

3 The sieve of Atkin The sieve of Atkin [6] is a modern and efficient algorithm for primes enumeration. We present two algorithms based on it, one using numbers and the other indices. Both are based on the version which 푁푀푎푥 has a complexity 푂(푁푀푎푥) in time and space. Modified versions achieve up to 푂 ( ) in time ln ln(푁푀푎푥) 1 +표(1) and 푂 (푁푀푎푥2 ) in space.

3.1 Atkin algorithm This algorithm is based on the following three results from [6]. Proposition 3-1 Let 푛 > 3 be a square-free integer. Then 푛 is prime if and only if one of the three following conditions is true: a. 푛 ∈ 1 + 4ℕ and there is an odd number of solutions to 푛 = 4푥2 + 푦2, (푥, 푦) ∈ ℕ2, b. 푛 ∈ 7 + 12ℕ and there is an odd number of solutions to 푛 = 3푥2 + 푦2, (푥, 푦) ∈ ℕ2, c. 푛 ∈ 11 + 12ℕ and there is an odd number of solutions to 푛 = 3푥2 − 푦2, 푥 > 푦, (푥, 푦) ∈ ℕ2.

We observe that the first congruence condition on 푛 can also be replaced by 푛 ∈ 1 + 12ℕ or 푛 ∈ 5 + 12ℕ. We also observe the following for an odd integer 푛:

• If 푛 = 4푥2 + 푦2, 푦 must be odd. • If 푛 = 3푥2 + 푦2 or 푛 = 3푥2 − 푦2, 푥 and 푦 must have opposite parity. Furthermore if 푛 is square-free, 푥 and 푦 must be in ℕ∗, with 푥 < √푛/2 and 푦 < √푛. Remark 3-1 We can compute the remainder modulo 12 of 푎푥2 + 푏푦2 depending on modulo 12 of 푥 and 푦. This gives us the different cases to check in Atkin sieve. We present them in table 3-1, noting that there is no case for 푦 mod 12 = 0 and 푦 mod 12 = 6.

Table 3-1: Atkin sieve cases depending on remainders modulo ퟏퟐ of 풙 and 풚. 푥\푦 1 2 3 4 5 7 8 9 10 11 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 0 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 1 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 2 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 3 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2

13

3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 5 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 6 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 7 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 8 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 9 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 10 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 3푥2 + 푦2 11 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 4푥2 + 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2 3푥2 − 푦2

We could run the sieve looping through 12x12 blocks of (푥, 푦) according to this table, but for readability we do not implement this optimization in the algorithms below. We note however that this would save all the modulo operations.

Algorithm 3-1 SieveOfAtkin(푁푀푎푥): 푁푀푎푥 > 3 is an integer. This function returns the list of all prime numbers less than 푁푀푎푥.

First step : intialisation of variables

퐿푝 ← {2, 3} → Dynamic list of odd primes

푖푙 ← 2 → Number of primes in the list

Sieve[푁푀푎푥] ← {False, …,False} → Array of 푁푀푎푥 entries all initialized to False

풙풎풂풙 ← ⌈√푁푀푎푥/2⌉ − 1 → Bound for 푥

풚풎풂풙 ← ⌈√푁푀푎푥⌉ − 1 → Bound for 푦

Second step : iteration for first case

For 푥 = 1 To 풙풎풂풙

For y = 1 To 풚풎풂풙 Step 2 → 푦 must be odd 푛 ← 4푥2 + 푦2

If 푛 < 푁푀푎푥 And (푛 mod 12 = 1 Or 푛 mod 12 = 5) Do Sieve[푛] ← !Sieve[푛] → Switch the boolean value Sieve[푛]

14

End If End For End For Third step : iteration for second and third cases

For 푥 = 1 To 풙풎풂풙 Step 2

For 푦 = 2 To 풚풎풂풙 Step 2 → case where 푥 is odd and 푦 even 푛 ← 3푥2 + 푦2

If 푛 < 푁푀푎푥 And (푛 mod 12 = 7) Do Sieve[푛] ← !Sieve[푛] End If If 푥 > 푦 Do 푛 ← 3푥2 − 푦2

If 푛 < 푁푀푎푥 And (푛 mod 12 = 11) Do Sieve[푛] ← !Sieve[푛] End If End If End For End For

For 푥 = 2 To 풙풎풂풙 Step 2

For y = 1 To 풚풎풂풙 Step 2 → case where 푥 is even and 푦 is odd 푛 ← 3푥2 + 푦2

If 푛 < 푁푀푎푥 And (푛 mod 12 = 7) Do Sieve[푛] ← !Sieve[푛] End If If 푥 > 푦 Do 푛 ← 3푥2 − 푦2

If 푛 < 푁푀푎푥 And (푛 mod 12 = 11) Do Sieve[푛] ← !Sieve[푛] End If End If End For End For

15

Fourth step : remove multiples of prime squares

For 푛 = 5 To 풚풎풂풙 Step 2 → multiples of 2 and 3 are ignored by the previous iterations If Sieve[푛] Do

2 2 For 푖 = 푛 To 푁푀푎푥 − 1 Step 2푛 Sieve[푖] ← False End For End If End For Last step : return list of primes from the sieve

For 푛 = 5 To 푁푀푎푥 − 1 Step 2 If Sieve[푛] Do

퐿푝(푖푙) ← 푛

푖푙 ← 푖푙 + 1 End If End For

Return (퐿푝, 푖푙)

3.2 Atkin algorithm with indices We can rewrite proposition 3-1 as: Corollary 3-2: 푘 is the index of a prime number if and only if 2푘 + 3 is square-free and one of the three following conditions is true:

푦2−3 a. 푘 ∈ (1 + 6ℕ) ∪ (5 + 6ℕ) and there is an odd number of solutions to 푘 = 2푥2 + , 2 3푥2+푦2−3 b. 푘 ∈ 2 + 6ℕ and there is an odd number of solutions to 푘 = , 2 3푥2−푦2−3 c. 푘 ∈ 4 + 6ℕ and there is an odd number of solutions to 푘 = with 푦 < 푥. 2

The relationships presented in the following remark are used in the next algorithm. Remark 3-2: For the fourth step (square multiples elimination), we note that if 푛 = 2푘 + 3, the index of 푛2 is 2푘2 + 6푘 + 3 and that the step of 2푛2 translates into a step of 푛2 = (2푘 + 3)2 for indices.

Algorithm 3-2 IndexSieveOfAtkin(푁푀푎푥): 푁푀푎푥 > 3 is an odd integer. This function returns the list of all prime numbers less than 푁푀푎푥.

First step : intialisation of variables

16

퐿푝 ← {2, 3} → Dynamic list of primes

푖푙 ← 2 → Number of primes in the list

푘푀푎푥 ← (푁푀푎푥 − 3)⁄2 → Index of 푁푀푎푥

Sieve[푘푀푎푥] ← {False, …,False} → Array of 푘푀푎푥 entries all initialized to False

풙풎풂풙 ← ⌈√푁푀푎푥/2⌉ − 1 → Bound for 푥

풚풎풂풙 ← ⌈√푁푀푎푥⌉ − 1 → Bound for 푦

Second step : iteration for first case

For 푥 = 1 To 풙풎풂풙

For y = 1 To 풚풎풂풙 Step 2 → 푦 must be odd

푦2−3 푘 ← 2푥2 + 2

If 푘 < 푘푀푎푥 And (푘 mod 6 = 1 Or 푘 mod 6 = 5) Do Sieve[푛] ← !Sieve[푛] → Switch the boolean value Sieve[푛] End If End For End For Third step : iteration for second and third cases

For 푥 = 1 To 풙풎풂풙 Step 2

For 푦 = 2 To 풚풎풂풙 Step 2 → case where 푥 is odd and 푦 even

3푥2+푦2−3 푘 ← 2

If 푘 < 푘푀푎푥 And (푘 mod 6 = 2) Do Sieve[푛] ← !Sieve[푛] End If If 푥 > 푦 Do

3푥2−푦2−3 푘 ← 2

If 푘 < 푁푀푎푥 And (푘 mod 6 = 4) Do Sieve[푛] ← !Sieve[푛] End If End If End For

17

End For

For 푥 = 2 To 풙풎풂풙 Step 2

For y = 1 To 풚풎풂풙 Step 2 → case where 푥 is even and 푦 is odd

3푥2+푦2−3 푘 ← 2

If 푘 < 푘푀푎푥 And (푘 mod 6 = 2) Do Sieve[푛] ← !Sieve[푛] End If If 푥 > 푦 Do

3푥2−푦2−3 푘 ← 2

If 푘 < 푘푀푎푥 And (푘 mod 6 = 4) Do Sieve[푛] ← !Sieve[푛] End If End If End For End For Fourth step : remove multiples of prime squares

풚 −ퟑ For 푘 = 1 To 풎풂풙 → multiples of 3 are ignored by the previous iterations ퟐ If Sieve[푘] Do

2 2 For 푖 = 2푘 + 6푘 + 3 To 푘푀푎푥 − 1 Step (2푘 + 3) Sieve[푖] ← False End For End If End For Last step : return list of primes from the sieve

For 푘 = 1 To 푘푀푎푥 − 1 If Sieve[푘] Do

퐿푝(푖푙) ← 2푘 + 3

푖푙 ← 푖푙 + 1 End If End For

Return (퐿푝, 푖푙)

18

3.3 Performance of algorithms

In this section, we discuss theoretical complexity and present our results with the two algorithms implementing the sieve of Atkin.

The reference algorithm SieveOfAtkin has less operations index-based IndexSieveOfAtkin, which juggles between numbers and indices. But on the other hand SieveOfAtkin performs Euclidian divisions by 12, whereas IndexSieveOfAtkin does divisions by 6. This is due to the conversion of number 푛 into its index 푘 = (푛 − 3)⁄2. Furthermore, the latter only performs the sieve on odd numbers, which means effectively the memory space for the sieve is twice smaller.

On the graph 3-3 below, we plot the computation time in seconds for both algorithms. The curve 푇3 corresponds to SieveOfAtkin and the curve 푇4 to IndexSieveOfAtkin. We observe empirically that computation time of both algorithms looks slightly higher than linear, even though theoretically the number of operations appears to be linear in 푁푀푎푥. Details of the Maple options used to get the regression are given in appendix 8.2.

Graph 3-3: computation time 푻 (푵푴풂풙) in seconds for both algorithms (Sieve of Atkin)

−19 2 −9 푇3 (푁푀푎푥) ≃ 4.90 × 10 × 푁푀푎푥 + 8.55 × 10 × 푁푀푎푥 R =0.9996 −19 2 −9 푇4 (푁푀푎푥) ≃ 3.79 × 10 × 푁푀푎푥 + 7.40 × 10 × 푁푀푎푥 R =0.9999

9 The second algorithm is faster for larger values of 푁푀푎푥, roughly for 푁푀푎푥 > 10 . For such values the cost of encoding numbers to indices is offset by the gain on modulo operations and halving the size of the sieve. We note also that memory size is halved for the second algorithm.

19

4 Wheel sieve with indices We first describe Pritchard’s wheel sieve. Then we adapt it to indices and discuss a way to generate the integers of the turning wheel.

4.1 Description of Pritchard’s wheel sieve This description is based on [7] and [4]. The wheel sieve operates by generating a set of numbers that are coprime with the first 푞 prime numbers. The second of these is the next prime, multiples of which are then eliminated (by turning the wheel).

More precisely, let 푝0 = 2, 푝1 = 3 … the sequence of prime numbers and let: 푞

Π푞 = ∏ 푝푘 푘=0 ℛ(푚) = {푥 ∈ ⟦1, 푚 − 1⟧| gcd(푥, 푚) = 1}

풲푞 = ℛ(Π푞)

The following proposition describes a “turn of the wheel”.

Proposition 4-1-1: We have the following inductive formula for 풲푞:

풲0 = {1}, 풲1 = {1,5}, 풲2 = {1,7,11,13,17,19,23,29}

푝푞+1−1

∀푞 ∈ ℕ, 풲푞+1 = ( ⋃ (풲푞 + 푥Π푞)) ∖ 푝푞+1⟦1, Π푞 − 1⟧ 푥=0

Proof: The Chinese theorem ensures that 푚 ∈ 풲푞+1 if and only if 푚 mod Π푞 ∈ 풲푞 and 푚 ∉ 푝푞+1ℕ. This gives the desired set equality.

Furthermore, induction formula for 풲푞 can also be used to recursively build the sequence of prime numbers:

Proposition 4-1-2: The second smallest element of 풲푞 (푞 ≥ 1) is the next prime 푝푞+1.

Proof: The first element is 1, which is obviously not prime. For 푞 ≥ 1, 푝푞 ≥ 3 and from proposition 4-

1-1 we can show (see corollary 4-2-2 later on) that 풲푞 has at least 2 elements. The second one must then be the smallest integer coprime with 푝0 … 푝푞, and thus must be 푝푞+1.

The elements of 풲푞 are called pseudo-primes (at order 푞). Some of them are primes and others are not. However, we have a boundary condition to identify some of the primes:

2 Proposition 4-1-3: All integers in 풲푞 and less than 푝푞 are sure to be primes.

2 Proof: Any integer less than 푝푞 is either prime or has a divisor among 푝0 … 푝푞. The latter is impossible by definition of 풲푞.

20

2 To enumerate primes up to 푁푀푎푥, we thus have to keep turning the wheel as long as 푝푞+1 < 푁푀푎푥.

As Π푞 grows exponentially (in particular it can be easily proven from Bertrand’s postulate that Π푞 > 2 푝푞 from 푞 = 2), while we are only interested in pseudo-primes up to 푁푀푎푥, we may replace in practice 푁푀푎푥 풲푞 by 풲푞 = 풲푞 ∩ ⟦1, 푁푀푎푥⟧.

Proposition 4-1-4: The following inductive formula (or wheel turn) is true for all 푁푀푎푥:

푁푀푎푥 max(푝푞+1−1,⌊ ⌋) 훱푞 푁 푁푀푎푥 푀푎푥 ∀푞 ∈ ℕ, 풲푞+1 = ⋃ (풲푞 + 푥Π푞) ∖ 푝푞+1 ⟦1, ⌊ ⌋⟧ ∩ ⟦1, 푁푀푎푥⟧. 푝푞+1 푥=0 [( ) ] 2 푁푀푎푥 { } Furthermore, if 푁푀푎푥 > 9, then as soon as 푝푞 ≥ 푁푀푎푥, 푃푁푀푎푥 = {푝0 … 푝푞} ∪ (푊푞 ∖ 1 ). Proof: By double inclusion (cf. proof of proposition 4-2-3). The second identity comes from the fact 2 that if 푁푀푎푥 > 9, 푝푞 ≥ 푁푀푎푥 implies 푞 ≥ 2.

Thus, when we turn the wheel, we remove integers that are, for a given 푚 ∈ 풲푞, and 푥, 푦 integers, of the form:

푚 + 푥Π푞 = 푦푝푞+1

One way to do that is to remove all multiples of 푝푞+1. We will show however in section 4.2 that there is a relationship between the value of 푥, the multiples of Π푞 which are added to 풲푞, and the composite numbers 푦푝푞+1 which must be removed of the wheel 풲푞+1, so that the index 푥 to remove can be predicted from 푚 or conversely.

4.2 Index wheel sieve ′ ′ Definition 4-2: We note Π푞 the product of all odd primes up to 푝푞, i.e. Π푞 = 2Π푞. We also note:

푁(푚, 푎, 푞) = 푚Π푞 + 푎 and, with 푎′ the index of 푎: 푁(푚, 2푎′ + 3, 푞) − 3 푘(푚, 푎′, 푞) = = 푚Π′ + 푎′ 2 푞 the index of 푁(푚, 푎, 푞).

′ ′ We let 풲푞 be the set of indices corresponding to 풲푞, with 1 replaced by Π푞 + 1 (which index is Π푞 − 1): 푛 − 3 풲′ = { , 푛 ∈ 풲 ∖ {1}} ∪ {Π′ − 1} 푞 2 푞 푞 In this section, we describe how we adapt the wheel sieve to work with indices of odd integers. The limit 푁푀푎푥 is supposed to be an odd integer of index 푘푀푎푥.

21

Recurrence relation verified by the index wheel sieve:

′ ′ ′ The initial index wheels are 풲0 = {0}, 풲1 = {1,2}, 풲2 = {2,4,5,7,8,10,13,14}. ′ ′ Remark 4-2-1: The first element of 풲푞 is the index of the prime number 푝푞+1. 풲푞 is included in 푝 −3 ⟦ 푞+1 , Π′ − 1⟧. 2 푞 ′ Proof: Since we remapped 1 to Π푞 + 1 in 풲푞 to define 풲푞, and because the indexing map is ′ increasing, the first element of 풲푞 is the index of prime 푝푞+1 from proposition 4-1-2 (we note that it ′ works even for 푞 = 0), and its last element is Π푞 − 1.

Proposition 4-2-1: The index wheel sieve is the only sequence of sets verifying:

′ 풲0 = {0}

푝푞+1−1 푝푞+1 − 3 ∀푞 ∈ ℕ, 풲′ = ( ⋃ (풲′ + 푚Π′ )) ∖ { + 푦′푝 , 푦′ ∈ ⟦0, Π′ − 1⟧} 푞+1 푞 푞 2 푞+1 푞 푚=0

′ Furthermore, indices in the wheel 풲푞 up to 푘푀푎푥 correspond to all remaining prime numbers up to

푁푀푎푥 (on top of 푝0 … 푝푞) as soon as:

2 푝푞 − 3 ≥ 푘 2 푀푎푥 Proof: This comes from the definition 4-2 of the index wheel sieve, the proposition 4-1-1 and from observing that the index of any odd multiple 푦푝푞 of 푝푞 is of the form:

푦푝푞 − 3 푝푞 − 3 푦 − 1 = + 푦′푝 , 푦′ = 2 2 푞 2 If we let 푝 = 2푖 + 3, this corresponds to the definition of 푘(푦′, 푖) in [8]: 푘(푦′, 푖) = 푖 + (2푖 + 3)푦′. Eliminating multiples of the next prime by solving a Diophantine equation:

′ Proposition 4-2-2: For a given 푐 ∈ ⟦0, Π푞 − 1⟧, there exists a unique (푚푐, 푦푐) ∈ ⟦0, 푝푞+1 − 1⟧ × 풲푞 ′ such that 푐 + 푚푐Π푞 = 푦푐푝푞+1. Furthermore, 푚푐 only depends of 푐 mod 푝푞+1, 푚0 = 0 and for 푐1 = ′ (−Π푞) mod 푝푞+1,

푚푐1 = 1.

For all 푐 ∈ 풲푞 one has 푐 mod 푝푞+1 = 푚푐푐1 mod 푝푞+1

′ ′ Remark 4-2-2: Using indices, we must solve (푚, 푦 ) in the following equations for 푎′ ∈ 풲푞: 푝푞+1 − 3 푎′ + 푚Π′ = + 푦′푝 푞 2 푞+1 푝 −3 so we will let 푐 = 푎′ − 푞+1 . 2

22

′ Proof: Because Π푞 and 푝푞+1 are coprime, existence and unicity of the solution are well-known. In [9] we introduced the concept of normalizer of such a Diophantine equation, and have shown its additive and multiplicative property.

′ ′ Clearly if 푐 ≡ 푑 [푝푞+1] then (푚푐 − 푚푑)Π푞 ≡ 0 [푝푞+1] and as Π푞 and 푝푞+1 are coprime, 푚푐 ≡

푚푑 [푝푞+1]. ′ Also, because 0 + 0. Π푞 = 0. 푝푞+1 we deduce that 푚0 = 0. ′ Then from the fact that 푐1 + Π푞 ∈ 푝푞+1ℤ we get that 푚푐1 = 1. Furthermore, for all 푐, by multiplicative property:

푚푚푐푐1 ≡ 푚푐. 푚푐1 ≡ 푚푐 [푝푞+1] ′ ′ Thus, 푐 ≡ −푚푐Π푞 ≡ −푚푚푐푐1Π푞 ≡ 푚푐푐1 [푝푞+1].

This proposition gives us an effective way of building all couples (푐, 푚푐) modulo 푝푞+1: start from

(푐1, 1) and add it to itself (modulo 푝푞+1) up to 푝푞+1 − 1 times (the last time we will get the couple

(0,0 = 푚0)).

′ 푞 Corollary 4-2-2: 풲푞 and 풲푞 have ∏푘=1(푝푘 − 1) elements. Proof: Let us proceed by induction on 푞. The property is true for 푞 = 0. Assume it is true for a given 푞 ∈ ℕ. From proposition 4-2-1,

푝푞+1−1 푝푞+1 − 3 풲′ = ( ⋃ (풲′ + 푚Π′ )) ∖ { + 푦′푝 , 푦′ ∈ ⟦0, Π′ − 1⟧}. 푞+1 푞 푞 2 푞+1 푞 푚=0

푝푞+1−1 ′ ′ ′ ′ 푞 Thus ⋃ (풲 + 푚Π ) = ⋃ ′ ′(푐 + Π ⟦0, 푝 − 1⟧) has exactly 푝 ∏ (푝 − 1) 푚=0 푞 푞 푐 ∈풲푞 푞 푞+1 푞+1 푘=1 푘 ′ ′ elements, from which we must remove the indices of multiples of 푝푞+1. For a given 푐 ∈ 풲푞, from proposition 4-2-2 there is exactly one couple (푚, 푦) such that:

푝푞+1 − 3 푐′ + 푚Π′ = + 푦′푝 푞 2 푞+1 푝 −3 i.e. there is only one element of 푐′ + Π′ ⟦0, 푝 − 1⟧ in { 푞+1 + 푦′푝 , 푦′ ∈ ⟦0, Π′ − 1⟧}. So in 푞 푞+1 2 푞+1 푞 푝 −1 푝 −3 total there are exactly ∏푞 (푝 − 1) elements in (⋃ 푞+1 (풲′ + 푚Π′ )) ∩ { 푞+1 + 푦′푝 , 푦′ ∈ 푘=1 푘 푚=0 푞 푞 2 푞+1 ′ 푞 푞+1 ′ ⟦0, Π푞 − 1⟧}, thus (푝푞+1 − 1) ∏푘=1(푝푘 − 1) = ∏푘=1(푝푘 − 1) elements in 풲푞+1.

′푘푀푎푥 ′ Proposition 4-2-3: 풲푞 = 풲푞 ∩ ⟦0, 푘푀푎푥⟧ verifies the following induction property.

′ 푘푀푎푥 For all 푞 ∈ ℕ, 풲푞+1 is equal to:

푘푀푎푥 min(푝푞+1−1,⌊ ′ ⌋) Π푞 푝푞+1 − 3 2푘 + 3 1 ′푘푀푎푥 ′ ′ ′ ′ 푀푎푥 ⋃ (풲푞 + 푚Π푞) ∖ { + 푦 푝푞+1, 푦 ∈ ⟦0, min (훱푞 − 1, ⌊ − ⌋)⟧} ∩ ⟦0, 푘푀푎푥⟧ 2 2푝푞+1 2 푚=0 (( ) )

23

′ 푘푀푎푥 ′ ′ Proof: Let 푥 ∈ 풲푞+1 . From proposition 4-2-1, there exists 푐 ∈ 풲푞, 푚 ∈ ⟦0, 푝푞+1 − 1⟧ such that 푝 −3 푥 = 푐′ + 푚Π′ . But 푥 ≤ 푘 so 푚 ≤ ⌊푘 ⁄Π′ ⌋. Furthermore, 푥 ∉ { 푞+1 + 푦′푝 , 푦′ ∈ ⟦0, Π′ − 푞 푀푎푥 푀푎푥 푞 2 푞+1 푞 1⟧} so a fortiori:

푝푞+1 − 3 ′ ′ ′ 2푘푀푎푥 + 3 1 푥 ∉ { + 푦 푝푞+1, 푦 ∈ ⟦0, min (훱푞 − 1, ⌊ − ⌋)⟧}. 2 2푝푞+1 2

′ min(푝푞+1−1,⌊푘푀푎푥⁄Π푞⌋) ′푘푀푎푥 ′ Conversely, let 푥 ∈ (⋃푚=0 (풲푞 + 푚Π푞)) ∩ ⟦0, 푘푀푎푥⟧ such that 푥 ∉

푝푞+1−3 ′ ′ ′ 2푘푀푎푥−3 1 ′ { + 푦 푝푞+1, 푦 ∈ ⟦0, min (훱푞 − 1, ⌊ − ⌋)⟧}. The first condition means that 푥 ∈ 풲푞+1 if 2 2푝푞+1 2 푝 −3 푥 ∉ { 푞+1 + 푦′푝 , 푦 ∈ ⟦0, Π′ − 1⟧}. But if that were the case, there would be 푦′ ∈ ⟦1, Π′ − 1⟧ 2 푞+1 푞 푞 푝푞+1−3 ′ 푘푀푎푥−(푝푞+1−3)⁄2 2푘푀푎푥+3 1 such that 푥 = + 푦 푝푞+1. Thus 푦 ≤ = − , which cannot happen 2 푝푞+1 2푝푞+1 2

푝푞+1−3 ′ ′ ′ 2푘푀푎푥+3 1 because 푥 ∉ { + 푦 푝푞+1, 푦 ∈ ⟦0, min (훱푞 − 1, ⌊ − ⌋)⟧}. 2 2푝푞+1 2

4.3 Wheel sieve algorithms As per sections 4.1 and 4.2, the wheel sieve algorithms will consist in two steps:

(A) A first step where the wheel will always grow, as long as Π푞 < 푁푀푎푥, or: ′ Π푞 − 1 < 푘푀푎푥, (B) A second step where we will no longer grow the wheel, but will have to keep eliminating 2 composite numbers, as long as 푝푞 < 푁푀푎푥, or: 2 푝푞 − 3 < 푘 2 푀푎푥. 푁푀푎푥 ′ ′ 푘푀푎푥 This is equivalent to saying that we replace 풲푞+1 by 풲푞+1 and similarly 풲푞+1 by 풲푞+1 . During step (B) we do not add new pseudo-primes, only remove those that we rule out as multiples of the next prime. Because Π푞 grows exponentially, there will generally be more iterations in step (B) than in step (A).

Quick description of the steps of the index wheel sieve algorithm (see appendix for full algorithm):

As for the previous algorithms, we note 퐿푝 the list of primes and 푖푙 its number of elements. 퐼퐿푝 represents the list of indices of odd primes, and 푆퐼퐿푝 the list of indices of squared odd primes. At step 2 ′ 푞, 퐿푝 will contain all primes up to 푝푞 , coming from the wheel 풲푞, 퐼퐿푝 and 푆퐼퐿푝 being filled with the corresponding indices.

1- Intialisation of the sieve for 푞 = 1: 퐿푝 = {2,3,5,7}, 푖푙 = 4 퐼퐿푝 = {0,1,2}, 푆퐼퐿푝 = {3,11,23} ′ ′ and 풲1 = {1, 2} with Π1 = 3. ′ 2- While Π푞 < 푘푚푎푥 (step A): a. We take 푝푞+1 from 퐿푝 (or equivalently the first element of 풲푞). The list of pairs ′ (푐, 푚푐) such that 푐 + 푚푐Π푞 has to be eliminated is then computed, according to ′ proposition 4-2-2. Then we build the wheel 풲푞+1. 2 b. Once this is done primes in the interval ⟦푝푖푙−1 + 2, 푝푞+1 − 2⟧ are added to 퐿푝 and 푖푙, 퐼퐿푝 and 푆퐼퐿푝 are updated accordingly. Indices of the primes to add are those in

24

′ 풲푞+1 ∩ ⟦퐼퐿푝(푖푙 − 2) + 1, 푆퐼퐿푝(푞) − 1⟧. 3- While 푆퐼퐿푝(푞) < 푘푚푎푥 (step B): ′푘푀푎푥 ′ 푘푀푎푥 a. Remove indices of multiples of 푝푞+1 from 풲푞 to get 풲푞+1 . 2 b. Once this is done primes in the interval ⟦푝푖푙−1 + 2, 푝푞+1 − 2⟧ are added to 퐿푝 and 푖푙, 퐼퐿푝 and 푆퐼퐿푝 are updated accordingly. Indices of the primes to add are those in ′ 풲푞+1 ∩ ⟦퐼퐿푝(푖푙 − 2) + 1, 푆퐼퐿푝(푞) − 1⟧.

Remark 4-3-1: Let 푘1 and 푘2 be the indices of two odd numbers, respectively 푛1 and 푛2, such as 푛2 − 2 2 푛1 > 0. Let 훼 = 푘2 − 푘1. The difference between the indices 푛1 and 푛2 is: 2 훽 = 2훼 + 2훼푛1.

Furthermore, if 푚 is another integer, the difference between the indices of 푛1푚 and 푛2푚 is: 훾 = 훼푚.

Proof: Note that 푛2 − 푛1 = 2훼 and thus: 푛2 − 3 푛2 − 3 1 2 − 1 = (푛 − 푛 )(푛 + 푛 ) = 훼(푛 + 푛 ) = 훼(2푛 + 2훼) = 훽. 2 2 2 2 1 2 1 2 1 1 Similarly:

푛2푚 − 3 푛1푚 − 3 − = 훼푚 = 훾. 2 2

This last remark is used in steps 2-b. and 3-b. to fill 푆퐼퐿푝 and to perform step 3-a. Remark 4-3-2: The index wheel sieve involves operations with reduced input size compared with the 2 2 number version. This is clear from remark 4-3-1 where 훽 is exactly half of 푛2 − 푛1, for instance. ′ Similarly Π푞 is half of Π푞 so input is also reduced.

4.4 Performance of algorithms In this section, we present results from the previous algorithm of index wheel sieve, which we compare with a similar one on numbers (unspecified for to avoid a lengthy duplication). These results are similar to those obtained in the previous sections. As for the sieve of Atkin, we did not go for refinements that give a better time complexity, so theoretical complexity in terms of number of operations is 푂(푁) for both algorithms.

On the graph 4-4 below, we plot the computation time in seconds for both algorithms, for 푁푀푎푥 up to 9 6.10 . The curve 푇5 corresponds to the the algorithm WheelSieveReference and the curve 푇6 corresponds to the the algorithm IndexWheelSieve. The correlation coefficient 푅 of each regression is given on the graph. Details of the Maple options used to get the regression are given in appendix 8.3. We notice that complexity of both algorithms again seems empirically slightly higher than linear.

25

Graph 4-4: computation time 푻 (푵푴풂풙) in seconds for both algorithms (Wheel sieve)

푇 (푁 ) ≃ 5.25 × 10−10 × 푁 1.11 5 푀푎푥 푀푎푥 푅 = 0.9998

−9 1.06 푇6 (푁푀푎푥) ≃ 1.33 × 10 × 푁푀푎푥 푅 = 0.9999

Complexity is reduced by using indices, due to reduction of input size in the modulo and the multiplication operations (see Remark 4-3-2) and despite a higher number of operations with the algorithm IndexWheelSieve. Moreover, the amount of memory space used with indices is halved, due to the fact that we avoid even numbers completely.

5 Conclusion In theory, indices are a way to work with odd numbers only by not representing even numbers. Most mathematical relations must be reformulated for indices, which lead to a higher number of (conversion) operations, but in return the input size of other operations is reduced. In this article, we have shown how this indexing translates into optimized algorithms in applied mathematics. From a basic primality test implementation, to the sieve of Atkin and Pritchard’s wheel sieve, indices speeded up these algorithms, not by changing their complexity but by reducing the time cost by a constant factor, and generally also made them more efficient from a memory point of view.

Acknowledgments: We would like to thank François-Xavier VILLEMIN for his attentive comments and suggestions.

6 REFERENCES

[1]. René SCHOOF (2008), Four primality testing algorithms. Algorithmic , MSRI Publications, Volume 44. http://www.math.leidenuniv.nl/~psh/ANTproc/05rene.pdf.

[2]. Manindra AGRAWAL, Neeraj KAYAL, Nitin SAXENA (2004), PRIMES is in P. Ann. of Math. (2) 160, No. 2, pp. 781-793. MR2123939 (2006a:11170). http://annals.math.princeton.edu/wp-content/uploads/annals-v160- n2-p12.pdf.

26

[3]. Paul PRITCHARD (1981), A sublinear additive sieve for finding prime numbers. Communications of the ACM 24(1), pp. 18-23. https://dl.acm.org/doi/pdf/10.1145/358527.358540?download=true.

[4]. Paul PRITCHARD (1982), Explaining the Wheel Sieve. Acta Informatica 17, pp. 477-485. http://fuuu.be/polytech/INFOF404/Doc/Explaining%20the%20wheel%20sieve.pdf.

[5]. Paul PRITCHARD (1994), Improved Incremental Prime Number Sieves. Algorithmic Number Theory Symposium. pp. 280–288. CiteSeerX 10.1.1.52.835. http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.52.835&rep=rep1&type=pdf.

[6]. Arthur ATKIN AND Daniel BERNSTEIN (2003), Prime sieves using binary quadratic forms. Mathematics of Computation Volume 73, Number 246, pp. 1023-1030. https://www.ams.org/journals/mcom/2004-73- 246/S0025-5718-03-01501-1/S0025-5718-03-01501-1.pdf.

[7]. Gabriel PAILLARD, Felipe FRANCA, Christian LAVAULT (2013), A distributed wheel sieve algorithm using Scheduling by Multiple Edge Reversal. HAL-00794389. https://hal.archives-ouvertes.fr/hal-00794389.

[8]. Marc WOLF, François WOLF (2018), Representation theorem of composite odd numbers indices. SCIREA Journal of Mathematics, Vol. 3, pp. 106-117. http://article.scirea.org/pdf/11066.pdf.

[9]. Marc WOLF, François WOLF, Corentin LE COZ (2018), Calculation of extended gcd by normalization. SCIREA Journal of Mathematics. Vol. 3, pp. 118-131. http://article.scirea.org/pdf/11067.pdf.

7 APPENDIX: ALGORITHM OF THE INDEX WHEEL SIEVE

This algorithm enumerates odd primes up to the limit 푁푀푎푥. It is composed of a main function that is called IndexWheelSieve and the following auxilliary other functions: ′ 7-2- DiophantineSolutions(푃푟푖푚푒,Π푞) ′ ′ 7-3- WheelTurn(풲푞, 푞, 푃푟푖푚푒, 푃푟푖푚푒퐼푛푑푒푥, Π푞, 푘푀푎푥) ′ 7-4- RemoveMultiples(푆푞푢푎푟푒푃푟푖푚푒퐼푛푑푒푥, 푃푟푖푚푒, 풲푞) ′ 7-5- GetNewPrimes(풲푞, 푞, 퐿푝, 푖푙, 퐼퐿푝, 푆퐼퐿푝) Some marginal optimizations can still be performed, for instance modulo operations inside a loop can be replaced by substractions, and memory can be managed better. For the sake of readability we leave these optimizations out of scope.

Algorithm 7-1 IndexWheelSieve(푁푀푎푥): 푁푀푎푥 > 9 is an odd integer.

This function returns the list of all prime numbers up to 푁푀푎푥.

First step : intialisation of variables

퐿푝 ← {2, 3,5,7} → Dynamic list of primes

푖푙 ← 4 → Number of primes in the list

푘푀푎푥 ← (푁푀푎푥 − 3)⁄2 → Index of 푁푀푎푥

퐼퐿푝 ← {0,1,2}

27

푆퐼퐿푝 ← {3,11,23} ′ 풲푞 ← {1, 2} ′ Π푞 ← 3 푞 ← 1

Second step : Wheel inflation. Do

푃푟푖푚푒 ← 퐿푝(푞 + 1)

푃푟푖푚푒퐼푛푑푒푥 ← 퐼퐿푝(푞) ′ ′ Π푞+1 ← Π푞 × 푃푟푖푚푒 → Compute values of the new wheel from the previous one

′ ′ ′ 풲푞 ←WheelTurn(풲푞, 푞, 푃푟푖푚푒, 푃푟푖푚푒퐼푛푑푒푥, Π푞, 푘푀푎푥) ′ GetNewPrimes(풲푞, 푞, 퐿푝, 푖푙, 퐼퐿푝, 푆퐼퐿푝) ′ ′ Π푞 ← Π푞+1 푞 ← 푞 + 1 ′ While 푘푀푎푥 > Π푞

Third step : Wheel deflation.

While 푆퐼퐿푝(푞 − 1) < 푘푀푎푥

푃푟푖푚푒 ← 퐿푝(푞 + 1)

푆푞푢푎푟푒푃푟푖푚푒퐼푛푑푒푥 ← 푆퐼퐿푝(푞) ′ ′ 풲푞 ←RemoveMultiples(푆푞푢푎푟푒푃푟푖푚푒퐼푛푑푒푥, 푃푟푖푚푒, 풲푞) ′ GetNewPrimes (풲푞, 푞, 퐿푝, 푖푙, 퐼퐿푝, 푆퐼퐿푝) 푞 ← 푞 + 1 End While

Return (퐿푝, 푖푙)

′ Algorithm 7-2 DiophantineSolutions(푃푟푖푚푒,Π푞)

′ 푐1 ← 푃푟푖푚푒 − (Π푞 mod 푃푟푖푚푒) → Solution such that 푚 = 1

28

푐 ← 0 푆표푙푢푡푖표푛푠 ← {0 … 0} → Array of size 푃푟푖푚푒

For 푚 = 1 To 푃푟푖푚푒 − 1 Do

푐 ← (푐 + 푐1) mod 푃푟푖푚푒 푆표푙푢푡푖표푛푠(푐) ← 푚 End For Return 푆표푙푢푡푖표푛푠

′ ′ Algorithm 7-3 WheelTurn(풲푞, 푞, 푃푟푖푚푒, 푃푟푖푚푒퐼푛푑푒푥, Π푞, 푘푀푎푥) ′ ′ This function computes 풲푞+1 by duplicating the wheel 풲푞 and removing indices of multiples of

푃푟푖푚푒 = 푝푞+1.

First step : Compute all the pairs (푐, 푚푐) in the function DiophantineSolutions ′ 푆표푙푢푡푖표푛푠 ← DiophantineSolutions(푃푟푖푚푒,Π푞)

Second step : Iteration

′ 푊ℎ푒푒푙푆푖푧푒 ← Size(풲푞) 푇푎푏푙푒 ← Range({}, 푃푟푖푚푒) For 푗 = 0 To 푊ℎ푒푒푙푆푖푧푒 − 1 Do

′ 푎′ ← 풲푞(푗) 푐 ← (푎′ − 푃푟푖푚푒퐼푛푑푒푥) mod 푃푟푖푚푒 푚 ← 푆표푙푢푡푖표푛푠(푐) For 푦 = 0 To 푃푟푖푚푒푁푢푚푏푒푟 − 1 Do

′ 푛 ← 푎′ + 푦Π푞

If 푛 > 푘푚푎푥 Do Break End If If 푦 ≠ 푚 Do Append(푇푎푏푙푒(푦),푛) End If End For

29

End For

′ Third step : Build 풲푞+1 by concatenation ′ 풲푞+1 ← {} For 푦 = 0 To 푃푟푖푚푒푁푢푚푏푒푟 − 1 Do

′ Concatenate(풲푞+1,푇푎푏푙푒(푦)) End For

′ Return 풲푞+1

′ Algorithm 7-4 RemoveMultiples(푆푞푢푎푟푒푃푟푖푚푒퐼푛푑푒푥, 푃푟푖푚푒, 풲푞)

′ 풲푞+1 ← {} 푁푒푥푡푀푢푙푡푖푝푙푒 ← 푆푞푢푎푟푒푃푟푖푚푒퐼푛푑푒푥 ′ For 푗 = 1 To Size(풲푞)−1 Do ′ If 퓦푞(푗) > 푁푒푥푡푀푢푙푡푖푝푙푒 Do 푁푒푥푡푀푢푙푡푖푝푙푒 ← 푁푒푥푡푀푢푙푡푖푝푙푒 + 푃푟푖푚푒 푗 ← 푗 − 1 ′ Else If 퓦푞(푗) = 푁푒푥푡푀푢푙푡푖푝푙푒 Do 푁푒푥푡푀푢푙푡푖푝푙푒 ← 푁푒푥푡푀푢푙푡푖푝푙푒 + 푃푟푖푚푒 Else

′ ′ Append(풲푞+1,퓦푞(푗)) End If End For

′ Return 풲푞+1

′ Algorithm 7-5 GetNewPrimes(풲푞, 푞, 퐿푝, 푖푙, 퐼퐿푝, 푆퐼퐿푝)

This function adds new primes to the list 퐿푝 and updates 푖푙 and the other lists 퐼퐿푝 and 푆퐼퐿푝 (all passed by reference).

푆푞푢푎푟푒퐼푛푑푒푥 ← 푆퐼퐿푝(푞 + 1)

30

푗 ← 푖푙 − 푞 − 2 → Offset to take into account already known primes ′ 푁푒푤푃푟푖푚푒퐼푛푑푒푥 ← 풲푞(푗) While 푁푒푤푃푟푖푚푒퐼푛푑푒푥 < 푆푞푢푎푟푒퐼푛푑푒푥 Do

퐼퐿푝(푖푙 − 1) ← 푁푒푤푃푟푖푚푒퐼푛푑푒푥

훼 ← 퐼퐿푝(푖푙 − 1) − 퐼퐿푝(푖푙 − 2)

2 푆퐼퐿푝(푖푙 − 1) ← 푆퐼퐿푝(푖푙 − 2) + 2훼 + 2훼퐿푝(푖푙 − 1)

퐿푝(푖푙) ← 퐿푝(푖푙 − 1) + 2훼

푖푙 ← 푖푙 + 1 푗 ← 푗 + 1 ′ 푁푒푤푃푟푖푚푒퐼푛푑푒푥 ← 풲푞(푗) End While

8 APPENDIXES: MAPLE REGRESSIONS

Here are numeric values obtained from our implementation (Visual Studio C++ 2012) of the algorithms presented in this article.

8.1 BASIC PRIMALITY TEST AND PRIMES ENUMERATION

In table 8.1, numeric values of 푇1(푁푀푎푥) and 푇2(푁푀푎푥) are obtained respectively from the PrimeEnumeration and IndexPrimeEnumeration algorithms.

Table 8.1: numeric values of 푻ퟏ(푵푴풂풙) and 푻ퟐ(푵푴풂풙) in seconds. 7 8 8 9 9 9 9 푁푀푎푥 10 10 5 × 10 10 2 × 10 3 × 10 4 × 10

푇1(푁푀푎푥) 2.403 56.031 493.163 1306.884 3414.713 6271.249 8908.814

푇2(푁푀푎푥) 2.375 54.725 487.568 1275.921 3329.573 6105.386 8664.438

To fit these observations, Maple’s NonlinearFit function is used with the parameters below. Initial values for 푎 and 푏 were determined empirically. NonlinearFit(푎 × 푛푏/ ln(푛), X, Y, n, initialvalues = [푎 = 5.9 × 10−9, 푏 = 1.41], output = [leastsquaresfunction, residuals]) We get the following mathematical relationships:

푛1.40966993452829 푇 (푁 ) ≃ 5.79409775129480 × 10−9 × , 푅 = .99962000 1 푀푎푥 ln(푛)

푛1.406040046365699 푇 (푁 ) ≃ 6.10602965467609 × 10−9 × , 푅 = .99962009 2 푀푎푥 푙푛(푛)

31

8.2 THE SIEVE OF ATKIN

In table 8.2, numeric values of 푇3(푁푀푎푥) and 푇4(푁푀푎푥) are obtained respectively from the SieveOfAtkin and IndexSieveOfAtkin algorithms.

Table 8.2: numeric values of 푻ퟑ(푵푴풂풙) and 푻ퟒ(푵푴풂풙) in seconds. 8 8 9 9 9 9 9 푁푀푎푥 10 5 × 10 10 1.5 × 10 1.6 × 10 2 × 10 3 × 10

푇3(푁푀푎푥) 0.719 3.797 8.033 12.48 13.967 18.843 28.217

푇4(푁푀푎푥) 0.727 3.921 8.225 12.152 12.953 16.507 25.342

9 9 9 9 9 9 10 푁푀푎푥 4 × 10 5 × 10 6 × 10 7 × 10 8 × 10 9 × 10 10

푇3(푁푀푎푥) 41.534 54.871 72.044 84.511 100.727 116.093 133.184

푇4(푁푀푎푥) 35.27 46.261 57.418 70.311 84.291 98.047 110.96

This time we used Maple’s function Fit as below: Fit(푎 × 푛2 + 푏 × 푛, X, Y, 푛, summarize = embed) We get the following mathematical relationships:

−19 2 −9 푇3(푁푀푎푥) ≃ 4.90268369826396 × 10 × 푁푀푎푥 + 8.54576412559177 × 10 × 푁푀푎푥, 푅 = .999647

−19 2 −9 푇4(푁푀푎푥) ≃ 3.78795281632082 × 10 × 푁푀푎푥 + 7.39595089422000 × 10 × 푁푀푎푥, 푅 = .999926

8.3 WHEEL SIEVE WITH INDICES

In table 8.3, numeric values of 푇5(푁푀푎푥) and 푇6(푁푀푎푥) are obtained respectively from the WheelSieveReference and IndexWheelSieve algorithms.

Table 8.3: numeric values of 푻ퟓ(푵푴풂풙) and 푻ퟔ(푵푴풂풙) in seconds. 7 8 8 9 9 9 9 9 9 푁푀푎푥 10 10 5 × 10 10 2 × 10 3 × 10 4 × 10 5 × 10 6 × 10

푇5(푁푀푎푥) 0.071 0.496 2.783 5.407 10.931 17.070 23.944 31.150 37.501

푇6(푁푀푎푥) 0.064 0.457 2.657 4.936 9.995 15.121 20.995 26.260 32.351

We used again NonlinearFit with empirically determined initial values 푎 and 푏: NonlinearFit(푎 × 푛푏, X, Y, n, initialvalues = [푎 = 1.97461115539853 × 10−6, 푏 = 1.1], output = [leastsquaresfunction, residuals]). We get the following mathematical relationships: −10 1.11016647384427 푇5(푁푀푎푥) ≃ 5.25118782575365 × 10 × 푛 , 푅 = .99982444 −9 1.06187203820827 푇6(푁푀푎푥) ≃ 1.33020583039257 × 10 × 푛 , 푅 = .99986693

32