Basic Usage of Summa.m

A package for Symbolic and Infinite Sums Manipulation

Initialization

This loads the package from a location in the search path of Mathematica .

<<Summa.m

The symbols exported are given by ?Summa`*, but after the renaming occured in version 2.3 a more sensible list can be found with

?Summa`Sum*

The basic object defined in the package is Summa, a container that substitutes Sum and prevents evaluation. If you choose to disable the built-in Sum Evaluation to perform your symbolic manipulations, you won't even need to know a thing about it since it will be used transparently to the user (who will operate on Sum objects and will see output formatted as Sums.

?Summa

The other two main functions are devoted to enabling and disabling (either locally and globally) the original built-in evaluation associated with Sum. They are described in the next section

Setting the environment

Starting with version 2, once the package is loaded, the built-in evaluation of Sum is turned off by default for symbolic and infinite endpoints, while it is still active for numerical (integer) endpoints. This can be verified by displaying the value of the environmental variables $EnableSumEvaluation and $EnableNumericSum (it should've been called $EnableNumericSumEvaluation, but it was too long a name):

SumEvaluationStatus[]

Actually, built-in evaluation rules are still alive and kicking, but they will never have the chance to see a symbolic Sum, because when the endpoints are not numeric (not integers, to be exact) they will be automatically converted to Summa objects.

Normal evaluation can be restored  by means of EnableSumEvalution[Extent->All]. To manually switch off the built-in Sum evaluation process, the package offers the command DisableSumEvaluation[opt]. The option Verbose can be used to issue a warning message to the user.

EnableSumEvaluation[]	enables the built-in evalution process associated with Sum; only Summa objects ca be used to represent sums without being automatically evaluated. This behaviour is analogous to what happend with version 1.x of the package.
DisableSumEvaluation[]	disables the built-in evaluation process associated with Sum: every Sum is automatically converted into a Summa object (but it is displayed in all forms but InputForm as a sum) in order to allow the manipulation routines of the package to act on it.
Extent->Symbolic		Extent allows the user to specify if Mathematica has to take control over Sums with symbolic and/or numerical endpoints. It is possibile to have four cases, by combining the option values {Symbolic, Numeric, All, None} and the two procedures - these are not the four possible case one would expect, though, since Extent->Symbolic does affect every Sum and not only thse with symbolic endpoints (Numeric affects Summas, in a subsequent stage of the evaluation chain) . By default EnableSumEvaluation has Extent->All (which means that when it is invoked without options every sum is evaluated by Mathematica) and DisableSumEvaluation has Extent->Symbolic (which means that when called without parameters, it will pass to Mathematica's evaluator only the sums with numerical endpoints).
Verbose->True			Verbose is an option for the above two commands that can switch on and off a brief message warning the user on how the Sum will behavbe thereafter. It is by default set to True.

There are four possible states that can be reached invoking the enabling and disabling procedures with the corresponding value for the options Extent. Please note the disabling options are not fully independent: numerical evaluation can be disabled only on Summa objects, hence its effects on Sums is subordinated to the disabling of Sum Evaluation (this is a remnant of previous version of the package and is not reflected in the warning messages printed by the procedures - it will be fixed in a future release).

({{Case , Enable "",  , Disable, $EnableSumEvaluation, $EnableNumericSum}, {Sums with symbolic or  numeric
                
endpoints are evaluated by Mathematica
                
(default Mathematica behavior), All, or, None, True, True}, {Sums with symbolic or  numeric 
                
endpoints are  evaluated by 
                  Mathematica; 
 Summa objects with 
                symbolic or numeric 
endpoints are not
                 (that is Summa  evaluation
is  
                      totally inhibited) . , Symbolic, and, Numeric, True, False}, {Sums  are not evaluated by Mathematica
                
unless their endpoints are 
                numerical . 
                  
(default Summa . m behavior), Numeric, and, Symbolic, False, True}, {Sum Evaluation is totally inhibited,  
              either
for symbolic and for numerical 
                endpoints . , None, or, All, False, False}})

Specifying Extent->Symbolic in one of the two procedures won't alter the evaluation of Numeric sums, and viceversa.Certain states may require the application of two such procedures to be attained.

Options[EnableSumEvaluation]

Options[DisableSumEvaluation]

It is possible to enable or disable the evaluation only for a given expression, converting all the Summa into Sum and viceversa, before evaluating the expression. This behaviour can be accomplished by passing the expression to EnableSumEvaluation or DisableSumEvaluation.

EnableSumEvaluation[expr]	enables the built-in evalution process associated with Sum, substitutes every occurence of Summa in expr with Sum, and returns the expression over which Mathematica had performed its transformations. If the Scope is set to Local, as by default, Sum evaluation is turned off and every survived Sum is turned into a Summa. If the Scope is set to Global, the built-in evaluation is left enabled, with a warning message to the user (if Verbose is True).
DisableSumEvaluation[expr]	disables the built-in evalution process associated with Sum, substitutes every occurence of Sum in expr with Summa, and returns expr. If the Scope is set to Local, as by default, Sum evaluation is turned off and every survived Sum is turned into a Summa. If the Scope is set to Global, the built-in evaluation is left enabled, with a warning message to the user (if Verbose is True)..
Scope->Local					Scope is an option for the above two commands that states whether the change of environment should affect only the expression passed to them or every subsequent input of the user. It is by default set to Local.

Hence, there are several different ways to use this package and the functions it provides. 
	The default method consist in working with symbolic and infinite Sums as if there were no built-in evaluation associated to them: unless both endpoints be numeric, Sums don't evaluate and the manipulation routines of the package (for simplifying, reindexing, differentiation and integration) can be applied to them directly. Some care must be exerted when the user want to apply the built-in evaluation, since it has to turn it on, first, either globaly or locally, as described later on. 
	Another way to use the package consist in turning on the built-in evaluation and do the symbolic manipulations on Summa objects only, as it happened with versions prior to 2.x of Summa.m 
	A third way consist in switching from one environment to the other as the user sees fit. The package provides two functons that can be used to enabing or disabling the built-in evaluation process for all the subsequent input or only with respect to a single expression.
	When needed, even the evaluation for numerical endpoints can be inhibited.

Working with Sum objects directly: DisableSumEvalutation[]

Once the package is loaded, the built-in evaluation of Sum is turned off by default ($EnableSumEvaluation=False). Actually, the evaluation process is still there, but it won't have a chace to see a symbolic Sum, because every occurence of Sum will be automatically converted to Summa, over which the package manpulating function can operate. By default, Summa object with  numerical (integers, to be exact)  endpoints are reverted back to ordinary Sums and passed on to Mathematica's evaluator ($EnableNumericSum=True).

Normal evaluation can be restored  by means of EnableSumEvalution[]. To manually switch off the built-in Sum evaluation process, the package offers the command DisableSumEvaluation[]

DisableSumEvaluation[] disables the built-in  mechanism of evaluation for the Sum objects in Mathematica, allowing Sum  to be treated as a Summa object (see help for Summa). When this  function is invoked it prevents Mathematica from evaluating infinite and  symbolic sums as it would normally do. The function sets the (protected)  variable $EnableSumEvaluation to False and prevents Summa behavior from acting   on Sum.
DisableSumEvaluation[expr] disables the built-in Sum evaluation  and then substitutes every occurrence of Sum in expr with Summa . It  switches the standard evaluation on if the option Scope is set to Local,  as by default; with Scope->Global, builtin Sum evaluation is left off, as after DisableSumEvaluation[].  The option Verbose is used to choose  whether to display or not a message when the effect is global.   It is by default set to True."

DisableSumEvaluation[]

For example, this sum, that would ordinarily evaluate to (Pi^2)/6, is now left intact

Sum[1/k^2, {k, 1, ∞}]

Please note that, despite the output and traditional form  of this expression  look like a Sum, the internal representation (and its input form) show that there's a Summa object taking over in order to prevent evaluation.

Sum[1/k^2, {k, 1, ∞}] // OutputForm

Sum[1/k^2, {k, 1, ∞}] // InputForm

In fact the previous sum can be input in this way:

Summa[1/k^2, {k, 1, ∞}]

Since Sum is automatically replaced by Summa, we can input expressions using Sum and not worry about Summa objects anymore.

Obviously, the package can still work with Summa objects in the same way version 1.x did. The only difference, when DisableSumEvaluation[] has been invoked is that it necessary to tell Mathematica when we want the built-in Sum evaluation process to be re-estabilished, either locally (applied to a single expression) or globally. The procedures SummaToSum and EnableSumEvaluation take care of these tasks.

DisableSumEvaluation can be used to turn off the built-in evaluation of summas with numerical endpoints (it will affect Sums too only if their evaluation has been disabled with Extent->Symbolic). This is how to do it globally

DisableSumEvaluation[Extent -> Numeric]

For example

expr = Sum[1/k^2, {k, 1, 3}]

InputForm[%]

expr == EnableSumEvaluation[expr, Extent -> Numeric]

Here we re-enable Numeric sum evaluation.Symbolic sum evaluation is left in its previuos state

EnableSumEvaluation[Extent -> Numeric]SumEvaluationStatus[]

Working with Summa objects only: EnableSumEvalutation[]

It is possibile to let the functions of the package operate on Summa objects only, leaving the built-in Sum evaluation process unaltered. This can be achieved by means of the command EnableSumEvaluation[] (the default value for option Extent is All) and results in the same functionalty of older versions of the package.

EnableSumEvaluation[] enables the built-in  mechanism of evaluation for Sum objects with symbolic endpoints in Mathematica. When this  function is invoked it causes Mathematica to evaluate sums as with a  fresh kernel. Summa objects are still available.   EnableSumEvaluation[] sets the (protected) variable  $EnableSumEvaluation to True and allows Summa behavior to ovveride Sum.
EnableSumEvaluation[expr] enables the built-in Sum evaluation  and then substitutes every occurrence of Summa in expr with Sum. It  switches the standard evaluation off if the option Scope is set to Local,  as by default; with Scope->Global, built-in Sum evaluation is left on, as   after EnableSumEvaluation[]. The option Verbose is used to choose  whether to display or not a message when the effect is global.   It is by default set to True.

After invoking the procedure the (protected) variable $EnableSumEvaluation - whose value is by default set to 0 - is set to 1, and the added definition of Sum that made it act as a Summa object, won't apply anymore.

EnableSumEvaluation[]

SumEvaluationStatus[]

We can see that Sum is working as it would in a fresh Mathematica session:

{Sum[1/k^2, {k, 1, ∞}], Sum[1/k^2, {k, 1, 3}]}

Hence, if we want to perform the symbolic manipulations allowed by the package we have to explicitly use Summa objects. When $EnableSumEvaluation and $EnableNumericSum are set to True, version 2.x of the Summa.m package acts in the same way version 1.x did. There is , though, a subtlety: Summas with numerical endpoint are automatically converted to Sum and evaluated.

{Summa[1/k^2, {k, 1, ∞}], Summa[1/k^2, {k, 1, 3}]}

We can disable that behavior too by setting $EnableNumericSum to False (the warning message is not adequate, and it will be rewrintten in a future release).

DisableSumEvaluation[Extent -> Numeric]

{Summa[1/k^2, {k, 1, ∞}], Summa[1/k^2, {k, 1, 3}]}

Switching the environment, either globally or locally

Globally enabling and disabling Sum evaluation

It possible to switch from one environment to the other by issuing the corresponding enabling or disabling command. For example, this set the environment to the default condition after having loaded the package.

DisableSumEvaluation[];

expr = 
      Sum[((Subscript[a, k]) + 3/k)/k, {k, 1, Infinity}] + 
        Sum[1/(2^n), {n, 0, ∞}]

expr=BringOut[SumExpand[expr]]

We know that the internal representation of the above sums is in term of Summa object. We might want mathematica to act upon the convergent series obtained: it is no use, tohogh, trying to substitute Summa occurences with Sum since every instance of Sum will be evaluated as Summa and nothing will happen

expr /. Summa -> Sum

We have to stop Summa from taking control over Sum: to do this we use the command EnableSumEvalutation[] that restores the built-in evaluation process associated with Sum.

EnableSumEvaluation[]

Note that, even if we have enabled the Sum evaluation process, expr is still internally expressed in terms of Summa objects, to which Sum does not apply. We must then manually substitute the occurences of Summa we want to evaluate (we can choose with pattern matching those we want to act upon) with Sum e let Mathematica perform its magic:

expr /. Summa -> Sum

New inputs will of course be treated as conventional Mathematica Sum object.

Sum[1/k^2, {k, 1, ∞}]

The enabling and disabling procedures can be prevented from printing warning messages specifying a proper value for the option Verbose.

DisableSumEvaluation[Verbose -> False];

Locally enabling Sum evaluation

It is also possible to enable Sum evaluation in a single espression, automatically substituting every occurence of Summa with Sum or vice versa. This is useful when, after having manipulated the expressions by means of the functions supplied with the package, we want Mathematica to perform some of its magic over what we obtained.

When $EnableSumEvaluation==False
SumManipulation[expr]	Performs the manipulations on expressions containg Summa objects and Sums that are automatically evaluated to Summa.
EnableSumEvaluation[expr]	Temporarily restores the built-in evaluation process associated to Sum and evaluate the expression passed as if all the sums contained were Sum. It returns the object simplified by mathematica with all the instaces of Sum replaced by Summa (as it happens in the environment with $EnableSumEvalution set to False).

\(expr = 
      Sum[\((a\_k + 3/k)\)/k, {k, 1, Infinity}] + 
        Sum[1/2\^n, {n, 0, ∞}]; 

    expr = BringOut[SumExpand[expr]]\)

The first two series converge and can be simplified (the first being a geometric series and the second converging to (Pi^2)/6). So we let mathemtica take care of them:

expr = EnableSumEvaluation[expr]

The previous command is in fact equivalent to

\(EnableSumEvaluation[Verbose -> False]; 

    expr = expr /. Summa -> Sum; 

    DisableSumEvaluation[Verbose -> False]; 

    expr /. Sum -> Summa\)

As we can see the sum evaluation process is still disabled (and all Sums are replaced by Summa in order to let the manipulation routine act on them) but the simplification has already taken place

expr // InputForm

Sum[1/k^2, {k, 1, ∞}] // InputForm

If we set the option Scope to Global the expression is returned in terms of  plain Sum(s) in the traditional Mathematica environment with Sum evaluation enabled.

Locally disabling Sum evaluation

The reverse operation, temporarily disabiling Sum evaluation and substituting every occurence of Sum with Summa, can be used with expressions that contains commands to perform simplifications and manipulations over Sums. The HoldFirst attribute of DisableSumEvaluation prevents these procedures to be applied on conventional Sums before the environment has been properly set. The result is returned in terms of Sum objects in an environment with Sum evaluation enabled.

When $EnableSumEvaluation==True
SumManipulation[expr]	Must not be used, since the manipulation command are set to act on Summa objects and the Sums will evaluate before being passed to thema, generating error messages.
DisableSumEvaluation[SumManipulation[expr]]		Temporarily disables the built-in evaluation process associated to Sum and performs the simplifications expressed by the Sum manipulation commands as if all the sums contained were Summa object. It returns the object with all the instaces of Summa replaced by Sum (as it happens in the environment with $EnableSumEvalution set to True) thus allowing Mathematica to perform further simplifications on it before giving it back to the user.

Suppose we are in an environment that allows to manipulate Summa objects but let the Sum objects be evaluated by the Mathematica kernel:

EnableSumEvaluation[Verbose -> False]

Suppose, also, that we have the following sum, a part of which does not evaluate because Mathematica does not recognize any known pattern (note that the second series, a geometric series, is immediatly evaluated)

expr = 
      Sum[((Subscript[a, k]) + 3/k)/k, {k, 1, Infinity}] + 
        Sum[1/(2^n), {n, 0, ∞}]

We might want to manipulate the first series by expanding its term and by extracting the constant factors. We can do this by simply wrapping the manipulation commands with DisableSumEvaluation, or by passing them to the procedure like this

expr = BringOut[SumExpand[expr]] // DisableSumEvaluation

As we can see, we had only Sum symbols in expr before evaluation and we have only Sum symbols in expr after evaluation

InputForm[expr]

The above command is in fact equivalent to the sequence of statements

\(DisableSumEvaluation[Verbose -> False]; 

    expr = expr /. Sum -> Summa; 

    EnableSumEvaluation[Verbose -> False]; 

    expr /. Summa -> Sum\)

If we pass the expression to DisableSumEvaluation with the option Scope set to Global the last two command are not issued and the expression is returned in terms of Summa objects in an evnironment where sum evaluation is disabled.

Basic Usage

To demonstrate the features of version 2 of the package Summa.m, we will work directly with Sum's signature. To use Summa objects while letting Sum evaluate as usual, please refer to section "Setting the environment".

DisableSumEvaluation[]

First thing first, we create a few sums. In the default environment after loading the package they are automatically converted into Summa objects

\(\(\ \((
        lista\  = 
          \ {
			s1\  = \ Sum\ [\(a\_k\) x^k, \ {k, \ 0, \ Infinity}], 

            			\ s2\  = \ 
              Sum[a\_k\ x^\((k\  - \ 3)\), \ {k, \ 0, \ Infinity}], 
			\ 
            s3\  = \ Sum[\((x\  - \ 1)\)\ b\_k\ x^k, \ {k, \ 0, \ Infinity}]

            			})\) // ColumnForm\)\)

We can see that the InputForm is indeed that of a Summa:

s1 // InputForm

Now we can explore the manipulation functions. They are for the most part rule based., so it is possible to apply them to general expressions (such as lists or equations) containing sums to have them automatically applied to every single sum contained therein. This is a feature chosen at design stage because the package was meant to operate on differential equations, and at the time it was deeemed to be more useful than overloading Expand, Simplify, D and Integrate to let them operate properly on Summa objects.

Element extraction (version dependent, at present)

The following function extracts the coefficients of (x^k) inside the Summa objects: it is quite rude, but its purpose is to get the coefficients at the end of a simplification.

SumCoefficient[Summa[el,it],x] returns  Coefficient[el,x].
SumCoefficient[expr,x,0] returns expr when all  the powers of x are set to zero.

SumCoefficient[#,x^k]&/@ lista

Mma v4 gets a different coefficients,

probably because of the modified simplification procedures.Have to check this out and provide a patch and make the results consistent. What is better? 0 or a power of x? I guess 0 is better. I wonder what the results on version 5 and 5.1 are.

SumToTerm (GetElement) takes whatever is inside Summa objects, but leaves untouched whatever is outside. This is not a bug: it's a feature.

SumToTerm[expr] replace the sums with their terms, by simply dropping the Sum structure and the iterator.

SumToTerm[{lista,lista+5-Sin[x]}]

The reason for this bug, er.. feature, is that when we have to apply the principle of identity of polynomials to an equation line this one:

eq = 
      (Subscript[a, 0]) + (Subscript[a, 1]) x + (Subscript[a, 2]) x^2 + 
          Sum[(Subscript[a, k]) x^k, {k, 3, ∞}] == 0;

it may be easier to proceed by simply suppressing the Summa structure

SumToTerm[eq]

despite mathematically abominable, if we keep in mind that k may vary from 3 to infinity, this trick will lead to the correct result, i.e. (Subscript[a, k])=0 for k=0,1,2,..

Expansion and simplification

Here  is a more complex espression to handle

espr=(1-x^2)s1-2s2+s3

Let's expand it

SumExpand[expr] expands what is inside every sum and  makes a separate sum for each term. It is usually used in connection with  BringIn. This function shares the same options as Expand.

espr2=SumExpand[espr]

Here's another example, that exploits the built-in evaluation of Sum of Mathematica, wrapping EnableSumEvaluation around the expression to enable it locally. If we specify the object directly in the body of EnableSumEvaluation we have to use Summa instead of Sum because the substitution Sum->Summa wouldn't take place inside that bounds.

SumExpand[Summa[a k^2  +  g[k],  {k, 1,  n}]]//EnableSumEvaluation

We can use Sum when the object is evaluated externally to the EnableSumEvaluation[] 'walls'.

temp=Sum[a k^2  +  g[k],  {k, 1,  n}];
SumExpand[temp]//EnableSumEvaluation

Sometimes a single expansion is not enough. SumExpandAll performs the expansion until the result no longer change. And it applies BringIn at the end of this process

SumExpandAll[expr] repeatedly expands what is inside  every sum and makes a separate sum for each term until the expression no  longer changes. It also brings premultiplying factors inside the sums.  This function shares the same options as ExpandAll.

SumExpandAll[espr]

If we bring the factors inside the Summa objects in espr2 we obtain the same result

BringIn[expr] brings the eventual factor pre-multiplying a  sum inside the sum symbol.In doing so, if the internal   variable $Explode is set to True, it performs an automatic  expansion of what is inside.\n  BringIn[expr, c] multiplies the addendum of the sum by c and   divides the whole sum by the same amount. The quantity  c must not depend on the index.

espr3=BringIn[espr2]

BringIn has no effect on functions of the index that are outside the Sum: that is a function of k will not be brought inside a sum with index k. To force this behavior it is necessary to give another name to the index.

espr4 = {f[k] Sum[(Subscript[a, k]) x^k, {k, 0, ∞}], 
        f[j] Sum[(Subscript[a, k]) x^k, {k, 0, ∞}]}

BringIn[espr4]

>From version 2.2 of the package, BringIn can take a second argument c that specifies a quantity to be brought inside the sum. In order not to change the value of a sum, since the addendum is multiplied by c, the sum is divided by the same amount. The quantity c must not depend on the index of the sum; if it does, the sum is left untouched. Please note: if you apply this function to an expression with several sums the transformation will be carried out only for those sums whose index is not contained in the factor c. Also, BringIn[expr, c] is strictly targeted on the quantity c, and does not perform the operation carried out by BringIn without arguments.

BringIn[espr4, x^2]

BringOut takes out of the sum everything that does not explicitly depend on the index

BringOut[expr] brings out of every sum in expr everything that does not contains the index of the sum.
BringOut[expr,c] divides the addendum of the sum by c and multiplies the whole sum by the same amount.The quantity c must not depend on the index.

s = 
      Sum[3 (Subscript[a, k]) x^2 y x^k + 2  x (Subscript[b, k]) + 1/k, {k, 1, Infinity}]

BringOut[s]

When the element that remains inside the sum does not depend upon the index k, a  sum of ones will be produced (this has been added since v1.2.1)

BringOut[Sum[f[x], {k, 0, ∞}]]

Since evaluation is inhibithed for symbolic and infinite results, the Sum will not simplify even if it is convergent or Mathematica could find the sum. Consider for example the case of the sum of of finite number n of items of the series above:

BringOut[Sum[f[x], {k, 0, n}]]

Sometimes it is advisable to let Mathematica operate on partial results. In the default environment set up after loading the package, $EnableSumEvaluation is set to False, so we must resort to EnableSumEvaluation to let Mathematica perform its magic (while when $EnableBuiltin is True we can  substitute Summa with Sum by means of a simple replacement rule (targeted by pattern matching, if needed) ).

EnableSumEvaluation[%]

Like BringIn, BringOut allows for a second argument, to specify what (index-free) factor should be brought out of the sum. BringOut[expr, c] divides the addendum of the sum by c and multiplies the whole sum by the same amount. This manipulation can prove useful in several circumstances (see for example the perturbation method to compute a finite sum in closed form).

BringOut[Sum[x^k, {k, 0, n}], x]

Sometimes it is necessary to expand or simpify the terms of the sum before applying BringIn or BringOut

BringOut[Sum[((Subscript[a, k]) + 3/k)/k, {k, 1, Infinity}]]

BringOut[SumExpand[Sum[((Subscript[a, k]) + 3/k)/k, {k, 1, Infinity}]]]

The first Sum is known to converge to ((π^2)/6). We leave that simplification to the built-in evaluator of Mathematica.

EnableSumEvaluation[%]

Reindexing and the such

We can align all the exponents of x, by using SumExponentAlign (AlignExponent): the indexes are adjusted accordingly

SumExponentAlign[expr,x,k->L[k]] shifts the index of every sum  that is in expr, has index k and contains x^(f[k]) in order to  have all of them with the same power of x: x^L[k]. It is not  allowed to change the index identifier. x may be (x-x0) or whatever.
This procedure automatically expands the elements of each sum before  searching for the exponent of x. The default expansion can be avoided by  setting the option Explode->False. This is advisable when coping with  powers of (x-x0).

espr4=SumExponentAlign[espr3,x,k->k-3]

SumExponentAlign  performs an automatic expansion and simplification of the objects passed to it. In certain cases this is not advisable, since the automatic simplification performed by Mathematica can cause problems, as is shown below. It is useful in these cases to set the option Explode->False

s0 = 
      Summa[(Subscript[a, k]) (x - 1)^(k - 2), {k, 0, Infinity}]

SumExponentAlign[s0,x-1,k->k+1]

SumExponentAlign[s0,x-1,k->k+1,Explode->False]

SumIndexAlign (AlignIndex) can make every Summa object with index k start from the same initial value

SumIndexAlign[expr,{k,k0}] shifts the index of every sum  that is in expr and has index k, in order to have them all to start from  value k0.

Suppose we want to see all the Sums starting from k=0. Here's what we need to do:

SumIndexAlign[%,{k,0}]

And we can change the index by shifting its value by calling SumReIndex (ReIndexSum)

SumReIndex[expr,k->L[k]] shifts the index as  indicated in L[k]. The shift affects every sum contained in expr that has  index k. It is not allowed to change the index identificator.
Example: SumReIndex[expr,k->k-2]

SumReIndex[%,k->k+2]

SumSplit[sum,n0] (BreakSum[sum,n0]) can be used to split a Sum in two. The first part will have index ranging from the original initial value up to (n0-1), while the second part will have it start from n0 and up to the original end value. If one of the two parts as numerical (integer for the time being) endpoints, it will be automatically expanded

SumSplit[expr,n0] breaks in two all the sums contained  in expr so that one of them will start from the value n0.  The sums with numerical starting and ending points are automatically  expanded (as is for Sum).

This explicit the first few terms of each sum, leaving the Summa objects to start with the value 5

espr5=SumSplit[espr4,5]

Simplification

SumSimplify (SimplifySum) simplifies the espression passed to it, consolidating separated Summa objects with the same index into a single Summa.

SumSimplify[expr] reduce all the sums with the same  indexes (that is with the same index name, start and final values) to  one single sum. This function shares the same options as Simplify.

espr=SumSimplify[espr5]

The command SumSimplifyEach (SimplifyEachSum) may be useful when it is needed to simplify the terms inside each Sum.

SumSimplifyEach[expr] simply maps Simplify  onto the elements of each sum in expr. It does not affect whatever is  outside. This function shares the same options as Simplify

SumSimplifyEach[
      (x^2 - 3  x + 2)/(x - 1) + 
        Summa[(x - 1) (x - 2)/(x - 1) (Subscript[a, k]), {k, 0, ∞}]]

If FullSimplify is what we need to trat certain expressions, we can resort to the other two simplifying functions: SumFullSimplify and Sum FullSimplifyEach. all the simplifying functions accepts as second argument the same options as Simplify and FullSimplify, plus those for Expand (only Modulus, since Trig is already available in Simplify and FullSimplify) that is internally used by some rules.

Options[SumSimplify]

Options[SumFullSimplify]

Elementary Differentiation and Integration

Please note: the differentiation and integration procedures do not check for the required convergence of infinite series prior to perform their tasks. The user must know when it is possible to differentiate or integrate a series term by term. As usual the rule is: if you really want to use this weapon, make sure not to aim at your foot.

Term by term Differentiation

Differentiation can be applied to object such as equations without the need to map it onto the separate sides. It has to be noted that both the differentiation and the integration procedures were developed to cope with simple polynomial expressions, as they arise in the application of power methods to ordinary differential equations. Also, no attempt is made to verify that the conditions to operate a term by term differentiation are met. Checking  due convergence is up to the user.

SumD[expr,x] (and SumD[expr,{x,n}]) differentiate with respect  to x (n times). This procedure can be applied directly to equations.  It has an option Inside that when set to False avoids to automatically  bring inside the factors premultiplying the sums.   This function shares the same options as D.

s = x^2 Sum[(Subscript[a, k]) x^k, {k, 0, Infinity}]

SumD[s,x]

When Inside is set to False, the factors in front of sums are not taken inside

SumD[s,x,Inside->False]

We can see that the result is indeed the same as before by bringing them in and simplifying the result

BringIn[%]//SumSimplify

These are other examples

SumD[Summa[(Subscript[a, k]) x^k, {k, 0, Infinity}], {x, 3}]

SumD[f[x]+g[x]Sum[h[x],{k,0,Infinity}],x]

SumD[f[x]+g[x]Sum[h[x],{k,0,Infinity}],x,Inside->False]

SumD[f[x](g[x]+Sum[h[x],{k,0,Infinity}]),x]

SumD[espr,x]

It is possible to employ SumD to perform differentiation of more involved expressions, but it has to be clear that this was not what it was written for, and that whenever the expression contain a Summa object only the basic differentiation rules are tried. It is possible to add more elaborated ones, though, by modifying diffRule2 inside the package.

s1 = Sum[(Subscript[a, n]) x^n, {n, 0, ∞}]; 
    s2 = Sum[(Subscript[b, n]) x^n, {n, 0, ∞}];

SumD[s1 s2, x]

SumD[1/s1, x]

SumD[s2/s1, x]

SumD[f[s1], x]

There is another function that differentiates exclusively what is inside Summa objects, and for this reason it has to be used with great care. It's exitence is jstified by the fact that it may prove faster in certain circumstances (alas, its name did not come out well from the renaming frenzy).

SumDEach[s,x] and (SumDEach[s,{x,n}]) differentiate with respect  to x, n times. This procedure can be applied only to sums (and sums of sums)  since it operates exclusively by moving D inside the sum  symbol. When  used with mixed expressions it gives wrong results:
	SumDEach[f[x] + Summa[g[x],{k,n1,n2}]=f[x] + Summa[g'[x],{k,n1,n2}]. 
This function shares the same options as D

SumDEach[1/x + Sum[(Subscript[a, k]) x^k, {k, 0, ∞}] + Cos[x^2], x]

Confront this with the output from SumD

DSum[1/x + Sum[(Subscript[a, k]) x^k, {k, 0, ∞}] + Cos[x^2], x]

SumDEach can be used to steadily aim at one's foot. One has to be careful when they choose to pull the trigger.

We end this short introduction by mentioning a very common side effect of differentiation: when dealing with power series, differentiation has an indirect effect on the startign value of the summation index. By removing constant terms,

ys = Sum[(Subscript[a, k]) x^k, {k, 0, ∞}]

(y1s = SumD[ys, x]) == SumSplit[SumD[ys, x], 1]

(y2s = SumD[ys, {x, 2}]) == SumSplit[SumD[y1s, x], 1] == 
      SumSplit[SumD[ys, {x, 2}], 2]

SumD[ys, {x, 3}] == SumSplit[SumD[y2s, x], 1] == 
      SumSplit[SumD[y1s, {x, 2}], 2] == SumSplit[SumD[ys, {x, 3}], 3]

Term by term Integration

A rude procedure to perform term by term integration is provided by SumIntegrate (IntegrateSum)

SumIntegrate[expr,x] and SumIntegrate[expr,{x,a,b}]  integrate term by term with respect to x. When the option Inside is set to  False integrals not depending on the index variable are brought outside  the summa objects.  This function shares the same options as Integrate.

s = x^2 Sum[(Subscript[a, k]) x^k, {k, 0, Infinity}]

SumIntegrate[s,x]

The implementation of IntegrateSum mimicks the one previously adopted  for DSum:  an automatic application of the linearity property of the integral is performed. Automatic threading over equations is  allowed.

SumIntegrate[ f[x] g[x] + a h[x] == Cos[x] - w[x] , x]

Here's another example

y = Sum[(Subscript[a, n]) Exp[I n π x], {n, 0, ∞}]

DSum[y, x]

SumIntegrate[%, x]

This shows a definite integration leading to conditioned integral (in v3)

SumIntegrate[s,{x,0,1}]

We can feed SumIntegrate the same options we would have fed to Integrate

SumIntegrate[s,{x,0,1},GenerateConditions->False]

Older versions of Summa.m did not pass options to Integrate, and it was necessary to force the evaluation of the If structure with the desired condition

%  /.  Re[k] > -3 -> True

Here we compute the integral

\(TraditionalForm
    \`∫\_0
        \%∞\(\( x\^\(2\ n + 1\)\ 
              \(∑e\^\(\(-k\)\ π\ x\)\)\+\(k = 0
                  \)\%∞\)\/e\^\(π\ x\)\) 
        dx\)

SumIntegrate[
      x^(2  n + 1)/Exp[Pi x] 
        Sum[Exp[-k Pi x], {k, 0, ∞}], {x, 0, ∞}, 
      GenerateConditions -> False]

We can let Mathematica further elaborate the result by appending //EnableSumEvaluation

%  // EnableSumEvaluation

The option Inside allows to bring index independent quantities outside Summa objects. In a way it is equivalent to the application of  BringOut at the end of the integration process

SumIntegrate[Sum[(Subscript[a, k]) f[x], {k, 0, ∞}], {x, a, b}]

SumIntegrate[Sum[(Subscript[a, k]) f[x], {k, 0, ∞}], {x, a, b}, 
      Inside -> False]

Should the integral depend on the index k, BringOut would sort no effect.

SumIntegrate[Sum[(Subscript[a, k]) f[x, (Subscript[b, k])], {k, 0, ∞}], {x, a, b}, 
      Inside -> False]

Applying Summa to 'separable nested sums'

The package Summa was developed for 'one-dimensional' sums and would require a substantial rewriting of most functions to allow sensible manipulation of multiple sums. Anyway, by strectching a bit the rules given for simple sums, it is possible to operate a few simplifications on multidimensionals problems as well. With due attention, Summa can be applied to problems involving a certain kind of nested sums.

Handling multiple sums

Sums with multiple iterators in Summa.m

In Mathematica, multiple sums require a specific signature:

Sum[el (i, j,  ... ), {i, i0, n}, {j, j0, m},  ... ] .

We can see how Mathematica behaves by re-enabling built-in sum evaluation

\(EnableSumEvaluation[Verbose -> False]; 

    Sum[a\_\(j, k\), {j, 0, 3}, {k, 2}]\)

{Sum[(Subscript[a, j, k]), {j, 0, n}, {k, 2}], 
      Sum[(Subscript[a, j, k]), {k, 2}, {j, 0, n}]}

In the most general case, the terms to be summed over the indices depend on the indices themselves in a non separable manner. For example:

Sum[(Subscript[a, j]) (Subscript[b, k - j]), {j, 0, 2}, {k, 2}] // Simplify

When Summa is loaded and the built-in sum evaluation is overridden, multiple indices sums with numerical (integer) endpoints are automatically passed to Sum for evaluation, as it happens with simple sums. For example consider the triple sum

\(DisableSumEvaluation[Verbose -> False]; 

    Sum[\(a\_j\) \(b\_k\) c\_l, {j, 1, 2}, {k, 0, 3}, {l, 0, 2}] // Simplify
      \)

With the default setting of Summa.m, multiple sums with at least one symbolic or infinite endpoint are converted to Summa objects and are left unevaluated.

Sum[(Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {j, 1, 3}, {k, 0, n}, {l, 0, 2}]

We can see that this is indeed a Summa object, as shown by its InputForm.

InputForm[%]

At present, formatting is the only facility provided by the Summa package that is oriented towards sums with multiple iterators. No simplification procedure is designed to be used on multiple sums with that kind of signature.

The problem with nested sums: localization of the indices

It is nonetheless possible, though, to manually manipulate a certain kind of  nested (simple) sums. In fact, when the it is possibile to express the summand as a product of factors each depending on a single index, the sum can be cast into a nested form (with each factor pertaining to the sum over the corresponding index)

el[i, j,  ...  , k]  =  f[i] g[j] ...  h[k]Sum[ f[i] g[j] h[k], {i, i0, n}, {j, j0, m}, {k, k0, p}]Sum[Sum[ Sum[f[i] g[j] h[k], {i, i0, n}], {j, j0, m}], {k, k0, p}]Sum[h[k] Sum[ g[j] Sum[f[i], {i, i0, n}], {j, j0, m}], {k, k0, p}]

This approach is limited by the fact that when sums of this kind are passed to Mathematica's evaluator their indices are treated as local to each nested Sum structure.For this reason, Mathematica won't be able to recognize the dependence from indices that belong to outer Sums. Nested one-dimensional sums are thus a source of potential problems and it is imperative not to let Mathematica evaluate them in the standard way. For example, the evaluation of a nested sum depending on three indices can lead to incorrect results:

\(EnableSumEvaluation[Verbose -> False]; 
SumEvaluationStatus[]\)

expr = 
      Sum[ Sum[ Sum[ (Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {j, 1, n}] , {k, 0, 3}] , {
          l, 1, 2}]expr /. n -> 2 // Simplify

The correct result can be obtained with correct Mathematica syntax and is:

expr = 
      Sum[(Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {l, 1, 2}, {k, 0, 3}, {j, 1, n}] // Simplify
        expr /. n -> 2 // Simplify

We can see where the 'nested sums problem' is with a simple Trace:

Trace[
        Sum[Sum[Sum[(Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {j, 1, n}], {k, 0, 3}], {l, 1, 
            2}], Sum] // ColumnForm

Basically, this is what happened: only the innermost sum recognizes j as the legitimate index; the outer sums consider their elements as constants and perform a simple sum of those constants over the range of their indices.Here's how we can exploit the HoldAll attribute of Sum to mimick this behavior step by step:

{t1 = Sum[(Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {j, 1, n}], t2 = Sum[t1, {k, 0, 3}], 
      t3 = Sum[t2, {l, 1, 2}], t3 /. n -> 2 // Simplify}

If we really insist in using nested sum for multiple sums with separable summands, there are two possibile workarounds.

First workaround: manually distribute the factors

The first workaround consists in embedding each factor in the nested sum with respect to the corresponding index. Once we have separated the summand into factors that depend on one index each, and rewrite the sum in the following manner (that we could call a separable nested sum):

\(TraditionalForm\`\(	
    ∑\+\(j = 0\)\%n
          \(∑\+\(k = 0\)\%3\(∑\+\(l = 1\)\%2 a\_j\ b\_k\ c\_l\)\) = 
      ∑\+\(l = 0\)\%2\((
          c\_l\ \(∑\+\(k = 0\)\%3\((b\_k\ \(∑\+\(j = 1\)\%n a\_j\))
                \)\))\)\)\)

In the latter form, Mathematica can give the correct result for the sum

Sum[(Subscript[c, l]) Sum[(Subscript[b, k]) Sum[(Subscript[a, j]), {j, 1, n}], {k, 0, 3}], {l, 1, 2}] // 
      Simplify

We can verify that by using a numerical value for n. The result is indeed equal to that obtained when Mathematica is fed the correct form for multiple sums.

Simplify[% /. n -> 2]

Second workaround: disabling every form of sum evaluation

The second way is to disable automatic multiple Sum evaluation even when the endpoints are numerical. This will allow the user to perform every single simplification he or she needs step after step, keeping Mathematica's evaluator away from nested sums until they are cast into their final form. DisableSumEvaluation and EnableSumEvaluation have an option Extent that can be use to switch on and off the evaluation of Numeric and or Symbolic sums.

DisableSumEvaluation[Extent -> All]

Usage examples

Nested separable sums with symbolic or infinite endpoints can be manipulated as Summa objects. We already know that Mathematica is not designed to cope with sums in nested forms.

EnableSumEvaluation[Verbose -> False]Sum[Sum[Sum[(Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {j, 1, n}], {k, 0, 3}], {l, 1, 2}]
      % /. n -> 2

But, after loading Summa.m the evaluation of sums with symbolic or infinite endpoints is disabled by default, and so we can perform the simplifications we need prior to pass the result to the evaluator.

DisableSumEvaluation[]

Sum[Sum[Sum[(Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {j, 1, n}], {k, 0, n}], {l, 1, n}]

BringOut[%]

We can see that the following result happens to be correct

Sum[Sum[Sum[(Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {j, 1, n}], {k, 0, 3}], {l, 1, 2}]
      % /. n -> 2 // Simplify

Non separable summands can't be separated.

Sum[
      Sum[Sum[(Subscript[a, j]) (Subscript[b, k - j]) (Subscript[c, l]), {j, 1, n}], {k, 1, n}], {l, 1, 
        n}]

At least not completely

BringOut[%]

Here is another example

nested = Sum[n a[k] - Sum[a[j], {j, 1, n}], {k, 1, n}]

We can expand the sum and extract the factors that do not depend on each sum's index. A single function, SumExpand, can do that for us.

sep = nested // SumExpand

The sum of 1's from 1 to n is easily managed by mma's evaluator. We pass the expresssion to it, locally

EnableSumEvaluation [sep] // Simplify

now we can tell Mathematica that an index is an index by any other name.

% /. j -> k

A quicker way to get the same result is this:

EnableSumEvaluation [sep /. j -> k]

Multiple sums with mixed numerical and symbolical endpoints can lead to incorrect results if their evaluation is not inhibited. Please use this package with the utmost care when dealing with nested sums whose endpoint could be made numeric at some point of the computation. Always make sure that the sum has been thoroughly simplified before enabling evaluation!

DisableSumEvaluation[Extent -> All]

Sum[Sum[Sum[(Subscript[a, j]) (Subscript[a, k]) (Subscript[a, l]), {j, 0, n}], {k, 1, 3}], {l, 1, 2}]

BringOut[%]

EnableSumEvaluation[%]

{Sum[ 
              Sum[ Sum[ (Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {j, 0, n}] , {k, 1, 3}]
                 , {l, 1, 2}] /. n -> 2 // Simplify, 
        
Sum[
            Sum[Sum[(Subscript[a, j]) (Subscript[b, k]) (Subscript[c, l]), {j, 0, 2}], {k, 1, 3}], {l, 1, 
              2}] // Simplify} // ColumnForm

EnableSumEvaluation[%, Extent -> Numeric] // Simplify

Let's restore the evaluation for numerical endpoints.

EnableSumEvaluation[Extent -> Numeric]SumEvaluationStatus[]

Putting things together

Combining different procedures

Starting with a single expression, many possible results can be obtained by combining different procedures in different ways. Consider for example the simple Sum

expr = 
      Sum[((Subscript[a, n]) + 4  x^2) x^n, {n, 0, ∞}] + 
        x Sum[((Subscript[b, n]) - x^2) x^n, {n, 2, ∞}]

SumExpand will expand the term inside each sum, while SumExpand all will reiterate this procedure and will ultimately break apart every possibile sum

expr // SumExpand

expr // SumExpandAll

Applying BringOut to the result from SumExpand gives a result that differs from those obtained above

expr // SumExpand // BringOut

And different is also the result obtained by swapping the procedures.

expr // BringOut // SumExpand

Another different form for the result is obtained with SumExpandAll

expr // SumExpandAll // BringOut

Sometimes it's useful to apply the same procedure more than once.

expr // SumExpand // BringOut // SumExpand

Limiting the scope of the functions applied to Sums (*)

This is an undocumented feature. See the commands SumMap, SumMapAt...in the notebook "The making of Summa".