16 ms·
Boycott Numerical Recipes (2007)
- forgotpwd16 4y agoThought Numerical Recipes was used mostly in courses for students to learn about numerical methods rather using those pre-made routines for building large programs.
- eesmith 4y agoMost people using NR aren't building large programs. Think about a student who learned from NR, then in grad school needs a method, and in the spirit of "I'm smart, I can do this myself", copies the method out of the book. In larger projects, someone is more likely to be aware of alternatives, and the issues related to using source covered under the NR copyright.
- Pamar 4y ago... hesitantly raises his hand Back in ... 1991? I did use the C version of the Simplex Method almost straight from the book. I needed a concise linear programming optimization module that would be called in the middle of a not-really-concise production programming system handling (automotive) engines and gearboxes production for a couple of FIAT plants. Basically a short-period scheduler to decide what to produce (slave to an immense system running on IBM mainframes; COBOL, again). So I quickly put together the C version (with minimal modifications) and it chugged along happily on a VAX for at least a decade.
- eesmith 4y agoThanks for the counter-example. :) Did your company also license the code? To explain my frame of mine, I was thinking how it was used in 2007 or later. In the early 1990s, there wouldn't have been much off-the-shelf/free&open-source options. The GNU Scientific Library didn't start until 1996, for example (according to Wikipedia).
- Pamar 4y agoNo. I was aware of the issue at the time, and this is part of the reason for me to alter the source a bit. In my defense, the people I was working for at the time did not even understood the topic when I talked about that.
- eesmith 4y agoI think also that 30+ years ago software copyright was farther in the background. The "Don't Copy that Floppy" propaganda, for example, didn't start until 1992.
- magicalhippo 4y agoWhat are some good, current sources for learning about and implementing numerical algorithms like those in Numerical Recipes? I get that for most just using Numpy, GSL or similar library would be sufficient, but what if you really want to implement them yourself.
- rramadass 4y agoYou might find the book Matters Computational: Ideas, Algorithms, Source Code by Jorg Arndt (the book is freely available) and the accompanying FXT library useful - https://www.jjj.de/fxt/fxtpage.html https://www.jjj.de/fxt/fxtpage.html
- deleted 4y ago[deleted]
- Fronzie 4y agoThe Eigen library (https://eigen.tuxfamily.org https://eigen.tuxfamily.org) has great attention to numerical robustness and accuracy in it's implementation. The documentation is good, but for the numerical discussions, you'd have to read the source code.
- owlbite 4y agoThe main problem is each subsection of a chapter in NR is really a subfield in and of itself, and to adequately describe a decent modern implementation is at least one if not multiple books. First make sure you're familiar with background issues in numerical analysis/computation such that you're generally familiar with IEEE floating point and its foibles, numerical stability, basic error analysis etc. Figure out which algorithm you're interested, find a couple of open source implementations (academics generally generate a vast array of these, though many may become abandonware), look at any papers they are associated with/mention and read those. Now you're ready to start writing. Once you have a basic implementation, most fields have a set of standard problems they benchmark on. Find those and see how you compare on numerical accuracy and performance against the libraries you looked at before.
- lambda 4y ago
- hzhou321 4y agoI never thought that you are supposed to copy the code from a book blindly. If you do that, there must be some library that you can use that work better. So treating the code as pseudo code, I thought numerical recipes were excellent, better than text books in many aspects.
- throwaway81523 4y agoThere is no date on this but it is pretty old, since I remember thekerfluffle from probably 10+ years ago. I don't know if the NR license was ever adjusted but the software was nothing special anyway. I did learn a lot from the books, from a semi-neophyte perspective. I think serious numerics experts pooh pooh them though.
- pletnes 4y agoI always had the impression that NR was about getting a broad overview of the field. I imagine each chapter covers at least a whole field of numerical research. If you’re working on applications of numerics, it is indeed important to know what’s available out there. The NR code itself I’ve never used, really.
- throwaway81523 4y agoIt's more of an intro level book, aimed at scientists rather than numerics geeks or or people into theoretical math. So it does a good job of presenting things simply and in ways that don't require navigating too many fine points. That approach mostly works, though it leaves openings for things to go wrong. The topics (root finding, integration, etc.) are similar to what you'd see in an undergrad numerics course. It specifically doesn't have anything about PDE's, since it defines that as the boundary between introductory and advanced topics.
- nereye 4y agoFWIW, there is a whole chapter (17 in the first edition, 20 in the third/current edition, don’t have a second edition in front of me but would be surprised if it didn’t have one) on Partial Differential Equations. It’s about 50+ pages in the first edition and 70+ in the third. But I take your point, the chapter does admit to being intended as “the briefest possible useful introduction” and notes that the topic would require another volume entirely dedicated to it.
- throwaway81523 4y ago
- amelius 4y agoIf you're looking for a better book, I can recommend: Matrix computations, by Golub and van Loan.
- FabHK 4y agoOh, the bible. It is a great and thorough book (maybe not ideal for beginners). What it covers is quite different from NR, though.
- haunter 4y agoHuh glad it's not about cooking because I was ready to be ranting (ie recipes using 1 tablespoon instead of X grams)
- AussieWog93 4y agoFunny you mention that. I was ready to rant the opposite (ie, that recipes should not include exact measurements). I really, strongly believe that our obsession with measurement and repeatability is a net negative that has taught a whole generation to treat cooking like a standardised test rather than a creative form of human expression. You look at the older generations from cultures that value cooking and they simply don't give a fuck about what the recipe says to do.
- creata 4y ago> that recipes should not include exact measurements Wouldn't that make cooking much less accessible?
- greggsy 4y agoIt’s tricky - people have different tastes, and ingredients may change from region to region. Furthermore, making people measure things with a scale rather than a cup adds significant effort and time in the scheme of things.
- kergonath 4y agoIt takes less time to get the scale out of the drawer than figuring out which bloody cup I have to use.
- AussieWog93 4y ago>figuring out which bloody cup I have to use Unless you're baking, you could literally use any cup you have in your house (yes, even a drinking glass!). Unless you're baking, it really doesn't matter, and that's the beauty of it.
- greenyoda 4y agoThe current license can be found here: http://numerical.recipes/aboutNR3license.html http://numerical.recipes/aboutNR3license.html
- forgotpwd16 4y agoSeems nr.com is no more. Wonder why they decided (or should I say how much they're offered) to switch away from such a premium domain.
- jlebar 4y agoI remember being disappointed by this book. I wanted to read about algorithms for choosing a random float in [0,1], and IIRC its only suggestion was randint()/INT_MAX. This is wrong in part because the smallest nonzero value you'll ever choose is 1/INT_MAX, which is much larger than the smallest nonzero float. Is there a better book out there? I was hoping for something fabulous like Hacker's Delight but for floating point.
- ouid 4y agoChoosing a random float doesn't mean very much without a distribution.
- pmoriarty 4y agoRandomness is not a property of numbers but of distributions.
- raegis 4y agoActually I believe it is better to say randomness is a property of a sequence of numbers. So a "random sequence" has members chosen independently of each other, but all from the same probability distribution. And random number generators create random sequences which follow a given distribution.
- shirleyquirk 4y agoIf you want a random number in [0,1] with a uniform distribution from N random bits, I don't see how you can expect an epsilon of less than 1/(2**N-1)
- enriquto 4y agoThe GSL library is indeed great! It provides a free implementarion of all methods described in NR, and many more. The source code of GSL is somewhat readable, but I find NR still very helpful for the textual descriptions of the methods. Also, the venerable ccmath library by the late Daniel Atkinson is an extraordinary jewel of readability, simplicity, portability and performance among numerical codes.
- deleted 4y ago[deleted]
- chaboud 4y agoI've used Numerical Recipes in C heavily since 1996, but I've never used the code (which isn't great). Instead, I've used it as a reference to understand approaches and algorithms. Any code I've made using that book has been my own. If you know how to code and want a leg up on understanding an algorithm, NR is a very convenient structural cheat sheet.
- owlbite 4y agoBut its algorithms are often incorrect, inefficient and numerically unstable. Just use a library written by an expert in whatever your area of interest is.
- toast0 4y agoIsn't this book essentially a library written by experts[1] in numerical processing? You can't just use a library by experts. You have to know or learn how to evaluate said library for correctness, efficiency, and stability (numerical and operational). If you know how to do that, you may be able to use a flawed library as a tool to get the shape of your processing quickly and fill in the rest of the details yourself. [1] They've published a major book through three editions and the book cover calls them leading scientists.
- bluenose69 4y agoIt's been a very long time since I've used NR, but it was pretty terrible code that was a poor competitor for NAG and IMSL. The discussion of algorithms, being informal and well-illustrated, was the high point of the books. The code, not so much. I had the Fortran book and so, when the C book came out, I bought that as well. The C code seemed to have been auto-generated by the Fortran code, and it was really quite terrible. Functions in the fortran code had arguments for what I'd call "work arrays". There was some risk in that, because if the documentation told you to give space for 2N+1 floating point values and you gave 2N, you might get into problems. I don't think that was a real problem in practice, because people were accustomed to this general way of working and so they were careful. The C code took a different approach. The functions allocated and deallocated space as needed. And, since lots of functions called other functions for very simple things, there was a massive amount of memory juggling going on. This made the functions be wildly slow. So, the point of the boycott was not terribly relevant, because I think pretty much everyone trying to use that C code just rewrote it, anyway.
- deleted 4y ago[deleted]
- jeffwass 4y agoThis 100%. 20+ years ago I took my NR class as part of my physics PhD program, it was a required course for all physics and astronomy students. I don't think anybody in the class was planning to use the actual recipes from the book as a drop-in placement for their work, but it was to explain the methods behind the software we all used (Matlab in my group, IDL and IRAF for the astronomers, etc), so users can make the best choice for which curve fitting or regression or optimisation routines to call, and avoid potential pitfalls. To me it seems like an OS class that uses minix to explain behind-the-scenes operation system functionality. Hardly anyone in the class will go on to use Minix as their primary OS in their future career. (I've not done any formal CS study, so forgive the analogy).
- deleted 4y ago[deleted]
- Animats 4y ago
- sbrorson 4y agoAs somebody who came to scientific computing late in life, after spending years as a physicist then an engineer, I will step up to defend NR, if only for fun (and because I like the book for what it is). At least one commenter here dismissed NR, saying that it is equivalent to an undergraduate numerical analysis book. Well, duh! That's one of its strengths! It is a good book for an audience like me -- somebody with scientific background but with no formal numerical analysis training who needs to write some numerical code. The target reader is an engineer who needs to implement something specific. That's a very common scenario -- you are given the job of implementing some calculation as part of a larger project. You're not an expert in the particular mathematical discipline. You don't want to fool around trying to find an algo in some book since you don't know which of the zillions of numerical analysis books to look at. Also, most books will just give you a general algo, not ready-to-run code. Everybody knows how hard it can be to translate a wordy description of an algo into real code. If you had the budget you'd just hire somebody to do it for you. NR solves your problem -- you use the code and your problem is solved so you can move on to the next step of your project. A different commenter here suggested using Golub and Van Loan instead. That's laughable. First off, as others pointed out, their "Matrix Compuations" book addresses numerical linear algebra exclusively. NR is a general-purpose numerical analysis book, so covers a much larger topic set. But secondly, Matrix Computations is difficult reading for non-mathematicians. Even if I needed to implement some sort of matrix decomposition, I would find it a pain to use that book as a source. (Yes, I am sure some testosterone-soaked HN commenter will now say that they read "Matrix Computations" in 3rd grade as a way to prove how smart they are. Allow me to roll my eyes now.) The real complaint made in the linked post involves the licensing terms of the code in NR. I agree the license stinks by today's standards. But the book was originally written back in the 1980s. My copy is from the early 1990s. Back then the GPL was basically unknown outside of a group of happy hackers at MIT. Software licensing certainly not a topic occupying mindspace of ordinary scientists or engineers. There was some DOS-based "freeware" circulating on 3.5" disks, but the whole "free (libre) software" movement was still in the future -- it needed the internet to become widespread in order to take off. Finally, I can imagine the NR authors wanted some sort of copyright or license which prevented wholesale copying of their work by folks who would try to profit off it. It's reasonable for them to have wanted to get some monetary reward for their hard work. Their license is probably an artifact of its time. In my travels I have seen situations where code used in commercial products incorporates this or that function presented in NR. For example, I saw the FFT algo used in a test widget. (I authored none of the copied code -- I simply observe it in projects done by others.) What's funny is that NR's FFT algo is not particularly great. However, the guys who needed an FFT probably didn't know that. They probably would not have cared anyway -- they just wanted a working solution and that's what they got from NR. I am sure that little violations of the NR license happen all the time. It may not be strictly legal, but I also see people making Xerox copies of copyrighted books and journal articles all the time too. Finally, regarding alternatives like GSL, ccmath, or whatever is available on netlib, those projects post-date NR. In any event, the internet is what made all those things widely available. I bought my copy of NR in a bookstore before that happened.
- sam36 4y agoHeh, I haven't seen or read NR but added it to my wishlist after watching Terry Davis mention it [at 8:15] https://www.youtube.com/watch?v=25hLohVZdME https://www.youtube.com/watch?v=25hLohVZdME Seemed to work well enough for him.
- lupire 4y agoDon't tell me what to boycott unless it's the worst. Tell me what's good.
- NelsonMinar 4y agoIt's worth putting this book in historical context. It was first published in 1986. Numerical programming like this was very much a black art and the book was an well researched, documented, usable set of algorithms with (mostly) working code. Open source code was a very new idea (FSF was only established a year before, and while there are earlier precedents like BSD source it was all very new.) Source code distributions were awkward; absolutely nothing like github of course, just a few FTP servers which maybe you could get code from if you knew they existed and had Internet access. Typing in code from a book seemed perfectly reasonable.
- kragen 4y agoOpen source code was a very new idea, perhaps going back no further than the first SHARE meeting 31 years earlier in 01955, but imposing legal restrictions on source code distribution was an even newer idea. (But what about open-source numerical methods? Well, EISPACK had been published in 01974, 12 years before NR came out.) Typing in code from a book was perfectly reasonable. The issue today, though, is not what restrictions the book's copyright holders imposed, or purported to impose, in 01986. The issue is the restrictions they impose today.
- Aardwolf 4y ago> 01974 People from the year 100000 might be offended by this notation. But in seriousness, what is the extra 0 for? Even without it, 1974 and 10000 are perfectly distinguishable, and for computers good methods to store long dates use binary storage formats, so amount of ASCII decimal digits doesn't matter there
- deleted 4y ago[deleted]
- sitkack 4y agoIt is for Y10k compliance, https://longnow.org/ideas/02013/12/31/long-now-years-five-digit-dates-and-10k-compliance-at-home/ https://longnow.org/ideas/02013/12/31/long-now-years-five-di...
- spekcular 4y agoIssues with the license aside, there are substantial problems with the core algorithmic material of the book. The provided codes and approaches are often just plain incorrect. Quoting from a review: "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'...." Source: https://www.uwyo.edu/buerkle/misc/wnotnr.html https://www.uwyo.edu/buerkle/misc/wnotnr.html
- buescher 4y agoThere was a numerical analyst at JPL back in the day that absolutely savaged NR. Remember, the kind of engineering they do at JPL has to be correct, not just plausible. Also, noncommercial alternatives to things like Matlab (octave, the python interfaces to Netlib libraries, etc) weren't as mainstream then, and science and engineering research had a bigger "get a book and roll your own" ethic. https://web.archive.org/web/19990202153232/http://math.jpl.nasa.gov/nr/nr.html https://web.archive.org/web/19990202153232/http://math.jpl.n... I've seen it breed horrors - "senior" people instructing interns to implement its matrix inversion routine line-by-line in Matlab. Today it would be Python. Oh, and here's a list of alternatives, from the heyday of NR: https://web.archive.org/web/19990202141044/http://math.jpl.nasa.gov/nr/nr-alt.html https://web.archive.org/web/19990202141044/http://math.jpl.n...
- B1FF_PSUVM 4y agoI just like this phrase from the Usenet comments in the first link: > Their code has the implicit assumption that all elliptic problems have homogeneous Dirichlet boundary conditions!
- FabHK 4y agoI think the basic problem is that the algorithms were for exposition, not production quality (they would not guard against under/overflow, edge cases, etc.)
- bitwize 4y ago> These conditions are so restrictive that of course everybody breaks them, often without knowing it. Thus, the NR license makes itself a farce. It doesn't necessarily make the license a farce. An Oracle-like business model can be established by auditing the users of the NR library and assessing fees for license violations, including the inadvertent ones.
- nxpnsv 4y agoI used NR for a gauss elimination in FORTRAN back in the 90s. Next time I needed NR, I just used GSL. Nowadays I mostly stick to numpy...
- willis936 4y agoIANA numerical expert, but I have written a lot of MATLAB in the past decade. There are NR algorithms not present in MATLAB that are very useful. When trying to find the nearest index in one very large monotonically increasing vector in another you could use interp1, but what is much faster is to do a binary search. There is no binary search function in MATLAB. It's lightning fast to use the NR-C algorithm for a binary search in MATLAB. If you want to find many nearest indexes, then interp1 likely faster.
- topaz0 4y agoNote that the article is not about denigrating the algorithms, and is instead entirely about the license restrictions.
- willis936 4y agoI know but a lot of HN comments about the algorithm quality. It seems like a moot point because even if the algos were obsolete, the license issues remain. I don't think the algos are obsolete though.
- moonbug 4y agoI really can't imagine anyone finding NR now, except as a dusty relic on a lab office shelf
- mhh__ 4y agoBoycott C. In C++ or even better a language like D or Ada or whatever with built-in slices you can write assertions that explicitly encode assumptions and "what I meant to write, modulo bugs"-isms much more easily than in C. How long is that array? How big can that float be before the model is unstable? Maybe express the units in the type system etc.
- hpcjoe 4y agoI used NR a bit more in grad school (late 80s/early 90s) than undergrad. I had (have) the Fortran version. I used some of the ODE integration bits in some code I worked on in grad school, though we put that project away after we switched to a different DFT MD code. FWIW, that code (with NR) still compiles/runs. Tried it a few months ago. As an undergrad, I had a research project which used Markov methods, and I had to generate some fairly large (at the time) matrices. I wrote that code in Fortran, on a PC/AT system (1986, so ...). It also ran on an IBM 3090 VF 180 mainframe at Stony Brook. What I recall from that time, was the professor giving me a text on Markov methods, and me learning what I needed to construct the transition probabilities (matrix elements). I remember writing extensive tests within the code, called sanity checks, which I reported on. Fortran, no assert statement at the time, and its nice to see a note "COMPUTATION IS INSANE DO NOT TRUST" error message when you ran into problems. Honestly, that process taught me a number of things. 1st, the code you need may or may not have been written by someone else, and you really need to make sure you have sanity checks built in to establish the portions you can and cannot trust. Later when I used the NR code, I added sanity checks into their code, to make sure we weren't getting into strange spaces. 2nd, it is (often very) important to exploit mathematical features of your problems (symmetries, relation of derivatives to exact closed form equations, etc.) to simplify your calculation. Plug and crank is usually the wrong approach, and you need a solid understanding of your problem domain to have a fighting chance at not producing a garbage simulation. I've followed these coding practices for decades at this point, through many languages and systems. NR was a great way to start with these things, but I picked up Hamming's, Hildebrant's, and many other numerical analysis books along the way, taught myself, and generated code that was hopefully sane. I don't care so much about the license of NR, as I am not distributing code containing it. My thesis advisor warned me about that in early 90s. So that was removed from code I shared. I guess I am a bit sad that I offered said book to offspring as she starts a PhD in MechE later this year, and I don't think she wants it. She did take my numerical analysis books though, so I'm happy about that.