Complex elementary functions
- Cost
- A few evaluations of real elementary functions at the target precision plus a few guard bits; for acf in the strict modes, retries with more guard bits as for arf.
The complex elementary functions of acb (balls), acf (rounded floating point) and nfloat_complex (fixed precision) are built from the real functions of Elementary functions: each part of the result is a short combination of real exponentials, logarithms, sines and cosines, chosen so that no part is spoiled by cancellation in a region where it could be computed accurately. This page gives the formulas, the branch cuts, and the way acf rounds the parts.
Throughout, with real and .
Formulas#
Exponential, sine and cosine. The parts are products of real functions of and of ,
and each factor is computed with its own relative accuracy, so that each part has the relative accuracy of a product. The hyperbolic functions are and , and the functions of use the real functions of (with the exact reduction of ) and of .
Logarithm. , with the real part computed by arb_log_hypot, which forms exactly (or to the needed precision) near the unit circle so that the real part keeps its relative accuracy there, and the imaginary part by .
Tangent and cotangent. In acb, for the tangent is the quotient , and for
where the exponential is small, so that the result comes out without cancellation; the cotangent likewise. The rounded functions of acf use the forms
and , , whose denominators and are sums of squares: each part is a quotient of accurately known numbers, also when it is exponentially small against the other (the real part of is about for large ). The hyperbolic tangent and its relatives are , , and .
Square root. For , , and for , : the sum is always one without cancellation.
Inverse functions. In terms of the logarithm and the square root,
with log1p for the arctangent so that it stays accurate near 0, and the real functions on the real axis inside their domains. These formulas also define the branch cuts below.
On the axes all functions reduce to real ones (for example and for , and ), and the parts that are exactly zero are set to zero.
Branch cuts#
The multivalued functions return their principal values, with the branch cuts of the DLMF [NIST2012]: for the logarithm and the square root, for , and , for and , and for ; the values on a cut are those of The principal branches. In ball arithmetic a rectangle that touches or crosses a cut must enclose the values on both sides, so its result is wide; the analytic variants of acb return an indeterminate result instead (Branch cuts). acf has no signed zeros: a number with a zero imaginary part lies on the cut and gets the value given there.
Register paths#
On 64-bit machines, at precisions of one and two limbs, acb_exp, acb_exp_pi_i, acb_log, acb_sin_cos and acb_sin_cos_pi of narrow rectangles, the functions of nfloat_complex and those of acf with mantissas of at most two limbs compose the register paths of the real kernels (Register fast paths) into both parts at once, with an error count per part. For acb the input radii are then propagated through bounds on the derivative, as for the real functions; for acf the parts are certified like the frames of arf.
Rounding in acf#
acf rounds each part of the result to prec bits. In the strict modes each part is correctly rounded, whatever its size against the other: the compositions are evaluated at an increasing working precision until the error bound of each part decides its rounding, as in Correctly rounded elementary functions. Since every part is a product or quotient of accurately known real numbers (or a real function of an exactly known number), its relative error bound is a small multiple of the working precision, independently of the other part.
The relaxed modes guarantee the relative accuracy of the complex number instead: in ARF_RND_FAST each part is within 1 ulp and in ARF_RND_ACCURATE within 0.51 ulp of the larger part (at prec bits). A part much smaller than the other may then have a worse relative accuracy or be zero, but such a part does not slow the evaluation down. In the strict modes, a part exponentially smaller than the other must be resolved; for the tangent and cotangent near , the imaginary part is with
which is computed directly, so that the directed modes are rounded from the sign of when is far below an ulp: takes about a microsecond at 53 bits in every mode for up to about 1000 (beyond, the cost grows with the bits of that the real part needs: a few milliseconds at ). The tangent family gives nan for (the real part for the hyperbolic functions) beyond about , like the exponential functions it is made of.
Exact results. No window of bits decides the rounding of a dyadic value, so the exact results must be recognised: the zeros of the sine and cosine of at the half-integers (the imaginary part of , say), integer powers (and small dyadic powers of exact roots) with at most bits, the powers of for any integer exponent, dyadic square roots, and the parts that are exactly zero or a multiple of on the axes.
Values next to a rounding boundary. A part can also lie within any distance of a dyadic number without being one, when the parts of the argument differ in size by many bits: the real part of is , that of is . Retrying until the gap shows would take a working precision proportional to it. Instead, a part still undecided at a working precision well above prec is compared exactly with the rounding boundary that its approximation is next to (the nearest number of prec bits, or of prec + 1 bits for ARF_RND_NEAR): the part rounds like a sliver for the sign of , or like for .
- For
acf_inv,acf_div,acf_sqrtandacf_rsqrtthe sign of is that of a polynomial in the inputs and : for the real part of ; for the square root , , which squares to (and likewise for and the quotients by of the reciprocal root). These are sums of exact terms, whose sign is found by adding the terms in decreasing magnitude exactly until the rest cannot reach half the partial sum, so that no sum spans the gap to a negligible term. Such a part is decided atprec+ 64 bits whatever the gap. For the elementary functions, a transcendental part can come that close to a dyadic number only near an exact point of the function (0; for the logarithm; the multiples of for the functions of ; for the square-root branch points of the inverse sine and cosine; the simple poles of cot, csc and their relatives; infinity for the inverse functions), where
with a rotation of (or at infinity), rational (the series of
fmpq_poly), at a pole, , a unit and at a branch point when it is dyadic. Multiplied by a positive denominator ( at a pole, at infinity), or of the expansion minus is a sum of exact monomials in the parts of and with integer coefficients and powers of : summed with the exact sign within each power of , at any spread of the exponents (which catches exact cancellations such as , whose real part is ), correctly rounded byarf_sumwhere several powers of combine, and with as a ball across them, the sign decided when the sum exceeds the bound on the omitted terms. The imaginary part of the logarithm is , rounded byarfdirectly. The power near is with the binomial sum as exact terms and exact when it is dyadic, and for a tiny it is in ball arithmetic.
A value that neither decides (none is known) would keep the retries from converging, so they stop at a working precision of bits (plus twice the spread of the exponents of the argument's parts, up to bits, for the functions computed from balls below), and the approximation is then rounded as it stands.
Inverse functions. The inverse trigonometric and hyperbolic functions, expm1, log1p and the functions round the balls of the corresponding acb functions at increasing working precisions: in the strict modes until both endpoints of the ball of each part round to the same number, in the relaxed modes until the radii lie below resp. times the larger part. The precision grows at least geometrically, so that a part that vanishes to many more bits than the accuracy shows is resolved in a logarithmic number of steps. For with the real part is with a tiny , rounded from the sign of like the asymptotic cases of arf. Off the axes the parts are transcendental at dyadic arguments, so that the strict loop terminates. An argument very close to an axis ( with , on the axis and away from the branch cuts) is evaluated as , with the remainder bounded by the Cauchy estimates on a disk around (Corollary 13 of Error propagation), so that the small part comes out with its own relative accuracy at the usual working precision: takes about two microseconds at 53 bits.
Division and square roots. and form the numerators , and the denominator exactly, so that each part is one correctly rounded quotient of exact numbers (when the terms of a sum are so far apart that they cannot cancel, they are rounded to a working precision instead and the quotient is certified). The square root uses the formulas above at an increasing working precision, with the dyadic roots computed exactly.
Fixed precision: nfloat_complex#
The functions of nfloat_complex evaluate the same kind of formulas once, in the precision of the context, with no guard bits except for the exact evaluation of near the unit circle: each part typically has an error of a few ulps relative to the magnitude of the result (a small part of a large result can have a large relative error), and directed rounding is not respected.
Use in FLINT#
void acb_sin_cos(acb_t s, acb_t c, const acb_t z, slong prec)Referenced from#
- acf.h (module)
acf_pow- Correctly rounded elementary functions (algorithm)
- Elementary functions (algorithm)
- Special functions (overview)
References#
- [NIST2012] National Institute of Standards and Technology, Digital Library of Mathematical Functions (2012), https://dlmf.nist.gov/
The FLINT team, “Complex elementary functions,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/special-functions/complex-elementary.html (generated 2026-11-17).
@misc{flint-doc-algorithms-special-functions-complex-elementary,
author = {{The FLINT team}},
title = {{Complex elementary functions}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/special-functions/complex-elementary.html},
note = {Generated 2026-11-17}
}