Branch Cuts For Complex Elementary Functions
Branch Cuts For Complex Elementary Functions
Elementary Functions
or
Much Ado About Nothing's Sign Bit
W. KAHAN
ABSTRACT
Zero has a usab Ie sign bi t on some computers, but not on
others. This accident of computer arithmetic influences the
definition and use of familiar complex elementary functions like
V, arctan and arccosh whose domains are the whole complex plane
with a slit or two drawn in it. The Principal Values of those
functions are defined in terms of the logarithm function from
which they inherit discontinuities across the slit (s). These
discontinuities are crucial for applications to conformal maps
with corners. The behaviour of those functions on their slits
can be read off immediately from defining Principal Expressions
introduced in this paper for use by analysts. Also introduced
herein are programs that implement the functions fairly accu-
rately despite roundoff and other numerical exigencies. Except
at logarithmic branch points, those functions can all be conti-
nuous up to and onto their boundary slits when zero has a sign
that behaves as specified by IEEE standards for floating-point
arithmetic; but those functions must be discontinuous on one
side of each slit when zero is unsigned. Thus does the sign of
zero lay down a trail from computer hardware through programming
language compilers, run-time support libraries and applications
programmers to, finally, mathematical analysts.
I. INTRODUCTION
Conventions dictate the ways nine familiar multiple-valued
complex elementary functions, namely
throughout the complex plane except for discontinuities across The IEEE standards 754 and p854 take a different approach.
certain straight lines called "slits" so situated as to maximize They prescribe representations for both +0 and -0 but do not
the reign of continuity, conserving as many as possible of the distinguish between them during ordinary arithmetic operations,
properties of these functions' familiar real restrictions to apt so the ambiguity is benign. Rather than think of + 0 and -0 as
segments of the real axis. There can be no dispute about where distinct numerical values, think of their sign bit as an auxili-
to put the slits; their locations are deducible. However, Princi- ary variable that conveys one bit of information (or misinforma-
pal Values have too often been left ambiguous on the slits, tion) about any numerical variable that takes on 0 as its value.
causing confusion and controversy insofar as computer programmers Usually this information is irrelevant; the value of 3 + x is no
have had to agree upon their definitions. This paper's thesis different for x:= +0 than for x := -0, and the same goes for
is that most of that ambiguity can and should be resolved; how- the functions signum (x) and sign(y,x) mentioned above. How-
ever, on computers that conform to the IEEE standards 754 and ever, a few extraordinary arithmetic operations are affected by
p854 for floating-point arithemetic the ambiguity should not be zero I s sign; for example 1/ (+0) +ca but 1/ (-0) = -co .. To re-
eliminated entirely because, paradoxically, what is left of it tain its usefulness, the sign bit must propagate through certain
usually makes programs work better. arithmetic operations according to rules derived from continuity
What has to be ambiguous is the sign of zero. In the past, considerations; for instance (-3)(+0):= -0, (-0)/(-5) =+0,
most people and computers would assign no sign to zero except (-0) - (+0) = -0, etc. These rules are specified in the IEEE
under auress, and then they would treat the sign as + rather standards along with the one rule that had to be chosen arbitra-
than For example, the real function rily:
signum(x) := +1 if x> 0 S -8 := +0 for every string s representing a finite real number.
:= 0 if x o Consequently when t=s, but O¢t¢co, then s - t and t-8
-I if x < 0
both produce + 0 instead of opposi te signs. (That is why, in
illustrates the traditional noncommittal attitude toward zero's
IEEE style arithmetic, s - t and - (t-s) are numerically equal
sign, whereas the Fortran function
but not necessarily indistinguishable.) Implementations of ele-
sign(l.O, := + 1 .0 if x;;. 0
mentary transcendental functions like sin(z) and tan(z) and
:= -1.0 if x < 0 ,
their inverses and hyperbolic analogs, though not specified by
must behave as if zero had a + sign in order that this function
the IEEE standards, are expected to follow similar rules; if
and its first argument have the same magnitude. Just as
[(0) = 0 <1 '(0), then the implementation of I(z) is expected
sign ( I .0, x) is continuous at x 0+, i.e. as x approaches zero
to reproduce the sign of z as well as its value at z = ±O ..
from the right, so can each principal value above be continuous That does happen in several libraries of elementary transcenden-
as its slit is reached from one side but not from the other. tal functions; for instance, it happens on the Motorola 68881
Sides can be chosen in a consistent way among all the elementary
Floating-Point Coprocessor, on Apple computers in their Standard
complex functions, as they have been chosen for the implementa-
Apple Numerical Environment, in Intel's Common Elementary Function
tions built into the Hewlett-Packard hp-15C calculator that will
Libraries for the i8087 and i80287 floating-point coprocessors,
be used to illustrate this approach.
in analogous libraries now supplied with the Sun III, with the must be invariant under reflection in the origin z = O. Finally,
ELXSI 6400 and with the IBM PC/RT, and in the C Math Library the slit(s) must begin and end at branch-points: these are
currently distributed with 4.3 BSD UNIX for machines that con- singularities around which some branch of the function cannot be
form to IEEE 754. With a few unintentional exceptions, it represented by a Taylor nor Laurent series expansion. A slit can
happens also on the hp-71R,hand-held computer, whose arithmetic end at a branch point at infinity.
was designed to conform to IEEE p854. Consequently the slit for v', £n and ZW turns out to be
If a programmer does not find these rules helpful, or if the negative real axis. Then the slits for arcsin, arccos and
he does not know about them, he can ignore them and, as has been arctanh turn out to be those parts of the real axis not between
necessary in the past, insert explicit tests for zero in his pro- -I and + I; similarly those parts of the imaginary axis not be-
gram wherever he must cope with a discontinuity at zero. On the tween -i and +i serve as slits for arctan and arcsinh. The
other hand, if the standards' rules happen to produce the desired slit for arccosh, the only slit with a finite branch-point (-\)
results without such tests, the tests may be omitted leaving the inside it, must be drawn along the real axis where z ~ + I. None
programs simpler in appearance though perhaps more subtle. This of this is controversial, although a few other writers have at
is just what happens to programs that implement or use the times drawn the slits elsewhere either for a special purpose or
elementary functions named above, as will become evident below. by mistake; other tastes can be accommodated by substitutions
sometimes so simple as writing, say, £n(-l)-£n(-I/z) in place
2. WHERE TO PUT THE SLITS of £n(z) to draw its slit along (and just under) the positive
Each of our nine elementary complex functions f(z) has a real axis instead of the negative real axis.
slit or slits that bound a region, called the principal domain,
inside which f(z) has a principal value that is single valued 3. WHY DO SL ITSMATTER ?
and analytic (representable locally by power series), though it A computer program that includes complex arithmetic opera-
must be discontinuous across the slit(s). That principal value tions must be a product of a deductive process. One stage in
is an extension, with maximal principal domain, of a real elemen- that process might have been a model formulated in terms of ana-
tary function f(x) analytic at every interior point of its lytic expressions that constrain physically meaningful variables
domain, which is a segment of the real x-axis. To conserve the without telling explicitly how to compute them. From those
power series' validity, points strictly inside that segment must expressions somebody had to deduce other complex analytic expres-
also lie strictly inside the principal domain; therefore the sions that the computer will evaluate to solve the given physical
slit(s) cannot intersect the segment's interior. Let z* =x- iy problem. The deductive process entails transformations among
denote the complex conjugate of z =x + iy; the power series for which some may resemble algebraic manipulations of real expres-
f(x) satisfy the identity f(z*) = f(z)* within some complex sions, but with a crucial difference:
neighbourhood of the segment's interior, so the identity should Certain transformations, generally val id for real
persevere throughout the principal domain' s interior too. expressions, are valid for complex expressions only
while their variables remain within suitable regions
Consequently complex conjugation must map the slit(s) to itself/ in the complex plane.
themselves. The slit(s) of an odd function f(z) == - f(-z) Moreover, those regions of validity can depend disconcertingly
regions of convergence, etc. In general, singularities can be
upon the computer that will be used to evaluate the expres-
sions in question. For example, simplifying the expression hard to find; in our examples the singularities are obviously
the pole at 2'" I, the branch-point 2 = 0, and respective slits
";(21 (4 I») ,/( II (4 - I») to ";(4) I (4 I) seems legitimate in so
0< 2 < I, 2 < I and 2 < 0 whereon the quanti ties under square
far as they both describe the same complex function, one that is
continuous everywhere except for a pole at 4 = I and a jump- root signs are negative real.
2. Taken together, the singularities partition the complex
discontinuity along the negative real axis 2 < O. And when those plane into a collection of disjoint connected components.
two expressions are evaluated upon a variety of computers includ- Inside each such component locate a sma?? aontinuum
upon which the equivalence of the given two expressions
ing the ELXSI 6400, the Sun III, the IBM PC/RT, the IBM pcl AT, can be decided; that decision is valid throughout the
PCIXT and PC using i80287 or" i8087, and the hp-71B, they component's interior.
agree everywhere within a rounding error or two. But when the The "small continuum" might be a small disk inside which
same expressions are evaluated upon a different collection of both expressions are represented by the same Taylor series; or
computers including CRAYs, the IBM 370 family, the DEC VAX it could be a curvilinear arc within which both expressions take
line, and the hp-15C, those expressions take opposite signs values that can be proved equal by the laws of real algebra.
along the negative real axis! An experience like this could Other possibilities exist; some will be suggested by whatever
undermine one's faith in some computers. motivated the attempt to prove that the given expressions are
What deserves to be undermined is blind faith in the power equivalent. In our example, the two expressions are easily
of Algebra. We should not believe that the equivalence class of on that part of the real axis where 2 > 1 , which
proven equal
expressions that all describe the same complex analytic function happens to lie inside the one connected component into which the
can be recognized by algebraic means alone, not even if rela- slits along the rest of the real axis divide the complex plane.
tively uncomplicated expressions are the only ones considered. Therefore the two expressions must be equivalent everywhere in
To locate the domain upon which two analytic expressions take the complex plane except possibly for real 2 < 1•
equal values generally requires a combination of algebraic, 3. The singularities cons ti tute loci in the plane upon
which the processes in steps 1 and 2 above can be
analytical and topological techniques. The paradigm is familiar
repeated, finally leaving isolated singular points to
to complex analysts, but it will be summarized here for the sake be handled individually. End of paradigm.
of other readers, using the two expressions given above for In our example, the slit along 2 < 1 is partitioned into
concrete illustration. the branch-point at Z = O. Each
two connected components by
How to decide where two analytic expressions describe Whether the two expres-
component has to be handled separately.
the same function. sions are equivalent on a component must depend upon the defini-
I. Locate the singularities of each constituent subexpression tion of complex ";2 on its slit where Z < 0; there diverse
of the given expressions. That is what this paper is about.
computers appear to disagree.
The singularities of an analytic function are the boundary More generally, programmers who compose complex analytic
points of its domain of analyticity. These will consist of poles, expressions out of the nine elementary functions listed at this
branch-points and slits in this paper; but more generally they paper's beginning will have to verify whether their expressions
would include certain contours of integration, boundaries of
deliver the functions that they intend to compute. In principle, 4. PRINCIPAL VALUES ON THE SLITS, IEEE STYLE
that verification could proceed without prior agreements about Since all the slits in question lie on either the real or
the functions' values on their slits if instead analysts and pro- the imaginary axis, every point z on a slit is represented in
grammers were obliged to supply an explicit expression to handle at least two ways, at least once with a +0 and at least once
every boundary situation as they intend. Such a policy seems with a -0 for whichever of the real and imaginary parts of z
inconsiderate (not to say unconscionable) considering how hard vanishes. Benignly, ambiguity in z at a discontinuity of f(z)
some singu~arities are to find, and how easy to overlook; but permits fez) to be defined formally continuously, except possi-
that policy is not entirely heartless since verifying correctness bly at the ends of some slits, by continuation from inside the
along a boundary costs the intellect nearly as much as writing principal domain. This continuity goes beyond mere formality.
down a statement of intent about that boundary. The trouble with By analytic continuation, the domain of each of our nine elemen-
those statements is that they generally contain inequalities and tary functions fez) extends until it fills out a Riemann
tests and diverse cases, and as they accumulate they burden Surface; think of this surface as a multiple covering wrapped
proofs and programs with a dangerously enlarged capture cross- like a bandage around the Riemann Sphere and mapped onto it
section for errors. And almost all of those statements become continuously by f. To construct f's principal domain, cut the
superfluous in programs after we agree upon reasonable defini- bandage along the slit(s) and discard all but one layer covering
tions for the functions in question on their slits. the sphere. That layer is a closed surface mapped by f con-
For instance, in our examp Ie above we had to discover tinuously onto a subset of the sphere. The shadow of that layer
whether the two expressions agreed on an interval 0 < z < 1 that projected down upon the sphere is the principal domain; it con-
lies strictly inside the dom~in of the desired function's analy- sists of the whole sphere, but with slit(s) covered twice. That
ticity, not on its boundary. That interval turns out to be a is why we wish to represent slits ambiguously.
removable singularity, and it does remove itself from all the Here are some illustrative examples, the first of a real
computers mentioned above because they evaluate both expressions function that is recommended for any implementation of IEEE
correctly on that interval; diverse computers disagree only on standard 754 or p854.
the boundary where the desired function is discontinuous. Per- copysign(x, y) := ± x where the sign bit is that of y, so }
haps that's just luck. (Unlucky examples do exist and one will copysign(1,+O) =+1 = lim copysign(l, y) at y= 0+, and (4.1)
be presented later.) Let us accept good luck with gratitude copysign(l,-O) -I = lim copysign(l, y) at y = 0-.
whenever it simplifies our programs. v(-I+iO) =+O+i=lim,/(-I +iy) at y= 0+; } (4.2)
Complex analytic expressions that involve slits and other v(-I-iO) =+0 - i = lim,j(-I +iy) at y = c- .
singularities are intrinsically complicated, and they get more Consequently, v(z*) =v(z)* for every z, and v(llz) = I/v(z) too.
compl icated when rounding errors are taken into account. Our These identities persist within roundoff provided the programs
objective cannot be to make complicated things simple but rather, used for square root and reciprocal are those, supplied in this
by choosing reasonable values for our nine elementary functions paper, that would have been chosen anyway for their efficiency
on their slits, to make them no worse than necessary.
and accuracy.
174 W. KAHAN BRANCH CUTS 175
arccos (2 + iO) == +0 - i arccosh(2) directly, not by first coercing the real to complex, lest the
= lim arccos(2 + iy)
sign of zero be rendered uninformative; the same goes for com-
at y 0+;)
(4.3)
binations of pure imaginary quantities with complex variables.
arccos(2 - iO) == +0 + i arccosh(2)
And doing arithmetic directly this way saves execution time that
lim arccos(2+iy) at y == 0- •
would otherwise be squandered manipulating zeros.) When z is
An implementation of arccos that preserves full accuracy in the
near ± I the expression a(z) nearly vanishes and loses its rela-
imaginary part of arccos (2 + i y) when Iy I is very tiny can be
tive accuracy to roundoff. Although this loss could be avoided
expected to get its sign right when y = ± 0 too without extra
by rewriting a (z) := v' (z - I) (z + I»), doing so would obscure
tests in the code; such a program is supplied later in this
the discontinuity on the imaginary axis in a cloud of roundoff
paper.
which obliterates Re (z) whenever it is very tiny compared wi th
But the foregoing examples make it all seem too simple.
1 as well as when it is ±O.
The next example presents a more balanced picture.
Also obscure is what happens at the ends of some slits.
Let function a(x) := V(x 2 - \ ) for real x with x 2 ;> I,
Take for example £n(z)=£n(p)+ ie, where p= Izi and e=arg(z)
and let b(x):= a(x) for real x;> \ note that b(x) is not
j
are the polar coordinates of z =x + iy and satisfy
yet defined when x ~ \. The principal values of the complex
x = p cos e, y == p sin e, p;> 0 and -11" ~ e ~ 1f
extensions of a and b following the principles enunciated
Evidently p:= +v(x 2 + y2), and when 0 < p < +co then
above turn out to be
e := 2 arctan (y/(p+x») if x;> 0, or
a(z) = v'(z2- I) = a(-z}, and :=2arctan(p-x)/y) if x~O.
b(z) v'(z-I)v(z+ I) =-b(-z) . At the end of the slit where z = x = y p == 0 (and tn = -co)
Both a and b are defined throughout the complex plane and both the value of e may seem arbitrary, but in fact it must cohere
have a slit on the real axis running from I to + I, but a has with other almost arbitrary choices concerning division by zero
another slit that runs along the entire imaginary axis separat- and arithmetic with infinity. A reasonable choice is to inter-
ing the right half-plane where a b from the left half-plane pose the reassignment
where a=-b. The functions are different because generally if p == 0 then x := copysign (\, x)
v'(~) v'(n) v'(~ n) when largO;) + arg(n) I < 1f between the computations of p and e above. More about that
v( ~ n) when larg(O + arg(n) I> 11" later.
=±
v'( ~ n) (hard to say which) when i; n ~ O. The foregoing examples provide an unsettling glimpse of
Both functions a and b are continuous up to and onto ambiguous the complexities that have daunted implementers of compilers and
boundary points in IEEE style arithmetic, as described above, run-time libraries who would otherwise extend to complex arith-
only if that arithmetic is implemented carefully; in particular, metic the facilities they have supplied for real floating-point
the expression z + I should not be replaced by the ostensibly computation. These complexities are attributable to failures,
equivalent z + (I + iO) lest the sign of zero in the imaginary in complex floating-point arithmetic, of familiar relationships
part of z be reversed wrongly. (Generally, mixed-roode arith- like algebraic identities that we have come to take for granted
metic combining real and complex variables should be performed in the arena of real variables. Three classes of failures can
be discerned:
investigation of an analytic function f(z) whose domain is slit
(i)
The domain of an analytic expression can enclose singu-
along some segment of the real or imaginary axis; say the real
larities that have no counterparts inside the domain
of its real restriction. That is why. for example. axis. When 2 =X + iy crosses the slit, f(z) jumps discontin-
'/( z2 - I) '# '/(2 I) -Ie2 + I) •
uously as y reverses sign although f(z) is continuous as z
(ii) Rounding errors can obscure the singularities. That is
2 approaches one side of the slit or the other. Consequently the
why, for example, -1(2 --,1) =-1(2 1)(z+I») fails so
badly when either z2 = I very nearly or when z2 < 0 two limits
very nearly. To avoid this problem, the programmer may
f(x+iO):= limf(x+iy) as y-+O+ and
have to decompose complex arithmetic expressions into
separate computations of real and imaginary parts. f(x - iO):= limf(x + iy) as y -+ 0-
thereby forgoing Some of the advantages of a compact
notation. both exist, but they are different when x has a real value
inside the slit. Ideally. a subroutine P(z) programmed to
(iii) Careless handling can turn infinity or the sign of zero
into misinformation that subsequently disappears leaving compute f(z) should match these values; P(x±iO)=f(x± iO)
behind only a plausible but incorrect result. That is
respectively should be satisfied within a small tolerance for
why compilers must not transform z - I into z - (I + iO) •
as we have seen above, nor - (-x x 2) into x + x 2 • as roundoff. This normally happens in IEEE style arithmetic as a
we shall see below, lest a subsequent logarithm or square
by-product of whatever steps have been taken to ensure that
root produce a nonzero imaginary part whose sign is oppo-
site to what was intended. P(x + iy) = f(x + iy), within a similarly small tolerance, for
The first two classes are hazards to all kinds of arith- all sufficiently small but nonzero Iyl. To generate a discon-
metic; only the third kind of failure is peculiar to IEEE style tinuity, the subroutine P must contain constructions similar to
arithmetic with its signed zero. Yet all three kinds, must be copysign ( ••• ,y) or arctan(1/y) possibly with "y" replaced by
linked together esoterically because the third kind is not some other expression that either vanishes or tends to infinity
usually found in an applications program unless that program as y -+ O. That expression cannot normally be a sum or difference
suffers also from the second kind. The link is fragile, easily like arctan(y-l) +'IT/4 or exp(y) 1 that vanishes by cancella-
broken if the rational operations or elementary functions, from tion, because roundoff can give such expressions values (typic-
which applications programs are composed. contain either of the ally 0) that have the wrong sign when iyl is tiny enough.
last two kinds of failures. Therefore. implementers of compilers Instead, to preserve accuracy when Iyl is tiny, that expression
and run-time libraries bear a heavy burden of attention to detail must normally be a real product or quotient involving a power of
if applications programmers are to realize the full benefit of the y or sin (y) or some other bui It-in function that vanishes with
IEEE style of complex arithmetic. That benefit deserves Some y and therefore should inherit its sign at y = ± O. Thus does
discussion here if only to reassure implementers that their careful implementation of compiler and library combine with care-
assiduity will be appreciated. ful applications programming to yield correct behaviour on and
The first benefit that users of IEEE style complex arith- near the slit. And if two such carefully programmed subroutines
metic notice is that familiar identities tend to be preserved P(z), though based upon different formulas, agree within roundoff
more often than when other styles of arithmetic are used. everywhere near the slit, then the foregoing reasoning implies
The mechanism that preserves identities can be revealed by an that normally they have to agree on the slit too; this is the
way IEEE style arithmetic preserves identities like -I(z*) = (-12)*
andv'(IIZ)=lh/z that would have to fail on slits if zero lower free boundary of the jet, then from left to right along
no sign.
the jet's,upper free boundary and back along the upper wall.
Of course, applications programmers generally have things This is just what happens when fez) is plotted from a one-line
more important than the preservation of identi ties on their program on the hp-71 B calculator, which imp lements the proposed
minds. Figure I shows a more typical and realistic example. IEEE standard p854. But when fez) is programmed onto the hp-
2
Here I(z) :=I+z +zv'(I+z 2 )+R-n(z2+ z v'(I+z 2 )), and we con- 15C, whose zero is unsigned, the lower wall disappears. Its pre-
strue the, equation 1;;:== fez) as a conformal map, from the plane image, the lower part of the imaginary axis where ali < -I, is
of z = x + iy to the plane of I;; = I;; + in, that maps the right half- mapped during the computation of fez) into the slit that belongs
plane x;;' + 0 onto the space occupied by a liquid that is forced to V and R-n; the upper part zli > 1 gets mapped onto the same
by high preSSure to Jet into a slot. The walls of the slot, slit. For lack of a signed zero, that slit gets attached to a side
where I;; < 0 and n == ±'TT, should be the images of those parts of that is right for the upper wan but wrong for the lower wall,
the imaginary axi s z2 < - 1 lying beyond ± i. The free surf aces thereby throwing the pre-image of the lower wall away into a tiny
of the jet, curving forward from I;; = ±i'TT and then back to segment of the upper wall. To put the lower wall back, x must be
<: = - 00 ±i'TT/2, should be the image of that segment of the increased from 0 to a tiny positive value while y runs from-oo
imaginary axis -1 < < 0 between ±i.
to-I. (How tiny should x be? That's a nontrivial question.)
The misbehaviour revealed in the foregoing example fez)
----Wall
liquid flow
1-'
Wail air 'I
J
'-in air I;; := a(z) maps the slit z plane onto the I;; plane outside the
• liquid flow circle 1<:1;;. I; vertical lines in the z plane map to stream
';-plane z-planc
lines in the vertical flow of a fluid around the circle. Imple-
FIG. 1 Conformal map I;; ;=f(z) of half-plane menting a(z), the programmer notices that he can reduce two
to jet with free boundary expensive square roots to one by rewriting
The picture of fez) should be symmetrical about the real a(z) := z + v(z:i.+ I) copysign(l, Re(z»).
axis because f(z*) = fez) *. As z runs up the imaginary axis, The two expressions for a(z) match everywhere in IEEE style
wi th x == +0 and y running from -GO through -I toward -0 and arithmetic; but when zero has only one sign, say +, the second
then from + 0 through + I toward +00, its image I;; = fez) should
expression maps the lower part of the imaginary axis, where
run from left to right along the lower wall and back along the zli < -I, into the inside instead of the outside of the circle,
although a(z) should be continuous there.
dispatched properly; and then familiar identities will persist,
The ease with which IEEE style arithmetic handled the
despite roundoff, more often than in other styles of arithmetic.
important singularities near z = ±i in the examples above should
This thought would comfort us more if the aberrations were
not be allowed to persuade the reader that all singularities can
easier to uncover. Locating potential aberrations remains an
be dispatched so easily. The singularities f(O) and f(oo) and
onerous task for an applications programmer, regardless of the
the overflows near z = 00 would have to be handled in the usual
style of arithmetic; however that style can affect the locus of
ways if they did not lie so far off the left-hand side of the
aberration fundamentally. In IEEE style arithmetic, a program-
picture that nobody cares. Another kind of singularity that did
med implementation of a complex analytic function can take
not matter here, but might matter elsewhere, insinuated weasel
aberrant boundary values, different from what would be produced
words like "not usually", "tends to be" and "normally" into the
by continuation from the interior, because of roundoff or similar
earlier discussion of Sums and differences that normally vanish
phenomena. In arithmetic without a signed zero, such an aberra-
by cancellation. Sums and differences can vanish without cancel~ .
tion can be caused as well by an unfortunate choice of analytic
lation if they combine terms that have already vanished; an
expression, though the programmer has implemented it faithfully.
example is h(x) ;=x+x 2 when x=O. Evaluating h(±O) in IEEE
The fact that an analytic expression determines the values of an
style real arithemetic yields +0 instead of ± 0 respectively,
analytic function correctly inside its domain is no reason to
losing the sign of zero. h(x) has other troubles: it signals
expect the boundary values to be determined correctly too when
Underflow when x is very tiny, suffers inaccuracy when x is
zero is unsigned.
very near - I , and becomes Invalid at x=-oo. Simply rewriting
h(x) :=x(l +x) dispels all these troubles, but is slightly less
5. PRINCIPAL VALUES ON THE SLITS, hp-J5C STYLE
accurate for very tiny Ixl than is h(x) :=-(-x - x 2). which
Of course, the hp-15C is not the only machine with an
preserves accuracy and the sign of zero for all tiny real x.
metic one function must be continuous onto the top of the slit mulas
and the other onto the bottom. Evidently no general rule attach- I(z) = P(z-S)+p(z-S)y«z-6)/e) , or
ing a slit to one of its sides can depend solely upon the slit's I(z) P(z-S)+p(z-S)R.n «z-6)/e) , or
shape nOr solely upon the function's values off the slit. And I(z) = P (some nonintegral power of y( (z - 6) /e») ,
yet, paradoxically, the hp-15C appears to follow just such a where e=lim(S-z)/!S-z! as z-+6 along the slit, so 101=1
rule, namely and (z-S)/e < 0 in the slit, and P(t) and p(t) are represent-
Counter>-CloakUJiBe Continuity (CCC) : able by power series around t= O. Given 13 and 1 and its slit,
Attach each slit to whichever side is approached when o and P and pare oanonioal (determined uniquely). Formulas
the finite branch-point at its end is circled counter- slightly more general than these, but still essentially unique,
clockwise.
cope with more general elementary functions or with isolated
Thus when z is real and negative CCC defines YZ = iY!z!
branch-points at 00.
and R.n (z) = R.n Iz I + in. Actually CCC is merely a mnemonic summary
The dominant terms of these canonical formulas provide
of the implications, for the nine functions that are the subject
approximations useful near branch-points, and are therefore pre-
of this note, of the following more general convention applica-
cious to analysts and programmers who have to exploit or compen-
ble also to b(z) above, as CCC is not.
sate for singularities, so these formulas should not be violated
The Pr>ineipal Expr>eBBion:
I'
...... half-strips in the right half-plane. Indeed, q(03) = -g(03) in
------11
• a
~a e<f:-d: C '. b --. the tear-drop except. if zero is unsigned, q(03) = -g(03)* for
(I
-4.5 '. -4
:1
", -3
I
0
-1.
••• 4 -4.5 < 03 < -4. Is it likely that a few trial evaluations will
reveal the difference between q(03) and g(z)?
c·-+-
The examples presented in this paper may give the impres-
I d· ---,lIoe·
sion that an analyst will benefit far less than a programmer
(-plane z -plane from Principal Expressions because their benefits seem meagre
unless slits run along straight lines. Moreover a signed Zero
Seems useless. except when slits lie in the real and imaginary
FIG. 2 Conformal map I; :=g(z) of slit plane to slotted strip
axes. True; but not the whole truth. Despite that applications
The cost of computing g(z) comes mostly from two loga-
of elementary functions frequently relocate their slits to non-
ri thms entai led by two calls upon arccosh. Two logarithms can
standard places, the functions so constructed have to be communi-
be reduced to one by means of a page or so of algebraic manipu-
cated to humans and to computers in terms of combinations of the
lation starting from the Principal Expression tabulated for
standard elementary functions with which we are all acquainted.
arccosh above; the result is a ppoof that
For instance, let e(z) be an analytic extension of arcsin(03)
g(z) ==2R-n(v'«z+4)/3)h/(z+3) + v'o3)2/(2\1'(o3+3) +\I'z)) from the upper half-plane across its slits z2 > I into the lower
Without Principal Expressions, one might resort instead to for- half-plane, where we relocate the slits to run down from ± I
mulas like
along some paths to -ioo. Can e(03) be expressed in terms of
Arccosh(03) Q,n(03 ±,I (z2 - I») + 2ik'TT for k = 0, ± I, ±2, ••• arcsin (z)? Yes. In the upper half-plane or between the new
i arccos(z).
7. IMPLEMENTATION NOTES
Group 8: arccosh(z) -arccosh (-z), i1T, -i1T.
Six inverse trigonometric and hyperbolic functions are de-
The answers may depend upon whether arithmetic is per- fined in terms of R.n and '1/ by Principal Expressions tabulated
formed in hp-15C style or in IEEE style, the difference appear- above in such a way as might appear to provide one-line programs
ing only when a slit lies in the real or the imaginary axis. to compute those functions in, say, Fortran. Unfortunately, round-
off can cause such programs to lose their relative accuracy near
6. SUMMARY their zeros or poles; and overflow can occur for large arguments
Two different styles of ari thmetic induce two different even though the desired function has an unexceptionable value.
mental attitudes towards the connection between analytic expres- Programs to compute complex elementary functions robustly and
sions and analytic functions. fairly accurately are surprisingly complicated, so much so as to
IEEE style arithmetic encourages the extension by contin- justify supplying them in this paper. Actually, we supply algo-
uity of every complex analytic function from the interior of its rithms that can be converted into programs on various machines
domain to the boundary, including both sides of slits that are by being adapted to the peculiarities of diverse programming
distinguishable with the aid of a signed ±O, Consequently, two languages and computing environments.
expressions that represent the same function everywhere inside Certain Environmental Constants that characterize impor-
its domain are likely to match everywhere on the boundary too; tant attributes of computer arithmetic may be specified precisely
most exceptions are correlated with roundoff problems. when that arithmetic conforms to IEEE 754 or p854; otherwise
Arithmetic with an unsigned 0 permits continuous extension they might be slightly vague:
n := Overflow threshold Nextafter(+co, 0) Algebraic operations upon a NaN reproduce it. Both infinities
E := Roundoff threshold 1.0- Nextafter (1.0,0) and NaN~ can be produced by our algorithms, and both wi 11 be
A := Underflow threshold = 4(I-E)/n in IEEE 754
accepted as inputs to them.
Smallest possible no. = Nextafter(O.O, J) 2EA The IEEE standards prescribe responses to five kinds of
in IEEE 754.
exceptions:
Here N"extafter is a function specified in the appendix to IEEE
Invalid Operation, ();;erflo'W. Divide-by-Zero.
754; it perturbs its first argument by one ulp (one Unit in
Underflo'W. Inexact.
its Last 'Place) towards the second. That appendix also includes
Each kind has its flag. to be raised to signal that its kind of
copysign, which was described early in this paper, and two func-
exception has occurred; each kind produces a defauU resuZt.
tions scalb and logb that will be used later. Let 6 be the
respectively
arithmetic's radix, 2 for IEEE 754, or 2 or 10 for p854. For
NaN, +00, +00, gradual underflow, rounded result.
any floating-point x and integer N, scalb (x • N) := 6N x compu-
Gradual underfZo'W approximates any value between ±A with an
ted without first computing so Over/Underflow is signalled
error smaller than €A instead of flushing it to zero. Neither
only if the final value deserves it. Logb(NaN) is NaN. which
this feature nor flags figure as much as they could and should
stands for "Not a Number" and is produced by invalid operations
in our algorithms. In environments that conform fully to IEEE
like 0/0, 0"". ""/co and 00_00; 10gb (±oo) := +00; logb(O):=-oo
754, as does the Standard Apple Numerical Environment (SANE) on
with Divide-by-Zero signalled; and if A <: Ixl < 00 then logb(x)
Apple computers, robust exception-handling complicates programs
is an integer such that 1 <: Iscalb(x. -logb(x)}1 < 6. The same
much less than ours have been complicated by our desire to pro-
may be true when 0 < Ixl < A. but early implementations may in-
vide algorithms adaptable also to machines that do not conform
stead yield logb(x):= logb(A) in that case. Like the proce-
to the Si.:andards. Most of our algorithms can be adapted to such
dures I dexp and frexp in the C library. scalb and togb are
machines by merely excising references to features that those
practically indispensible for scaling and for computing loga-
machines do not support. For instance. a statement like "If
rithms and exponentials.
x = 00 then ••• " will be deleted for machines that have no infi-
Certain detail s, particularly those that pertain to 00
nity; however, some obvious precaution against division by zero
and NaN, are peculiar to IEEE style arithmetic. Otherwise the
may have to be inserted elsewhere instead. Machines that flush
algorithms presented here for various complex elementary trans-
underflows to zero instead of underflowing gradually may produce
cendental functions. though designed for IEEE style arithmetic,
less accurate results when they approach the underflow thres-
can be used with other reasonably rounded binary floating-point
holds ±A.
arithmetics to get comparable results. Our algorithms assume
Our algorithms would be simpler, some much simpler. if every
either that zero always has a + sign, or else that its sign
arithmetic operation accepted and produced intermediate results
obeys the rules specified by IEEE 754 and p854. Those stan-
of wider range and precision than our algorithms are normally
dards also specify rules for +(10 and -co and for NaN. Predi-
expected to accept or produce. Such a situation arises when the
cates like x=y. x<y and x < y are all false; but x""'"y
transcendental functions are intended for a higher-level language
and x'/> yare true when either or both of x and yare NaN.
like Fortran that supports only Single- and Doub1e- precision
variables, but the implementer has access to another wider should be accomplished not by actual multiplication but rather
format like IEEE 754's Extended format. That is implemented in by swaps and sign reversal; iz :=-y+ix. In a similar way, an
floating-point coprocessor chips such as the Intel i8087 and expression that is syntactically pure imaginary with an unsigned
i80287 used in the IBM PC, PC/XT and PC/AT, the Motorola fl888 I zero for its real part should be handled in a way that avoids
used in a host of 68000-based workstations, the Western Electric both unnecessary arithmetic and unnecessary hazards. For instance,
32106, ,and also in Apple's SANE. But no such Extended format is+z := x+i(S+y), (i8)z := i(8z),
is provided by the National Semiconductor 32081 used in the IBM z/(i8) := -i(z/S) , (is)/z := i(S/z).
PC/RT, nor by the Weitek 1164/1165 chips used in the Sun III In languages where a construction 1 ike CMPLX (x , y) is used to
among others, nor by the NCUBE multiprocessor array. nor by create the complex value z :=x+ iy, the expression CMPLX (0,8)
Fairchild's Clipper; for their sakes we use devious formulas should be treated as is, whereas CMPLX(+O,S) and CMPLX(-O,8)
to preserve accuracy and avoid spurious overflows. should be treated as intentional attempts by the programmer to
In the programs below. e,p,e,s, t, 14 v,x,y, t; and n introduce an appropriately signed zero into the calculation. Of
denote real variables; w :=u+iv, z :=x+iy and t,; :=t;+in de- course, both attempts will produce the same CMPLX(+ 0,8) on a
note complex variables; and a star denotes not multiplication machine whose only zero is + O.
but complex conjugation: z*=x-iy. Mixed-mode arithmetic upon
one real and one complex variable is presumed N(J! to be per- 8. COMPLEX ZEROS AND INFINITIES
formed by coercing the real to complex, but rather in a way that All four zeros ±O ± iO are arithmetically equal. Whether
avoids unnecessary hazards like Oco or co- <0 by avoiding unneces- all complex infinities should be arithmetically equal is a topo-
sary real operations: logical question. When dealing' with complex algebraic (not
S+z := (S+x) +iy, Sz :=Sx+iSy, z/S :=x/S+iy/S; but transcendental) functions, the most convenient topology is that
S/z:=S/(x+(y/x)y)-i<Y/x)(S/(x+(y/x)y)) if Iyl <; lxi,
of the Riemann sphere with its unique point at infinity. A
:=(x/y)(S/(y+(x/y)x))-iS/(Y+(x/y)x) if Ixl '" Iyl,
metria (distance function) that induces that topology is the
with due attention to spurious over/underflows and zeros and Chordal Metria :
infinities.
Chord (z , l;) := Iz - r,; I / v' « I+ Iz 12) ( I + Ir,; 12) )
Ideally, the operators Re and 1m, that select the Real if I z I < co and It,; I < co,
and Imaginary parts respectively, should be interpreted in a way := Chord (I / z , I / r,;) if z =P 0 and l; =P 0 ;
that avoids unnecessary computation of the unwanted part when- ..;; Chord (0, co):= Chord(co, 0) := I .
ever possible. For instance, Re (wz) should be evaluated by In this topology, every algebraic function is a continuous
computing only ux-vy, without evaluating Im(wz) too. Besides (though perhaps multi-valued) map of the sphere to itself. So
saving time, this policy avoids spur.ious exceptions like overt are our nine elementary functions f(z). Only a function discon-
underflow that might afflict only the unwanted part. tinuous at infinity can be affected by its multiplicity of
Note too, to conserve ±O, that -z is not O-z though representations there; an important instance is the equality
they be equal arithmetically; and similarly w-z is the same as case f(z) z. To combat ambiguity at infinity a programmer
-z+w but not -(z-w). Multiplication or division by i ="'-1 can map all its representations upon one of them, namely real
+co, by invoking the function the Riemann sphere, can approximate arbitrary asymptotic direc-
PROJ (x + iy) := x + iy if Ix I *' co and Iy I *' co , tions at best crudely,
:= + co + i copysign (0, y) otherwise, Crudely, but not quite arbitrarily. The approximations
before performing any operation discontinuous at infinity. Of should be predictable and consistent with reasonable expecta-
course, PROJ is just the identity function on machines that tions; in particular, it seems reasonable to expect
lack a way to represent co. wz exp(~n(W)+~n(Z» and w/z=exp(~n(W)-,tn(Z»
The topology of the Riemann sphere is inappropriate for to hold within an allowance for roundoff even for infinite or
Z
functions like e that have an essential singularity at infi- zero products and quotients. These relations imply Iwzl = Iwllzl
nity. Instead, different representations of infinity are custo- and Iw/zl = Iwi/izi at 0 and 00, equations that can be satisfied
marily associated with different paths that tend to infinity in exactly; another implication is that
some asymptotic way, justifying assertions like arg(wz) arg(w) + arg(z) mod 2rr and
exp(-co+iy)=O and lexp(+co+iy)1 co for all finite y. arg(w/z) arg(w) -arg(z) mod 2rr
For example, "00 + i2" could represent a path asymptotically have to be approximated within the set of ten values available
parallel to the positive real axis and 2 units above it; for arg(1;;) when I::; is zero or infinite. Those values turn out
"00+ ioo" would have to represent a path parallel to that traced to be:
by exp(S+ i8) as 13-++ 00 for some fixed but unknown 8 strictly arg(+O±iO) arg(+""± is) = ±O for all finite 13 ,
between 0 and rr/2. Unfortunately, programming languages like arg (+"" ± ioo) ±rr/4,
Fortran represent complex variables by pairs of reals in such a arg(S ± ioo) = ±1f/2 for all finite 13 ,
way as allows at most nine asymptotic directions (8) to be repre- arg(-co± ioo) = ±31f/4,
sented by two real variables of which at least one is ± 00. Those arg(- 0 ± iO) = arg(--<x>± is) = ±1f for all finite e;
directions are arg(NaN + i Anything) and arg (Anything + i NaN) are both NaN.
8: ±rr -3rr/4 -'rr/2 -rr/4 ±O Thus, any coherent scheme for computing complex products,
z: -00 ±is -oo-ioo S-ico 4co ±i"" +00 ±is quotients and logarithms at zero and infinity can be regarded
8: rr/4 rr /2 h/4 NaN as a scheme that rounds arg(l::;) into one of the ten values above
Z: +oo+ioo S+i"" -oo+i"" NaN±i"" or ± ""± i NaN. when I::; is zero or infinite. To be acceptable, such a scheme
(Here e stands for any finite real number.) should not add much to the cost of complex multiplication and
These complex infinities z are the only ones available. By division. The procedure Box that follows seems tolerable.
default, in the absence of some contrivance programmed explicit-
ly to cope with other asymptotic directions, every infinite 9. THE PROCEDURES
complex result, especially of multiplication and division, has Box supplants the explicit calculation of arg during
to be approximated by something chosen from the available com- multiplication and division. It is followed by procedures and
plex infinities z in a fashion resembling the way real numbers auxiliary procedures that calculate the Principal Expressions
are rounded to the ones representable in floating-point. That of the Elementary Functions of Table 1, and algorithms for CTANH
default rounding, while fully satisfactory in the topology of and CTAN are given too. Several real special functions are
usen by these procedures; indeed the only complex auxiliary func- If Y =co then x:= y ;
tion that occurs during the computation of the inverse trigono- t:=x-y;
} ;
k 2
·..
'0' To compute p:= l(x+iy)/2 I scaled to avoid Over/Underflow. • •• This program seems to handle all cases correctly:
CSSQS(x+iy): =p+ik, with an integer k. "'y(-S±iO)=+O ± iy(S) for all 13;;.0.
Integer k; ••• ..,I (x ± iClO) = +00 ± iCIO for aU x, finite,
k :=0 ; • • 0
infinite or NaN, and if x is NaN then
Save and reset the Over/Underflow flags;
p := x 2 + y2 ; ••• Multiply twice and add.
·.. "Invalid Comparison" is signalled too.
• •• For all finite S,
U (p:#p or p=CIO) and (Ixl =CIO or Iyl =(0) then P:=CIO ••• y(NaN + is) , .J(S + and .J(NaN+
else if the Overflow flag was just raised, or are all NaN + i NaN;
the Underflow flag was just raised and p < '}.J'2. } y(+CIO± is) =+CIO ± iO ;
CLOGS(x+ iy,J): O"For use with J"*O only when Ix+iyl CACOSH(z) : • • • Based upon formulas:
••• is huge. This program is particularly helpful for ••• I; := arcsinh(Re( ../(z - 1) * ../ (z + I»)) ;
••• inverse trigonometric and hyperbolic functions that • •• n : .. 2 arc t an ( Im ( ../(z - 1) ) / Re ( ../ (z + J ) )) ;
• •• behave like 11,n (2z) for huge Iz I. This program uses ••• Suppress any Divide-by-Zero signal when z <:: -I •
• •• ' a subprogram 11,n 1 p (x) := in( I + x) presumed .to be Return (I; + in); end CACOSH.
avpilable with full relative accuracy for all tiny
• •• real x. Such a program exists in various math. ••• To compute I;+in = r;. := arcsin(z) = arcsin{x+ iy) •.
••• libraries, included that for 4.3 BSD Unix, Intel's CASIN(x+iy): "'Based upon formulas:
• •• CEL and Apple's SANE. The accuracy of 11,n I p ••• 1;:= arctan(x/Re("/(I-z)"/{1 +z»));
••• influences the choice of thresholds TO, TI and T2. ••• Suppress any Divide-by-Zero signal when z <:: -I •
else p:= 11,n(p)/2 + (k+J) 11,n2; ••• To compute I; + r;. := arctanh(z) = arctanh(x + iy)
8 :=ARG(x+iy) ;
CATANH(x + iy):
Return (p+i8); end CLOGS. Constants a:= ../W)/4, p:= I/a ;
13:= copysign(1 ,x) ; z:= Sz*;'" Copes with unsigned O.
If x> a or Iyl > a ••• To avoid overflow.
then { n := copysign('lr/2. y); 1;:= Re( II (x + iy) )
"'To compute 1;+ in = r;.:= 11,n(z)=11,n(x+iy).
CLOG(Z) :=CLOGS(z,O). else if x 1
then { 1;:= 11,n(../(../(4+y2»)/../(lyl +p));
n := copysign('IT/2 + arctan( (ly I + p)/2), y)/2}
else'" Normal case. Using 11,n I p (u) := in{1 + u)
O"To compute I;+in = r;.:= arccos(z) = arccos(x+iy). ••• accurately even if u is tiny.
••• Suppress any Divide-by-Zero signal when z <:: -I • • •• All cases appear to be handled correctly.