 sum - Maple Programming Help

Home : Support : Online Help : Mathematics : Inert Functions : sum/details

sum

definite and indefinite symbolic summation

Sum

inert form of sum

Calling Sequence

 sum(f, k) $\sum _{k}f$ sum(f, k=m..n, parametric, formal=b) $\sum _{k=m}^{n}f$ sum(f, k=alpha) $\sum _{k=\mathrm{\alpha }}f$ sum(f, k=expr) $\sum _{k=\mathrm{expr}}f$ Sum(f, k) ${\sum }_{k}f$ Sum(f, k=m..n) ${\sum }_{k=m}^{n}f$ Sum(f, k=alpha) ${\sum }_{k=\mathrm{\alpha }}f$ Sum(f, k=expr) ${\sum }_{k=\mathrm{expr}}f$

Parameters

 f - expression k - name; summation index m, n - integers or arbitrary expressions parametric - (optional) literal name b - (optional) either $\mathrm{true}$ or $\mathrm{false}$ alpha - RootOf expression expr - expression, of type algebraic, not containing k

Basic Information

 • This help page contains complete information about the sum command. For basic information on the sum command, see the sum help page.

Description

 • 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 $\frac{1}{2}{n}^{2}-\frac{1}{2}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 $\sum _{k}{k}^{2}$.

Note

 • 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.

Details

 • The call sum(f, k) computes an indefinite sum of $f\left(k\right)$ with respect to $k$. It computes an anti-difference $g\left(k\right)$ of $f\left(k\right)$ such that $g\left(k+1\right)-g\left(k\right)=f\left(k\right)$ in general (SumTools[IndefiniteSum][Indefinite]).
 • The call sum(f, k=m..n) computes the definite sum of $f\left(k\right)$ over the given range $m..n$. That is, it computes $f\left(m\right)+f\left(m+1\right)+\mathrm{...}+f\left(n\right)$. 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$.

$\left(\sum _{k=l}^{m-1}f\right)+\left(\sum _{k=m}^{n}f\right)=\sum _{k=l}^{n}f$

 • The call sum(f, k=alpha) computes the definite sum of $f\left(k\right)$ 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 $\mathrm{expr}$ for $k$ in $f$.
 • For indefinite summation, Maple uses the following methods:
 a. Polynomials are summed using a formula based on Bernoulli polynomials.
 b. 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.
 c. 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.
 d. The method of accurate summation.
 e. 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:
 a. 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.
 b. Creative telescoping method for computing closed forms of definite sums of hypergeometric terms.
 c. 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).
 d. 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.

Options

 • 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.

Examples

Indefinite sums

Polynomials:

 > $\mathrm{sum}\left({k}^{2},k\right)$
 $\frac{{1}}{{3}}{}{{k}}^{{3}}{-}\frac{{1}}{{2}}{}{{k}}^{{2}}{+}\frac{{1}}{{6}}{}{k}$ (1)

Rationals:

 > $\mathrm{sum}\left(\frac{k+{k}^{2}+{5}^{\frac{1}{2}}k-1}{\left({k}^{2}+{5}^{\frac{1}{2}}k-1\right)k},k\right)$
 ${-}\frac{{1}}{{3}{}\left({k}{-}\frac{{3}}{{2}}{+}\frac{\sqrt{{5}}}{{2}}\right)}{-}\frac{{1}}{{3}{}\left({k}{-}\frac{{1}}{{2}}{+}\frac{\sqrt{{5}}}{{2}}\right)}{-}\frac{{1}}{{3}{}\left({k}{+}\frac{{1}}{{2}}{+}\frac{\sqrt{{5}}}{{2}}\right)}{-}\frac{{4}{}{\mathrm{\Psi }}{}\left({k}\right)}{\left(\sqrt{{5}}{-}{3}\right){}\left({3}{+}\sqrt{{5}}\right)}$ (2)

Hypergeometric terms:

 > $\mathrm{sum}\left(\frac{{4}^{k}{k}^{4}}{\mathrm{binomial}\left(2k,k\right)},k\right)$
 $\frac{\left({2}{}{k}{-}{1}\right){}\left({63}{}{{k}}^{{4}}{-}{140}{}{{k}}^{{3}}{+}{60}{}{{k}}^{{2}}{+}{26}{}{k}{-}{6}\right){}{{4}}^{{k}}}{{693}{}\left(\genfrac{}{}{0}{}{{2}{}{k}}{{k}}\right)}$ (3)

2-fold hypergeometric terms:

 > $\mathrm{sum}\left(k\left(\frac{1}{2}k\right)!,k\right)$
 ${2}{}\left(\frac{{k}}{{2}}\right){!}{+}{2}{}\left(\frac{{k}}{{2}}{+}\frac{{1}}{{2}}\right){!}$ (4)

Sum of hypergeometric terms:

 > $\mathrm{sum}\left(\frac{{2}^{2k-1}}{k\left(2k+1\right)\mathrm{binomial}\left(2k,k\right)}+\frac{{\left(k+1\right)}^{2}{4}^{k+1}}{\left(k+2\right)\left(k+3\right)},k\right)$
 ${-}\frac{{{2}}^{{2}{}{k}{-}{1}}}{\left(\genfrac{}{}{0}{}{{2}{}{k}}{{k}}\right){}{k}}{+}\frac{\left({k}{-}{1}\right){}{{4}}^{{k}{+}{1}}}{{3}{}\left({k}{+}{2}\right)}$ (5)

Accurate summation

 > $\mathrm{sum}\left(\mathrm{\Gamma }\left(k+1\right)-\mathrm{\Gamma }\left(k\right)-\mathrm{\Psi }\left(k\right),k\right)$
 $\frac{\left({{k}}^{{4}}{-}{{k}}^{{3}}{-}{6}{}{{k}}^{{2}}{-}{6}{}{k}{-}{5}\right){}\left({\mathrm{\Gamma }}{}\left({k}{+}{1}\right){-}{\mathrm{\Gamma }}{}\left({k}\right){-}{\mathrm{\Psi }}{}\left({k}\right)\right)}{{{k}}^{{2}}{+}{k}{+}{3}}{-}\frac{\left({{k}}^{{5}}{-}{{k}}^{{4}}{-}{10}{}{{k}}^{{3}}{-}{9}{}{{k}}^{{2}}{-}{2}\right){}\left({\mathrm{\Gamma }}{}\left({k}{+}{2}\right){-}{\mathrm{\Gamma }}{}\left({k}{+}{1}\right){-}{\mathrm{\Psi }}{}\left({k}{+}{1}\right)\right)}{{k}{}\left({{k}}^{{2}}{+}{k}{+}{3}\right)}{+}\frac{\left({k}{+}{1}\right){}\left({{k}}^{{3}}{-}{5}{}{{k}}^{{2}}{+}{4}{}{k}{-}{2}\right){}\left({\mathrm{\Gamma }}{}\left({k}{+}{3}\right){-}{\mathrm{\Gamma }}{}\left({k}{+}{2}\right){-}{\mathrm{\Psi }}{}\left({k}{+}{2}\right)\right)}{{k}{}\left({{k}}^{{2}}{+}{k}{+}{3}\right)}$ (6)

 > $\mathrm{sum}\left(\frac{\left({k}^{2}-2k-1\right){2}^{k}}{\left(k+1\right){k}^{2}\left(k+3\right)!},k\right)$
 $\frac{\left({k}{+}{3}\right){}\left({\prod }_{{\mathrm{_i}}{=}{1}}^{{k}{-}{1}}{}\frac{{2}}{{\mathrm{_i}}{+}{4}}\right)}{{12}{}{k}}{+}\left({\sum }_{{k}}{}\frac{\left({{k}}^{{2}}{+}{2}{}{k}{-}{1}\right){}\left({\prod }_{{\mathrm{_i}}{=}{1}}^{{k}{-}{1}}{}\frac{{2}}{{\mathrm{_i}}{+}{4}}\right)}{{12}{}{{k}}^{{2}}}\right)$ (7)

Sum of a logarithm of a rational function (provided the argument of the logarithm has constant sign):

 > $\mathrm{sum}\left(\mathrm{ln}\left(2k+1\right),k\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{assuming}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}0\le k$
 ${\mathrm{ln}}{}\left({2}\right){}{k}{+}{\mathrm{ln}}{}\left({\mathrm{\Gamma }}{}\left({k}{+}\frac{{1}}{{2}}\right)\right)$ (8)
 > $\mathrm{sum}\left(\mathrm{ln}\left(2k+1\right),k\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{assuming}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}k\le -1$
 ${\mathrm{ln}}{}\left({2}\right){}{k}{-}{\mathrm{ln}}{}\left({\mathrm{\Gamma }}{}\left(\frac{{1}}{{2}}{-}{k}\right)\right){+}{I}{}{k}{}{\mathrm{\pi }}$ (9)

Library extension mechanism:

 > $\mathrm{sum}\left(\mathrm{sin}\left(k\right)\mathrm{cos}\left(k+1\right)-\mathrm{\Psi }\left(k\right),k\right)$
 $\frac{{-}{2}{}{\mathrm{\Psi }}{}\left({k}{+}{1}\right){}{k}{}{\mathrm{sin}}{}\left({1}\right){-}{{\mathrm{sin}}{}\left({1}\right)}^{{2}}{}{k}{+}{2}{}{\mathrm{\gamma }}{}{\mathrm{sin}}{}\left({1}\right){+}{2}{}{\mathrm{\Psi }}{}\left({k}\right){}{\mathrm{sin}}{}\left({1}\right){-}{{\mathrm{cos}}{}\left({k}\right)}^{{2}}{+}{2}{}{\mathrm{sin}}{}\left({1}\right){}{k}}{{2}{}{\mathrm{sin}}{}\left({1}\right)}$ (10)

Definite sums

Classical telescoping:

 > $\mathrm{sum}\left(\mathrm{binomial}\left(2n-2k,n-k\right){2}^{4k}{\left(2k\left(2k+1\right)\mathrm{binomial}\left(2k,k\right)\right)}^{-1},k\right)$
 $\frac{{{2}}^{{4}{}{k}}{}\left(\genfrac{}{}{0}{}{{2}{}{n}{-}{2}{}{k}}{{n}{-}{k}}\right){}\left({-}{2}{}{n}{+}{2}{}{k}{-}{1}\right)}{{2}{}\left(\genfrac{}{}{0}{}{{2}{}{k}}{{k}}\right){}{k}{}\left({2}{}{n}{+}{1}\right)}$ (11)
 > $\mathrm{sum}\left(\mathrm{binomial}\left(2n-2k,n-k\right){2}^{4k}{\left(2k\left(2k+1\right)\mathrm{binomial}\left(2k,k\right)\right)}^{-1},k=1..n\right)$
 ${-}\frac{\left(\genfrac{}{}{0}{}{{2}{}{n}{-}{2}}{{n}{-}{1}}\right){}\left({-}{8}{}{n}{+}{4}\right)}{{2}{}{n}{+}{1}}$ (12)

Creative telescoping:

 > $\mathrm{sum}\left({\mathrm{binomial}\left(2n,2k\right)}^{2},k=0..n\right)$
 $\frac{{\left({-1}\right)}^{{n}}{}\left(\genfrac{}{}{0}{}{{2}{}{n}}{{n}}\right)}{{2}}{+}\frac{\left(\genfrac{}{}{0}{}{{4}{}{n}}{{2}{}{n}}\right)}{{2}}$ (13)

Conversion method:

 > $\mathrm{sum}\left(\frac{\frac{{2}^{2k}}{{\mathrm{\pi }}^{\frac{1}{2}}}\mathrm{\Gamma }\left(k-n\right)\mathrm{\Gamma }\left(k+n\right)}{\mathrm{\Gamma }\left(2k+1\right)}{z}^{k},k=0..\mathrm{\infty }\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{assuming}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{abs}\left(z\right)\le 1$
 ${-}\frac{\sqrt{{\mathrm{\pi }}}{}{\mathrm{cos}}{}\left({2}{}{n}{}{\mathrm{arcsin}}{}\left(\sqrt{{z}}\right)\right){}{\mathrm{csc}}{}\left({\mathrm{\pi }}{}{n}\right)}{{n}}$ (14)

Pattern match (Abel's type):

 > $\mathrm{sum}\left(\frac{{\left(2+k\right)}^{k-2}{\left(1+n-k\right)}^{n-k}}{k!\left(n-k\right)!},k=0..n\right)$
 $\frac{{\left({n}{+}{3}\right)}^{{n}}}{{4}{}{n}{!}}{-}\frac{{\left({n}{+}{3}\right)}^{{n}{-}{1}}}{{6}{}\left({n}{-}{1}\right){!}}$ (15)

Maple returns the call unevaluated if it cannot find a closed form.

 > $\mathrm{sum}\left(a\left(k\right){x}^{k},k=0..n\right)$
 ${\sum }_{{k}{=}{0}}^{{n}}{}{a}{}\left({k}\right){}{{x}}^{{k}}$ (16)

If the inert function is used, Maple returns unevaluated.

 > $\mathrm{Sum}\left(\frac{k}{k+1},k=0..n\right)=\mathrm{sum}\left(\frac{k}{k+1},k=0..n\right)$
 ${\sum }_{{k}{=}{0}}^{{n}}{}\frac{{k}}{{k}{+}{1}}{=}{n}{+}{1}{-}{\mathrm{\Psi }}{}\left({n}{+}{2}\right){-}{\mathrm{\gamma }}$ (17)

Some definite sums may return an expression containing inert Sums.

 > $\mathrm{sum}\left(\mathrm{binomial}\left(-n,3k\right),k=-n+1..-1\right)$
 $\frac{{22}}{{9}{}{{2}}^{{n}}}{+}\frac{{2}{}{I}{}{\left(\frac{{1}}{{2}}{+}\frac{{I}{}\sqrt{{3}}}{{2}}\right)}^{{n}}{}\left({-}{9}{}\sqrt{{3}}{+}{4}{}{I}\right)}{{9}}{+}\frac{{2}{}{I}{}{\left(\frac{{1}}{{2}}{-}\frac{{I}{}\sqrt{{3}}}{{2}}\right)}^{{n}}{}\left({9}{}\sqrt{{3}}{+}{4}{}{I}\right)}{{9}}{+}\frac{{\sum }_{{\mathrm{_z2}}{=}{0}}^{{n}{-}{1}}{}\frac{{\left({1}{+}{I}{}\sqrt{{3}}\right)}^{{\mathrm{_z2}}}{}\left({3}{}\left({\sum }_{{\mathrm{_z3}}{=}{0}}^{{\mathrm{_z2}}{-}{1}}{}\frac{{-}\frac{{I}}{{3}}{}{\left({-}{1}{-}{I}{}\sqrt{{3}}\right)}^{{\mathrm{_z3}}}{}\left({3}{}{I}{}\left({\sum }_{{\mathrm{_z4}}{=}{0}}^{{\mathrm{_z3}}{-}{1}}{}{-}\frac{{\left({1}{+}{I}{}\sqrt{{3}}\right)}^{{\mathrm{_z4}}}{}\left({455}{}{{\mathrm{_z4}}}^{{4}}{+}{1843}{}{{\mathrm{_z4}}}^{{3}}{+}{2524}{}{{\mathrm{_z4}}}^{{2}}{+}{1340}{}{\mathrm{_z4}}{+}{228}\right){}\left(\genfrac{}{}{0}{}{{3}{}{\mathrm{_z4}}}{{\mathrm{_z4}}}\right)}{{3}{}{{2}}^{{\mathrm{_z4}}}{}\left({\mathrm{_z4}}{+}{2}\right){}\left({2}{}{\mathrm{_z4}}{+}{3}\right){}\left({\mathrm{_z4}}{+}{1}\right){}\left({2}{}{\mathrm{_z4}}{+}{1}\right)}\right){+}{19}{}{I}{-}{19}{}\sqrt{{3}}\right)}{{{2}}^{{\mathrm{_z3}}}}\right){-}{38}\right)}{{3}}}{{{2}}^{{n}}}$ (18)
 > $\mathrm{sum}\left(-\mathrm{exp}\left(-k\right),k\right)$
 ${-}\frac{{{ⅇ}}^{{-}{k}}}{{{ⅇ}}^{{-1}}{-}{1}}$ (19)
 > $\mathrm{sum}\left(\frac{1}{k!},k=0..\mathrm{\infty }\right)$
 ${ⅇ}$ (20)
 > $\mathrm{sum}\left(\frac{1}{{k}^{2}},k=1..\mathrm{\infty }\right)$
 $\frac{{{\mathrm{\pi }}}^{{2}}}{{6}}$ (21)
 > $\mathrm{sum}\left(\frac{k}{k+1},k=\mathrm{RootOf}\left({x}^{3}-2\right)\right)$
 ${2}$ (22)

Formal sums

 > $\mathrm{sum}\left({k}^{\frac{3}{2}},k=1..\mathrm{\infty }\right)$
 ${\mathrm{\infty }}$ (23)
 > $\mathrm{sum}\left({\left(-1\right)}^{k},k=1..\mathrm{\infty }\right)$
 ${\sum }_{{k}{=}{1}}^{{\mathrm{\infty }}}{}{\left({-1}\right)}^{{k}}$ (24)

If _EnvFormal is assigned true, the sum command uses resummation methods to return a finite result for various classes of divergent sums.

 > $\mathrm{_EnvFormal}≔\mathrm{true}$
 ${\mathrm{_EnvFormal}}{≔}{\mathrm{true}}$ (25)
 > $\mathrm{sum}\left({k}^{\frac{3}{2}},k=1..\mathrm{\infty }\right)$
 ${\mathrm{\zeta }}{}\left({-}\frac{{3}}{{2}}\right)$ (26)
 > $\mathrm{sum}\left({\left(-1\right)}^{k},k=1..\mathrm{\infty }\right)$
 ${-}\frac{{1}}{{2}}$ (27)

Setting _EnvFormal to false will also trigger detection of removable singularities in the interval of summation for numerical bounds.

 > $\mathrm{sum}\left(\frac{\mathrm{sin}\left(x\right)}{x},x=-1..1\right)$
 ${1}{+}{2}{}{\mathrm{sin}}{}\left({1}\right)$ (28)
 > $\mathrm{_EnvFormal}≔\mathrm{false}$
 ${\mathrm{_EnvFormal}}{≔}{\mathrm{false}}$ (29)
 > $\mathrm{sum}\left(\frac{\mathrm{sin}\left(x\right)}{x},x=-1..1\right)$
 > $\mathrm{_EnvFormal}≔'\mathrm{_EnvFormal}'$
 ${\mathrm{_EnvFormal}}{≔}{\mathrm{_EnvFormal}}$ (30)

Using option formal instead of _EnvFormal has the advantage that the effect is local to the sum command; no "undoing" is necessary.

 > $\mathrm{sum}\left({\left(-1\right)}^{k},k=1..\mathrm{\infty },\mathrm{formal}\right)$
 ${-}\frac{{1}}{{2}}$ (31)
 > $\mathrm{sum}\left({\left(-1\right)}^{k},k=1..\mathrm{\infty }\right)$
 ${\sum }_{{k}{=}{1}}^{{\mathrm{\infty }}}{}{\left({-1}\right)}^{{k}}$ (32)

Examples for the parametric case

The summand is a hypergeometric term in the summation variable.

 > F := binomial(2*k-3,k)/4^k;
 ${F}{≔}\frac{\left(\genfrac{}{}{0}{}{{2}{}{k}{-}{3}}{{k}}\right)}{{{4}}^{{k}}}$ (33)
 > Sum(F,k=0..n) = sum(F,k=0..n,parametric);
 ${\sum }_{{k}{=}{0}}^{{n}}{}\frac{\left(\genfrac{}{}{0}{}{{2}{}{k}{-}{3}}{{k}}\right)}{{{4}}^{{k}}}{=}\left\{\begin{array}{cc}\frac{\left(\genfrac{}{}{0}{}{{2}{}{n}{-}{1}}{{n}}\right){}\left({2}{}{n}{+}{4}\right)}{{{4}}^{{n}{+}{1}}}& {n}{\le }{0}\\ \frac{{3}}{{4}}& {n}{=}{1}\\ \frac{\left(\genfrac{}{}{0}{}{{2}{}{n}{-}{1}}{{n}}\right){}\left({2}{}{n}{+}{4}\right)}{{{4}}^{{n}{+}{1}}}{+}\frac{{3}}{{8}}& {2}{\le }{n}\end{array}\right\$ (34)

The summand is a rational function in the summation variable.

 > sum(1/k, k=a..b);
 ${\sum }_{{k}{=}{a}}^{{b}}{}\frac{{1}}{{k}}$ (35)
 > sum(1/k, k=a..b, parametric);
 $\left\{\begin{array}{cc}{0}& {a}{=}{b}{+}{1}\\ {\mathrm{\Psi }}{}\left({b}{+}{1}\right){-}{\mathrm{\Psi }}{}\left({a}\right)& {1}{\le }{a}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{0}{\le }{b}\\ {\mathrm{\Psi }}{}\left({-}{b}\right){-}{\mathrm{\Psi }}{}\left({1}{-}{a}\right)& {a}{\le }{0}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{b}{\le }{-1}\\ {\mathrm{FAIL}}& {\mathrm{otherwise}}\end{array}\right\$ (36)

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);
 ${\sum }_{{k}{=}{0}}^{{n}}{}{\left({-1}\right)}^{{k}}{}\left(\genfrac{}{}{0}{}{{n}}{{k}}\right){}{k}{=}\left\{\begin{array}{cc}{0}& {n}{\le }{0}\\ {-1}& {n}{=}{1}\\ {0}& {2}{\le }{n}\end{array}\right\$ (37)
 Without option parametric, the generic answer $0$ is returned.
 > sum((-1)^k*binomial(n, k)*k, k = 0 .. n);
 ${0}$ (38)
 In general, the piecewise expression returned may contain an unevaluated, inert Sum.
 > s := sum((-1)^k*binomial(n, k)*k^3, k=0..n, parametric);
 ${s}{≔}\left\{\begin{array}{cc}{0}& {n}{\le }{0}\\ {\sum }_{{k}{=}{0}}^{{n}}{}{\left({-1}\right)}^{{k}}{}\left(\genfrac{}{}{0}{}{{n}}{{k}}\right){}{{k}}^{{3}}& {1}{\le }{n}{\le }{3}\\ {0}& {4}{\le }{n}\end{array}\right\$ (39)
 Use the value command in order to evaluate the piecewise result at a point.
 > eval(s, n=2);
 ${\sum }_{{k}{=}{0}}^{{2}}{}{\left({-1}\right)}^{{k}}{}\left(\genfrac{}{}{0}{}{{2}}{{k}}\right){}{{k}}^{{3}}$ (40)
 > value((40));
 ${6}$ (41)

Special sums.

 > Sum(q^n, n=1..infinity) = sum(q^n, n=1..infinity, parametric);
 ${\sum }_{{n}{=}{1}}^{{\mathrm{\infty }}}{}{{q}}^{{n}}{=}\left\{\begin{array}{cc}{-}\frac{{q}}{{q}{-}{1}}& \left|{q}\right|{<}{1}\\ {\mathrm{\infty }}& {1}{\le }{q}\\ {\mathrm{undefined}}& {\mathrm{otherwise}}\end{array}\right\$ (42)

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);
 $\frac{{{x}}^{{10001}}}{{x}{-}{1}}{-}\frac{{x}}{{x}{-}{1}}$ (43)
 > whattype(f);
 ${\mathrm{+}}$ (44)
 > nops(f);
 ${10000}$ (45)

For short finite sums, the sum command uses the add command.

 > sum(x^k,k=1..10);
 ${{x}}^{{10}}{+}{{x}}^{{9}}{+}{{x}}^{{8}}{+}{{x}}^{{7}}{+}{{x}}^{{6}}{+}{{x}}^{{5}}{+}{{x}}^{{4}}{+}{{x}}^{{3}}{+}{{x}}^{{2}}{+}{x}$ (46)
 ${{x}}^{{10}}{+}{{x}}^{{9}}{+}{{x}}^{{8}}{+}{{x}}^{{7}}{+}{{x}}^{{6}}{+}{{x}}^{{5}}{+}{{x}}^{{4}}{+}{{x}}^{{3}}{+}{{x}}^{{2}}{+}{x}$ (47)

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:
 > powersum(1,5);
 ${363}$ (48)
 ${363}$ (49)
 > powersum(1,n);
 $\frac{{{3}}^{{n}{+}{1}}}{{2}}{-}\frac{{3}}{{2}}$ (50)

The results from sum and add differ when the upper bound is less than the lower bound.

 > sum(x^k,k=5..1);
 ${-}{{x}}^{{4}}{-}{{x}}^{{3}}{-}{{x}}^{{2}}$ (51)
 ${0}$ (52)

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}{≔}\left[\begin{array}{c}{1}\\ {2}\\ {3}\\ {4}\\ {5}\end{array}\right]$ (53)
 > v[k];
 ${15}$ (54)
 > sum(v[k],k=1..5);
 > sum('v[k]',k=1..5);
 ${15}$ (55)

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}$ (56)
 ${55}$ (57)
 ${55}$ (58)