Ruud H.G. van Tol on Sun, 23 Oct 2022 14:53:03 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: binomial coefficient with negative args



On 2022-10-22 21:46, Christian Krause wrote:

the binomial coefficient in GP behaves differently than I thought for negative arguments. For instance, binomial(-2,-4) yields 0 (zero). In Wolfram Alpha the result is 3. The paper by Kronenburg <https://arxiv.org/pdf/1105.3689.pdf> states this:

image.png

For binomial(-2,-4), the second case applies: (-1)^(-2+4) * binomial(4-1,-2+4) = binomial(3,2) = 3. This is consistent with Wolfram Alpha. They also document the same definition here <https://mathworld.wolfram.com/BinomialCoefficient.html>.

Why does PARI/GP yield different results for binomial() with negative arguments?

I assume that is because the needed extension was just never implemented.

See src/basemath/bibli2.c, lines 1012 and after:

GEN
binomial(GEN n, long k)
[...]
if (k < 0) return gen_0;

-- --

Simplistic workaround:

? my_binomial(n,k)=if(k>=0,binomial(n,k),(-1)^(n-k)*binomial(-k-1,n-k))
%1 = (n,k)->if(k>=0,binomial(n,k),(-1)^(n-k)*binomial(-k-1,n-k))

? my_binomial(-2,-4)
%2 = 3

-- Ruud