Functions

Elementary functions

eze^z, the trigonometric and the hyperbolic functions of a complex number, enclosed in a rectangle at whatever precision you ask for. These are single-valued. The ones with branch cuts (logarithm, roots, powers, inverses) are on the next page.

Calling them

import { exp, sin, cos, tan, sinh, cosh, tanh, rect } from "@ratmath/complex";

String(exp("1 + i"));        // "1.4686939399 + 2.2873552872i ± 1.7e-21"
String(sin("1 + i"));        // "1.29845758142 + 0.63496391478i ± 8.5e-22"
String(cos("i"));            // "1.54308063482 + 0i ± 8.5e-22": cosh(1), and the imaginary part encloses 0
String(tan("1 + i"));        // "0.27175258532 + 1.08392332734i ± 8.5e-22"

exp("1 + i", 200);           // the second argument is the precision in bits (default 64)
exp("1 + i", { bits: 200 }); // or an options object
sin(rect("1 + i", "1/100")); // an enclosure in, an enclosure of every value out

The result is a Rect. For an exact input its size is about 2−bits2^{-\text{bits}} relative to the value (the work is done with guard bits and rounded outward at the end). For an input that is itself an enclosure, the size is whatever the input's width forces.

How they are computed

Each one separates into real functions of the real and imaginary parts, which analytic encloses rigorously:

ex+iy=excos⁡y+i exsin⁡y e^{x+iy} = e^x\cos y + i\,e^x\sin y sin⁡(x+iy)=sin⁡xcosh⁡y+icos⁡xsinh⁡ycos⁡(x+iy)=cos⁡xcosh⁡y−isin⁡xsinh⁡y \sin(x+iy) = \sin x\cosh y + i\cos x\sinh y \qquad \cos(x+iy) = \cos x\cosh y - i\sin x\sinh y

The hyperbolic functions are the same ones turned a quarter of the way round: sinh⁡z=−isin⁡(iz)\sinh z = -i\sin(iz) and cosh⁡z=cos⁡(iz)\cosh z = \cos(iz). The tangents are quotients, tan⁡z=sin⁡z/cos⁡z\tan z = \sin z/\cos z, and refuse with code pole when the enclosure of the denominator contains 0, which is how you learn that an input rectangle may contain a pole.

Because the real intervals for xx and yy are independent, a rectangle is the natural shape here: the enclosure of eze^z over a rectangle is the product of an interval for exe^x with intervals for cos⁡y\cos y and sin⁡y\sin y, with no wasted room beyond what a rectangle around a curved image must have.

What "certified" means here

The true value is inside the rectangle returned. Always, not with high probability. That lets the output prove things: if two enclosures do not intersect, the numbers are different; if the enclosure of f(z)f(z) excludes 0, then ff has no zero at zz (or anywhere in an input rectangle). It cannot prove equality, since a rectangle that contains 0 says only "possibly zero"; for that see the exact layer in Complex rationals or the equality tests in symbolic.

Is it holomorphic? The Cauchy–Riemann equations

A function f=u+ivf = u + iv of z=x+iyz = x + iy, with uu and vv continuously differentiable, is complex differentiable exactly where

ux=vy,uy=−vx, u_x = v_y, \qquad u_y = -v_x,

and then f′(z)=ux+i vxf'(z) = u_x + i\,v_x. cauchyRiemann(u, v) takes uu and vv as formulas in xx and yy, differentiates them symbolically, and reduces the two residuals ux−vyu_x - v_y and uy+vxu_y + v_x to lowest terms. Both 0 means the equations hold wherever the formulas are defined (holds: true, with the derivative). A residual that does not reduce to 0 is evaluated at sample points with certified enclosures; one that excludes 0 is a witness (holds: false). If neither happens the answer is null, never a guess.

import { cauchyRiemann } from "@ratmath/complex";

cauchyRiemann("x^2 - y^2", "2*x*y").holds;        // true: it is z²
cauchyRiemann("x^2 - y^2", "2*x*y").derivative;   // "2*x + i·(2*y)", that is 2z
cauchyRiemann("log(x^2+y^2)/2", "atan(y/x)").holds;   // true off the axis: log z
cauchyRiemann("x", "-y").reason;                  // "u_x − v_y = 2, which is not 0 at …": conj(z)

Quick first, exact after

refined(name, z, { bits }) wraps any function as a Core Refinement: a fast low-precision value at once (.quick), and the certified one when asked (.exact()). An interface can show the quick value while a slider moves and sharpen it when the slider stops.

import { refined } from "@ratmath/complex";

const r = refined("exp", "1 + i", { bits: 300 });
r.quick.value;    // [1.4686939399158851, 2.2873552871788423] as doubles
r.quick.trust;    // "good" ("unsure" when the input is on a branch cut)
r.exact();        // the Rect at 300 bits
Try itEdit the code and run it with @ratmath/complex and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs