# primorial(negative)

Marc Glisse marc.glisse at inria.fr
Tue Nov 10 06:39:35 UTC 2015

```On Mon, 9 Nov 2015, Marco Bodrato wrote:

> Ciao,
>
> Il Dom, 8 Novembre 2015 9:27 am, Marc Glisse ha scritto:
>> add primorial. However, I am not sure what the expected behavior is for
>> negative numbers. For factorial it was a clear error. For primorial, we
>> could return 1, same as we do for primorial(0). Or we could throw as we do
>> for factorial. Any opinion?
>
> We have never been completely coherent with primes and negative numbers, I
> fear:
> mpz_probab_prime_p (-3) returns "prime", but
> mpz_nextprime (-5) returns 2 ...
>
> I do not see any particular mathematical meaning for primorial (-n).

Prod_{p prime, p<=n} p
for n=1, n=0, n=-1, etc, the list is empty, so the product is 1 (that's
what I have in the current version of the code).

> I'd explicitly document that the function is defined only for
> non-negative numbers...

Ok, I'll change the function to throw an exception, like factorial. I
assume it should only throw for negative numbers, not 0 or 1?

Any opinion on fibonacci for negative numbers? The recursion makes it well
defined for negative numbers (f(-n) is f(n), except that the sign depends
on the parity of n).

Other functions you would particularly like to see in the C++ interface?
(I'd like 'binomial', but it is a bit more complicated because it takes 2
arguments)

Two things I would have liked recently:
1) mp*_hash so I could specialize http://en.cppreference.com/w/cpp/utility/hash
(I only want to interface it, I don't want to write or even review such an
implementation myself because I don't know anything about hashes, and
since it does not require a cryptographic hash we might want to give it
an ugly name like mp*_hash_weak so people are not tempted to misuse it)
2) (probably more from the C side) The last time I wanted primorial(n), I
also wanted the corresponding list of primes. Using mpz_nextprime is not
the same thing, and since primorial already computes the list anyway, I
don't really feel like re-implementing a sieve...

--
Marc Glisse
```