Whereas the sieve of Eratosthenes marks off each non-prime for each of its prime factors, the sieve of Pritchard avoids considering almost all non-prime numbers by building progressively larger wheels, which represent the pattern of numbers not divisible by any of the primes processed thus far.
It thereby achieves a better asymptotic complexity, and was the first sieve with a running time sublinear in the specified bound.
Its asymptotic running-time has not been improved on, and it deletes fewer composites than any other known sieve.
It was created in 1979 by Paul Pritchard.[2]
Since Pritchard has created a number of other sieve algorithms for finding prime numbers,[3][4][5] the sieve of Pritchard is sometimes singled out by being called the wheel sieve (by Pritchard himself[1]) or the dynamic wheel sieve.[6]
To find all the prime numbers less than or equal to a given integer , a sieve algorithm examines a set of candidates in the range ,
and eliminates those that are not prime, leaving the primes at the end.
The sieve of Eratosthenes examines all of the range, first removing all multiples of the first prime , then of the next prime , and so on.
The sieve of Pritchard instead examines a subset of the range consisting of numbers that occur on successive wheels,
which represent the pattern of numbers left after each successive prime is processed by the sieve of Eratosthenes.
For the 'th wheel represents this pattern.
It is the set of numbers between and the product of the first prime numbers that are not divisible by any of these prime numbers (and is said to have an associated length).
This is because adding to a number doesn't change whether or not it is divisible by one of the first prime numbers,
since the remainder on division by any one of these primes is unchanged.
So with length represents the pattern of odd numbers;
with length represents the pattern of numbers not divisible by or ; etc.
Wheels are so-called because can be usefully visualized as a circle of circumference with its members marked at their corresponding distances from an origin.
Then rolling the wheel along the number line marks points corresponding to successive numbers not divisible by one of the first prime numbers.
The animation shows being rolled up to 30.
It's useful to define for to be the result of rolling up to .
Then the animation generates .
Note that up to , this consists only of and the primes between and .
The sieve of Pritchard is derived from the observation[1] that this holds generally:
for all , the values in are and the primes between and .
It even holds for , where the wheel has length and contains just (representing all the natural numbers).
So the sieve of Pritchard starts with the trivial wheel and builds successive wheels until the square of the wheel's first member after is at least .
Wheels grow very quickly, but only their values up to are needed and generated.
It remains to find a method for generating the next wheel.
Note in the animation that can be obtained by rolling up to and then removing times each member of .
This also holds generally: for all , .[1]
Rolling past just adds values to , so the current wheel is first extended by getting each successive member starting with , adding to it, and inserting the result in the set.
Then the multiples of are deleted.
Care must be taken to avoid a number being deleted that itself needs to be multiplied by .
The sieve of Pritchard as originally presented[2] does so by first skipping past successive members until finding the maximum one needed, and then doing the deletions in reverse order by working back through the set.
This is the method used in the first animation above.
A simpler approach is just to gather the multiples of in a list, and then delete them.[7]
Another approach is given by Gries and Misra.[8]
If the main loop terminates with a wheel whose length is less than , it is extended up to to generate the remaining primes.
The algorithm, for finding all primes up to N, is therefore as follows:
Start with a set W={1} and length=1 representing wheel 0, and prime p=2.
As long as p2 <= N, do the following
if length < N then
extend W by repeatedly getting successive members w of W starting with 1 and inserting length+w into W as long as it doesn't exceed p*length or N;
increase length to the minimum of p*length and N.
repeatedly delete p times each member of W by first finding the largest <= length and then working backwards.
note the prime p, then set p to the next member of W after 1 (or 3 if p was 2).
if length < N then extend W to N by repeatedly getting successive members w of W starting with 1 and inserting length+w into W as long as it doesn't exceed N;
On termination, the rest of the primes up to N are the members of W after 1.
Example
To find all the prime numbers less than or equal to 150, proceed as follows.
Start with wheel 0 with length 1, representing all natural numbers 1, 2, 3...:
1
The first number after 1 for wheel 0 (when rolled) is 2; note it as a prime.
Now form wheel 1 with length 2x1=2 by first extending wheel 0 up to 2 and then deleting 2 times each number in wheel 0, to get:
1 2
The first number after 1 for wheel 1 (when rolled) is 3; note it as a prime.
Now form wheel 2 with length 3x2=6 by first extending wheel 1 up to 6 and then deleting 3 times each number in wheel 1, to get
1 23 5
The first number after 1 for wheel 2 is 5; note it as a prime.
Now form wheel 3 with length 5x6=30 by first extending wheel 2 up to 30 and then deleting 5 times each number in wheel 2 (in reverse order!), to get
1 235 7 11 13 17 19 23 25 29
The first number after 1 for wheel 3 is 7; note it as a prime.
Now wheel 4 has length 7x30=210, so we only extend wheel 3 up to our limit 150.
(No further extending will be done now that the limit has been reached.)
We then delete 7 times each number in wheel 3 until we exceed our limit 150, to get the elements in wheel 4 up to 150:
The first number after 1 for this partial wheel 4 is 11; note it as a prime.
Since we've finished with rolling, we delete 11 times each number in the partial wheel 4 until we exceed our limit 150, to get the elements in wheel 5 up to 150:
The first number after 1 for this partial wheel 5 is 13.
Since 13 squared is at least our limit 150, we stop.
The remaining numbers (other than 1) are the rest of the primes up to our limit 150.
Just 8 composite numbers are removed, once each.
The rest of the numbers considered (other than 1) are prime.
In comparison, the natural version of Eratosthenes sieve (stopping at the same point) removes composite numbers 184 times.
Pseudocode
The sieve of Pritchard can be expressed in pseudocode, as follows:[1]
algorithm Sieve of Pritchard isinput: an integer N >= 2.
output: the set of prime numbers in {1,2,...,N}.
letW and Pr be sets of integer values, and all other variables integer values.
k, W, length, p, Pr := 1, {1}, 2, 3, {2};
{invariant: p = pk+1 and W = Wk {1,2,...,N} and length = minimum of Pk,N and Pr = the primes up to pk}
whilep2 <= Ndoif (length < N) then
Extend W,length to minimum of p*length,N;
Delete multiples of p from W;
Insert p into Pr;
k, p := k+1, next(W, 1)
if (length < N) then
Extend W,length to N;
returnPrW - {1};
where next(W, w) is the next value in the ordered set W after w.
procedure Extend W,length to nis
{in:W = Wk and length = Pk and n > length}
{out:W = Wkn and length = n}
integer w, x;
w, x := 1, length+1;
whilex <= ndo
Insert x into W;
w := next(W,w);
x := length + w;
length := n;
procedure Delete multiples of p from W,lengthisinteger w;
w := p;
whilep*w <= lengthdow := next(W,w);
whilew > 1 dow := prev(W,w);
Remove p*w from W;
where prev(W, w) is the previous value in the ordered set W before w. The algorithm can be initialized with instead of at the minor complicaion of making next(W,1) a special case
when k = 0.
This abstract algorithm uses ordered sets supporting the operations of insertion of a value greater than the maximum, deletion of a member, getting the next value after a member, and getting the previous value before a member.
Using one of Mertens' theorems (the third) it can be shown to use of these operations and additions and multiplications.[2]
Implementation
An array-based doubly-linked list s can be used to implement the ordered set W, with s[w] storing next(W,w) and s[w-1] storing prev(W,w).
This permits each abstract operation to be implemented in a small number of operations.
(The array can also be used to store the set Pr "for free".)
Therefore the time complexity of the sieve of Pritchard to calculate the primes up to in the random access machine model is operations on words of size .
Pritchard also shows how multiplications can be eliminated by using very small multiplication tables,[2] so the bit complexity is bit operations.
In the same model, the space complexity is words, i.e., bits.
The sieve of Eratosthenes requires only 1 bit for each candidate in the range 2 through , so its space complexity is lower at bits.
Note that space needed for the primes is not counted, since they can printed or written to external storage as they are found.
Pritchard[2] presented a variant of his sieve that requires only bits without compromising the sublinear time complexity,
making it asymptotically superior to the natural version of the sieve of Eratostheses in both time and space.
However, the sieve of Eratostheses can be optimized to require much less memory by operating on successive segments of the natural numbers.[9] Its space complexity can be reduced to bits without increasing its time complexity[3]
This means that in practice it can be used for much larger limits than would otherwise fit in memory, and also take advantage of fast cache memory.
For maximum speed it is also optimized using a small wheel to avoid sieving with the first few primes (although this does not change its asymptotic time complexity).
Therefore the sieve of Pritchard is not competitive as a practical sieve over sufficiently large ranges.
Geometric model
At the heart of the sieve of Pritchard is an algorithm for building successive wheels.
It has a simple geometric model as follows:
Start with a circle of circumference 1 with a mark at 1
To generate the next wheel:
Go around the wheel and find (the distance to) the first mark after 1; call it p
Create a new circle with p times the circumference of the current wheel
Roll the current wheel around the new circle, marking it where a mark touches it
Magnify the current wheel by p and remove the marks that coincide
Note that for the first 2 iterations it is necessary to continue round the circle until 1 is reached again.
The first circle represents , and successive circles represent wheels .
The animation on the right shows this model in action up to .
It is apparent from the model that wheels are symmetric.
This is because is not divisible by one of the first primes if and only if is not so divisible.
It is possible to exploit this to avoid processing some composites, but at the cost of a more complex algorithm.
Related sieves
Once the wheel in the sieve of Pritchard reaches its maximum size, the remaining operations are equivalent to those performed by Euler's sieve.
The sieve of Pritchard is unique in conflating the set of prime candidates with a dynamic wheel used to speed up the sifting process.
But a separate static wheel (as frequently used to speed up the sieve of Eratosthenes) can give an speedup to the latter, or to linear sieves, provided it is large enough (as a function of ).
Examples are the use of the largest wheel of length not exceeding to get a version of the sieve of Eratosthenes that takes additions and requires only bits,[3] and the speedup of the naturally linear sieve of Atkin to get a sublinear optimized version.
Bengalloun found a linear smoothly incremental sieve,[10] i.e., one that (in theory) can run indefinitely and takes a bounded number of operations to increment the current bound .
He also showed how to make it sublinear by adapting the sieve of Pritchard to incrementally build the next dynamic wheel while the current one is being used.
Pritchard[5] showed how to avoid multiplications, thereby obtaining the same asymptotic bit-complexity as the sieve of Pritchard.
Runciman provides a functional algorithm[11] inspired by the sieve of Pritchard.
^Bays, Carter; Hudson, Richard H. (1977). "The segmented sieve of Eratosthenes and primes in arithmetic progressions to 1012". BIT. 17 (2): 121–127. doi:10.1007/BF01932283. S2CID122592488.
Halaman ini berisi artikel tentang kebangkitan terakhir pada akhir zaman. Untuk kegunaan lain, lihat Kebangkitan (disambiguasi). Bagian dari seriEskatologi AntaragamaAkhir zaman Apokaliptisisme Fenomena 2012MilenarianismeArmageddonPengadilan TerakhirKebangkitan orang matiYa'juj dan Ma'jujEskatologi Lia Eden Eskatologi HinduEskatologi Hindu Eskatologi IslamTempat 'Arasy Âkhirah Barzakh Firdaws `Adn Jannah Jahannam Jahim Kaʿbah Mahsyar Shirāth Pohon Neraka Tokoh Utama Dābbat al-Ard Dajjāl ...
Anime series discography Neon Genesis Evangelion discographyStudio albums5Live albums2Compilation albums4Singles15Soundtrack albums12 King Records logo The soundtracks of Neon Genesis Evangelion were produced for the 1995 anime series of the same name and its sequels, remakes and spinoffs. Shiro Sagisu composed the tracks under the direction of Hideaki Anno, director of the series. In addition to Sagisu's compositions, the soundtracks include pieces by Masami Okui, Kotono Mitsuishi and a wide...
Pour les articles homonymes, voir Route 265. Interstate 265 Gene Snyder Freeway (Kentucky)Lee H. Hamilton Highway (Indiana) Informations Longueur 67,3 km (41.8 mi) En service 1977 [réf. nécessaire] - Localisation États Kentucky Indiana Comtés KY: JeffersonIN: Clark, Floyd Intersections Extrémité anti-horaire I-64 / US 150 / SR 62 près de New Albany Intersections I-65 près de Jeffersonville I-71 à Louisville I-64 à Louisville Extrémité horaire I-65 in Louisville Résea...
هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (أبريل 2020) جزء من سلسلة مقالات حولالتسويق أسس التسويق المنتج السعر الترويج التوزيع مفاهيم رئيسة بحث السوق خطة التسويق إدارة التسويق إنفاق تسويقي بنية تسويقية نظام المع
The China SyndromePoster promosional The China SyndromeSutradara James Bridges Produser Michael Douglas Ditulis oleh Mike Gray T. S. Cook James Bridges PemeranJane FondaJack LemmonMichael DouglasSinematograferJames CrabeDistributorColumbia PicturesTanggal rilis 16 Maret 1979 (1979-03-16) Durasi122 menitNegara Amerika Serikat Bahasa Inggris Anggaran$5.9 juta[1]Pendapatankotor$51,718,367[2] The China Syndrome adalah sebuah film cerita seru Amerika 1979 yang mengisahkan tent...
У Вікіпедії є статті про інші значення цього терміна: Фудзімі. Координати: 35°54′53″ пн. ш. 138°14′27″ сх. д. / 35.91472° пн. ш. 138.24083° сх. д. / 35.91472; 138.24083 Фудзімі Країна Японія Острів Хонсю Регіон Тюбу Префектура Наґано ISO 3166-2 20362-9 Площа 144,66 км² (1 кв�...
One of a KindAlbum mini karya Monsta XDirilis01 Juni 2021 (2021-06-01)Genre K-pop hip hop EDM[1] R&B[2] Durasi23:55Label Starship Entertainment Kakao Entertainment Kronologi Monsta X Flavors of Love(2021) One of a Kind(2021) No Limit(2021) Singel dalam album One of a Kind GamblerDirilis: 1 Juni 2021 Penilaian profesional Skor ulasan Sumber Nilai NME [3] The Kraze 9/10[4] One of a Kind adalah album mini kesembilan dari grup vokal pria asal Korea Sel...
هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (مارس 2019) تشارلز ر. فلويد (بالإنجليزية: Charles R. Floyd) معلومات شخصية تاريخ الميلاد سنة 1881 تاريخ الوفاة سنة 1945 (63–64 سنة) مواطنة الولايات المتحدة مناصب الحياة ا
Sitio de Puerto Argentino Parte de guerra de las MalvinasFecha 1 de mayo-11 de junio de 1982Lugar Isla SoledadConflicto Bloqueo naval y asedioResultado Victoria británicaConsecuencias Debilitamiento de las fuerzas argentinas previo al ataque terrestreBeligerantes Argentina Reino Unido Comandantes Mario Benjamín MenéndezOscar JofreErnesto Crespo Sandy WoodwardJeremy Moore Unidades militares Comando Conjunto MalvinasFuerza Aérea Sur Fuerza de Tareas 317 [editar datos en Wikidata]&...
Creation spirit in some schools of philosophy This article is about philosophical concept of a Universal Fashioner. For other uses, see Demiurge (disambiguation). Part of a series onTheism Types of faith Agnosticism Apatheism Atheism Deism Henotheism Ietsism Ignosticism Monotheism Monism Dualism Monolatry Kathenotheism Omnism Pandeism Panentheism Pantheism Polytheism Transtheism Specific conceptions Brahman Creator Demiurge Deus Father Form of the Good God Great Architect Monad Mother Summum ...
Chiasso–Mailand Die Strecke bei CamnagoDie Strecke bei CamnagoStrecke der Bahnstrecke Chiasso–MailandStreckennummer (BAV):600 (Chiasso–Grenze CH-I)Streckennummer (RFI):25Fahrplanfeld:600Kursbuchstrecke (IT):27Streckenlänge:51 kmSpurweite:1435 mm (Normalspur)Stromsystem:3000V =Zweigleisigkeit:ja Legende S 10 S 40 Gotthardbahn aus Immensee 50,765 Chiasso Endstation 238 m Schweiz/Italien Monte Olimpino 2 (7.209 m) Monte Olimpino 1 (1.925 m) Hafenbahn Como 46,...
National Football League franchise in New Orleans, Louisiana New Orleans Saints Current seasonEstablished November 1, 1966; 57 years ago (1966-11-01)[1]First season: 1967Play in Caesars SuperdomeNew Orleans, LouisianaHeadquartered in Metairie, Louisiana New Orleans Saints logoNew Orleans Saints wordmarkLogoWordmarkLeague/conference affiliations National Football League (1967–present) Eastern Conference (1967–1969) Capitol Division (1967; 1969) Century Divisio...
This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: The Dangerous Transmission – news · newspapers · books · scholar · JSTOR (May 2015) (Learn how and when to remove this template message) The Dangerous Transmission AuthorFranklin W. DixonCountryUnited StatesLanguageEnglishSeriesHardy BoysGenreDetective, mysteryPublisherAladdin P...
New Zealand Labour Party politician Angela RobertsMember of the New Zealand Parliamentfor Labour party listIn office17 October 2020 – 14 October 2023 Personal detailsBorn1968 or 1969 (age 53–55)[1]Political partyLabourSpouseIan AngleseyChildren2ProfessionTeacher Angela Susan Roberts[2] is a New Zealand teacher, unionist and politician. Early life and career Roberts spent 20 years in the education sector teaching economics and drama.[3] In ...
International airport serving Tenerife, Canary Islands, Spain Los Rodeos redirects here. For other uses, see Rodeo (disambiguation). This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Tenerife North–Ciudad de La Laguna Airport – news · newspapers · books · scholar · JSTOR (September 2012) (Learn how and when ...
Book by Ralph Fletcher Spider Boy Hardcover first editionAuthorRalph FletcherGenreYoung adultPublisherClarion BooksPublication date1997-04-14Media typePrint (Hardcover)Pages183ISBN978-0-395-77606-3OCLC35029741LC ClassPZ7.F634 Sp 1997 Spider Boy is a young adult novel written by Ralph Fletcher, first published in 1997. Plot summary Bobby Ballenger is starting a new school a thousand miles from his old home. He moved from Naperville, Illinois to New Paltz, New York and his interest in...
Family of sea anemones For other uses, see Alicia. Alicia Alicia rhadina (solitary anemone) Scientific classification Domain: Eukaryota Kingdom: Animalia Phylum: Cnidaria Class: Hexacorallia Order: Actiniaria Family: Aliciidae Genus: AliciaJohnson, 1861 Alicia is a genus of sea anemones in the family Aliciidae and contains the following species:[1] Alicia beebei Carlgren, 1940 Alicia mirabilis Johnson, 1861 Alicia pretiosa (Dana, 1846) Alicia rhadina Haddon & Shackleton, 1893 Alic...
Indonesian beefsteak dish Selat soloSelat SoloCourseMain coursePlace of originIndonesiaRegion or stateCentral JavaServing temperatureHotMain ingredientsBraised beef tenderloin served in thin watery sauce, served with vegetables and potato Media: Selat solo Selat solo (Javanese for: Solo salad) is a Javanese dish influenced by Western cuisine; it is a specialty of Solo city, Central Java, Indonesia. It consists of braised beef tenderloin served in thin watery sauce made from a mixtur...
The topic of this article may not meet Wikipedia's notability guideline for music. Please help to demonstrate the notability of the topic by citing reliable secondary sources that are independent of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the article is likely to be merged, redirected, or deleted.Find sources: Laurentian's Atoll – news · newspapers · books · scholar · JSTOR (April 2...