Ask Your Question
0

Binomial expansion

asked 2022-05-02 09:16:16 +0200

Emmanuel Charpentier gravatar image

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 flag offensive close merge delete

Comments

1

What is a¨b ?

tmonteil gravatar imagetmonteil ( 2022-05-02 11:28:03 +0200 )edit

a typo for a+b.

Sorry...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-05-02 23:25:13 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2022-05-06 18:30:53 +0200

dan_fulea gravatar image

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

edit flag offensive delete link more

Comments

@dan_fulea :

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

Thanks for your answer. Close, but no cigar..

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-05-07 20:56:28 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-05-02 09:16:16 +0200

Seen: 330 times

Last updated: May 06 '22