Documentation |
Add patterns for definite and indefinite summation
This functionality does not run in MATLAB.
sum::addpattern(pat, k, res, <[var, …], <[cond, …]>>) sum::addpattern(pat, k = a .. b, res, <[var, …], <[cond, …]>>)
sum::addpattern(pat, k, res) teaches sum to make use of .
sum::addpattern(pat, k=a..b, res) teaches sum that .
A part of a computer algebra system's summation abilities stems from mathematical pattern matching. The MuPAD^{®} pattern matcher can be extended at runtime with sum::addpattern.
For definite summation, each bound is either an arithmetical expression which may contain pattern variables, or an identifier which can be used as a variable in the result and condition terms.
Users can include pattern variables and conditions on these by giving additional arguments. These conditions, as well as the result, are protected from premature evaluation, i.e., it is not necessary to write hold( _not @ iszero )(a^2-b), a simple not iszero(a^2-b) suffices.
The difference between not iszero(a^2-b) and a^2-b <> 0 when given as a condition is that the latter takes into account assumptions on the identifiers encountered, while the first does not. Cf. Example 4.
Patterns introduced by sum::addpattern are also used in recursive calls of sum and are automatically extended to include simple applications of summation by change of variables. Cf. Example 1.
Calling sum::addpattern changes the expressions returned by future calls to sum.
Not surprisingly, MuPAD does not know how to do an indefinite summation with the function foo:
sum(foo(n), n)
We add a pattern for this function:
sum::addpattern(foo(k), k, bar(k))
sum(foo(n), n)
Note that this pattern is also used indirectly:
sum(foo(k+3),k)
Definite sums can be added similarly:
sum::addpattern(foo(k), k=1..infinity, bar(k))
sum(foo(k), k=1..infinity)
The above pattern will also match this definite sum with different bounds:
sum(foo(k), k=3..infinity)
Note that this pattern is also used indirectly:
sum(foo(k)+1/k^3, k=1..infinity)
The bounds may also be variables occurring in the pattern or the result:
sum::addpattern(foo(k,a), k=0..a, bar(a), [a])
sum(foo(k,7), k=0..7)
The name of the summation variable used in the call to sum::addpattern does not restrict later calls to sum:
sum::addpattern(x^(2*i+1)/(2*i+1), i=0..infinity, piecewise([abs(x) < 1, arccoth(x) + PI/2*sqrt(-1/x^2)*x]), [x])
sum(x^(2*n+1)/(2*n+1),n=0..infinity)
Conditions are checked using is and therefore react to assumptions:
sum::addpattern(binomial(-1/2, k)*x^(2*k^2 + 1)/(2*k + 1), k = 0..infinity, arcsinh(x), [x], [abs(x) < 1])
sum(binomial(-1/2, k)*x^(2*k^2 + 1)/(2*k + 1), k = 0..infinity) assuming -1 < x < 1
sum(binomial(-1/2, k)*x^(2*k^2 + 1)/(2*k + 1), k = 0..infinity) assuming x > 1
If MuPAD cannot decide whether the conditions are satisfied, a piecewise defined object is returned:
sum(binomial(-1/2, k) * x^(2*k^2+1)/(2*k+1), k = 0..infinity)
If either the conditions are not satisfied or substituting the values into the result yields an error, the pattern is ignored. There is no need to include a condition to guard against an error, MuPAD simply computes the sum as usual:
sum::addpattern(c^k, k=0..n, (c^n-1)/(c-1), [c]); sum(1^k, k=0..n)
pat |
The pattern to match: an arithmetical expression in k. |
k |
The summation index: an identifier. |
a .. b |
The boundaries for a definite summation: arithmetical expressions or identifiers. |
res |
The pattern for the result of the summation: an arithmetical expression |
var, … |
"pattern variables": placeholders in pat and ret, i.e., identifiers or indexed identifiers. They do not represent themselves but almost arbitrary MuPAD expressions not containing k. You may restrict them by the conditions in the 5th parameter. |
cond, … |
Conditions on the pattern variables |