Ask Your Question

Revision history [back]

Incorrect symbolic sum w/binomial coefficients

This should give (t+1)^(n-1), but instead it gives 0:

sage: var('n k t');
sage: sum(binomial(n-1,k-1)*t^(k-1), k, 1, n)
0

A version w/o -1's works correctly:

sage: var('n k t');
sage: sum(binomial(n,k)*t^k, k, 0, n)
(t + 1)^n

With -2's, it's left unevaluated:

sage: var('n k t');
sage: sum(binomial(n-2,k-2)*t^(k-2), k, 2, n)
sum(t^(k - 2)*binomial(n - 2, k - 2), k, 2, n)

However, Mathematica and Maple can do problems like this. E.g., in Mathematica,

In[1]:= Sum[Binomial[n-2, k-2]*t^(k-2), {k, 2, n}]
Out[1]= (1 + t)^(-2 + n)

With positive offsets instead of negative offsets, it works correctly:

sage: var('n k t');
sage: sum(binomial(n+2,k+2)*t^(k+2), k, -2, n)
(t^2 + 2*t + 1)*(t + 1)^n

The result is correct, although it could be simplified better: (t + 1)^(n + 2)

Version: 'SageMath version 9.2, Release Date: 2020-10-24'

I also get the same results on sagecell.sagemath.org