Add patterns for definite and indefinite summation
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
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^2b)
, a simple not
iszero(a^2b)
suffices.
The difference between not iszero(a^2b)
and a^2b
<> 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^n1)/(c1), [c]); sum(1^k, k=0..n)

The pattern to match: an arithmetical expression in 

The summation index: an identifier. 

The boundaries for a definite summation: arithmetical expressions or identifiers. 

The pattern for the result of the summation: an arithmetical expression 

"pattern variables": placeholders in 

Conditions on the pattern variables 
Object of type DOM_NULL