1
$\begingroup$

I was trying to simplify a summation of two terms, as follows

FullSimplify[Sum[1, {n, 1, k}] + Sum[x[n], {n, 1, k}]]

However, the simplification was not performed as I expected:

Sum_nok

When I split the summation in two, I obtain the expected result, as follows:

enter image description here

Am I doing something wrong?

I do not understand why Mathematica does not apply the additivity property in the first case. Is there a procedure to include properties in Mathematica Functions?

EDIT: COMPLETE ANSWER

A complete inclusion of the additivity property in summation can be obtained by the following code:

Unprotect[Sum];
Sum[Plus[leftArg_, rightArg__], {variable_, argStart_, argEnd_}] := 
 Sum[Plus[leftArg], {variable, argStart, argEnd}] + 
  Sum[Plus[rightArg], {variable, argStart, argEnd}]
Protect[Sum];
$\endgroup$
  • 1
    $\begingroup$ The problem is that Sum[1, {n, 1, k}] is already automatically evaluated. $\endgroup$ – J. M.'s discontentment Jan 31 '17 at 16:41
3
$\begingroup$

I guess the Mathematica Programmers decided, that this is not nessecary. I for myself could also believe, that there are situations where this +1 can make it easier to get a closed expression for your sum.

But if you want to really have this functionality, you can overload it:

Unprotect[Sum];
Sum[Plus[leftArg_, rightArg__], {variable_, argStart_, 
   argEnd_}] := (argEnd - argStart + 1)*leftArg + 
   Sum[Plus[rightArg], {variable, argStart, argEnd}] /; 
  FreeQ[leftArg, variable]
Protect[Sum];

Now your Mathematica behaves like you wished:

Sum[x[n] + 1, {n, 1, k}]
Sum[x[n] + 1, {n, 5, k}]

k + Sum[x[n], {x, 0, k}]

-4 + k + Sum[x[n], {x, 5, k}]

_

EDIT: Also notice, that for Mathematica, this isn't a simplification. They're are actual equally complex:

LeafCount[Sum[x[n] + 1, {n, 1, k}]] == LeafCount[k + Sum[x[n], {n, 1, k}]]

True

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ That's solved my problem! Thank you very much! $\endgroup$ – Rodrigo Jan 31 '17 at 17:17

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.