In broad outline, the reason is that Numerical Recipes values simplicity above other virtues that may frequently be more important. Complex problems frequently have complex solutions, or require complex processes to arrive at any solution whatever. This is not a new insight: H. L Mencken (1880-1956) wrote
... there is always a well-known solution to every human problem -- neat, plausible, and wrong.
Prejudices, second series (1920), or equivalently
For every complex problem, there is a solution that is simple, neat, and wrong.These lessons are, however, too frequently forgotten, and appear to have been forgotten in the instance of the planning and execution of Numerical Recipes. More specific reasons not to use Numerical Recipes are outlined below. There are excellent alternatives.
"There is a series of books and associated software with the name Numerical Recipes in the titles that provide descriptions of numerical algorithms and associated programs in popular programming languages....
"The good news is that this series gives exceptionally broad coverage of computational topics that arise in scientific and engineering computing at a very reasonable price.... The bad news is that the quality and reliability of the mathematical exposition and the codes it contains are spotty. It is not safe, we have found, to take discussions in the book as authoritative or to use the codes with confidence in the validity of the results.
"The authors are identified on the book jacket as `leading scientists' and [we] have no reason to think that they are not. However, there is no claim that they have special competence in numerical analysis or mathematical software. At least in the parts of the book that [we] have studied closely, they do not demonstrate any such competence.
"Published reviews of the book[s] have fallen into two classes: Testimonials and reviews by scientists [including Kenneth Wilson, Nobel Laureate] and engineers tend to extol the broad scope and convenience of the products, without seriously evaluating the quality, while reviews by numerical analysts are very critical of the quality of the discussions and the codes....
"Two reviews by numerical analysts are:
`This chapter describes numerical methods for ODE's from the viewpoint of 1970. If the authors had consulted an expert in the subject or read one of the good survey articles available, I think they would have assessed the methods differently and presented more modern versions of the methods.'[Since Shampine wrote this, the authors of NR have consulted a worker active in the field. Unfortunately, a great many other experts in the field consider the advice they got to be very poor indeed -- extrapolation methods are almost always substantially inferior to Runge-Kutta, Taylor's series, or multistep methods.]
"He also remarks that adaptive methods for numerical quadrature problems are not treated in NR although they are much in favor by numerical analysts.
"Dr. Hanson is a former editor of the algorithms department of the Association for Computing Machinery Transactions on Mathematical Software (ACM TOMS). He ran tests of the nonlinear least-squares codes from NR and made comparisons with published results of better known codes LMDIR from MINPACK and NL2SOL.... He found the NR codes sometimes required up to 20 times as many iterations as the comparison codes. He noted that the control of the Levenberg-Marquardt damping parameter λ was not sufficiently sophisticated, permitting overflow or underflow of λ to occur... the algorithm in NR is a very bare-bones implementation of the ideas presented in the referenced 1963 paper by Marquardt. Many significant enhancements of that idea have been given in the intervening 27 years. [We] would expect the codes LMDIR, NL2SOL, and their successors to be much more EFFICIENT AND RELIABLE [editor's emphasis].
"[Our] present attention to the NR products was initiated by calls for consultation .... Two involved the topics mentioned above.... Other calls led us to scrutinize Sections 6.6, Spherical Harmonics and 14.6, Robust Estimation
"...The discussion, algorithms, and code given in section 6.6 is internally consistent and the choices of the recursions to use in computing the associated Legendre functions are ones recommended by specialists in the topic as being stable. No warning is given, however, regarding the fact that there are a number of alternative conventions in use regarding signs and normalization factors.... [If one naively combined results from NR codes with results from other sources] one would probably obtain incorrect results.
"In reading the section on robust estimation, [we were] skeptical of Figure 14.6.1(b) that shows a `robust straight-line fit' looking substantially `better' than a `least-squares fit'....
"To check [our] doubts about this figure, [we] enlarged it and traced the points and the `fitted' lines onto graph paper to obtain data with which [to] experiment....
"We computed a least squares fit.... The particular `robust' method illustrated by figure 14.6.1(b) is not identified. However, since the only method for which NR attempts to give code in this area is L1 fitting, [we] computed an L1 fit to the data as an example of a `robust' fit.... [We] used a subroutine CL1, that was published in the algorithms department of ACM TOMS in 1980, to obtain an L1 fit in which [we] could have confidence. [We] also applied the NR code MEDFIT to the data and obtained a fit that agreed with the CL1 fit to about three decimal places.
..."As expected, the least-squares fit is not as far from the visual trend as in figure 14.6.1(b) and the L1 fit is not as close.... It appears that the lines labelled `fits' in the NR figure 14.6.1(b) are not the result of any computed fitting at all, but are just suggestive lines drawn by the authors to buttress their enthusiasm for `robust' fitting. An uncritical reader would probably incorrectly assume that figure 14.6.1(b) illustrates the performance of actual algorithms.
"The objective function in an L1 fitting problem is not differentiable at parameter values that cause the fitted line to interpolate one or more data points. The authors indicate some awareness of this fact but not of all its consequences for a solution algorithm. Typically, the solution to this problem will interpolate two or more data points, and in the authors' algorithm, it would be common for trial fits in the course of execution of the algorithm to interpolate at least one data point;... suffice it to note that it is easy to produce data sets for which the MEDFIT/ROFUNC code will fail.
"One data set that causes looping is [x = 1, 2, 3; y = 1, 1, 1]. Another that causes looping in a different part of the code is [x = 2, 3, 4; y = 1, 3, 2]. A data set on which the code terminates, but with a significantly wrong result is [x = 3, 4, 5, 6, 7; y = 1, 3, 2, 4, 3]. Because of the faulty theoretical foundation, there is no reason to believe any particular result obtained by this code is correct, although by chance it will sometimes get a correct result....
"Conclusions
"The authors of Numerical Recipes were not specialists in numerical analysis or mathematical software prior to publication of this book and its software, and this deficiency shows WHENEVER WE TAKE A CLOSE LOOK AT A TOPIC in the book [editor's emphasis]. The authors have attempted to cover a very extensive range of topics. They have basically found `some' way to approach each topic rather than finding one of the best contemporary ways. In some cases they were apparently not aware of standard theory and algorithms, and consequently devised approaches of their own. The MEDFIT code of section 14.6 is a particularly unfortunate example of this latter situation.
"One should independently check the validity of any information or codes obtained from `Numerical Recipes'...."
We haven't investigated the quality of every one of the NR algorithms and codes, nor the exposition in every chapter of NR (we have more productive things to do). But sampling randomly (based on calls for consultation) in four areas, and finding ALL FOUR faulty, we have very little confidence in the rest.
(27 Nov 1991)
"You can add the section on PDE's to the list of `bad'. The discussion
of relaxation solvers for elliptic PDE's starts off OK (in about 1950,
but that is OK for a naive user if he is not in a hurry) but then
fails to mention little details like boundary conditions! Their code
has the implicit assumption that all elliptic problems have
homogeneous Dirichlet boundary conditions!
"Then they have their little coding quirks, like accessing their arrays the wrong way and putting unnecessary IF and MOD statements inside of inner loops....
"On the other hand, I did learn something from their discussion of the Conjugate Gradient technique for solving systems of linear equations. I did not like their implementation, but the discussion was OK."
"Example: Section 9.5 claims that Laguerre's method, used for finding zeros of a polynomial, converges from any starting point. According to Ralston and Rabinowitz, however, this is only true if all the roots of the polynomial are real. For example, Laguerre's method runs into difficulty for the polynomial f(x) = x^n + 1 if the initial guess is 0, because f'(0) = f''(0) = 0."
"Both are low-modulus generators with a shuffling buffer, in one case with the bottom bits twiddled with another low-modulus generator. The moduli are just too low for serious work, and the resulting generators even out too well."
"Additionally, it would be nice to caution users that this formula is only an asymptotic approximation to the true function (which nobody, apparently, has figured out yet), and that the method is horribly unstable for small λ."
According to Stephan, this bug has been fixed in the newest (as of 30 May 2002) edition. He continues (30 May 2002):
As an aside, even if some of the complaints on your web site are out of date and have long been fixed, I still think that it acts as a necessary counterweight to the almost unanimous praise that is heaped on NR.
"I could add that the NR treatment of the polytope (or "simplex") algorithm AMOEBA has a major flaw that I am aware of. NR does acknowledge the tendency of this algorithm to stop at local minima. They recommend restarting it to reduce this tendency, but the driver routine in the "NR Example Book" (1988 version) omits this aspect. I have run into several applications that routinely give the wrong answer because the authors missed the explanation tucked at the end of the NR text or relied on the NR driver routine."
I've always liked Romberg integration just because it is often so fast. But I've found similar problems on occasion with the Numerical Recipes Fortran routine. The problem seemed to be that the routine will occasionally get a lucky guess as to the answer, and return prematurely. In the IDL routine I tried setting K=8 instead of K=5 and so far have not have a problem (haven't tested much yet though!) I've also tried to fix this in the past by requiring two successive good guesses. But does anyone have another suggestion?
.... in the case of the Fourier transform stuff, it might be wise for someone else to confirm my result. I'm sufficiently inexperienced with FFTs to not be sure if the result I saw was an artifact of my usage and/or understanding of how it's supposed to work.
On those few occasions when I used Numerical Recipes as a starting point for code that I incorporated into my own library, I performed extensive testing to make sure there weren't any ways to cause crashes (like division by zero), and invariably I'd find holes that needed to be patched. I've also found more efficient coding alternatives. Numerical recipes resorts to some floating point calculations in one of the sorting routines that I found a simple integer alternative for (at least their floating point stuff wasn't inside a loop). I've also got some experience with their Simplex implementation (AMOEBA), and discovered it could get trapped inside the routine and fail to converge. For example, if the chi-square hypersurface is sufficiently complex, then when the simplex is shrunk, it's possible that one of the vertices will find itself at a *higher* chi-square value than it was before the simplex was shrunk! Code that locks up in an internal loop is unacceptable.
A B -B Awhich is twice the size of the original complex matrix. It is this real matrix that gets diagonalised. Even so, the results seem to have a lower accuracy than the ones obtained from mathc90. The example given in the user guide to mathc90 was less accurately solved by Numerical Recipes. seconds required for solving matrices of:
dimension: Numerical Recipes mathc90 --------- ----------------- ------- MacG3 | Cray-J90 G3 | Cray-J90 90 x 90 1 s | 7 s 1 s | 1 s 180 x 180 17 s | 57 s 3 s | 7 s 270 x 270 132 s | 191 s 12 s | 22 s 360 x 360 500 s | 432 s 43 s | 53 s time with NR / time with mathc90 6-11 in the G3 7-9 in the CrayThe program was exactly the same in both machines and compiled with the optimization option -O3. It was run interactively in the Cray under conditions of normal use (i.e. several users logged in and with batch jobs running in the background). [Editor's note: The software in the package
I don't know if the senders want to be publicly identified. If you're interested in contacting them, send me e-mail, and I'll ask them to contact you.
Our experience, and that of many others, is that it is best to get numerical
software from reliable sources. The easiest and cheapest is
Netlib, which includes the collected
algorithms from ACM Transactions on Mathematical Software (which have
all been refereed), and a great many other algorithms that have withstood the
scrutiny of the peers of the authors, but in ways different from the formal
journal refereeing process. The editor of this page has collected
links to several other sources.
Compiled by W. Van Snyder. I've removed my e-mail address to avoid
spam, but you might try
nospam AT math DOT jpl DOT nasa DOT gov, after changing nospam to vsnyder
And for a response to some of the above, see the NR response.