# mpz_prevprime

Marco Bodrato bodrato at mail.dm.unipi.it
Thu Aug 22 16:59:15 UTC 2019

```Ciao,

Il Gio, 22 Agosto 2019 10:32 am, Niels Möller ha scritto:
> "Marco Bodrato" <bodrato at mail.dm.unipi.it> writes:
>> I'd suggest to extend the range for mpz_nextprime.
>> Can we consider both positive and negative primes?

> I think that's a bit unusual. We can compare with the corresponding
> functions in pari/gp. These differ from gmp by nextprime(p) == p
> if p is prime. And they don't consider negative numbers to be primes.

You are right, and the last one is a relevant difference.

Within pari/gp we have:

? isprime(17)
%1 = 1
? isprime(-17)
%2 = 0

For our library, if we have
mpz_neg (x, y);
then the following condition is always true (for any y and n):
mpz_probab_prime_p (x, n) == mpz_probab_prime_p (y, n)

If p is a positive prime, -p is a prime element in the ring of integers.
Right?

So, if we consider -7 as a prime number, then why should we say that 2 is
the correct answer to _nextprime if e.g. -10 is given as a starting point?

Ĝis,
m

```