Up | Next | Tail |
This package carries out the Taylor expansion of an expression in one or more variables and efficient manipulation of the resulting Taylor series. Capabilities include basic operations (addition, subtraction, multiplication and division) and also application of certain algebraic and transcendental functions.1
The most important operator is taylor. It is used as follows:
where exp is the expression to be expanded. It can be any REDUCE object, even an expression containing other Taylor kernels. var is the kernel with respect to which exp is to be expanded. var0 denotes the expansion point about which and order the order up to which expansion is to take place. If more than one (var, var0, order) triple is specified taylor will expand its first argument independently with respect to each variable in turn. For example,
taylor(e^(x^2+y^2),x,0,2,y,0,2);
will calculate the Taylor expansion up to order \(X^{2}*Y^{2}\):
2 2 2 2 3 3 1 + y + x + y *x + O(x ,y )
Note that once the expansion has been done it is not possible to calculate higher orders. Instead of a kernel, var may also be a list of kernels. In this case expansion will take place in a way so that the sum of the degrees of the kernels does not exceed order. If var0 evaluates to the special identifier infinity, expansion is done in a series in 1/var instead of var.
The expansion is performed variable per variable, i.e. in the example above by first expanding \(\exp (x^{2}+y^{2})\) with respect to \(x\) and then expanding every coefficient with respect to \(y\).
There are two extra operators to compute the Taylor expansions of implicit and inverse functions:
takes a function f depending on two variables var and depvar and computes the Taylor series of the implicit function depvar(var) given by the equation f(var,depvar) = 0, around the point var0. (Violation of the necessary condition f(var0,depvar0)=0 causes an error.) For example,
implicit_taylor(x^2 + y^2 - 1,x,y,0,1,5);
gives the output
1 2 1 4 6 1 - ---*x - ---*x + O(x ) 2 8
takes a function f depending on var and computes the Taylor series of the inverse of f with respect to var0. For example,
inverse_taylor(exp(x)-1,x,y,0,8);
yields
1 2 1 3 1 4 1 5 y - ---*y + ---*y - ---*y + ---*y + (3 terms) 2 3 4 5 9 + O(y )
When a Taylor kernel is printed, only a certain number of (non-zero) coefficients are shown. If there are more, an expression of the form (\(n\) terms) is printed to indicate how many non-zero terms have been suppressed. The number of terms printed is given by the value of the shared algebraic variable taylorprintterms. Allowed values are integers and the special identifier ALL. The latter setting specifies that all terms are to be printed. The default setting is \(5\).
The part operator can be used to extract subexpressions of a Taylor expansion in the usual way. All terms can be accessed, irregardless of the value of the variable taylorprintterms.
If the switch taylorkeeporiginal is set to on the original expression exp is kept for later reference. It can be recovered by means of the operator
taylororiginal(exp:exprn):exprn
An error is signalled if exp is not a Taylor kernel or if the original expression was not kept, i.e. if taylorkeeporiginal was off during expansion. The template of a Taylor kernel, i.e. the list of all variables with respect to which expansion took place together with expansion point and order can be extracted using .
taylortemplate(exp:exprn):list
This returns a list of lists with the three elements (var,var0,order). As with taylororiginal, an error is signalled if exp is not a Taylor kernel.
taylorcoefflist(exp:exprn):list
This returns a list of two element lists (list of exponents,coefficient). Each exponent corresponds to a variable in the template. For homogenous expansion, each exponent is replaced by a list of exponents, as the template has a list of variables instead of a single one. Again, an error is signalled if exp is not a Taylor kernel.
See the test file for examples.
The operator
taylortostandard(exp:exprn):exprn
converts all Taylor kernels in exp into standard form and resimplifies the result.
The boolean operator
taylorseriesp(exp:exprn):boolean
may be used to determine if exp is a Taylor kernel. (Note that this operator is subject to the same restrictions as, e.g., ordp or numberp, i.e. it may only be used in boolean expressions in if or let statements.
Finally there is
taylorcombine(exp:exprn):exprn
which tries to combine all Taylor kernels found in exp into one. Operations currently possible are:
Addition, subtraction, multiplication, and division.
Roots, exponentials, and logarithms.
Trigonometric and hyperbolic functions and their inverses.
Application of unary operators like log and atan will nearly always succeed. For binary operations their arguments have to be Taylor kernels with the same template. This means that the expansion variable and the expansion point must match. Expansion order is not so important, different order usually means that one of them is truncated before doing the operation.
If taylorkeeporiginal is set to on and if all Taylor kernels in exp have their original expressions kept taylorcombine will also combine these and store the result as the original expression of the resulting Taylor kernel. There is also the switch taylorautoexpand (see below).
There are a few restrictions to avoid mathematically undefined expressions: it is not possible to take the logarithm of a Taylor kernel which has no terms (i.e. is zero), or to divide by such a beast. There are some provisions made to detect singularities during expansion: poles that arise because the denominator has zeros at the expansion point are detected and properly treated, i.e. the Taylor kernel will start with a negative power. (This is accomplished by expanding numerator and denominator separately and combining the results.) Essential singularities of the known functions (see above) are handled correctly.
Differentiation of a Taylor expression is possible. If you differentiate with respect to one of the Taylor variables the order will decrease by one.
Substitution is a bit restricted: Taylor variables can only be replaced by other kernels. There is one exception to this rule: you can always substitute a Taylor variable by an expression that evaluates to a constant. Note that REDUCE will not always be able to determine that an expression is constant.
Only simple taylor kernels can be integrated. More complicated expressions that contain Taylor kernels as parts of themselves are automatically converted into a standard representation by means of the taylortostandard operator. In this case a suitable warning is printed.
It is possible to revert a Taylor series of a function \(f\), i.e., to compute the first terms of the expansion of the inverse of \(f\) from the expansion of \(f\). This is done by the operator
taylorrevert(exp:exprn,oldvar:kernel, NEWVAR:kernel):exprn
EXP must evaluate to a Taylor kernel with OLDVAR being one of its expansion variables. Example:
taylor (u - u**2, u, 0, 5)$ taylorrevert (ws, u, x);
gives
2 3 4 5 6 x + x + 2*x + 5*x + 14*x + O(x )
This package introduces a number of new switches:
taylorautocombine
causes Taylor expressions to be automatically combined during the simplification process. This is equivalent to applying taylorcombine to every expression that contains Taylor kernels. Default is on.
taylorautoexpand
makes Taylor expressions “contagious” in the sense that taylorcombine tries to Taylor expand all non-Taylor subexpressions and to combine the result with the rest. Default is off.
taylorkeeporiginal
forces the package to keep the original expression, i.e. the expression that was Taylor expanded. All operations performed on the Taylor kernels are also applied to this expression which can be recovered using the operator taylororiginal. Default is off.
taylorprintorder
causes the remainder to be printed in big-\(O\) notation. Otherwise, three dots are printed. Default is on.
verboseload
will cause REDUCE to print some information when the Taylor package is loaded. This switch is already present in PSL systems. Default is off.
taylor should always detect non-analytical expressions in its first argument. As an example, consider the function \(xy/(x+y)\) that is not analytical in the neighborhood of \((x,y) = (0,0)\): Trying to calculate
taylor(x*y/(x+y),x,0,2,y,0,2);
causes an error
***** Not a unit in argument to QUOTTAYLOR
Note that it is not generally possible to apply the standard REDUCE operators to a Taylor kernel. For example, coeff or coeffn cannot be used. Instead, the expression at hand has to be converted to standard form first using the taylortostandard operator.
*** Cannot expand further... truncation done
You will get this warning if you try to expand a Taylor kernel to a higher
order.
*** Converting Taylor kernels to standard representation
This warning appears if you try to integrate an expression containing Taylor kernels.
***** Branch point detected in ...
This occurs if you take a rational power of a Taylor kernel and raising the
lowest order term of the kernel to this power yields a non analytical term
(i.e. a fractional power).
***** Cannot replace part ... in Taylor kernel
The part operator can only be used to either replace the template of a Taylor
kernel (part 2) or the original expression that is kept for reference (part 3).
***** Computation loops (recursive definition?): ...
Most probably the expression to be expanded contains an operator whose
derivative involves the operator itself.
***** Error during expansion (possible singularity)
The expression you are trying to expand caused an error. As far as I know
this can only happen if it contains a function with a pole or an essential
singularity at the expansion point. (But one can never be sure.)
***** Essential singularity in ...
An essential singularity was detected while applying a special function to a
Taylor kernel.
***** Expansion point lies on branch cut in ...
The only functions with branch cuts this package knows of are (natural)
logarithm, inverse circular and hyperbolic tangent and cotangent. The
branch cut of the logarithm is assumed to lie on the negative real axis.
Those of the arc tangent and arc cotangent functions are chosen to be
compatible with this: both have essential singularities at the points \(\pm i\). The
branch cut of arc tangent is the straight line along the imaginary axis
connecting \(+1\) to \(-1\) going through \(\infty \) whereas that of arc cotangent goes through
the origin. Consequently, the branch cut of the inverse hyperbolic tangent
resp. cotangent lies on the real axis and goes from \(-1\) to \(+1\), that of the latter
across \(0\), the other across \(\infty \).
The error message can currently only appear when you try to calculate the inverse tangent or cotangent of a Taylor kernel that starts with a negative degree. The case of a logarithm of a Taylor kernel whose constant term is a negative real number is not caught since it is difficult to detect this in general.
***** Input expression non-zero at given point
Violation of the necessary condition f(var0,depvar0)=0 for the arguments of
implicit_taylor.
***** Invalid substitution in Taylor kernel: ...
You tried to substitute a variable that is already present in the Taylor kernel
or on which one of the Taylor variables depend.
***** Not a unit in ...
This will happen if you try to divide by or take the logarithm of a Taylor
series whose constant term vanishes.
***** Not implemented yet (...)
Sorry, but this feature is not implemented, although it is possible to do so.
***** Reversion of Taylor series not possible: ...
You tried to call the taylorrevert operator with inappropriate
arguments. The second half of this error message tells you why this operation
is not possible.
***** Taylor kernel doesn’t have an original part
The Taylor kernel upon which you try to use taylororiginal was
created with the switch taylorkeeporiginal set to off and does
therefore not keep the original expression.
***** Wrong number of arguments to TAYLOR
You try to use the operator taylor with a wrong number of arguments.
***** Zero divisor in TAYLOREXPAND
A zero divisor was found while an expression was being expanded. This
should not normally occur.
***** Zero divisor in Taylor substitution
That’s exactly what the message says. As an example consider the case of a
Taylor kernel containing the term 1/x and you try to substitute x by 0.
***** ... invalid as kernel
You tried to expand with respect to an expression that is not a kernel.
***** ... invalid as order of Taylor expansion
The order parameter you gave to taylor is not an integer.
***** ... invalid as Taylor kernel
You tried to apply taylororiginal or taylortemplate to an
expression that is not a Taylor kernel.
***** ... invalid as Taylor Template element
You tried to substitute the taylortemplate part of a Taylor kernel with
a list of incorrect form. For the correct form see the description of the
taylortemplate operator.
***** ... invalid as Taylor variable
You tried to substitute a Taylor variable by an expression that is not a kernel.
***** ... invalid as value of TaylorPrintTerms
You have assigned an invalid value to taylorprintterms. Allowed
values are: an integer or the special identifier all.
TAYLOR PACKAGE (...): this can’t happen ...
This message shows that an internal inconsistency was detected. This is not
your fault, at least as long as you did not try to work with the internal data
structures of REDUCE. Send input and output to the REDUCE developers
mailing list, together with the version information that is printed out.
At the moment there is only one REDUCE package that I know of: the extendible power series package by Alan Barnes and Julian Padget. In my opinion there are two major differences:
The interface. They use the domain mechanism for their power series, I decided to invent a special kind of kernel. Both approaches have advantages and disadvantages: with domain modes, it is easier to do certain things automatically, e.g., conversions.
The concept of an extendible series: their idea is to remember the original expression and to compute more coefficients when more of them are needed. My approach is to truncate at a certain order and forget how the unexpanded expression looked like. I think that their method is more widely usable, whereas mine is more efficient when you know in advance how many terms you need.
Up | Next | Front |