1 | initial version |
What should I do?
Nothing ;-).
Let's start from the binomial formula :
sage: a, b, c, i, j = var("a, b, c, i, j")
sage: BF=(a+b)^i==sum(a^j*b^(i-j)*binomial(i, j), j, 0, i, hold=True) ; BF
(a + b)^i == sum(a^j*b^(i - j)*binomial(i, j), j, 0, i)
($$ {\left(a + b\right)}^{i} = {\sum_{j=0}^{i} a^{j} b^{i - j} \binom{i}{j}} $$
Let's generalize it by using wildcards :
sage: w0, w1, w2 = (SR.wild(u) for u in range(3))
sage: BFG = BF.subs({a:w0, b:w1, i:w2}) ; BFG
($1 + $0)^$2 == sum($1^($2 - j)*$0^j*binomial($2, j), j, 0, $2)
$$ {\left(\$1 + \$0\right)}^{\$2} = {\sum_{j=0}^{\$2} \$1^{\$2 - j} \$0^{j} \binom{\$2}{j}} $$
and use it on a general form of your original expression :
sage: Ex=(a + b)^i + (a - b)^i ; Ex
(a + b)^i + (a - b)^i
$$ {\left(a + b\right)}^{i} + {\left(a - b\right)}^{i} $$
sage: ExT=Ex.subs(BFG) ; ExT
sum(a^j*(-b)^(i - j)*binomial(i, j), j, 0, i) + sum(a^j*b^(i - j)*binomial(i, j), j, 0, i)
$$ {\sum_{j=0}^{i} a^{j} \left(-b\right)^{i - j} \binom{i}{j}} + {\sum_{j=0}^{i} a^{j} b^{i - j} \binom{i}{j}} $$
which can be rewritten ("contracted") as a single sum :
sage: ExTR=ExT.maxima_methods().sumcontract() ; ExTR
sum(a^j*(-b)^(i - j)*binomial(i, j) + a^j*b^(i - j)*binomial(i, j), j, 0, i)
$$ {\sum_{j=0}^{i} a^{j} \left(-b\right)^{i - j} \binom{i}{j} + a^{j} b^{i - j} \binom{i}{j}} $$
whose summand can be factored as :
sage: ExTR.operands()[0].collect_common_factors() a^j((-b)^(i - j) + b^(i - j))binomial(i, j)
$$ a^{j} {\left(\left(-b\right)^{i - j} + b^{i - j}\right)} \binom{i}{j} $$
Now, assuming that $a,b\in\mathbb{R},\,b>0$ :
if $i-j$ is odd, $\left(\left(-b\right)^{i - j} + b^{i - j}\right)=-\left(b\right)^{i - j} + b^{i - j}=0$
if $i-j$ is even, $\left(\left(-b\right)^{i - j} + b^{i - j}\right)=2\,b^{i - j}$.
All non-zero terms of the sum are therefore products whose $b$ factor is at an even power ; therefore, if $b$ is a square root, these terms can all be simplified as a real without (external) radical.
That's (more or less) what Sage does when putting its computation results in its "preffered format", which has already been the cause of very many questions...
HTH,
2 | No.2 Revision |
What should I do?
Nothing ;-).
Let's start from the binomial formula :
sage: a, b, c, i, j = var("a, b, c, i, j")
sage: BF=(a+b)^i==sum(a^j*b^(i-j)*binomial(i, j), j, 0, i, hold=True) ; BF
(a + b)^i == sum(a^j*b^(i - j)*binomial(i, j), j, 0, i)
($$ {\left(a + b\right)}^{i} = {\sum_{j=0}^{i} a^{j} b^{i - j} \binom{i}{j}} $$
Let's generalize it by using wildcards :
sage: w0, w1, w2 = (SR.wild(u) for u in range(3))
sage: BFG = BF.subs({a:w0, b:w1, i:w2}) ; BFG
($1 + $0)^$2 == sum($1^($2 - j)*$0^j*binomial($2, j), j, 0, $2)
$$ {\left(\$1 + \$0\right)}^{\$2} = {\sum_{j=0}^{\$2} \$1^{\$2 - j} \$0^{j} \binom{\$2}{j}} $$
and use it on a general form of your original expression :
sage: Ex=(a + b)^i + (a - b)^i ; Ex
(a + b)^i + (a - b)^i
$$ {\left(a + b\right)}^{i} + {\left(a - b\right)}^{i} $$
sage: ExT=Ex.subs(BFG) ; ExT
sum(a^j*(-b)^(i - j)*binomial(i, j), j, 0, i) + sum(a^j*b^(i - j)*binomial(i, j), j, 0, i)
$$ {\sum_{j=0}^{i} a^{j} \left(-b\right)^{i - j} \binom{i}{j}} + {\sum_{j=0}^{i} a^{j} b^{i - j} \binom{i}{j}} $$
which can be rewritten ("contracted") as a single sum :
sage: ExTR=ExT.maxima_methods().sumcontract() ; ExTR
sum(a^j*(-b)^(i - j)*binomial(i, j) + a^j*b^(i - j)*binomial(i, j), j, 0, i)
$$ {\sum_{j=0}^{i} a^{j} \left(-b\right)^{i - j} \binom{i}{j} + a^{j} b^{i - j} \binom{i}{j}} $$
whose summand can be factored as :
sage: ExTR.operands()[0].collect_common_factors()
$$ a^{j} {\left(\left(-b\right)^{i - j} + b^{i - j}\right)} \binom{i}{j} $$
Now, assuming that $a,b\in\mathbb{R},\,b>0$ :
if $i-j$ is odd, $\left(\left(-b\right)^{i - j} + b^{i - j}\right)=-\left(b\right)^{i - j} + b^{i - j}=0$
if $i-j$ is even, $\left(\left(-b\right)^{i - j} + b^{i - j}\right)=2\,b^{i - j}$.
All non-zero terms of the sum are therefore products whose $b$ factor is at an even power ; therefore, if $b$ is a square root, these terms can all be simplified as a real without (external) radical.
That's (more or less) what Sage does when putting its computation results in its "preffered format", which has already been the cause of very many questions...
HTH,