The Lucas-Lehmer Prime Number Test

(scientificamerican.com)

61 points | by beardyw 7 days ago

5 comments

  • jmount 6 hours ago
    The original Agrawal, Kayal, Saxena "Primes is in P" paper is actually an amazing effort in clarity https://annals.math.princeton.edu/wp-content/uploads/annals-... .
  • IsTom 8 hours ago
    My favourite prime checking algorithm is that for n < 100 if it looks prime, it is prime.
    • freehorse 6 hours ago
      Up to 100 it is relatively simple, if you remove the even numbers, the multiples of 3 (summing up their digits recursively gives 3 6 or 9), and those that end at 5, you end up with 25 numbers out of which 22 (88%) are primes. If you further exclude 49 which you should remember is 7^2 from the multiplication table, and 77 that is obviously divisible by 7, you are left with 22/23 chance a number that passes these exclusion criteria is not 91 and hence it is a prime.
      • jeffbee 5 hours ago
        > summing up their digits recursively gives 3 6 or 9

        What does this part mean? For example 57.

        • zdimension 5 hours ago
          57 is 3 times 19.

          The standard divisibility rule for 3, 6 and 9 in base 10 is to sum the digits until you only have one left and check if it's one of those. Here, 5+7=12, 1+2=3, so 57 is divisible by 3.

          • jeffbee 5 hours ago
            Ah I see what is meant by recursively here. Thanks!
        • hollerith 5 hours ago
          5 plus 7 is 12, which of course has a 1 and a 2, the sum of which is 3.
    • throwaway81523 7 hours ago
      Like the famous Grothendieck prime of course.
      • xorbax 7 hours ago
        Definitely makes me feel better about my own work
    • emaccumber 7 hours ago
      The annoying child in me will always remember correcting my freshman math teacher when he needed a prime number and wrote 91 on the chalkboard.
    • GMoromisato 7 hours ago
      Are there any numbers that don't look prime but are, in fact, prime? [Other than 2, I suppose.]
      • andruby 6 hours ago
        11, 13, 17 and 19 used to trip me up. And maybe 67
        • mootothemax 3 hours ago
          67 has absolutely no right to be prime. Sitting there looking all innocent.
    • wbl 1 hour ago
      57
    • conradev 6 hours ago
      This only works if you know multiplication tables which is not a given in America these days.
      • gosub100 5 hours ago
        "not given" != "not able to learn"
    • ridiculous_fish 6 hours ago
      Except 91.
  • Nevermark 8 hours ago
    Just grab some paper, a pen, and check that no number equal or smaller than its square root divides into it evenly.

    That is it. That is all. Pish posh.

    • WCSTombs 8 hours ago
      The example given in the article is 2^127 - 1, which was historically proved to be prime without computers using a clever method now known as the Lucas-Lehmer test. Your algorithm is not practical for that number.
      • Nevermark 7 hours ago
        Ah, but I can assure you, it is just that simple.

        If a number is not prime, then it is the product of at least two numbers smaller than itself.

        If any of them are larger than its square root, all others must be smaller, or their product would be larger than the candidate prime.

        Ergo, just check that the candidate is not evenly divisible by any number equal or lower than its square root.

        This reasoning holds, independent of scale.

        QED. Check mate. Shazam.

        • mysterydip 7 hours ago
          Perfect example of how "if the code is compact, it's fast" can be deceiving :)
          • Nevermark 2 hours ago
            Search is all you need!

            If you have the time.

            Or if we can expand quantum superposition algorithms from 2^N states, for quantum circuits with N control qubits, to 2^(T*N) superpositions over T time steps, via some kind of superposition tree recursion. The number of superpositions increasing exponentially for T steps (and then reducing for another T steps) on a single recursive physical circuit.

            That is not supported by the physical laws we have, but it is an interesting idea.

        • xpe 5 hours ago
          The obvious and naive method described above is O(sqrt(N)). For N ~= 2 ^ 127, that is about 2 ^ 64. / The Lucas-Lehmer method described in the article is better (how much better is an exercise for the reader).
      • great_wubwub 8 hours ago
        /r/whoosh
        • eps 7 hours ago
          Nah, the joke just was fairly flat and low-effort.
  • NetMageSCW 6 hours ago
    Pay wall.
    • WolfeReader 6 hours ago
      Imagine browsing the web without an ad blocker.
  • politelemon 8 hours ago
    [flagged]
    • zamadatix 8 hours ago
      The scourge of HN submission rules - "you can submit anything and it's up to everyone else to actually be able to access it".

      https://archive.is/8R0Fq

      • tomhow 5 hours ago
        The HN rule is that anything can be posted if it is accessible to everyone, including via a paywall workaround if it has a paywall that is porous.

        The community has converged on this being the least-worst approach after wrestling with the issue for well over a decade, and it's sufficient to helpfully post the archive link with a snarky editorial comment :)

      • Terr_ 8 hours ago
        If I had my 'druthers designing a new link-share/comment system, the visibility (and mirrors or excerpts) for the target would be part of the model.

        In other words, an icon showing whatever-wall status, submitter can add an alternate link, etc.

    • smcin 5 hours ago
      The standard etiquette on HN is not to bother saying that, just post its archive link already.
    • xeonmc 8 hours ago
      I guess that's the answer then -- you need a subscription instead of a computer.
    • NSPG911 7 hours ago
      i found out that most articles behind paywalls dont even need the wayback machine to be viewed

      if you are using firefox, just enter reading mode and you can read the entire article without popups in your preferred background, text color, font, etc