Talk:Sieve of Atkin

message: I'm hoping that someone, if I don't have time to do it, will fill in details like how the sieve determines how many values for x and y fulfill the deletion question.  If we can move the article more toward the easy reading of Sieve of Eratosthenes, that would be great. — 131.230.133.185 5 July 2005 19:26 (UTC)
I concure!
I agree. I would help if I understood the algorithm. Now it's off to somewhere else for a better explanation.  — Preceding unsigned comment added by 176.42.70.2 (talk) 17:35, 26 November 2012 (UTC)
thread_title: Comments

message: I just did some rewording on the algorithm.
However, I do not know exactly about the algorithm, and am confused by the following:
:Then, for each remaining number, n:
:In class one, count the number of combinations of x > 0 and y > 0 that are solutions to 4x2 + y2 = n. 
:In class two, count the number of combinations of x > 0 and y > 0 that are solutions to 3x2 + y2 = n. 
:In class three, count the number of combinations of x > 0, y > 0, and x>y that are solutions to 3x2 - y2 = n. 
:If the count was even, delete the number from the list.
What are classes?  The article says "If the count was even".  If what count was even (any one of them or the sum of them)?
Clarification would make the article easier to read and understand.
--mets501 04:12, 4 March 2006 (UTC)
replies: text: I think the "classes" are the backup lists (i.e., the ones that hold values that are not yet determined to be prime) that were just mentioned previously.  I'm not sure enough about this to edit the page myself, however, as I'm not familiar with the Sieve of Atkin. In regards to the count being even, it refers to the number of combinations for each listed "class".  If the number of combinations (say for class 1, of 4x^2 + y^2 = n) is even for the current n, then you get rid of the number.  Any word from an expert on this would be great, however.  Opblaaskrokodil 03:27, 26 March 2006 (UTC)

text: The solutions certainly have to be integers, otherwise there would be an infinite number of solutions for every number. As for 91, you missed (5, 4). -- EJ 22:06, 4 May 2006 (UTC)
thread_title:  Class One, Class Two, Class Three 

message: I removed the clean up tag because I couldn't figure out why it was put on in the first place. Anyone who wants to put the tag back on had better explain not only why but also why they couldn't fix what they thought was wrong with the page themselves in the first place. Anton Mravcek 20:48, 8 May 2006 (UTC)
replies: text: I'm not sure why a cleanup tag was justified either (unless because the explanation of the algorithm leaves a bit to be desired).  I did add an expandsect tag to the "proof and explanations" section; there is currently no explanation of why the business with calculating the various numbers of combinations of x and y actually helps weed out non-primes.  Maybe it would be obvious to a mathematician why this is so, but it sure isn't obvious to me.  In fact, I have no idea (if I did, I'd add the extra explanation myself).  Zoicon5 18:06, 26 May 2006 (UTC)
replies: text: I went and looked up the original paper using the external link; this was clear enough for me to be able to add further explanation of the part I hadn't understood before, so I did that (and removed the "expandsect" tag). Zoicon5 19:13, 26 May 2006 (UTC)

text: I've cleaned up the article quite a bit, making it simpler and easier to follow (like the Sieve of Eratosthenes article) and showing where to obtain proofs of the various assertions.  I've removed quasi-optimizations in favor of understandability (the reader can choose his own optimizations or copy the C code linked at the bottom). — 131.230.133.186 18:53, 28 May 2006 (UTC)
thread_title:  Clean up tag removed 

message: Everyone seems locked into the concept that in exhaustive testing for primality of N, factors up to √N must be considered, and they persist in using a name called Limit for their description of the range of N to be worked through so that they repeatedly talk about √Limit in controlling matters. Since most integers do not have integer square roots this is messy at best and in terms of computational effort, wastefully requires the evaluation of square roots. A better description of the bounds on the possible factors f would be for f^2 <= N rather than f <= √N. And then if you think about the choice of possible factors (as in the division method http://mersennewiki.org/index.php/Trial_factoring) you soon see that only primes should be considered, and it is best to start with the smallest (since more numbers are divisible by 2 than by 3, etc.) working from a small array of prime numbers, and then you need recall only the highest index so far needed, that is f = Prime(i) for i up to LastIndex, the last index for which Prime(LastIndex)^2 <= N, or similar schemes.
And then you might realise that the actual requirement to check N for primality by trial division is as follows: use as factors the primes P(i) with i from 1 to Last such that N < P(Last + 1)^2. For instance, suppose that 5 is the last prime factor being considered as a possible divisor for N. On the face of it, as soon as N reaches 25, you would extend the test list from {2,3,5} to {2,3,5,7}. But this is not necessary. There is no need to test with 7 until 49 = 7*7 is reached, because until then, N = 2*7 need not be tested against 7 because 2 would already be tested for, nor need it be tried for N = 3*7, nor for N = 5*7. Only when N = 7*7 is reached would the test divisions by {2,3,5} not suffice.
In the current context, if MaxFactor is the largest factor that will be considered, then the upper bound for N is MaxFactor^2 and there is no confusion of square roots, especially of numbers that are not perfect squares. Further, if MaxFactor is a prime, say P(i), then the upper bound will be P(i + 1)^2 - 1, though P(i)^2 will do, as would (P(i) + 2)^2 since P(i) + 2 <= P(i + 1) for i > 1. Whichever, the idea is to avoid littering the description with √N and similar. 
NickyMcLean 21:00, 4 December 2006 (UTC)
thread_title: Limits

message: Why does the introduction talk about modulo 60 whilst the pseudo code uses modulo 12?
138.251.95.1 09:12, 20 April 2007 (UTC)
replies: text: Because the algorithm in the introduction includes wheel factorization mod 5, which is avoided in the pseudocode. -- EJ 12:28, 20 April 2007 (UTC)

text: Remainders divisible by 5 are ignored by the mod 60 algorithm because the only point of using mod 60 instead of mod 12 is to apply wheel factorization mod 5 as an unrelated optimization. This optimization is (1) completely arbitrary (why not do mod 7 or mod 11 wheel factorization as well?), (2) tangential to the main idea of the algorithm, and (3) it unnecessarily clutters the code and makes it harder to understand what's really going on. If you actually study the explanation of the algorithm, you'll see that the conditions under which the parity of the number of solutions to the three quadratics corresponds to primality only depend on their residue class mod 12. — Emil J. 11:20, 20 November 2009 (UTC)
thread_title:  modulo 60 

message: I have tried both on my computer to compute the primes from 2 to 1000000, and the Sieve of Eratosthenes went nearly twice as fast.  I can upload video of me doing it too, and/or upload my code, to a separate website.  This discussion may be continued on my talk page...
JIMOTHY46ct 16:54, 25 January 2008 (UTC)
replies: text: The algorithm is assymptotically faster by a factor of log log N; for practical purposes, that's essentially a constant (and not very large at that), hence it competes with other multiplicative constants representing various overheads. The moral is, the relative speed of the sieve of Atkin vs. sieve of Eratosthenes is extremely sensitive to various optimization tricks used in the implementation. To do it justice, take a look at the implementation at  (which also includes a similarly optimized implementation of the sieve of Eratosthenes for the purposes of comparison). It is written by D. J. Bernstein, who is not only a coauthor of the sieve of Atkin, but also a very skilled programmer, unbeatable by any human when it comes to this kind of optimization. It's a fairly safe bet that his implementation of either of the two sieves beats yours by an order of magnitude. -- EJ (talk) 17:18, 25 January 2008 (UTC)

text: It was probably too subtle but Sieve of Atkin#Computational complexity had a piped link on 'O' in O(N/log log N). The link explains asymptotic growth but I have added a clearer link to Asymptotic computational complexity. PrimeHunter (talk) 17:45, 25 January 2008 (UTC)

text: I believe you now that I saw the code (it was too complicated for me to understand), but it was unfortunate that it wouldn't build properly...
JIMOTHY46ct 18:02, 25 January 2008 (UTC)

text: Having implemented both the pseudo code and the algorithm I have, if you look at the discussion above, found that they differ (not insubstantially) in speed. Would it be possible to change them so that they are both the Sieve of Atkin? I shall do this if I can find some time in the next couple of days.
Farpov (talk) 12:14, 14 April 2008 (UTC)

text: The pseudocode is not O(N/log log N); the sweep has to be done more carefully for that to happen.  See the Atkin-Bernstein paper. CRGreathouse (t | c) 03:22, 19 December 2011 (UTC)

text: Then the pseudocode is not a valid representation of the algorithm and should be corrected or removed.  Directing us to the paper is not a solution to this deficit in this article.  Since the whole point of the Sieve of Atkins is as a more efficient prime generator, I think that the point of an encyclopedic article about it should, at the very least, include some *valid* presentation of how it achieves that.  Since the pseudocode manages to block any chance of the reader might have had to understand the principal computational feature of this algorithm, at this point it constitutes far more harm than benefit.  This is also the kind of thing for which "CLEAN-UP" is needed here. 68.36.102.254 (talk) 22:06, 20 March 2012 (UTC)
replies: text:  So fix it, if you don't think it's good enough. CRGreathouse (t | c) 02:09, 21 March 2012 (UTC)
replies: text:  I would if I could but I cannot, because I came here to learn what makes Sieve of Atkins better than the Sieve of Eratosthenes.  Alas, this article's misleading content has left me as ignorant as ever of that matter.  You see the problem?  RBarryYoung (talk) 01:29, 29 March 2012 (UTC)

text: Carl Bohn: A properly implemented Sieve of Eratosthenes never uses division.  It only uses addition to step across a "strikeout-list", that's a big part of it's efficiency, which is slightly sub-linear (except for the list allocation which is linear of course).  I have written versions in VB myself and would be willing to take a look at what you have, if you so desire  (time permitting).  (I am on Gmail with the same username as here). RBarryYoung (talk) 19:02, 27 December 2013 (UTC)
thread_title:  How is this faster than the Sieve of Eratosthenes? 

message: The directions say to initialize it with 2, 3, and 5, but you can do it without initializing 5 and, according to the original paper, you don't need 5 (it says they start looking for prime numbers by considering primes >3) and the pseudo code seems to agree (otherwise the last loop would start at 7 and not 5). What gives? --M1ss1ontomars2k4 03:18, 2 July 2010 (UTC)
replies: text: Unlike the pseudocode, the description in the "Algorithm" section implements wheel factorization modulo 5 (or rather 60), which requires that prime 5 receives special treatment.—Emil J. 12:22, 2 July 2010 (UTC)
thread_title:  Initialization of initial prime numbers 

message: The lead states: "[it] marks off multiples of primes squared, rather than multiples of primes". It is unclear at all on the face of it whether it means the multiples of primes are squared, or it is the multiples of the squared primes that are marked. The  English parsing is ambiguous here. WillNess (talk) 13:00, 24 August 2011 (UTC)
replies: text: No takers in half a year?????? WillNess (talk) 08:51, 15 December 2011 (UTC)
replies: text: It means multiples of the squared prime. I have reworded the lead paragraph to make this clearer. Gandalf61 (talk) 09:48, 15 December 2011 (UTC)
replies: text:  Note that a naive implementation, as in our lede, takes time \Omega(n) and thus the algorithm is no longer O(n/\log\log n). CRGreathouse (t | c) 03:21, 19 December 2011 (UTC)
thread_title:  Ambiguity in the lead 

message: "It was created in 2004 by A. O. L. Atkin and Daniel J. Bernstein.[1]"
with [1] being a reference to the 2004 paper.
But the linked code on djb's website has copyright notices of 1999 and the wayback machine has versions of the page from 2003 (at least) that contain the same files, http://web.archive.org/web/20030623074834/http://cr.yp.to/primegen.html.
so maybe 'created' isn't the right word here?  — Preceding unsigned comment added by 50.78.244.161 (talk) 16:35, 17 May 2012 (UTC)
thread_title:  Timeline issue 

message: For the pseudocode bit, can we use words and the few commonly accepted mathematical symbols ( - + / ^ etc) used in programming languages? Instead of upside-down letter A's and wierd Greek-looking E's? As far as programming goes I don't think they're even in EBCDIC! You'd have a hard job getting them through any compiler.
The existing example isn't pseudocode, it's just drawn-out maths. For people who haven't learned the more advanced and esoteric maths, pseudocode is a way of mentally drawing one through a process in a simple way, without using symbols and the compressed and intrinsic knowledge of what processes they represent. With an advanced mathematical education, I'm sure the meaning just leaps off the page for you. For everyone else you may as well print a gigantic question mark. Also, it's not usual to use superscript, you'd usually use ^2 for squared ^3 for cubed, ^x for to-the-power-x etc.
Programming languages use words for their routines, for good reasons. So if someone actually understands what this all means, please do us a favour and fix it up nice. 188.29.164.213 (talk) 00:15, 12 October 2013 (UTC)
replies: text: Note you are replying to a post dated 12 October 2013. PrimeHunter (talk) 14:55, 19 October 2015 (UTC)
thread_title:  Pseudocode