I'm working with this function

aExpl[G_,T_] := -2^(G - 2 T) Sum[(-1)^r (2 r - 1) Binomial[G,2 r] Sum[(-1/2)^j Binomial[r, G - T - j] Binomial[G - T - j,T], {j, G - T - r, G - 2 T}], {r, T, G/2}]

and I have no problems with it when written like this. Specifically, I get

aExpl[0,0] = 1
aExpl[1,0] = -1
aExpl[2,1] = 1

as you can check for yourself. I would like to have my sums evaluated and I tried to do that with and without specifying my conditions in more than one way. But whatever I do, the answer comes out as

((-1)^(1 + G - T) 2^(-1 + G) ((-1 + G - T) (-1 + 2 T) Binomial[G, 2 T] + (1 + T) (1 + 2 T) Binomial[G, 2 (1 + T)]) Gamma[-1 + G - T] Gamma[1/2 + T])/(Sqrt[\[Pi]] Gamma[G])

which obviously doesn't work for those three specific values. I tried redefining the function in parts, so that the above result holds for values that interest me and are defined (G>=2T && G>=3), along with setting problematic values explicitly.


This gives the correct result for all values, but the main reason why I have the function aExpl[G,T] in the first place is to sum it over Gs and Ts. But I can't do that, because Mathematica messes something up again. For Example aExpl[0,T] gives 0, which obviously isn't the case.

What in the world is going on here? :O

  • $\begingroup$ What code did you use to generate that unsatisfactory "sum" expression? $\endgroup$
    – MarcoB
    Jan 15, 2021 at 18:27

2 Answers 2


alYour result is actually a rather pathological function. The problematic term is the ratio of Gamma[G - T - 1]/Gamma[G] for integer arguments, which gives indeterminate (infinity/infinity) whenever (G == 0 && T [Element] Integer) and infinity (sometimes multiplied by zero from the rest of the result function) whenever (G, T [Element] Integer) && (G <= T + 1). You would have to set explicit values for all cases with G = 0 and all cases with (G, T [Element] Integer) && (G <= T + 1) that 'interest' you.

Edit: Now I think there is no real problem here. For all cases (apart from the three you quoted) the result is correct:

Table[{{G, T}, 
aExpl[G,T], (1/(Sqrt[Pi]*Gamma[G]))*(-1)^(1 + G - T)*
2^(-1 + G)*((-1 + G - T)*(-1 + 2*T)*Binomial[G, 2*T] + (1 + T)*(1 + 2*T)*
Binomial[G, 2*(1 + T)])*Gamma[-1 + G - T]*Gamma[1/2 + T]},
{G, 0, 7, 1}, {T, 0, G/2, 1}]]]

The three cases have the problem with the Gamma function I described above. And the case (G=0,T) is not covered by your condition (G>=2T && G>=3) and restricts the summation to zero.


Your summation function has certain peculiar behavior which needs to have special cases beyond the general cases. Your original function (with tweaks):

aExp1[G_Integer, T_Integer] := -2^(G - 2 T)
   Sum[(-1)^r (2 r - 1) Binomial[G, 2 r] 
      Sum[(-1/2)^j Binomial[r, G - T - j]
                   Binomial[G - T - j, T], 
   {j, G - T - r, G - 2 T}], {r, T, G/2}];

My version without explicit summation is the following:

aexp1[G_Integer, T_Integer] := If[T<0 || G<2 T,
   0, -(-1)^(G+T) 2^(G-2 T-2) If[G<=2, 2,
   If[T==3, 1/2, 1]] Which[T==0, G-2, T==1,
      G (G-1), True, G (G-1) (G-2) Product[
      G-T-i, {i, 2, T-1}] / 
   If[T<4, Max[1, T], T!]]];

My version returns 0 if T<0 or G<2*T while your version returns non zero results for those cases.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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