3
$\begingroup$

Something seems to have gone awry with the analytic sum (v9.0.1). Here I insert specific values:

Sum[Binomial[n, 2 k - 1] a^(n - 2 k + 1) b^(2 k - 1), {k, 1, n/2}] /. {a -> 4.2, b -> 1.2, n -> 3}

returns 92.232.

With[{a = 4.2, b = 1.2, n = 3}, Sum[Binomial[n, 2 k - 1] a^(n - 2 k + 1) b^(2 k - 1), {k, 1, n/2}]]

returns 63.504

Did I do something wrong? or is the analytic sum not quite right? Bug, perhaps? Maybe n is assumed integer in the first case?

| improve this question | | | | |
$\endgroup$
  • 1
    $\begingroup$ try with even n. i suspect that n/2 is a problem for the analytic soluton $\endgroup$ – george2079 Nov 21 '14 at 12:48
4
$\begingroup$

The problem is the symbolic Sum is assuming n/2 ∈ Integers && n >= 2. We can see this with the option GenerateConditions -> True:

Sum[Binomial[n, 2 k - 1] a^(n - 2 k + 1) b^(2 k - 1), {k, 1, n/2}, 
  GenerateConditions -> True]
ConditionalExpression[1/2 a^n (((a + b)/a)^n - (-1 + b/a)^n), 
  n/2 ∈ Integers && n >= 2]

A fix is to take the floor of n/2:

Sum[Binomial[n, 2 k - 1] a^(n - 2 k + 1) b^(2 k - 1), {k, 1, Floor[n/2]},
  GenerateConditions -> True]
ConditionalExpression[(* messy expression *), 
  Floor[n/2] >= 1 && (a != b^2/a || Re[n] > 0) && Floor[n/2] ∈ Integers]
Sum[Binomial[n, 2 k - 1] a^(n - 2 k + 1) b^(2 k - 1), 
  {k, 1, Floor[n/2]}] /. {a -> 4.2, b -> 1.2, n -> 3}
63.504
| improve this answer | | | | |
$\endgroup$
  • $\begingroup$ Nice. In your experience, does GenerateConditions -> True often prove useful as a first step for debugging in cases like this? $\endgroup$ – DumpsterDoofus Nov 21 '14 at 22:07
  • 1
    $\begingroup$ @DumpsterDoofus, yes. Whenever I see something odd about Sum, this is what I try first. $\endgroup$ – Chip Hurst Nov 23 '14 at 18:48
3
$\begingroup$

The only important variable here is n.

The first case, when n in undefined, is "symbolical summation". The second, when n is fixed in advance, is an ordinary summation. In the first case general "close form" answer is derived, then numerical value of n is substituted. In the second case explicit summation is performed from the very beginning.

Obviously, here symbolic summation fails. "Symbolic summation" actually is not a summation in the ordinary sense. You can read about these methods for example in the fantastic free book. Symbolic summation, which is based on derivation and solving reccurence relations, seems failing here, as you can see comparing

(Sum[Binomial[n, 2 k - 1] a^(n - 2 k + 1) b^(2 k - 1), {k, 1, 
             n/2}] /. {n -> 3}) // Simplify

a^3 + 3 a b^2

and

Binomial[n, 2 k - 1] a^(n - 2 k + 1) b^(2 k - 1) /. {n -> 3, k -> 1}

3 a^2 b

(sum in this case has only single term).

Why symbolic summation fails is an interesting question and requires further investigation. It can be bug or it can simply be impossible to symbolically account for n/2 condition.

| improve this answer | | | | |
$\endgroup$
2
$\begingroup$

comment with figures.. The issue can be illustrated more simply looking at this:

 Sum[ i , {i, 1, n/2}]
 Sum[ i , {i, 1, 3/2}]
 Sum[ i , {i, 1, Floor[n/2]}] /. n -> 3
 Sum[ i , {i, 1, Ceiling[n/2]}] /. n -> 3
 Sum[ i , {i, 1, n/2}] /. n -> 3
 1/8 n (2 + n)
    1
    1
    3
    15/8
 Show[{
  ListPlot[ 
     Table[ {n, Sum[ i , {i, 1, Ceiling[n/2]}]} /. n -> j , { j, 1, 10}] ,
         Joined -> True, PlotStyle -> Red],
  ListPlot[ 
     Table[ {n, Sum[ i , {i, 1, Floor[n/2]}]} /. n -> j , { j, 1, 10}] ,
         Joined -> True, PlotStyle -> Green],
  ListPlot[ 
     Table[ {n, Sum[ i , {i, 1, n/2}]} /. n -> j , { j, 1, 10}] , 
         Joined -> True, PlotMarkers -> Automatic]}]

enter image description here

The case where you fail to specify if you want Floor or Ceiling is mathematically ambiguous, and you get some intermediate value.

| improve this answer | | | | |
$\endgroup$
  • $\begingroup$ It means that analytical (or "close form") answer has no meaning without additional information. So cannot be treated as a bug of Sum. Its a feature. $\endgroup$ – user18792 Nov 21 '14 at 16:33
1
$\begingroup$

I compared this with Maple 18.02, both on windows 7, 64 bit. Maple symbolic and numerical both give the same result, which is 65.23200003. Maple symbolic result does not appear the same as Mathematica symbolic only result. Maple uses special function LegendreP in its symbolic result.

Compare: Maple symbolic only result:

restart;
r:=sum(binomial(n, 2*k - 1)*a^(n - 2*k + 1)* b^(2*k - 1), k=1..n/2);

Mathematica graphics

evalf(subs({a=4.2,b=1.2,n=3},r));
(*65.23200003*)

Mathematica symbolic result

 mma=Sum[Binomial[n, 2 k - 1] a^(n - 2 k + 1) b^(2 k - 1), {k, 1, n/2}]

Mathematica graphics

  mma /. {a -> 4.2, b -> 1.2, n -> 3}
  (*92.232*)

Looking the both results for different n, they agree for odd n only. (actually for n=2 Maple gives complex answer!)

maple = {1.2, 2.880000002*I, 65.23200003, 384.6528003, 2174.325120, 
    12032.95566, 65852.76052, 3.582293070*10^5}; (*from Maple worksheet*)
r = Table[{i, mma /. {a -> 4.2, b -> 1.2, n -> i}, maple[[i]]}, {i, 1, 8, 1}];
r = Insert[r, {"n", "Mathematica", "Maple"}, 1];
Grid[r, Frame -> All]

Mathematica graphics

My guess is that Mathematica result is only valid for n>2 and even n, as Chip Hurst mentioned also above and also george2079 mentioned the even condition in the comment above.

| improve this answer | | | | |
$\endgroup$
0
$\begingroup$

The answer returned depends on the order in which ReplaceAll is applied and how it impacts the upper limit of Sum. In the first case above, the sum is performed first, producing the answer. 1/2 a^n (((a+b)/a)^n-(b/a-1)^n). Evaluating this for {a -> 4.2, b -> 1.2, n -> 3} gives 92.232. In the second case above, the substitution is performed before Sum. Hence, the upper limit n/2 becomes 1.5, which is treated as 1, and only the first term in the Sum is computed. Its value is 63.504.

| improve this answer | | | | |
$\endgroup$
  • $\begingroup$ As @george2079 commented, if n were an even integer, the results would be the same, for instance 384.653 for n->4 $\endgroup$ – bbgodfrey Nov 21 '14 at 13:14
  • $\begingroup$ try putting Ceiling[n/2] in both.. (cant test here) $\endgroup$ – george2079 Nov 21 '14 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.