I've obsoleted then MPIR function
int mpz_probab_prime_p (mpz_t N, int REPS)
The reasons for this are mainly that the random state used in the above
algorithm is reset on every function call. So two consecutive calls to this
function are NOT independent. The other reason is that the parameter REPS is
dependant on the algorithm used(which is Miller-Rabin).
We will maintain the old function interface for some time to come to maintain
compatibility.
The question remains as what to offer as a replacement. We could of course
offer no replacement? or at the bare minimum
int mpz_probable_prime_p (mpz_t N, int REPS, gmp_randstate_t STATE)
However I would like to suggest something like this.
Note: Some of these may not be functions but macros.
int mpz_practical_probable_prime_p(mpz_t N, gmp_randstate_t STATE)
return true if N is probably a prime and return false if N is certainly a
composite or (0,1,-1) . NOTE: I say N is probably a prime , NOT N is a
probable prime , which can mean something specific.
This would be the function that you would use in a integer prime factorization
program , optimized for speed , implemented as a bit of trial division , and
one iteration of small base random strong pseudoprime test , with corners cut
to make run faster(on average).
And the mathematically better defined
int mpz_probable_prime_p(mpz_t N, int PROB, gmp_randstate_t STATE)
return true iff N is a probable prime with less than 1/2^PROB error. This
allows us to use different algorithms to achieve the same maximum probability
of error. This would implemented robustly using the random strong pseudoprime
test , RQFT test and others. The underlying functions for this could be
exposed to the user, and shared with some other new mpz functions.
Jason
Here are the new functions:
int mpz_practical_prime_p(mpz_t N, gmp_randstate_t STATE,unsigned long div)
return true if N is probably a prime and return false if N is certainly a
composite or (0,1,-1) . NOTE: I say N is probably a prime , NOT N is a
probable prime , which can mean something specific.
This would be the function that you would use in a integer prime
factorization program , optimized for speed , implemented as a bit of trial
division , and one iteration of small base random strong pseudoprime test ,
with corners cut to make run faster(on average).div is a trial division bound
of which you have allready searched up to.
And the mathematically better defined
int mpz_probable_prime_p(mpz_t N, int PROB, gmp_randstate_t STATE,unsigned
long div)
return true iff N is a probable prime with less than 1/2^PROB error. This
allows us to use different algorithms to achieve the same maximum
probability of error. This would implemented robustly using the random
strong pseudoprime test , RQFT test and others. div is a trial division bound
of which you have allready searched up to.
I have said that the new function interfaces are preliminary , in case we want
to change anything.
This brings into question what the new mpz_next_probable_prime should do , ie
should it be practical or probable (with a defined probability) , at the
moment it is just the old mpz_probab_prime with 5 reps which would be
equivalent to a probability of 1 in 4^5 . Note: this is a maximum error and
is WAY over the top of most reasonable applications.
What do people think? What should we do ? , I am leaning towards having both
next_practical and next_probable(with a stated probability)
Jason
Note: The trial division I have used in the above fn's is just for
correctness , I will put faster code in a few days , so dont laugh at to
much :)
> Or getting rid of the mpz_next_prime_thing all-together , cant say I like it
> much. What do people use it for ?
I actually use it and find it very useful. If I'm doing some kind of
testing or other calculations on increasing primes it is very useful
just to call that function to get the next one to work with.
Right now unless you dig into the code it is hard to tell what the two
current prime functions really do. So a new defined function that
either provides a way to specify the algorithm to use or have
something very clearly defined would be a great benefit. If someone
is trying to do work that needs to be repeatable it would be good to
have a way for people to say, "Use MPIR with this is_prime/prob_prime
function using these parameters"
Jeff.
Looking quickly at the code, it seems that a version with sieving has
been written but it hasn't been tested or enabled.
I have changed the name to mpz_likely_prime_p , and I will do the same for the
nextprime one so that will now be mpz_next_likely_prime
Jason
> Hi , did you mean that results should be repeatable across different
> arch's ie 64/32bit ? or just repeatable on a set arch?
A set architecture would be fine, so people could say, using arch X,
with MPIR vY.Z then using this function with this seed will give you
the following output...
> For a set arch and random seed then everything is repeatable. For a
> set random seed and any arch then the urandom functions (uniformly
> distributed) are repeatable(or should be!!!) , the rrandom fn's are
> not. The mpz_probable_prime_p fn is "not" , although this is only
> because on some arch'es it may be faster to do more trial division
> than on others and so if you are (un)lucky you will give the function
> a number which is composite but passes the miller-rabin test but fails
> the trial div test. The mpz_likely_prime_p test is optimized for speed
> so has no guarentee , same for mpz_next_likely_prime_p.
The likely ones as you said are for speed so that is fine. It would
be good to document what you said above about arch/random seed being
repeatable or not just so people are aware in case they want to use
stuff across different platforms/archs.
Jeff.