| 1 | initial version |
The more "complicated" step of giving the compact expression for the sum $\displaystyle\sum_{0\le k\le n} \binom nka^kb^{n-k}$ is successfully delivered in sage.
sage: var('a,b,k,n')
(a, b, k, n)
sage: sum(binomial(n, k)*a^k*b^(n-k), k, 0, n)
(a + b)^n
But for the converse step, i do not see the reason to get the expansion (exactly in the form above, not with $a,b$ replaced, using $k$ as a running variable). I never saw this, i never felt the need for this in the given generality. Of course, for explicit, non-variable values of $n$ we can ask for the expansion:
sage: ((a + b)^5).expand()
a^5 + 5*a^4*b + 10*a^3*b^2 + 10*a^2*b^3 + 5*a*b^4 + b^5
Usually, we are using computer algebra systems (CAS) for a special (mathematical) human purpose, not for implementing all possible operations. Humans have a kind of sense for the progress, and implement then operations that are supporting the progress, thus simplifying an expression, making it more compact, is a wanted operation. Expanding the sum $(a+b)^n$ is not a simple task, since the implementer has to do this only for special cases. (Is the given expression a power? Is the exponent $n$ here, but maybe $n!+2022n(n+1)/2$ somewhere else, integer? Is the base, $a+b$ here, but $abc^7+nb^b$ elsewhere, a binomial? If yes, and this does not happen very often, provide a method expand_binomial maybe for the given expression.) Wanting the method is simple and natural, but implementing it...
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.