marc.glisse at inria.fr
Fri Nov 13 13:57:13 UTC 2015
(apparently I forgot to click on "send")
On Thu, 12 Nov 2015, paul zimmermann wrote:
>> Suggestions for the interface?
I don't have any particular suggestion. I have only needed this once, and
it would help if other people who have needed something similar could
explain what it was. If nobody needs it, we can forget it. And even
otherwise, I am not sure it belongs in GMP. Just asking.
In our case, we have code to compute (persistent) homology in several
fields Z/pZ at the same time, and the idea was to get a bunch of primes
(the most natural notion of bunch was those in some interval [p,q]).
Getting the primes takes a negligible amount of time compared to the rest.
> mpz_prime_t p;
> mpz_prime_init_ui (p, 17); /* initializes p to 17 */
> mpz_prime_next (p); /* p <- next_prime(p) */
> mpz_prime_clear (p);
> We could access the current prime by:
> mpz_prime_get_z (z, p);
mpz_prime_next vs mpz_nextprime is going to get confusing :-(
Maybe mpz_primes_* (plural) or some other longer name would help convey
In my original use-case, I want all primes between p and q (though I am
mostly interested in p=2). Does not knowing an upper bound complicate the
The idea was to use a simple sieve. If we don't start from 2, the doc
needs to be clear that you will pay for the sieve even if you are only
asking for a single prime.
If we are interested in small primes, using mpz_t could be wasteful. Maybe
mpz_prime_get_ui (p), and it would return 0 instead of the prime if it
doesn't fit? Enumerating all the primes that fit a 32-bit unsigned long
should be doable, so maybe having unsigned long as the only possible type
would be too restrictive?
More information about the gmp-discuss