Talk:AKS primality test

message: Added request for help cleaning up the mathematical formulae on Wikipedia talk:WikiProject Mathematics. Hv 13:41, 10 August 2005 (UTC)
replies: text:  variables need to be defined 68.6.112.70 03:48, 21 November 2005 (UTC)
replies: text: Which variables? -- Jitse Niesen (talk) 11:05, 21 November 2005 (UTC)
replies: text: x and a need to be defined 140.211.137.232 21:04, 4 March 2006 (UTC)
thread_title:  Formula cleanup 

message: In the section "algorithm" it's said: Find the smallest r such that or(n) > log2(n). That condition is not sufficient, because with only that limitation also Charmichael numbers outputs prime. The correct condition on r is:
Find the smallest r such that or(n) > log2(n) and n-1 is not divisible by r. Kaluppollo (talk) 13:28, 15 November 2009 (UTC)
replies: text: I don't understand your reasoning with Carmichael numbers, but at any rate if r divides n − 1, then the multiplicative order of n modulo r is 1, which is not greater than log2(n), hence your extra condition is redundant. — Emil J. 13:20, 16 November 2009 (UTC)
thread_title:  Finding r 

message: It is stated in the article:
"Again the AKS algorithm consists of two parts, and the first step is to find a suitable r; however, in the new version r is the smallest number such that or(n) > log2(n)."
However, it seems to me that that is the same as what is listed in the original algorithm in Step 2. Perhaps I am incorrect, but if not that sentence needs to be changed at the very least because it implies that the step was updated when in fact it appears not to be. I propose that the sentence be reworded or deleted.  —Preceding unsigned comment added by Jessemv (talk • contribs) 06:17, 20 November 2009 (UTC)
replies: text: The algorithm incorrectly described as the "original algorithm" in the article is actually the new one. I think we should stick to that new version of the algorithm as it is the published version, but reduce the discussion of the preliminary version and its updates to a history section or something like that. — Emil J. 11:36, 20 November 2009 (UTC)
replies: text: Done. — Emil J. 12:29, 20 November 2009 (UTC)
replies: text: Better. Nice job EmilJ. However, I think the article should state the original algorithm somewhere, although you are correct in sticking with the new algorithm. Also, are you sure the Big-O notation is the "soft-O" symbol? The mathematics is a little too complicated for me to handle, but I would still like to make sure that the symbol is used correctly. The Big-O notation seems to differ between the algorithm versions. Jessemv (talk) 01:22, 23 November 2009 (UTC)
replies: text: I see no reason to bother with an outdated preliminary version of an algorithm, and generally speaking, I don't understand why is it that this article seems to be pathologically obsessed with the old algorithm. This normally never happens in computer science or mathematics, people just refer to the final published version of a result in case of any differences. As for the big-O notation, all versions of the paper I've seen use O-tilde for the time bounds (and this is pretty much unavoidable, the extra polylog factors come from the time complexity of multiplication). Sometimes they write it as \tilde O and sometimes as O^\sim\,, but that's only a typographic change. — Emil J. 13:00, 23 November 2009 (UTC)
replies: text: Ok. Guess you're right about the algorithm. I just thought it would be a credit the original creators more to show what they thought up, but I now agree with you that the final version is more important. Thanks for the followup. Jessemv (talk) 22:41, 23 November 2009 (UTC)
thread_title:  New Algorithm Version error 

message: The algorithm was updated and improved shortly after release, but is not shown here: http://teal.gmu.edu/courses/ECE746/project/F06_Project_resources/Salembier_Southerington_AKS.pdf
In addition, (x a)^n x^n a (mod n) was changed to (x a)^n x^n a (mod x^r 1, n)  — Preceding unsigned comment added by Cable729 (talk • contribs) 20:36, 23 March 2011 (UTC)
thread_title:  Formula Update 

message: log^12(x) is log(log(...(x)...))
log(x)^12 is (log x)^12
Please synchronize formulas and textual description. Which is meant?--134.130.183.101 (talk) 08:35, 20 July 2011 (UTC)
replies: text: log^12(x) can also mean (log x)^12. That's what's meant in this article. --Roentgenium111 (talk) 14:25, 6 October 2011 (UTC)
thread_title:  History and running time 

message: In the external link to Scott Aaranson's paper, it states "The way they speed things up is to work, not only mod N, but also mod a polynomial XR − 1 (where R is a reasonably small prime)." The restriction of r being prime is not in the Wikipedia article. Which is right? Gaohoyt (talk) 18:41, 17 August 2012 (UTC)
replies: text: There’s no point in r being prime, and in the published paper, they allow composite r. However, in the first version of the paper, they used prime r, and Aaronson’s paper was presumably written before the update.—Emil J. 19:25, 17 August 2012 (UTC)
thread_title: Must r be prime?

message: The numberphile video about the AKS test is completely wrong.  I realize the presenter says it is the AKS test, but it is not.  It describes Hardy and Wright theorems 75 and 76, not the AKS test.  At the 2:26, the presenter waves his hands and says, they actually did something a little different, then moves on.  See Agrawal and Biswas "Primality and Identity Testing via Chinese Remaindering" (FOCS 1999, as paper in 2003), or read the actual AKS paper.  They are describing Lemma 2.1 of the V6 paper.  This is not AKS, it is not polynomial time, and it is not fast.
Please remove the link.  DAJ NT (talk) 16:40, 1 March 2014 (UTC)
replies: text: Having put it there, if others want it gone, I won't put it back a third time.  The argument isn't really with me, it's with James Grime of Cambridge.  user:JMOprof ©¿©¬ 16:56, 1 March 2014 (UTC)
thread_title:  Numberphile video 

message: The smallest r such that Or(31) > Log(31)2 is 17, not 29. Can someone else confirm, or did I do something wrong?
: It would help if some of the values were shown (e.g. what are maxk and maxr).  maxk = floor(24.54406...) = 24.  znorder(31,17) = 16, znorder(31,23) = 11, znorder(31,29) = 28.  r=29 is correct.  Double check with Pari/GP:
:     for (r=2,29,print(r" "znorder(Mod(31,r)))).
: DAJ NT (talk) 23:09, 22 May 2015 (UTC)
replies: text:  According to the page, it's not max r, it's min r. The page says nothing about the binary logarithm; so Log(31)^2 = 11.7923, so if the page is right, your own calculation shows that 17 is correct over 29.  — Preceding unsigned comment added by 75.168.59.69 (talk) 23:43, 22 May 2015 (UTC)
replies: text:  Nope, I'm wrong, it's in the text after the description of the algorithm. I'm going to add a subscript to indicate in the algorithm itself that the logarithm is binary. Thanks for catching my mistake!  — Preceding unsigned comment added by 75.168.59.69 (talk) 23:46, 22 May 2015 (UTC)
replies: text:  Thanks, that's a good edit.  It is in page 2 of the reference paper:  "We use log for base 2 logarithm, and ln for natural logarithm."  I've seen it trip up implementations. DAJ NT (talk) 00:16, 23 May 2015 (UTC)
thread_title:  r in the example is wrong 

message: In fact, x is not "over the integers" or "over the integers mod n".
The correct statement is:
#(x + a)^{n} \equiv (x^{n} + a) \pmod{n} \text{ in } \mathbb Z[x]
#: or
# (x + a)^{n} = (x^{n} + a) \text { in } \mathbb Z[x]/(n)
#: or
#(x + a)^{n} = (x^{n} + a) \text { in } \mathbb Z_n[x]
#:
#: Not-obviously-equivalent formulations are:
# (x + a)^{n} \equiv (x^{n} + a) \pmod{n} \text{ for } x \in \mathbb Z
#: and 
# (x + a)^{n} = (x^{n} + a) \text { for } x \in \mathbb Z_n[x]
What was in the article before 's edit resembles #4, while what was there afterward resembled #5, but we should be arguing about which of #1, #2, #3 should be in the article. — Arthur Rubin  (talk) 17:56, 1 February 2016 (UTC)
replies: text: I am in favour of 3, which is consistent with the formulation of later statements. Nxavar (talk) 19:29, 1 February 2016 (UTC)
replies: text: if a and b were both integers then it would be understood that the congruence modulo n notation a \equiv b\pmod{n} would imply that a, b \in \mathbb Z_n; likewise a and b being polynomials with n an integer, then the statement a \equiv b\pmod{n} implies that a, b \in \mathbb Z_n[x]. More specifically (x + a)^n \in \mathbb Z_n[x] and (x^n + a) \in \mathbb Z_n[x], where the coefficients for both of these two poly's would be in \mathbb Z_n and x itself is a free variable of the poly-space which is not necessarily restricted to \mathbb Z_n or even \mathbb Z. In fact restricting x \in \mathbb Z_n would limit the generality of the statement, and stating that 0x^0+1x^1 \in \mathbb Z_n[x] is redundant. 199.34.4.20 (talk) 22:04, 4 April 2016 (UTC)
thread_title:  x is a variable 

message: I have added a suggested more efficient algorithm for finding if n is a^b to the worked example.
If n=ip or n=i^p where integer i>1 and prime p<P where P is the smallest prime for which n<P^P then output composite.
If n = a^b < P^P then log n = b log a < P log P. Therefore either b < P or a < P. Therefore we could check for n=p^i and n=i^p. We don't need to check the first equation beyond the first division by p as other n=ip would be removed later. We only need check prime values as, for example, if n=9^9 it would also be 3^18 and 729^3.
I am a newby so please be kind if I have not followed procedure correctly.
TheOldRic (talk) 15:55, 15 February 2016 (UTC)
replies: text: That would be (even if you entered correctly) a different algorithm.  It's not AKS.  — Arthur Rubin  (talk) 09:10, 17 February 2016 (UTC)

text: I agree with Arthur, that it should just reflect the AKS algorithm.  Steps 1 and 3 aren't an optimization, but required for step 5+6 to be correct.  The implementation could certainly be different than the example, but I think that's unnecessary (a link to Perfect_power#Detecting_perfect_powers at best).  There are certainly better methods for perfect power detection, but that really is going way too far for this simple example.  If we were to do that, then we'd end up with a digression on fast modular polynomial multiplication via binary segmentation, which is far more critical to the algorithm performance.  Note that in a practical situation we would preface this test with fast compositeness tests (e.g. trial division, M-R, BPSW), so we're not wasting time on easily detected composites.  But that is purely up to an implementation -- the algorithm on the page includes everything necessary for correctness. DAJ NT (talk) 19:07, 17 February 2016 (UTC)
thread_title:  Stage 1, Power of an Prime? 

message: I was a bit confused over step 4. If n < r and step 3 takes r steps, then the number of applications of gcd is exponential in n. Then I noticed that the original paper has a footnote. As AKS prove that r is small (less than log^5 n), this step is only inserted for small n (AKS claim some nummber < 6). I think this footnote is necessary to avoid confusion and would like to see it added.  — Preceding unsigned comment added by Leentorenvliet (talk • contribs) 12:26, 8 August 2016 (UTC)
replies: text: It may be further worth pointing out that Step 3 is performing trial division from 2 to r.  So practically we wouldn't want to do a gcd with every integer, but just divisibility tests (probably with 2+odds, a wheel, or primes).  Step 4 then further works if r >= sqrt(n).  DAJ NT (talk) 14:59, 8 August 2016 (UTC)
thread_title:  Step 4 

message: Hello fellow Wikipedians,
I have just modified  on AKS primality test. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
*Added archive https://web.archive.org/web/20140219064936/http://www.dm.unito.it/~cerruti/ac/aks-crandall.pdf to http://www.dm.unito.it/~cerruti/ac/aks-crandall.pdf
When you have finished reviewing my changes, please set the checked parameter below to true or failed to let others know (documentation at ).
Cheers.—InternetArchiveBot (Report bug) 04:50, 1 October 2016 (UTC)
thread_title:  External links modified 

message: The section 'Proof of validity outline' refers to the algorithm steps by number, but appears to be wrong.
For instance it says the hardest part is step 6, 'ouput prime' which cannot be right. I suppose this should be 'the hardest part is step 5'. This makes me unsure about the other references, since I don't understand the algorithm myself.
:I am inclined to agree. But step 5 is mentioned in the previous paragraph. I think "hardest" here might mean most computationally expensive, but I am not sure. BernardoSulzbach (talk) 10:26, 23 January 2020 (UTC)
thread_title:  Renumbering of steps needed 

message: Recently I removed the mentioning of the generalized Riemann hypothesis from the lead because presenting the reasons why this algorithm is unique is already boged down with technicality, there is actually a whole section in this article just about that. There was disagreement because my edit didn't do justice to the status of the generalized Riemann hypothesis among conjectures. However, I insist that the accessibility of the lead is more important. Nxavar (talk) 09:10, 3 February 2020 (UTC)
replies: text: thanks for the civility of bringing this to talk. The discussion is about . I understand your worry. However, I don't think that simply stating "a conjecture" is any better than specifying the conjecture. They are not all created equal, some are much more difficult to (dis)prove than others and being specific here seems right. However, we both know our viewpoints on the matter. More people have to jump in order for this to reach consensus. BernardoSulzbach (talk) 18:17, 3 February 2020 (UTC)
replies: text: If I am interpreting this correctly, the fact that this algorithm bypasses the generalized Riemann hypothesis adds to its notability? I was thinking to put in the lead the fact that both the proof and the algorithm use 'elementary' mathematics. Which is also technical and probably confusing. Nxavar (talk) 08:54, 4 February 2020 (UTC)
replies: text: "I was thinking to put in the lead the fact that both the proof and the algorithm use 'elementary' mathematics. Which is also technical and probably confusing." Agree. I appreciate your efforts and your good intentions, but I think some things just cannot be broken down into simple terms without losing a lot of the important details along the way. BernardoSulzbach (talk) 18:26, 4 February 2020 (UTC)
replies: text:  I think the fact that it bypasses the RH does not show that it is unconditional. Also, I found a more elegant way to say that the proof is 'elementary'. I made relevant additions to the lead. Nxavar (talk) 16:34, 24 February 2020 (UTC)
replies: text:  I agree that it is better now. Thank you for dealing with criticism properly. BernardoSulzbach (talk) 16:48, 24 February 2020 (UTC)
thread_title:  Accessibility of the lead 

message: In the quoted reference am unable to find stmt 3 in the presented form:
: „For all 2 ≤ a ≤ min (r, n−1), check that a does not divide n: If a|n for some 2 ≤ a ≤ min (r, n−1), output COMPOSITE.“
Because of the possibility of r\geq n (see stmt 4) and thus \min(r,n-1) = n-1 this stmt 3 would consume time n-2 = |\{2,3,\ldots,n-1\}| = 2^{\log_2(n)}-2  which is exponential in the number \log_2(n) of bits of n.
In contrast, the true stmt 3 of the source has the form
: „If 1 < (a, n) < n for some a \le r, output COMPOSITE.“
Lemma 4.2Manindra Agrawal, Neeraj Kayal and Nitin Saxena (2002): PRIMES is in P shows that r \in \mathcal{O}(\log^6 n) which is better than his stmt 3 with its exhaustive loop „For all 2 ≤ a ≤ n−1“. –Nomen4Omen (talk) 14:45, 8 October 2020 (UTC)
thread_title:  Statement 3 of the algorithm​