View Single Post
Old 2017-01-21, 05:31   #8
CRGreathouse's Avatar
Aug 2006

3×1,993 Posts

Originally Posted by a1call View Post
Are there any values that you know of, that yield false but are in fact prime?
That shouldn't be too difficult to check given the limited number of known MPs.
The Mersenne exponents through 44497 check out. There are no false positives through 23209. I'm using this PARI code which should be somewhat more efficient than the GP above.
#include <pari/pari.h>
/* For use in gp:

testMersenne(ulong p)
  if (p < 4) return p > 1;
  pari_sp av = avma;
  GEN n = subiu(int2u(p), 1);
  pari_sp btop = avma;
  GEN a = utoipos(4);
  ulong k;
  long ret;
  for (k = 2; k <= p; ++k) {
    a = remii(shifti(addii(sqri(a), a), 1), n);
    if (gc_needed(btop, 1))
      a = gerepileuptoint(btop, a);
  ret = absequaliu(a, 4);
  avma = av;
  return ret;
CRGreathouse is offline   Reply With Quote