Slashdot Mirror


Turns out, Primes are in P

zorba1 writes "Manindra Agrawal et. al. of the Indian Institute of Technology Kanpur CS department have released a most interesting paper today. It presents an algorithm that determines whether a number is prime or not in polynomial time. While I haven't gone through the presentation in detail, it looks like a promising, albeit non-optimized, solution for the famous PRIMES in P problem."

34 of 436 comments (clear)

  1. for the sake of our eyes by fatmav · · Score: 5, Informative

    the ps version looks much better:
    http://www.cse.iitk.ac.in/primality.ps

    --
    // FIXME: put sig here
  2. Re:I always thought is was in P by Anonymous Coward · · Score: 5, Informative

    For P, it has to be polynomial in the size of _the input_. The input size here is log(n) since it requires log(n) bits to represent n. log(n)^12 hence is polynomial (which i believe their algo guarantees), whereas sqrt(n) is not.

  3. Re:I always thought is was in P by Walker · · Score: 3, Insightful

    What are you referring to as your input size n in O(n)? The number p? The correct size n is the number of digits of p. That algorithm is definitely non-polynomial for that (correct) n.

  4. Re:Big consequences related to encryption by God!+Awful · · Score: 5, Funny


    Well, encryption based on the multiplication of large primes, anyway.

    Yeah... that step in key generation where you check whether a candidate key is prime or not will now be performed with 100% confidence instead of that annoying 99.999999999999999% confidence we used to have.

    -a

  5. arg. I did it again by orz · · Score: 3, Informative

    hm... I'm not sure why it removes comparison symbols when set to plain text... oh well, I wrote out "is less than" this time

    They're saying the the time T necessary to determine whether or not an N digit number is prime satisfies this equation:

    T is less than N ^ k + a

    for some values (can be any finite value) of k and a.

    Basically, it's a statement about how well an algorithm scales to REALLY large numbers.

  6. Factoring might still be NP by IntelliTubbie · · Score: 5, Informative

    For those of you wondering about the implications for cryptography, this does not imply that composite numbers can be factored in polynomial time. This algorithm is simply a primality test -- that is, it tells you whether or not a number has any proper divisors (in polynomial time), but it doesn't tell you what these divisors actually are. Determining whether a number is prime has always been considerably easier than finding the prime factorization.

    In fact, for schemes like RSA -- where the key is the product of two large primes -- we already know that the number is composite, by definition, so a more efficient primality test doesn't give us any new information.

    Cheers,
    IT

    --

    Power corrupts. PowerPoint corrupts absolutely.

  7. What is 'x' and how is 'q' calculated? by Mr.+Sketch · · Score: 4, Interesting

    From looking at the algo, I can't figure out what 'x' (or maybe it's a chi) is? Can someone help? I've looked it over, but couldn't find a definition of it. I'm also assuming that the 'if (r is prime)' line is a recursive call to itself? Also, how do we determine 'q' the 'largest prime factor of r-1' ? Another recursive call to get the factors? I must admit, I'm kind of lost by the algo, but it's still interesting.

    1. Re:What is 'x' and how is 'q' calculated? by matrix0040 · · Score: 3, Informative

      no you dont need recursive call. as r is O(log(n)) so size of r is O(log log(n))) so if an exponential time algorithm is used for checking the primality of r, it'll be exp in log(log(n)) i.e. linear in log(n)

      Same goes with q. as it's "small" you can afford an exponential algoritm.

      also x is a variable, those eqns (12) really are polynomial eqns.

    2. Re:What is 'x' and how is 'q' calculated? by deblau · · Score: 4, Informative
      From looking at the algo, I can't figure out what 'x' (or maybe it's a chi) is? Can someone help? I've looked it over, but couldn't find a definition of it. I'm also assuming that the 'if (r is prime)' line is a recursive call to itself? Also, how do we determine 'q' the 'largest prime factor of r-1' ? Another recursive call to get the factors? I must admit, I'm kind of lost by the algo, but it's still interesting.
      OK, I'll address these points in order:

      First off, 'x' doesn't matter. The loop at the bottom checks a congruence of two polynomials over two finite rings (if I'm reading it right, the first is generated by x^r-1 and the second by the input n). Simplistically, this amounts to grinding out the coefficients of the two polynomials and verifying that the difference of the polys equals zero, modulo the ring generator. The actual 'value of x' is never used.

      Second, if you check the order statistic calculation, they're assuming worst-case on factoring 'r' (they apply order r^1/2 for that factorization). They then make an assumption that O(r^1/2) = O((log n)^3), or that O(r) = O((log n)^6), which seems rather suspect (as if they knew the answer ahead of time and plugged in a recursive value for it). Nevertheless, they do go to some length to show that such an r exists, and that it requires at most O((log n)^6) iterations of the first loop to find it.

      As for 'q', I think again it is determined by brute-force factoring r-1. On the one hand, r is small; on the other hand, that doesn't mean a damn thing when it comes to dealing with order statistics, which I think is also a little suspect.

      --
      This post expresses my opinion, not that of my employer. And yes, IAAL.
  8. Re:What's Polynomial Time? by Goonie · · Score: 5, Informative
    The technical definition is kinda long and complex, but in essence it's like this. Given a problem of some size n, a polynomial time algorithm is guaranteed to give a solution in time proportional to a polynomial of n. If a polynomial-time algorithm exists that solves a problem, then the problem is said to be in polynomial time.

    To give an example, say you've got a list of numbers and you want to know the sum. That can be done in linear time - ie, the time taken is proportional to the length of the list of numbers. The size of the problem (n) is defined by the length of the list and the time taken (T) is as follows: T = c1 * n + c0, where c1 and c0 are some fixed constants. The formula for T is a polynomial, and so the problem "LIST-SUM" is in polynomial time. It would still be in polynomial time if the formula for T was a polynomial with n^2, n^3, n^50 terms in it, or even terms like n^1.5 (because as n grows very large an n^1.5 term will always be smaller than an n^2 term).

    Showing you an example of something outside polynomial time is a little more difficult, but some standard examples are SAT (the satisfiability problem) or the travelling-salesman problem, which you can read about in any book on the subject.

    --

    Any sufficiently advanced technology is indistinguishable from a rigged demo
    --Andy Finkel (J. Klass?)
  9. Re:If this is true... by ipfwadm · · Score: 5, Informative

    They could have easily taken over the infrastructure of a modernized computer-bent, encryption-shielded society such as the US or Japan.

    Primality testing and factorization are not one and the same. It is possible to know that a number is not prime without knowing its factors. Breaking encryption requires factoring the product of two huge primes (it is already known that the number you're trying to factor is NOT prime, so Primes being in P is more or less useless by itself for this particular application), and factorization has yet to be shown to be in P.

  10. I'm dead tired by Henry+V+.009 · · Score: 3, Interesting

    I'm dead tired and will look at the paper in the morning. But right now I have a problem with step 6:
    "Let q be the largest prime factor of r-1"
    Won't getting q boost the thing back into power n complexity?

    1. Re:I'm dead tired by matrix0040 · · Score: 3, Informative

      no it wont as q is "small", as proved in lemma 4.2 r is O(log(n)^6) and so is an upper bound on q. so the size of q is O(log(log(n)) and an exponential time in that will be linear in log(n) !!

  11. If you're confused by "P" and "NP".... by Erpo · · Score: 5, Informative

    look here.

  12. Implications by davemarmaros · · Score: 5, Informative

    There are 2 different problems:
    1) Determining if a number is prime [is 909 prime?]
    2) Determining the factors of a number [what are the factors of 909?]

    This article claims to be able to solve problem 1 in Polynomial time.

    However, problem 2 is MUCH harder, and that is the one which will break cryptography as we know it. This article does not claim to solve problem 2, so we're safe for now.

  13. Re:Cryptography by God!+Awful · · Score: 3, Informative


    Out of interest, will this finding have any impact on the effectiveness of present day cryptography?

    Probably not. While it is possible that this research could lead to results in speeding up factoring, a faster algorithm for determining whether a number is prime is not going to compromise the security of RSA.

    Your RSA key pair is derived from 2 large primes. The way we generate keys is to randomly test large random numbers to see if any of them are prime. Ergo, we must already have an efficient formula for determining if a number is prime or not.

    FYI, the most commonly used algorithm is Euler's formula. Euler's formula doesn't actually tell you if a number is prime, but it will usually give a non-zero output if the number is not prime, so if you run it enough times with different inputs, you can be 99.99999% sure that a number is prime. However, a small percentage of numbers are "pseudoprimes" -- numbers that are not prime but which will also satisfy Euler's formula. Therefore, after you discover a candidate prime, you should use a different (slower) formula to double-check.

    Since this is fairly common knowledge among geeks who use encryption, I'm somewhat surprised that so many people here jumped to the same conclusion you did.

    -a

  14. Re:Big consequences related to encryption by Goonie · · Score: 3, Insightful

    Uh, no. Just because you can tell whether a number is prime in polynomial time, doesn't mean you can find the factors of a number in polynomial time, as I understand it.

    --

    Any sufficiently advanced technology is indistinguishable from a rigged demo
    --Andy Finkel (J. Klass?)
  15. Re:Oh yeah? Well... by braindead · · Score: 3, Funny
    • I have developed an algorithm that will determine if any number less than a google is prime in O(1). Above a google it degrades pretty fast, though.

    Aha... is that based on a precomputed sieve with 10^100 elements, by any chance? ;-)

    (it's googol, by the way. Google.com is obviously not prime, based on the fact that they haven't IPO'd yet)

  16. Re:Big consequences related to encryption by tbo · · Score: 5, Insightful

    Thank you. I'm glad someone finally pointed out that we already have a classical (as opposed to quantum) probabilistic algorithm for determining primality. Every other fool on this board is running around wearing his/her tin hat and shouting about RSA being defunct. All this does is push primality testing from the BPP complexity class into the P complexity class. It is significant in the sense that it weakens the argument for BPP being larger than P.

    Of course, we also have a polynomial-time algorithm for prime factorization (Shor's Algorithm). It's just that it requires a quantum computer, which is difficult to build. So far, the biggest number factored is 15... 1024 bit keys will be safe for a while yet. I believe it's 15 - 20 years until they're broken, if Moore's Law holds for quantum computers in terms of maximum number of qubits possible (so far, it roughly has, but then, we're only at about 7 qubits).

  17. We already knew that... by FalafelXXX · · Score: 5, Informative
    The famous result by Miller 1976 (and indepdently rediscovered(?) by Rabin 1980) already did that. The only difference is that their algorithm was in RP (randomized polynomial). Namely, if the algorithm says it is prime it might be wrong (with probablity half, say), and if it says that the number is not prime, then it is not prime for sure.

    Now, if you have a number n, you run this algorithm, say 20*log(n) times. If the algorithm says it is prime on all executions that it is prime, you know damn sure it is. If it says it isn't, you are sure it isn't. There is a rediclously tiny probablity that if the algorithm claims that it is prime in all executions, that it is still not prime. This probablity is so small, that it can be essentially ignored. Now, random bits are cheap nowadays, so this is quite satisfactory. This is in fact the algorithm that turned the RSA crypto system into a practical and useful algorithm, because suddently finding primes became easy.

    To break RSA, and become really famous, one has to come up with a polynomial time algorithm for factoring. It might even be that RSA can be broken without factoring, but this is still an open question (I think).

    Ahh, and BTW. Polynomial time means polynomial time in the size of the input. So if the number is n, the size of the input is O(log(n)), and the running time needs to be O( (log(n))^(O(1)) ).

    Ok. End of boredom.

    1. Re:We already knew that... by Mornelithe · · Score: 5, Informative
      I probably really shouldn't be replying, because it's been a while since I read how it works, but I can copy the algorithm and tell you where I think it would break (if at all). Please correct me where I'm wrong.
      1. Generate two random primes p and q
      2. Calculate n = pq and phi(n) = (p - 1)(q - 1) = n - (p + q) + 1 (Note: phi(n) is the number of primes less than n (Euler's totient function, I believe). phi(p) = p - 1 for prime p, and phi(pq) = phi(p)phi(q) for p relatively prime to q (note, this step breaks if p or q aren't prime))
      3. Generate e
      4. Calculate d, the inverse of e (mod phi(n)) (i.e. d*e = 1 (mod phi(n)))
      5. is the enciphering key, is the deciphering key
      6. For plaintext P, you get ciphertext C by doing: C = P^e mod n, and get P back by doing P = C^d mod n

      So, now there's the matter of why it works. Here we go:

      • Because of Fermat's Little Theorem, we know that a^(phi(n)) = 1 (mod n)
      • Since ed = 1 (mod phi(n)) we have: ed = 1 + k*phi(n) for some integer k
      • So, if we encipher and decypher, we have: (P^e)^d = P^(ed) (mod n)
      • Which also means we have: P^(1 + k*phi(n)) = P*(P^(k*phi(n))) = P*((P^phi(n))^k) = P*(1^k) = P (mod n)

      So when p or q are not prime, phi(n) != (p - 1)(q - 1), so when you calculate d, you'll get something that doesn't negate the encrypting process (because its not a multiplicative inverse mod the real phi(n)), so you'll probably get junk when you decipher.

      I don't really feel like doing a detailed analysis of the algorithm, but I imagine that this isn't used as a primality test because it's running time probably isn't polynomial time.

      --

      I've come for the woman, and your head.

  18. Primality testing has never been hard by sasami · · Score: 5, Informative

    This result, if true, is very interesting from a theory standpoint.

    As far as practice, it's fairly irrelevant. Probabilistic primality testing can be done in constant time with bounded error.

    The Miller-Rabin test will tell you if a number is prime with at most 1/4 probability of error. That sounds ridiculous, but the catch is that you can iterate it using a random parameter. Do the test twice and your probability drops to 1/16. Do it fifteen times and your chances of being wrong are about one billionth.

    If you're truly paranoid, do it 50 times. That'll bring the error rate of the algorithm magnitudes below the error rate of your hardware.

    ---
    Dum de dum.

    --
    Freedom is not the license to do what we like, it is the power to do what we ought.
  19. Re:What's Polynomial Time? by Kaz+Riprock · · Score: 4, Funny
    Back in the days of parachute pants, leg warmers, and the 80's, there was a man....a man with a rapping and dancing vision. His name...

    MC Polynomial.

    And he sang a song..."P can't Touch This". Before the drum break of this song, Poly sang:

    It's a prime, because you know
    P can't touch this
    P can't touch this
    Stop...Polynomial Time...

    Thus giving rise to a branch of mathematical order functions denoting the complexity of a problem...

    Either that or it's defined pretty well here.

    --
    Mordor...a magical, mythical land where women are more rare than dragons--but where every man would rather find a dragon
  20. Re:Knuth by MrByte420 · · Score: 3, Informative

    a Proof is not rigorus if it depends on unproven theorems. There are many examples if theories that were thought to be true and were later proved to be false. This proof relies on nothing more than a little abastract algebra, some number theory and good ole plain algebra..

    --
    If religous zealots don't believe in Evolution, then why are they so worried about bird flu?
  21. Re:p=np? by Vengie · · Score: 3, Interesting

    3-sat isnt it 3-cnf-sat? or is cnf typically dropped?

    --
    When in doubt, parenthesize. At the very least it will let some poor schmuck bounce on the % key in vi. (Larry Wall)
  22. The question is by einhverfr · · Score: 3, Funny

    Whether polynomial time is longer or shorter than prime time.

    --

    LedgerSMB: Open source Accounting/ERP
  23. O(num_bits**12) time estimates by Adam+J.+Richter · · Score: 5, Interesting

    We give a deterministic O((log n)**12) time algorithm for testing whether a number is prime.

    [Sorry, the Slashdot filter does not allow me to superscript the 12.]

    The algorithm takes O(log2(n)**12) time, where n is number being factored. If we optimistically assume that this algorithm can test the primality of a 16-bit number in one microsecond, then here is how long it would take to test time primality of some larger numbers.

    • 2**12 times as long for a 32-bit number = 4096 microseconds = 4 milliseconds,
    • 4**12 times as long for a 64-bit number = 16,777,216 microseconds = 16 seconds,
    • 8**12 times as long for a 128-bit number = 68,719,476,736 microseconds = 68,719 seconds = 19 hours,
    • 16**12 times as long for a 256-bit number = 281,474,976,710,656 microseconds = 9 years.

    I don't know what a realistic base time for this algorithm really would be, and I don't know where the cross over point against existing exponential time deterministic primality testing algorithms would be, but at least this provide a sense of how log2(n)**12 grows.

  24. Size matters by deblau · · Score: 3, Informative

    Note that this algorithm takes O((log n)^12). For this to actually be faster than, say, factoring n directly, and assuming a multiplicative factor of 1 in the order statistic, n has to be at least 3*10^22, or roughly 75 bits long. This algorithm is probably very ineffective at factoring small integers.

    --
    This post expresses my opinion, not that of my employer. And yes, IAAL.
  25. Re:I always thought is was in P by khuber · · Score: 3, Informative
    Er, I would call a simple divide "considerable".

    Assuming you meant "wouldn't call", division is definitely "considerable". Remember we are talking about large numbers. Try doing long division on paper for 35184535666823 divided by 4194319 (answer is 8388617) and you can see there is some work involved, even with these small numbers.

    The paper method of long division is O(n^2) and it turns out it can be done more efficiently: As I understand it, you can do division in the steps required for multiplication. Therefore the number of operations required to divide two n digit numbers is bounded by the best multiplication which is O(n lg n lg lg n) (from Knuth Volume II).

    This is about 57 for 10 digits and about 182 for 20 digits. You can see that doubling the number of digits here more than triples the required number of operations to compute this result! Likewise 30 digits require about 6 times more operations. You can see that the "n times" grows faster than the number of digits. Thus, division gets slower and slower the more digits you have to divide.

    -Kevin

  26. Re:bad in math? by kavau · · Score: 3, Insightful

    Hold your breath... the algorithm is log2(n)^12 where n represents the number to be tested, not the number of digits. If you denote the number of digits by m, that is, m = log2(n), you get a complexity of O(m^12). The algorithm is therefore polynomial in the number of digits, with a very large exponent of 12. This large exponent could easily hamper the practical use of the algorithm, as Adam correctly demonstrated. The upshot is: Adam is right, RelliK is wrong!

  27. Re:Big consequences related to encryption by fatphil · · Score: 3, Interesting

    The PRP tests used to check numbers for compositeness or probable primality
    actually test to see if this exponentiation procedure works.

    RSA does work with carmichael numbers instead of primes, for example, because

    a^c == a (mod c) for all a s.t. (a,c)==1, c a carmichael number

    Try it - it works!

    Phil

    --
    Also FatPhil on SoylentNews, id 863
  28. Re:What's Polynomial Time? by Goonie · · Score: 3, Informative
    Well, there are things that are definitely outside polynomial time - the halting problem for instance, which is undecidable no matter how much time you have. There are also problems that provably take exponential time even on a nondeterministic Turing machine. However, you are quite correct that TSP or SAT just might be in P (but it's pretty damn unlikely).

    I was trying to keep it simple because the original poster said that he didn't know anything about theoretical CS.

    --

    Any sufficiently advanced technology is indistinguishable from a rigged demo
    --Andy Finkel (J. Klass?)
  29. Re:What's Polynomial Time? by Salsaman · · Score: 5, Funny
    There is a remote island in the South Pacific called 'Polynosia' (not to be confused with 'Polynesia').

    The island has a number of strange customs.

    1) All the women on this island are called 'Polly' in reverence to the island's god, Polynose.

    2) The men of the island are very philosphical (maybe because all the women are called Polly, so it gets very confusing). They spend most of their time poring over mathematical problems.

    3) The island has strict laws on the use of technology. Telephones are not allowed, aircraft are not allowed to land there, in fact the only way to reach the island is by boat, nevertheless it is very popular with tourists.

    4) It is considered offensive to Polynose for anyone who is not a Polynosian woman (a Polly) to prepare food. Since the island is popular with holiday makers though, all of the enterprising Polly's have opened small restaurants called 'Polly-meal-time'.

    The men of the island, in order to discuss their mathematical musings, recently opened a cafe. To distinguish this from all the restaurants, they named it 'Polly-no-meal-time'.

    The article reports that recently a boatload of mathematicians visited Polynose, and told the island's men how to check if a number is prime.

    Thus the headline 'Primes can now be solved in Polly-no-meal-time'.

    /me ducks :-)

  30. Please STOP! by phliar · · Score: 4, Insightful
    Everyone: just because you start out by writing "I'm no mathematician, but..." doesn't means you can pull crap right out of your ass. Words mean things, and when you talk about math, words mean things exactly. Please don't misuse them.

    It's the Sieve of Eratosthenes. A number n is of size log(n). This is a deterministic algorithm; why bring up NP? What is the time complexity of division? And here's a hint: you start with n-digit (n=100) numbers and present an algorithm that runs in time 10^n. This is in P?

    Has anyone actually read the paper? The algorithm is outlined, with a complexity analysis. Don't forget, P-time doesn't mean usable.

    --
    Unlimited growth == Cancer.