0
$\begingroup$

A problem that I encountered multiple times when taking sums over expressions involving binomials, factorials, etc. is that Mathematica (version 11.2) returns indeterminate expressions when it should not.

An example:

If an urn contains n balls out of which q balls are red and n-q balls are blue. There are Binomial[q, z]*Binomial[n - q, k - z] possibilities for drawing k balls out of the urn so that z drawn balls are red and k-z drawn balls are blue. Summing over all possible values of z, one should obtain the total number of possibilities to draw k balls from the urn (regardless their colour). This number is Binomial[n,k].

Let's get Mathematica to compute this.

Sum[Binomial[q, z]*Binomial[n - q, k - z], {z, 0, k}]

This returns

((-1)^(2 + k) (-1 + k - n)!)/(k! (-1 - n)!)

This expression is indeterminate because (-1 + k - n)! and (-1 - n)! evaluate to ComplexInfinity.

I can get Mathematica to produce the correct result by substituting n->k0+k:

Sum[Binomial[q, z]*Binomial[k0 + k - q, k - z], {z, 0, k}]

This returns

(k + k0)!/(k! k0!)

which simplifies to Binomial[n,k] if I reverse the substitution.

It seems unsatisfying to me that Mathematica's result depend so sensitively on the way I define my variables. Why is that so and what can I do to ensure that I always define my variables in a way that Mathematica produces the correct results?

I have tried using assumptions but with no success. The lines

Assuming[n > k, Sum[Binomial[q, z]*Binomial[n - q, k - z], {z, 0, k}]]
Assuming[k0 > 0, Sum[Binomial[q, z]*Binomial[k0 + k - q, k - z], {z, 0, k}]]

produce the same results as if I wouldn't use Assuming.

$\endgroup$
1
$\begingroup$
s2 = Sum[Binomial[q, z]*Binomial[n - q, k - z], {z, 0, k}, 
  Assumptions -> {q, z, n, k} \[Element] Integers && k <= q && k - z <= n - q]

((-1)^(1 + k) n Pochhammer[1 - n, -1 + k])/k!

FullSimplify[s2 == Binomial[n, k], Assumptions -> {n, k} \[Element] Integers && k <= n]

True

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.