1
$\begingroup$

I am defining a function that involves a sum of binomial coefficients:

a[r_, k_, mx_] = Sum[Binomial[r + 2*k - d, d], {d, k, mx}]

For some inputs, this works fine. For others, it gives an indeterminate result. For instance:

In[235]:= a[4, 1, 3]

Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >>

There is no issue when computing the same sum but not as a function e.g.

In[232]:= Sum[Binomial[4 + 2*1 - d, d], {d, 1, 3}]
Out[232]= 12

Moreover, the sum in this case amounts to 5+6+1=12, so nothing strange is going on.

Any suggestions of what is going wrong and how to fix it? I have a feeling it has something to do with the HypergoemtricPFQ function that is used to evaluate the Binomial expressions. Thanks!

$\endgroup$
2
  • 1
    $\begingroup$ You should use := when setting the function $\endgroup$
    – Feyre
    Aug 3 '16 at 17:23
  • $\begingroup$ "I have a feeling it has something to do with the HypergeometricPFQ[]" - yes, the result returned is only generically correct, and can fail for special inputs, which unfortunately are the ones you're interested in. $\endgroup$ Aug 3 '16 at 17:34
1
$\begingroup$

Use SetDelayed to define your function:

In[24]:= a[r_, k_, mx_] := Sum[Binomial[r + 2*k - d, d], {d, k, mx}]

In[25]:= a[4, 1, 3]
(*Out[25]= 12*)
$\endgroup$
0

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.