Elementary functions
, 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 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:
The hyperbolic functions are the same ones turned a quarter of the way round: and . The tangents are quotients, , 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 and are independent, a rectangle is the natural shape here: the enclosure of over a rectangle is the product of an interval for with intervals for and , 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 excludes 0, then has no zero at (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 of , with and continuously differentiable, is complex differentiable exactly where
and then . cauchyRiemann(u, v) takes and as formulas in and , differentiates them symbolically, and reduces the two residuals and 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@ratmath/complex and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.