22

In the past, the Numerical Recipes book was considered the gold standard reference for numerical algorithms. The earliest Fortran Edition was followed by editions in C and C++ and others, bringing it then more up-to-date. Through these, it provided reference code for the state-of-the-art algorithms of the day.

Older editions are available online for free nowadays.

Unfortunately, I think it is now mostly useful only as a historic tome. The "software engineering" practices seem to me to be outdated, and the actual content hasn't kept pace with the literature.

What similarly comprehensive yet approachable references should the modern programmer look at instead?

Stewart
  • 357
  • 2
  • 9
  • 7
    The algorithms themselves are very good for general purpose problem-solving. It is their implementations that might leave something to be desired. But that is OK because the code in the book is simple enough to modify to whatever your tastes are. The implementations in the chapters are fairly "self-contained" and free of cruft. Numerical recipes is still a good reference for times when you need to implement some basic numerical stuff but don't want/need a huge complex or expensive library or framework. – Angelo Nov 14 '11 at 12:52
  • 3
    As it stands, this question could be considered offensive, it's certainly not very constructive. I have made use of Numerical Recipes throughout my career and would highly recommend it to anyone needing a ready reference for algorithms to solve complex problems. I have never used the code directly, but I have always implemented the algorithms in my own languages using my own preferred interfaces. The problems you appear to see are superficial, and there will usually be better algorithms out there if you care to look, but even then NR is useful to point you in the right direction. – Mark Booth Nov 14 '11 at 13:10
  • @MarkBooth I don't intend it to be offensive. I've used it extensively over the past *too many* years. I also don't deny that it is still a valuable starting point. But surely after 20-somethng years, there must be a better alternative? At least, something that already details those "better algorithms if you care to look" in the same well-written, approachable, format? – Stewart Nov 14 '11 at 13:36
  • 1
    @Angelo I agree that the implementations are fairly self-contained, and they make wonderful "reference implementations" (ignoring the few, well-documented, caveats that apply to some) as I said. – Stewart Nov 14 '11 at 13:42
  • To avoid controversy, I'd like to state that the current phrase *"The "software engineering" practises seem to me to be outdated"* is neither what I wrote nor what I meant. I was trying to imply that the coding style, and the non-OO, non-functional, form of these examples leads to some criticism/debate. I hope no modern programmer would write similar code, but within the historical context of NR, the style is understood and acceptable to me. – Stewart Nov 14 '11 at 13:59
  • 5
    I have to agree that the C and C++ code provided in the books proves once again that a good Fortran programmer can write good Fortran code in any language. However, these books are still a great reference. The explanations of the algorithms are very clear. The code is usable out of the box, and if it really offends your sensibilities you can always rewrite it yourself. It would still be much easier than to implement it from scratch. – Dima Nov 14 '11 at 18:28
  • 12
    Remember that the copyright restrictions on the code in NR are quite draconian. You are only allowed to personally key in the code for up to ten routines, and your are NOT allowed to distribute the resulting program to any other person or computer. In almost any working environment this means you are going to have to re-implement the algorithm anyway, so what would be the benefit of the authors providing a sophisticated OO or functional implementation? The service provided by the book is a clear explanation of important algorithms, not the provision of a strong math library. – Charles E. Grant Nov 14 '11 at 19:38
  • @Charles *"The service provided by the book is a clear explanation of important algorithms, not the provision of a strong math library."*. I fully agree, but that's the point: what reference provides equally clear and comprehensive explanations of the now-state-of-the-art algorithms, with emphasis on issues that would concern the modern programmer? e.g., parallelism, to name the most glaring concept. – Stewart Nov 14 '11 at 21:30
  • @Stewart, so you actually are looking for better, more recent algorithms? That doesn't seem to match the question as written and your latter comments which mention software engineering issues, OO, and functional implementations. Maybe you need to further revise the question? I was certainly confused. – Charles E. Grant Nov 14 '11 at 22:12
  • @Charles, in a nutshell, I want it brought up-tp-date: More recent algorithms, new topics of contemporary interest, and a style that better reflects modern software development. Given that this will probably never happen, what should the modern developer use as their "gold standard reference" for numerical methods? – Stewart Nov 14 '11 at 23:08
  • 2
    Interestingly enough, when I was a mathematics student, this book was regarded as something of a joke. I note that their C++ code was particularly bad, also add to that problems with the copyright. Sorry I can't recommend an alternative. – Antonio2011a Nov 15 '11 at 02:51
  • @Stewart If the current edits to your question don't match what you meant to say, please feel free to edit it again. One problem of this format is that it is sometimes a bit of a guessing game. – Stephen Nov 15 '11 at 13:36
  • @Stephen The question is still a valid question that I'm interested in - it is just that the justification I gave for the question has morphed a bit. – Stewart Nov 15 '11 at 16:46
  • 3
    Who cares what the code is like? Wrap it up nicely and never look at it. – David Heffernan Nov 17 '11 at 23:06
  • @DavidHeffernan Also, you are unlikely to have a license to use the code in commercial projects, so you'll need to reimplement the described algorithms anyway. Smelly code will encourage you to actually do that! – Stewart Nov 18 '11 at 10:47
  • @Stewart I have a license to use the code in my commercial project. You just need to write to them and request permission to use a small number of recipes. – David Heffernan Nov 18 '11 at 10:48
  • There is a [similar question](http://stackoverflow.com/questions/3162136/any-decent-alternatives-to-numerical-recipes) on SO – oleksii Nov 19 '11 at 00:28

3 Answers3

9

In terms of Numerical Recipes, we need two things - the understanding of how algorithms translates into programming implementation and second, a reference implementation that books things.

There seems to be NO combination of BOOK + Reference software. However, there are some good reference softwares and some of this provides reference to papers on the basis of such an algorithms.

Here is a list of some reference (mostly open source) libraries that might help:

  1. GNU Scientific Library
  2. LAPACK it has a good book as a user manual There is also LAPACK++ and other (TNT) derived/related packages. See this for more information.
  3. Boost Linear Algebra
  4. Armadillo
  5. BLAS

Other specific things are

  1. Apophenia for statistical models
  2. Colt
  3. FFTW
  4. The R package - and a book
  5. OpenCV
  6. Intel Math kernel Library
  7. For pattern recognition

You can also check out "Data Analysis with Open Source Tools".

Here is a huge list of comparison though i haven't verified everything.
http://www.netlib.org/utk/people/JackDongarra/la-sw.html

Dipan Mehta
  • 10,542
  • 2
  • 33
  • 67
4

Numerical Recipes is still, IMO, a useful book. It describes the algorithms really well, including their derivation, the situations in which they're useful, and alternatives to consider when they aren't. I've been using the book for years.

One thing I have never used is their code. I always write my own implementation based on the algorithms they describe. In that respect the quality of their code doesn't matter (and it is indeed questionable: in the 2nd edition C book, they define a collection of functions and macros to make arrays unit-indexed because the authors come from a Fortran background). As an example: I once had to implement FFT in Objective-C, so I used NR in Fortran to understand what FFT did and how the code should look.

Think of NR the same way you think of Knuth: you would never paste code from that book into your project.

3

Personally I like it, it's about the level I can understand

The code is Fortran translated to 'C' but that's OK you can just translate it back to Fortran and then into C++ yourself! There are advantages to the Fortran or C versions in that the code is pretty much self contained, you don't have to drag in a bunch of C++ classes to do matrices, complex, etc - especially given the quality of their coding!

There is a justifiable objection to the ludicrous copyright claims by the authors and I know a number of lecturers that ban NR in their classes. Among numerical experts the books also have a reputation as "enough information to get you into trouble". But their only suggestion is generally to use their personal code or buy NAG.

A suggested collection of alternate high quality numerical libs is at http://www.netlib.org/

Martin Beckett
  • 15,776
  • 3
  • 42
  • 69