# Binomial expansion

Let :

var("a, b, c, j", domain="integer")
assume(a>0, b>0, c>0)
ex=(a¨b)^c


I want to get the bionomial expansion of ex, i. e. sum(binomial(c, j)*a^j*b^(c-j), j, 0, c). I seem to rember that such a way exists in Sage, but for dear life I'm unable to remember it.

Can some kind soul come to the rescue of my aging neurons ?

edit retag close merge delete

1

Sort by » oldest newest most voted

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...

more

But for the converse step, i do not see the reason to get the expansion...

In this question, the OP was baffled by the fact that the solution given by Sage's solve_diophantine iq riddled with terms of the form $(a+b\sqrt{2})^t,\ t\in\mathbb{N}$, yet all solutions were integers for a large range of $t$. The key to explain this is that the terms of the successive powers of $b\sqrt{2}$ in the development are of alternating signs and cancel out. Therefore, I needed Sage to develop this expression.

I seem to remember to have seen this substitution "somewhere in Sage's documentation", but my aging neurons won't allow me to retrieve what I'm hunting...