Taylor models
A rectangle encloses one value. A Taylor model encloses a whole function on a disc: a polynomial, and a number that the difference between the polynomial and the function is proved never to exceed. Contour integrals, zero counts and residues in this package are all read off such models.
import { taylorModel, disc } from "@ratmath/complex";
const m = taylorModel("exp(z) - 3z^2", disc("1/2", "1/2"));
m.error; // about 3.4e-14: |f − P| ≤ this on the whole disc
m.at("3/4 + 1/4i"); // 0.55118761286 - 0.60124581415i ± 3.4e-14
m.range(); // a disc that holds every value f takes
m.integral(0, 1); // 0.71828182846 ± 3.4e-14, which is e − 2
m.derivative("1/4"); // a model of f′ on the smaller disc
The statement a model makes
A model of on the closed disc is a polynomial of degree at most and a number with
and with analytic there. Both halves matter. The bound is what makes every number that comes out of a model a proven enclosure. Analyticity is what lets a contour be moved inside the disc, an integral be read off an antiderivative, and Cauchy's estimate bound a derivative.
Arithmetic that keeps the statement true
Models on the same disc are added, multiplied and divided, and each operation moves into whatever it cannot keep.
- Sum. Polynomials add and so do the bounds.
- Product. : the terms of above degree are bounded by the sizes of their coefficients, and the cross terms by .
- Reciprocal. A candidate for is found as a power series, with no rigour needed. Then is computed as a model. If on the disc, cannot vanish there and . If no such is found the division is refused.
- exp, log, roots. Write with the value at the centre. Then , , and likewise for roots, each series cut off with its tail bounded. Sine, cosine and the hyperbolic functions come from exp.
Inside, the polynomial is kept in the scaled variable with , so the size of a polynomial on the disc is at most the sum of the sizes of its coefficients. Coefficients are whole numbers of units of , every rounding goes down, and every rounding is added to .
Refusing
An operation whose hypothesis cannot be shown is not carried out. The error says which, and the cure is a smaller disc.
taylorModel("1/z", disc("1/4", "1/2"));
// ComplexError division-by-zero: division by a function that may vanish on the disc of radius 0.5 about 0.25 + 0i
taylorModel("log(z)", disc("-1", "1/4"));
// ComplexError branch-cut: the principal branch jumps on the negative real axis.
// A logarithm cut elsewhere is fine on this disc:
taylorModel("log(-z) + i*pi", disc("-1", "1/4"));
The principal logarithm is not analytic across its cut, so a model of it on a disc that reaches the cut would be a model of a different function. That is why it is refused and not quietly continued.
What a model says
| call | returns |
|---|---|
| taylorModel(f, disc, { order, bits }) | The model. f is text in the variable z, or a function of one model built from add sub mul div neg pow scale and the package's exp log sqrt root pow sin cos tan sinh cosh tanh gamma zeta. Order defaults to 12 and bits to 96. |
| m.error | ε, a Rational |
| m.coefficients | The polynomial's coefficients in powers of z − c, exact complex rationals |
| m.at(z) | A Rect certain to contain f(z), for a point of the disc |
| m.range() | A Disc certain to contain every value on the disc |
| m.zeroCount() | The number of zeros of f in the disc when one coefficient outweighs the rest and ε together (Rouché's theorem), otherwise null |
| m.derivative(radius) | A model of f′ on a strictly smaller disc: the polynomial is differentiated, and Cauchy's estimate bounds the derivative of the part left out by ε/(r − radius) |
| m.integral(a, b) | A Rect certain to contain the integral from a to b along any path in the disc |
| CTM.z(disc), CTM.constant(disc, value) | The model of z itself, and of a constant, to build on by hand |
More order means a smaller ε, as long as the function is analytic on a disc comfortably larger than the model's. When ε stops shrinking the limit is the working precision, and more bits moves it.
@ratmath/complex and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.