mpz_nextprime deficiencies

Zimmermann Paul Paul.Zimmermann at loria.fr
Sun Sep 11 20:59:03 CEST 2011


       Dear Heinz,

> Date: Sun, 11 Sep 2011 10:30:50 +0200
> From: Heinz van Saanen <van.saanen at aon.at>
> 
> Hello,
> 
> mpz_nextprime is convenient, fast - and fails a bit too often. E.g:
> 
> 
> #include <gmp.h>
> 
> int main (void) {
> 
>      mpz_t p;
> 
>      // p+1 is NOT prime !!!
>      mpz_init_set_str(p, "189452997113368438678230", 10);
> 
>      while (1) {
>          mpz_nextprime(p, p);
>          if ( mpz_probab_prime_p(p, 14) == 0 )
>              gmp_printf("A false mpz_nextprime : %Zd\n", p);
>      }
> 
>      return 0;
> }

this is well known. See for example
http://www.trnicely.net/misc/mpzspsp.html#GMP431

> You may avoid this with a "counterpart" to mpz_probab_prime_p:
> 
> void mpz_nextprime (mpz t rop, mpz t op, int reps)

this is indeed a function I'd also like to have (with a different name
due to upward compatibility, maybe mpz_nextprime_reps).

Paul Zimmermann


More information about the gmp-bugs mailing list