Definite and indefinite summation
This functionality does not run in MATLAB.
sum(f, i) sum(f, i = a .. b) sum(f, i = RootOf(p, x))
sum(f, i) computes a symbolic antidifference of f(i) with respect to i.
sum(f, i = a..b) tries to find a closed form representation of the sum .
sum serves for simplifying symbolic sums (the discrete analog of integration). It should not be used for simply adding a finite number of terms: if a and b are integers of type DOM_INT, the call _plus(f $ i = a..b) gives the desired result, while sum(f, i = a..b) may return unevaluated. expand may be used to sum such an unevaluated finite sum. See Example 3.
sum(f, i) computes the indefinite sum of f with respect to i. This is an expression g such that f(i) = g(i + 1) - g(i).
It is implicitly assumed that i runs through integers only.
sum(f, i = a..b) computes the definite sum with i running from a to b.
If a and b are numbers, then they must be integers.
If b - a is a nonnegative integer, then the explicit sum f(a) + f(a + 1) + … + f(b) is returned, provided that this sum has no more than 1000 terms.
sum(f, i = RootOf(p, x)) computes the sum with i extending over all roots of the polynomial p with respect to x.
If f is a rational function of i, a closed form of the sum will be found.
See Example 2.
The system returns a symbolic call of sum if it cannot compute a closed form representation of the sum.
We compute some indefinite sums:
sum(1/(i^2 - 1), i)
sum(1/i/(i + 2)^2, i)
sum(binomial(n + i, i), i)
We compute some definite sums. Note that are valid boundaries:
sum(1/(i^2 + 21*i), i = 1..infinity)
sum(1/i, i = a .. a + 3)
We compute some sums over all roots of a polynomial:
sum(i^2, i = RootOf(x^3 + a*x^2 + b*x + c, x))
sum(1/(z + i), i = RootOf(x^4 - y*x + 1, x))
sum can compute finite sums if indefinite summation succeeds:
sum(1/(i^2 + i), i = 1..100)
_plus yields the same result more quickly if the number of summands is small:
_plus(1/(i^2 + i) $ i = 1..100)
In such cases, sum is much more efficient than _plus if the number of summands is large:
sum(1/(i^2 + i), i = 1..10^30)
Finite sums for which no indefinite summation is possible are expanded if they have no more than 1000 terms:
sum(binomial(n, i), i = 0..4)
An application of expand is necessary to expand the binomials:
Finite sums with more than 1000 terms are not expanded:
sum(binomial(n, i), i = 0..1000)
However, if one of the boundaries is symbolic, then _plus cannot be used:
_plus(1/(i^2 + i) $ i = 1..n)
_plus(binomial(n, i) $ i = 0..n)
sum(1/(i^2 + i), i = 1..n), sum(binomial(n, i), i = 0..n)
The following infinite sum cannot be computed symbolically:
sum(ln(i)/i^5, i = 1..infinity)
We obtain a floating-point approximation via float:
numeric::sum(ln(i)/i^5, i = 1..infinity)
An arithmetical expression depending on i
The boundaries: arithmetical expressions
An indeterminate of p
The function sum implements Abramov's algorithm for rational expressions, Gosper's algorithm for hypergeometric expressions, and Zeilberger's algorithm for the definite summation of holonomic expressions.