sum
definite and indefinite symbolic summation
Sum
inert form of sum
Calling Sequence
Parameters
Basic Information
Description
Note
Details
Options
Examples
Examples for the parametric case
Comparing sum and add
References
Compatibility
sum(f, k)
∑k⁡f
sum(f, k=m..n, parametric, formal=b)
∑k=mn⁡f
sum(f, k=alpha)
∑k=α⁡f
sum(f, k=expr)
∑k=expr⁡f
Sum(f, k)
Sum(f, k=m..n)
Sum(f, k=alpha)
Sum(f, k=expr)
f
-
expression
k
name; summation index
m, n
integers or arbitrary expressions
parametric
(optional) literal name
b
(optional) either true or false
alpha
RootOf expression
expr
expression, of type algebraic, not containing k
This help page contains complete information about the sum command. For basic information on the sum command, see the sum help page.
The sum command (definition of sum) is for symbolic summation. It is used to compute a closed form for an indefinite or definite sum. A typical example is sum(k,k=0..n-1), which returns 12⁢n2−12⁢n.
You can enter the sum command using either the 1-D or 2-D calling sequence. For example, sum(k^2, k) is equivalent to ∑k⁡k2.
To add a finite sequence of values, rather than compute a formula, use the add command. For example, add(k, k=0..9) returns 45. Although the sum command can often be used to compute explicit sums, it is strongly recommended that the add command be used in programs if an explicit sum is needed, in particular, when summing over all elements of a list, Array, Matrix, or similar data structure. For more details and examples, see the Comparing sum and add section in this help page.
The call sum(f, k) computes an indefinite sum of f⁡k with respect to k. It computes an anti-difference g⁡k of f⁡k such that g⁡k+1−g⁡k=f⁡k in general (SumTools[IndefiniteSum][Indefinite]).
The call sum(f, k=m..n) computes the definite sum of f⁡k over the given range m..n. That is, it computes f⁡m+f⁡m+1+...+f⁡n. If m=n+1, the value returned is 0. If m>n+1 are integers, the value returned is -sum(f, k=n+1..m-1). With these conventions, the following holds for all integers l,m,n.
∑k=lm−1⁡f+∑k=mn⁡f=∑k=ln⁡f
The call sum(f, k=alpha) computes the definite sum of f⁡k summed over the roots of a polynomial given by alpha where alpha must be a RootOf.
The call sum(f, k=expr) substitutes the value of expr for k in f.
For indefinite summation, Maple uses the following methods:
Polynomials are summed using a formula based on Bernoulli polynomials.
Rational functions of k are summed using the algorithm that solves the additive decomposition problem of rational functions. The result is a rational function plus a sum of terms involving the Polygamma function and its derivatives.
Hypergeometric terms, for example, expressions containing factorials (including binomial coefficients) and powers, are summed using Gosper's algorithm and the algorithm that solves the additive decomposition problem of hypergeometric terms. An extension of Gosper's algorithm is used to handle summands which are sums of hypergeometric terms. Koepf's extension to Gosper's algorithm is used to handle j-fold hypergeometric terms.
The method of accurate summation.
Additionally, a library extension mechanism is used to include sums for which an algorithmic approach to finding closed forms is not yet implemented or does not yet exist (that is, the pattern match approach is employed in principal). Currently the computable summands include expressions containing the harmonic function; the logarithmic function; the digamma and polygamma functions; and the sine, cosine, and exponential functions.
For definite sums, if n-m is a small integer, the sum is computed directly by adding up terms. Otherwise, Maple uses the following methods:
Classical telescoping computes a closed form of the definite sum of f over the specified range of k using telescoping method, or Newton-Leibniz's formula. That is, it first computes a closed form of the corresponding indefinite sum.
Creative telescoping method for computing closed forms of definite sums of hypergeometric terms.
Conversion method computes a closed form of the definite sum of f over the specified range of k by first converting the specified sum into hypergeometric functions. If possible, the output is then converted to standard functions.
Note: To access directly one of the above three methods, see Telescoping for (a), CreativeTelescoping for (b), and pFqToStandardFunctions for (c).
As in the case for indefinite sums, the pattern-match approach is also employed.
For definite sums depending on one or more parameters other than the summation variable, the result will in general be a function of these parameters. However, that result may only be correct in a generic sense; it may not be correct for all possible values of the parameter(s). Use option parametric (see the Options section in this help page) to obtain a complete case discussion that is correct for all possible integer values of the parameter(s).
If Maple cannot find a closed form for the summation, the function call is returned. (Maple displays the sum function using a stylized summation sign.)
The capitalized function name Sum is the inert sum function, which simply returns unevaluated. It appears gray so that it is easily distinguished from a returned sum calling sequence.
For divergent sums, the sum command may return infinity, -infinity, unevaluated, or a finite result correct in the sense of analytic continuation. This behavior can be changed by setting the _EnvFormal environment variable or using the formal option. By default, the _EnvFormal environment variable is unassigned.
If _EnvFormal is assigned true, the sum command uses resummation methods to return a finite result for various classes of divergent sums.
If _EnvFormal is assigned false, the sum command uses more convergence testing to detect divergence for infinite sums. It more often returns infinity, -infinity, or unevaluated for divergent sums. This may slow down the computation.
If _EnvFormal is assigned false and the summation bounds are numeric, the sum command also tries harder to detect removable singularities in the interval of summation, and returns an error in that case. By default, sum will try to remove them.
The SumTools[IndefiniteSum] package provides an extension mechanism (AddIndefiniteSum) that is used by sum. Using this facility, you can add summation definitions related to additional special functions.
For numerical summation, see evalf/Sum.
There are two cases where the result of a call to sum may contain inert Sums:
When option parametric is used (see the Examples for the parametric case section in this help page).
When a definite hypergeometric sum can be expressed in terms of nested indefinite sums, these may be returned in Sum form if they are too costly or too complicated to be evaluated in closed form.
If the option parametric is specified for a definite parametric sum, then a result is returned that is valid at least for all possible integer values of the parameter(s) occurring in the summand or the summation bounds. In general, the result is expressed in terms of piecewise functions. The piecewise result may contain FAIL or undefined. Here, FAIL is used to indicate that there is a singularity in the range of summation, and undefined indicates that the sum is divergent.
Using the option formal is equivalent to assigning to the environment variable _EnvFormal (see above): specifying formal=true (or just formal for short) is equivalent to assigning true to _EnvFormal, and formal=false is equivalent to assigning false to _EnvFormal.
Indefinite sums
Polynomials:
sum⁡k2,k
13⁢k3−12⁢k2+16⁢k
Rationals:
sum⁡k+k2+512⁢k−1k2+512⁢k−1⁢k,k
−13⁢k−32+52−13⁢k−12+52−13⁢k+12+52−4⁢Ψ⁡k5−3⁢3+5
Hypergeometric terms:
sum⁡4k⁢k4binomial⁡2⁢k,k,k
2⁢k−1⁢63⁢k4−140⁢k3+60⁢k2+26⁢k−6⁢4k693⁢2⁢kk
2-fold hypergeometric terms:
sum⁡k⁢12⁢k!,k
2⁢k2!+2⁢k2+12!
Sum of hypergeometric terms:
sum⁡22⁢k−1k⁢2⁢k+1⁢binomial⁡2⁢k,k+k+12⁢4k+1k+2⁢k+3,k
−22⁢k−12⁢kk⁢k+k−1⁢4k+13⁢k+2
Accurate summation
sum⁡Γ⁡k+1−Γ⁡k−Ψ⁡k,k
k4−k3−6⁢k2−6⁢k−5⁢Γ⁡k+1−Γ⁡k−Ψ⁡kk2+k+3−k5−k4−10⁢k3−9⁢k2−2⁢Γ⁡k+2−Γ⁡k+1−Ψ⁡k+1k⁢k2+k+3+k+1⁢k3−5⁢k2+4⁢k−2⁢Γ⁡k+3−Γ⁡k+2−Ψ⁡k+2k⁢k2+k+3
Additive decomposition of hypergeometric terms:
sum⁡k2−2⁢k−1⁢2kk+1⁢k2⁢k+3!,k
k+3⁢∏_i=1k−1⁡2_i+412⁢k+∑k⁡k2+2⁢k−1⁢∏_i=1k−1⁡2_i+412⁢k2
Sum of a logarithm of a rational function (provided the argument of the logarithm has constant sign):
sum⁡ln⁡2⁢k+1,kassuming0≤k
k⁢ln⁡2+ln⁡Γ⁡k+12
sum⁡ln⁡2⁢k+1,kassumingk≤−1
k⁢ln⁡2−ln⁡Γ⁡12−k+I⁢k⁢π
Library extension mechanism:
sum⁡sin⁡k⁢cos⁡k+1−Ψ⁡k,k
−sin⁡1⁢k2−csc⁡1⁢cos⁡k22−Ψ⁡k+1⁢k+k+Ψ⁡k+γ
Definite sums
Classical telescoping:
sum⁡binomial⁡2⁢n−2⁢k,n−k⁢24⁢k⁢2⁢k⁢2⁢k+1⁢binomial⁡2⁢k,k−1,k
24⁢k⁢2⁢n−2⁢kn−k⁢−2⁢n+2⁢k−12⁢2⁢kk⁢k⁢2⁢n+1
sum⁡binomial⁡2⁢n−2⁢k,n−k⁢24⁢k⁢2⁢k⁢2⁢k+1⁢binomial⁡2⁢k,k−1,k=1..n
−2⁢n−2n−1⁢−16⁢n+82⁢2⁢n+1
Creative telescoping:
sum⁡binomial⁡2⁢n,2⁢k2,k=0..n
−1n⁢2⁢nn2+4⁢n2⁢n2
Conversion method:
sum⁡22⁢kπ12⁢Γ⁡k−n⁢Γ⁡k+nΓ⁡2⁢k+1⁢zk,k=0..∞assumingabs⁡z≤1
−π⁢cos⁡2⁢n⁢arcsin⁡z⁢csc⁡π⁢nn
Pattern match (Abel's type):
sum⁡2+kk−2⁢1+n−kn−kk!⁢n−k!,k=0..n
n+3n4⁢n!−n+3n−16⁢n−1!
Maple returns the call unevaluated if it cannot find a closed form.
sum⁡a⁡k⁢xk,k=0..n
∑k=0n⁡a⁡k⁢xk
If the inert function is used, Maple returns unevaluated.
Sum⁡kk+1,k=0..n=sum⁡kk+1,k=0..n
∑k=0n⁡kk+1=n+1−Ψ⁡n+2−γ
Some definite sums may return an expression containing inert Sums.
sum⁡binomial⁡−n,3⁢k,k=−n+1..−1
229⁢2n+2⁢I⁢12−I⁢32n⁢9⁢3+4⁢I9+2⁢I⁢12+I⁢32n⁢−9⁢3+4⁢I9+∑_z2=0n−1⁡1+I⁢3_z2⁢3⁢∑_z3=0_z2−1⁡−I3⁢−1−I⁢3_z3⁢3⁢I⁢∑_z4=0_z3−1⁡−1+I⁢3_z4⁢455⁢_z44+1843⁢_z43+2524⁢_z42+1340⁢_z4+228⁢3⁢_z4_z43⁢2_z4⁢_z4+2⁢2⁢_z4+3⁢_z4+1⁢2⁢_z4+1+19⁢I−19⁢32_z3−3832n
sum⁡−exp⁡−k,k
−ⅇ−kⅇ−1−1
sum⁡1k!,k=0..∞
ⅇ
sum⁡1k2,k=1..∞
π26
sum⁡kk+1,k=RootOf⁡x3−2
2
Formal sums
sum⁡k32,k=1..∞
∞
sum⁡−1k,k=1..∞
∑k=1∞⁡−1k
_EnvFormal≔true
ζ⁡−32
−12
Setting _EnvFormal to false will also trigger detection of removable singularities in the interval of summation for numerical bounds.
sum⁡sin⁡xx,x=−1..1
1+2⁢sin⁡1
_EnvFormal≔false
Error, (in SumTools:-DefiniteSum:-ClosedForm) summand is singular in the interval of summation
_EnvFormal≔_EnvFormal
Using option formal instead of _EnvFormal has the advantage that the effect is local to the sum command; no "undoing" is necessary.
sum⁡−1k,k=1..∞,formal
The summand is a hypergeometric term in the summation variable.
F := binomial(2*k-3,k)/4^k;
F≔2⁢k−3k4k
Sum(F,k=0..n) = sum(F,k=0..n,parametric);
∑k=0n⁡2⁢k−3k4k=2⁢n−1n⁢2⁢n+44n+1n≤034n=12⁢n−1n⁢2⁢n+44n+1+382≤n
The summand is a rational function in the summation variable.
sum(1/k, k=a..b);
∑k=ab⁡1k
sum(1/k, k=a..b, parametric);
0a=b+1Ψ⁡b+1−Ψ⁡a1≤aand0≤bΨ⁡−b−Ψ⁡1−aa≤0andb≤−1FAILotherwise
The summand is a hypergeometric term in two variables.
Sum((-1)^k*binomial(n, k)*k, k=0..n) = sum((-1)^k*binomial(n, k)*k, k=0..n, parametric);
∑k=0n⁡−1k⁢nk⁢k=0n≤0−1n=102≤n
Without option parametric, the generic answer 0 is returned.
sum((-1)^k*binomial(n, k)*k, k = 0 .. n);
0
In general, the piecewise expression returned may contain an unevaluated, inert Sum.
sum(x^n/(3*n+2), n = 0 .. infinity, parametric);
LerchPhi⁡x,1,233x≤1∧x≠1∞1≤x∑n=0∞⁡xn3⁢n+2otherwise
Special sums.
Sum(q^n, n=1..infinity) = sum(q^n, n=1..infinity, parametric);
∑n=1∞⁡qn=−qq−1q<1∞1≤qundefinedotherwise
The sum command tries to find a formula for a definite sum, while the add command adds a finite sequence of terms.
sum(x^k,k=1..10000);
x10001x−1−xx−1
f := add(x^k,k=1..10000):
whattype(f);
`+`
nops(f);
10000
For short finite sums, the sum command uses the add command.
sum(x^k,k=1..10);
x10+x9+x8+x7+x6+x5+x4+x3+x2+x
add(x^k,k=1..10);
The add command can be used only if the summation bounds are numeric.
powersum := proc(a,b) local k; sum(3^k, k=a..b); end proc:
poweradd := proc(a,b) local k; add(3^k, k=a..b); end proc:
powersum(1,5);
363
poweradd(1,5);
powersum(1,n);
3n+12−32
poweradd(1,n);
Error, (in poweradd) range bounds in add must be numeric
The results from sum and add differ when the upper bound is less than the lower bound.
sum(x^k,k=5..1);
−x4−x3−x2
add(x^k,k=5..1);
In contrast to the sum command, the add command has special evaluation rules. Thus, no unevaluation quotes are necessary when summing over an expression that gives an error when evaluated at a non-integer.
v := Vector([1,2,3,4,5]);
v≔12345
v[k];
Error, bad index into Vector
add(v[k],k=1..5);
15
sum(v[k],k=1..5);
sum('v[k]',k=1..5);
The summation variable is local to the add command, but not to the sum command. The sum command raises an error if the summation variable has a value.
k := 42;
k≔42
add(k,k=1..10);
55
sum(k,k=1..10);
Error, (in sum) summation variable previously assigned, 2nd argument evaluates to 42 = 1 .. 10
sum('k','k'=1..10);
k := 'k':
In contrast to the sum command, the add command is implemented in the Maple kernel. When it is applicable, it is usually much more efficient. An exception to this rule is the case in which there is a large number of terms and the sum command is able to compute a closed form.
t := time():
for i from 1 to 1000 do add(x^k,k=1..10): end do: time() - t;
0.007
for i from 1 to 1000 do sum(x^k,k=1..10): end do: time() - t;
0.028
for i from 1 to 100 do add(x^k,k=1..10000): end do: time() - t;
1.481
for i from 1 to 100 do sum(x^k,k=1..10000): end do: time() - t;
0.014
Abramov, S.A. "Indefinite Sums of Rational Functions." In Proceedings ISSAC '95, pp. 303-308. Edited by A. H. M. Levelt. New York: ACM Press, 1995.
Abramov, S.A.; Carette, J.J.; Geddes, K.O.; and Le, H.Q. "Symbolic Summation in Maple." University of Waterloo Technical Report CS-2002-32, Department of Computer Science, 2002.
Abramov, S.A., and Petkovsek, M. "Rational Normal Forms and Minimal Decompositions of Hypergeometric Terms." Journal of Symbolic Computation, (May 2002): 521-543.
Abramov, S.A., and Petkovsek, M. "Gosper's Algorithm, Accurate Summation, and the discrete Newton-Leibniz formula." Proceedings ISSAC'05, (2005): 5-12.
Abramov, S.A., and van Hoeij, M. "Integration of Solutions of Linear Functional Equations." Integral Transformations and Special Functions, (1999): 3-12.
Abramov, S. A., and Zima, E. V. "D'Alembertian Solutions of Inhomogeneous Equations (differential, difference, and some other)." In Proceedings ISSAC '96, pp. 232-240. Edited by Y. N. Lakshman. New York: ACM Press, 1996.
Gosper, R.W., Jr. "Decision Procedure for Indefinite Hypergeometric Summation." Proceedings of the National Academy of Sciences, (January 1978): 40-42.
Koepf, W. "Algorithms for m-Fold Hypergeometric Summation." Journal of Symbolic Computation, (October 1995): 399-417.
Petkovsek, M.; Wilf, H.; and Zeilberger, D. A=B. Wellesley, Massachusetts: A. K. Peters Ltd., 1996.
Prudnikov, A. P.; Brychkov, Yu.; and Marichev, O. Integrals and Series, Volume 3: More Special Functions. Gordon and Breach Science, 1990.
Roach, K. "Hypergeometric Function Representations." In Proceedings ISSAC '96, pp. 301-308. Edited by Y. N. Lakshman. New York: ACM Press, 1996.
van Hoeij, M. "Finite Singularities and Hypergeometric Solutions of Linear Recurrence Equations." Journal of Pure and Applied Algebra, (June 1999): 109-131.
Zeilberger, D. "The Method of Creative Telescoping." Journal of Symbolic Computation, (March 1991): 195-204.
The sum command was updated in Maple 2016.
The formal option was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
See Also
add
collect
convert/StandardFunctions
evalf/Sum
expand
normal
product
RootOf
sum/numerical
SumTools
SumTools[IndefiniteSum][AddIndefiniteSum]
Download Help Document