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 <> states this:


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 <>.

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:

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