Skip to main content

2017 | Buch

The Mathematical-Function Computation Handbook

Programming Using the MathCW Portable Software Library

insite
SUCHEN

Über dieses Buch

This highly comprehensive handbook provides a substantial advance in the computation of elementary and special functions of mathematics, extending the function coverage of major programming languages well beyond their international standards, including full support for decimal floating-point arithmetic. Written with clarity and focusing on the C language, the work pays extensive attention to little-understood aspects of floating-point and integer arithmetic, and to software portability, as well as to important historical architectures. It extends support to a future 256-bit, floating-point format offering 70 decimal digits of precision.

Select Topics and Features: references an exceptionally useful, author-maintained MathCW website, containing source code for the book’s software, compiled libraries for numerous systems, pre-built

C compilers, and other related materials; offers a unique approach to covering mathematical-function computation using decimal arithmetic; provides extremely versatile appendices for interfaces to numerous other languages: Ada, C#, C++, Fortran, Java, and Pascal; presupposes only basic familiarity with computer programming in a common language, as well as early level algebra; supplies a library that readily adapts for existing scripting languages, with minimal effort; supports both binary and decimal arithmetic, in up to 10 different floating-point formats; covers a significant portion (with highly accurate implementations) of the U.S National Institute of Standards and Technology’s 10-year project to codify mathematical functions.

This highly practical text/reference is an invaluable tool for advanced undergraduates, recording many lessons of the intermingled history of computer hardw

are and software, numerical algorithms, and mathematics. In addition, professional numerical analysts and others will find the handbook of real interest and utility because it builds on research by the mathematical software community over the last four decades.

Inhaltsverzeichnis

Frontmatter
Chapter 1. Introduction
Abstract
The mathcw package contains source code files that provide replacements for C’s elementary functions. It exists to provide improved code for use by hoc (and other software) on platforms where the native library versions are deficient, to provide access to the full C99 math library at a time when few systems have it, and to provide an insulating layer to shield other software from system dependencies. When it is important that software produce (nearly) identical results on all platforms, avoiding the use of different underlying math libraries in favor of a single consistent library can be of significant help.
Nelson H. F. Beebe
Chapter 2. Iterative solutions and other tools
Abstract
Throughout much of this book, we need only a moderate amount of mathematics, mostly at the level that you learned in high school, with an occasional excursion into first-year college calculus. If you find calculus unfamiliar, or have simply forgotten most of what you learned about it, rest assured that the intent of this book is to use just enough mathematics to understand how to solve the problems that we address. Theorems and proofs and clever tricks in mathematics have their place, but we do not need them in this book.
Nelson H. F. Beebe
Chapter 3. Polynomial approximations
Abstract
We begin this chapter by introducing a convenient notation that is common in some branches of mathematics for indicating a numeric interval: a comma-separated pair of values, enclosed in square brackets or parentheses, with the convention that a bracket means that the endpoint is included, and a parenthesis indicates that the endpoint is excluded. Thus, [1, 2) is the set of values x for which \( 1 \le x < 2, \) and [2, 3] is the adjacent set for which \( 1 \le x \le 2, \). Endpoint distinction is often important in numerical computation, and we use that interval notation extensively in the rest of this book.
Nelson H. F. Beebe
Chapter 4. Implementation issues
Abstract
Cody and Waite specified their algorithms for the computation of the elementary functions in a language-independent way, although they wrote the accompanying ELEFUNT test package in Fortran. In principle, it should be straightforward to implement their recipes in any programming language on any operating system and any arithmetic system. However, for any particular environment, there are likely to be issues that need to be considered. In this chapter we discuss features of the C language and of the IEEE 754 arithmetic system that affect the implementation of the mathcw library, but we first examine a fundamental mathematical limitation on the accuracy of function evaluation.
Nelson H. F. Beebe
Chapter 5. The floating-point environment
Abstract
Prior to the 1999 ISO C Standard, no standard programming language offered a uniform way to access features of the floating-point environment. Until the advent of IEEE 754 floating-point arithmetic, no such access was even possible, because almost none of the older floating-point systems have programmable rounding directions or precision control, and floating-point exceptions are not dealt with by setting programmer-accessible flags, but instead are trapped by software interrupt handlers that set underflows to zero, and usually terminate the job on overflow or division by zero.
Nelson H. F. Beebe
Chapter 6. Converting floating-point values to integers
Abstract
This chapter treats the important subject of converting arbitrary floating-point numbers to whole numbers, where the results may be in either floating-point or integer data formats. A few important historical machines targeted at the scientific computing market, and described in Appendix H on page 947, make such conversions easy by virtue of not having a separate integer storage format. Integers are then just floating-point values with a zero exponent, and conversions may require little more than bit shifting, and possibly, rounding. Some scripting languages provide only numbers and strings, where all numbers are represented as floating-point values.
Nelson H. F. Beebe
Chapter 7. Random numbers
Abstract
Certain kinds of computations, such as sampling and simulation, need a source of random numbers. However, there are three significant problems when we try to compute such numbers:
  • Numbers in computers, whether integer or floating-point, are rational numbers. Such numbers can only approximate mathematical real numbers, and therefore, truly random numbers cannot be produced by any computer algorithm.
  • Most algorithms for generation of ‘random’ numbers produce a sequence of almost-always-different values that eventually repeats. The length of that sequence is called the period. By contrast, a stream of truly random numbers has occasional repetitions, and is never periodic.
  • Software for random-number generation often contains subtle dependencies upon the behavior, precision, and range of integer and floating-point arithmetic.
Nelson H. F. Beebe
Chapter 8. Roots
Abstract
The simplest of the elementary functions are those that compute roots of numbers. They are most easily calculated by a combination of argument range reduction, polynomial approximation to get an accurate starting value, and a rapidly convergent iterative solution. Some computer architectures include an instruction to compute the square root, because the required circuits can often be shared with those of the divide instruction.
Nelson H. F. Beebe
Chapter 9. Argument reduction
Abstract
Elementary functions whose argument range is large can often be related to similar functions with diminished arguments, where those functions are more easily, and more accurately, computed. The ultimate accuracy of elementary functions depends critically on how well that argument reduction is carried out, and historically, that has been the weak point in many vendor libraries. Although the argument-reduction problem is usually easy to state, it is not easy to solve, because it often requires access to arithmetic of higher precision than is available.
Nelson H. F. Beebe
Chapter 10. Exponential and logarithm
Abstract
The exponential function, and its inverse, the logarithm function, are two of the most fundamental elementary functions in all of mathematics, and in numerical computing. They also turn up hidden inside other important functions, such as the hyperbolic functions, the power function, and in the computation of interest and investment value, and lottery returns, in financial mathematics, a subject that we treat briefly at the end of this chapter.
Nelson H. F. Beebe
Chapter 11. Trigonometric functions
Abstract
Trigonometry, from the Greek words for triangle and measurement, has been of interest to (at least some) humans for more than four millennia, with early evidence of use in Egypt, India, Mesopotamia, and Greece. The common method of measuring angles in degrees, minutes, and seconds comes from the Babylonian sexagesimal (base-60) number system, although in modern mathematics and computer software, circular measure of radians, where 2π radians is the angle of one complete rotation through a circle, is preferred.
Nelson H. F. Beebe
Chapter 12. Hyperbolic functions
Abstract
The hyperbolic functions are often treated with the trigonometric functions in mathematical texts and handbooks [AS64, OLBC10, Chapter 4], because there are striking similarities in their series expansions, and the relations between family members, even though their graphs are quite different.
Nelson H. F. Beebe
Chapter 13. Pair-precision arithmetic
Abstract
In a few places in the mathcw library, we need to work with an intermediate precision having at least twice as many digits as storage precision. In almost all historical floating-point architectures, for single-precision computation, the double-precision format satisfies that requirement (see Table H.1 on page 948). However, for double-precision work, higher precision may be unavailable, as is the case in many programming languages, or it may be insufficiently precise, such as the IEEE 754 80-bit format compared to the 64-bit format.
Nelson H. F. Beebe
Chapter 14. Power function
Abstract
ISO Standards for other programming languages, such as Fortran and Pascal, provide even less information about the behavior of that function.
Nelson H. F. Beebe
Chapter 15. Complex arithmetic primitives
Abstract
Apart from Fortran and symbolic-algebra systems, few programming languages support complex arithmetic. The 1998 ISO C++ Standard adds a standard header file, <complex>, to provide a complex data-type template, and prototypes of complex versions of a dozen or so elementary functions. The 1999 ISO C Standard goes further, offering a standard header file, <complex.h>, and a new language keyword, _Complex. When <complex.h> is included, the name complex can be used as a synonym for the new keyword, allowing declaration of objects of type float complex, double complex, and long double complex.
Nelson H. F. Beebe
Chapter 16. Quadratic equations
Abstract
We mentioned in Chapter 2 the need for solving quadratic equations, but we deferred further discussion of how to do so until we could develop some essential tools. It is now time to tackle the problem.
Nelson H. F. Beebe
Chapter 17. Elementary functions in complex arithmetic
Abstract
Since the invention of complex arithmetic about two centuries ago, mathematicians have learned how to extend functions from the real line to the complex plane. The field of complex analysis is now well understood, and mathematics courses in that area are commonly offered in the first years of undergraduate college eduction.
Nelson H. F. Beebe
Chapter 18. The Greek functions: gamma, psi, and zeta
Abstract
Previous chapters of this book cover the elementary functions that are taught in secondary-school mathematics, and included in many programming languages. The gamma, psi, and Riemann zeta functions that we treat in this chapter are among the most important of the class known in mathematics and physics as special functions. As the class name suggests, they are more difficult, and less-commonly encountered, than the elementary functions.
Nelson H. F. Beebe
Chapter 19. Error and probability functions
Abstract
Like the gamma and psi functions, the functions treated in this chapter are among the most important of the special functions.
Nelson H. F. Beebe
Chapter 20. Elliptic integral functions
Abstract
The functions named in the title of this chapter have attracted the interest of several famous mathematicians, among them Abel, Euler, Gauss, Hermite, Jacobi, Kronecker, Lagrange, Legendre, Ramanujan, Riemann, and Weierstrass. Their properties are well-chronicled in several books, including [AS64, Chapter 17], [Law89], [OLBC10, Chapter 19], [Wal96], [Wei99], [GRJZ07, §8.1], and [JD08, Chapter 12], with extensive tables of properties and integrals of related functions in [BF71].
Nelson H. F. Beebe
Chapter 21. Bessel functions
Abstract
A large family of functions known as Bessel functions is treated in four chapters of the Handbook of Mathematical Functions [AS64, Chapters 9–12], with more coverage than any other named functions in that famous compendium. Although those functions were first discovered by Daniel Bernoulli (1700–1782), who in 1732 worked with the order zero function that is now known as J 0 (x), it was Friedrich Wilhelm Bessel who generalized them about 1824 and brought them to mathematical prominence, and they bear his name, instead of that of Bernoulli. Leonhard Euler (1707–1783) discussed their generalizations to arbitrary integer orders, J n (x), in 1764.
Nelson H. F. Beebe
Chapter 22. Testing the library
Abstract
The Cody/Waite book, Software Manual for the Elementary Functions [CW80], made two extremely important contributions to the quality of elementary-function libraries, which were frankly dismal on many computing systems until the mid to late 1980s.
Nelson H. F. Beebe
Chapter 23. Pair-precision elementary functions
Abstract
We discussed some of the limitations of pair-precision arithmetic in Chapter 13 on page 353. Although our pair precision routines for the basic operations of add, subtract, multiply, divide, square root, and cube root are on average correctly rounded in IEEE 754 arithmetic with the default round-to-nearest mode, we cannot guarantee correct rounding in general. Indeed, as the tables in Section 13.20 on page 379 show, worst-case errors of almost four ulps can be discovered by extensive testing with random arguments. In the non-default rounding modes of IEEE 754, errors of almost 10 ulps are found.
Nelson H. F. Beebe
Chapter 24. Accuracy of the Cody/Waite algorithms
Abstract
To assess the accuracy of the elementary functions provided by the mathcw library, it is best to let the ELEFUNT numbers speak for themselves. Table 24.1 on the next page through Table 24.23 on page 822 show typical results obtained at this author’s site and the Hewlett–Packard Test Drive Laboratory. The tables are prepared with the help of a small awk program that filters and reformats the output of make check to avoid errors from manual transcription.
Nelson H. F. Beebe
Chapter 25. Improving upon the Cody/Waite algorithms
Abstract
The Cody/Waite recipes in their book Software Manual for the Elementary Functions [CW80] are an excellent source of portable methods for computation of elementary functions. It is possible to do better, but sometimes only at the expense of portability, and often only by doing at least parts of the computation in higher precision, which may mean software arithmetic and a significant performance penalty.
Nelson H. F. Beebe
Chapter 26. Floating-point output
Abstract
Conversions of numerical values to string representations, and the reverse, are surprisingly complex and difficult. Older programming languages provide limited support, such as Fortran’s FORMAT statement specifier Iw for integer conversions, and Ew.d, Fw.d, and Gw.d for floating-point conversions.
Nelson H. F. Beebe
Chapter 27. Floating-point input
Abstract
The introduction to the last chapter briefly described format specifiers in C, Fortran, and Pascal. When used with the input facilities of those languages, they allow decimal data to be read easily, but binary, hexadecimal, and octal formats are unlikely to be widely supported.
Nelson H. F. Beebe
Backmatter
Metadaten
Titel
The Mathematical-Function Computation Handbook
verfasst von
Prof. Nelson H.F. Beebe
Copyright-Jahr
2017
Electronic ISBN
978-3-319-64110-2
Print ISBN
978-3-319-64109-6
DOI
https://doi.org/10.1007/978-3-319-64110-2

Premium Partner