proposal to change the return type/value of mpz_primorial_ui

Marco Bodrato bodrato at mail.dm.unipi.it
Mon Nov 8 17:57:44 UTC 2021


Ciao, Shane,

> On Sat, Nov 6, 2021 at 1:31 PM Marco Bodrato <bodrato at mail.dm.unipi.it> 
> wrote:
>> Il 2021-11-03 19:18 Shane Neph ha scritto:
>> > mpz_primorial_ui( ) is a great function.  Why not return the actual
>> > number of primes that go into that calculation?
>> 
>> It may make sense, but only if we add also another function: a way to
>> compute the number of primes in a range; or at least in the
>> range [1..n], i.e. pi(n) for a given unsigned long n.

Il 2021-11-06 22:29 Shane Neph ha scritto:
> That would be a nice solution.

If you really need both the primorial and the prime count, my solution 
is somehow a waste, because no memory of the sieved numbers is kept 
between the library calls. The numbers are sieved twice...

I got inspired by a piece of code that Seth Troisi sent a couple of 
years ago and I wrote a gmp_pi_ui(n) function with two variants, a 
trivial one (it calls gmp_primesieve) and an implementation of the 
Legendre strategy.

I attach it for comments. Compiled with -DMAIN it prints the number of 
primes up to increasing powers of two. On my computer, with small ranges 
it is slower than GP/Pari, for large ranges, it is faster...

Ĝis,
m
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pi.c
Type: text/x-c
Size: 4290 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20211108/9af1daa5/attachment.bin>


More information about the gmp-devel mailing list