proposal to change the return type/value of mpz_primorial_ui

Marco Bodrato bodrato at
Sun Nov 14 12:11:57 CET 2021

Ciao Shane,

Il 2021-11-11 23:58 Shane Neph ha scritto:
> First, thank you for your work.  I will be using it.  I'd like to see
> it or similar become part of the GMP library.

I'm not sure you can use it! :-D
I forgot a licence, so the default is "all rights reserved".
I send the code again, with a GPLv3+ licence, and a correction such that 
the function works also for the value 2^32-1 in a 32-bits environment.

Moreover, remember that this implementation uses functions that are 
internal, undocumented, and because of this subject to unexpected 
changes in the future.

Before seeing something like this in GMP, we have to at least decide the 
interface :-)
To write the function, I got inspiration from a code by Seth Troisi, who 
used more than a call to the prime counting function to get the n-th 
prime number. Should we allow recycling parts of the computations 
between calls? How?

> I also would like to see the primordial function return that same
> value because it knows the value.

True, but this is not the only information that the function "knows" and 
might be useful. Why not returning, e.g., the larger prime?

> In my work, I use primordial in ways similar to factorials, and I use
> it over a factorial because it simply grows faster.

Not the implementation in GMP :-)
mpz_primorial_ui is the "square free" version of mpz_fac_ui :-D
Strictly smaller, when the argument is larger than 3.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: pi_devel.c
Type: text/x-c
Size: 5934 bytes
Desc: not available
URL: <>

More information about the gmp-devel mailing list