Does the number of reps for mpz_probab_prime_p() really change much?

Dennis Clarke dclarke at blastwave.org
Wed Apr 29 23:27:09 CEST 2026


Dear Numerical deities :

I was fascinated by the manpage for mpz_probab_prime_p() at

     https://gmplib.org/manual/Number-Theoretic-Functions

     5.9 Number Theoretic Functions

     Function: int mpz_probab_prime_p (const mpz_t n, int reps)

     Determine whether n is prime. Return 2 if n is definitely prime,
     return 1 if n is probably prime (without being certain),
     or return 0 if n is definitely non-prime.

     This function performs some trial divisions, a Baillie-PSW probable
     prime test, then reps-24 Miller-Rabin probabilistic primality tests.
     A higher reps value will reduce the chances of a non-prime being
     identified as “probably prime”. A composite number will be
     identified as a prime with an asymptotic probability of less
     than 4^(-reps). Reasonable values of reps are between 15 and 50.

     GMP versions up to and including 6.1.2 did not use the Baillie-PSW
     primality test. In those older versions of GMP, this function
     performed reps Miller-Rabin tests.


Well that looks like just way too much fun to pass up playing with.

After writing up something[1] to go looking for twin primes p and p+2
it seemed reasonable to mess with the "reps" number. No matter what
I set past 24 the results really do not change. Is this a feature or
function that only gets interesting for really really big numbers up
in the 10^90 zone? Just curious.

My code suggests that input 2462906046175243 has results 50% certain
and the rest are probably primes. Maybe. Changing the reps to 48 or
downwards to 15 seems to make no difference.

Is that just the way things are ?

Also, whatever happened to GMP-ECM? [2]

-- 
-- 
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken

[1] https://git.sr.ht/~blastwave/bw/tree/bw/item/gmp_mpfr/pair.c

[2] is there a definitive place/URL where the most recent GMP-ECM
     code work resides?


-- 
--
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken



More information about the gmp-discuss mailing list