TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Boycott Numerical Recipes (2007)

155 pointsby arthurmorganabout 3 years ago

23 comments

bluenose69about 3 years ago
It&#x27;s been a <i>very</i> long time since I&#x27;ve used NR, but it was pretty terrible code that was a poor competitor for NAG and IMSL.<p>The discussion of algorithms, being informal and well-illustrated, was the high point of the books. The code, not so much.<p>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.<p>Functions in the fortran code had arguments for what I&#x27;d call &quot;work arrays&quot;. 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&#x27;t think that was a real problem in practice, because people were accustomed to this general way of working and so they were careful.<p>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.
评论 #30896106 未加载
评论 #30899239 未加载
评论 #30901638 未加载
评论 #30897224 未加载
评论 #30896662 未加载
NelsonMinarabout 3 years ago
It&#x27;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.
评论 #30898366 未加载
评论 #30898848 未加载
评论 #30900829 未加载
buescherabout 3 years ago
There 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&#x27;t as mainstream then, and science and engineering research had a bigger &quot;get a book and roll your own&quot; ethic. <a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;19990202153232&#x2F;http:&#x2F;&#x2F;math.jpl.nasa.gov&#x2F;nr&#x2F;nr.html" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;19990202153232&#x2F;http:&#x2F;&#x2F;math.jpl.n...</a><p>I&#x27;ve seen it breed horrors - &quot;senior&quot; people instructing interns to implement its matrix inversion routine line-by-line in Matlab. Today it would be Python.<p>Oh, and here&#x27;s a list of alternatives, from the heyday of NR: <a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;19990202141044&#x2F;http:&#x2F;&#x2F;math.jpl.nasa.gov&#x2F;nr&#x2F;nr-alt.html" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;19990202141044&#x2F;http:&#x2F;&#x2F;math.jpl.n...</a>
评论 #30900893 未加载
评论 #30903978 未加载
jlebarabout 3 years ago
I remember being disappointed by this book.<p>I wanted to read about algorithms for choosing a random float in [0,1], and IIRC its only suggestion was randint()&#x2F;INT_MAX. This is wrong in part because the smallest nonzero value you&#x27;ll ever choose is 1&#x2F;INT_MAX, which is much larger than the smallest nonzero float.<p>Is there a better book out there? I was hoping for something fabulous like Hacker&#x27;s Delight but for floating point.
评论 #30895669 未加载
评论 #30895596 未加载
评论 #30897936 未加载
评论 #30896286 未加载
评论 #30895594 未加载
评论 #30898047 未加载
评论 #30895665 未加载
throwaway81523about 3 years ago
There is no date on this but it is pretty old, since I remember thekerfluffle from probably 10+ years ago. I don&#x27;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.
评论 #30897031 未加载
评论 #30895441 未加载
评论 #30895661 未加载
enriqutoabout 3 years ago
The GSL library is indeed great! It provides a free implementarion of all methods described in NR, and <i>many</i> more. The source code of GSL is somewhat readable, but I find NR still very helpful for the textual descriptions of the methods.<p>Also, the venerable ccmath library by the late Daniel Atkinson is an extraordinary jewel of readability, simplicity, portability and performance among numerical codes.
chaboudabout 3 years ago
I&#x27;ve used Numerical Recipes in C heavily since 1996, but I&#x27;ve never used the code (which isn&#x27;t great). Instead, I&#x27;ve used it as a reference to understand approaches and algorithms. Any code I&#x27;ve made using that book has been my own.<p>If you know how to code and want a leg up on understanding an algorithm, NR is a very convenient structural cheat sheet.
评论 #30897500 未加载
spekcularabout 3 years ago
Issues 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.<p>Quoting from a review: &quot;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&#x27;s emphasis]. The authors have attempted to cover a very extensive range of topics. They have basically found `some&#x27; 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.<p>&quot;One should independently check the validity of any information or codes obtained from `Numerical Recipes&#x27;....&quot;<p>Source: <a href="https:&#x2F;&#x2F;www.uwyo.edu&#x2F;buerkle&#x2F;misc&#x2F;wnotnr.html" rel="nofollow">https:&#x2F;&#x2F;www.uwyo.edu&#x2F;buerkle&#x2F;misc&#x2F;wnotnr.html</a>
ameliusabout 3 years ago
If you&#x27;re looking for a better book, I can recommend:<p>Matrix computations, by Golub and van Loan.
评论 #30895934 未加载
willis936about 3 years ago
IANA numerical expert, but I have written a lot of MATLAB in the past decade.<p>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&#x27;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.
评论 #30898908 未加载
forgotpwd16about 3 years ago
Thought Numerical Recipes was used mostly in courses for students to learn about numerical methods rather using those pre-made routines for building large programs.
评论 #30895941 未加载
mhh__about 3 years ago
Boycott C.<p>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 &quot;what I meant to write, modulo bugs&quot;-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.
greenyodaabout 3 years ago
The current license can be found here: <a href="http:&#x2F;&#x2F;numerical.recipes&#x2F;aboutNR3license.html" rel="nofollow">http:&#x2F;&#x2F;numerical.recipes&#x2F;aboutNR3license.html</a>
评论 #30895597 未加载
bitwizeabout 3 years ago
&gt; These conditions are so restrictive that of course everybody breaks them, often without knowing it. Thus, the NR license makes itself a farce.<p>It doesn&#x27;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.
hpcjoeabout 3 years ago
I used NR a bit more in grad school (late 80s&#x2F;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&#x2F;runs. Tried it a few months ago.<p>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&#x2F;AT system (1986, so ...). It also ran on an IBM 3090 VF 180 mainframe at Stony Brook.<p>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 &quot;COMPUTATION IS INSANE DO NOT TRUST&quot; error message when you ran into problems.<p>Honestly, that process taught me a number of things.<p>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&#x27;t getting into strange spaces.<p>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.<p>I&#x27;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&#x27;s, Hildebrant&#x27;s, and many other numerical analysis books along the way, taught myself, and generated code that was hopefully sane.<p>I don&#x27;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.<p>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&#x27;t think she wants it. She did take my numerical analysis books though, so I&#x27;m happy about that.
hzhou321about 3 years ago
I 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.
magicalhippoabout 3 years ago
What are some good, current sources for learning about and implementing numerical algorithms like those in Numerical Recipes?<p>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.
评论 #30898572 未加载
评论 #30902601 未加载
评论 #30897904 未加载
评论 #30897628 未加载
nxpnsvabout 3 years ago
I 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...
haunterabout 3 years ago
Huh glad it&#x27;s not about cooking because I was ready to be ranting (ie recipes using 1 tablespoon instead of X grams)
评论 #30895590 未加载
评论 #30895614 未加载
moonbugabout 3 years ago
I really can&#x27;t imagine anyone finding NR now, except as a dusty relic on a lab office shelf
lupireabout 3 years ago
Don&#x27;t tell me what to boycott unless it&#x27;s the worst. Tell me what&#x27;s good.
sbrorsonabout 3 years ago
As 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).<p>At least one commenter here dismissed NR, saying that it is equivalent to an undergraduate numerical analysis book. Well, duh! That&#x27;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.<p>The target reader is an engineer who needs to implement something specific. That&#x27;s a very common scenario -- you are given the job of implementing some calculation as part of a larger project. You&#x27;re not an expert in the particular mathematical discipline. You don&#x27;t want to fool around trying to find an algo in some book since you don&#x27;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&#x27;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.<p>A different commenter here suggested using Golub and Van Loan instead. That&#x27;s laughable. First off, as others pointed out, their &quot;Matrix Compuations&quot; 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.<p>(Yes, I am sure some testosterone-soaked HN commenter will now say that they read &quot;Matrix Computations&quot; in 3rd grade as a way to prove how smart they are. Allow me to roll my eyes now.)<p>The real complaint made in the linked post involves the licensing terms of the code in NR. I agree the license stinks by today&#x27;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 &quot;freeware&quot; circulating on 3.5&quot; disks, but the whole &quot;free (libre) software&quot; 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&#x27;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.<p>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&#x27;s funny is that NR&#x27;s FFT algo is not particularly great. However, the guys who needed an FFT probably didn&#x27;t know that. They probably would not have cared anyway -- they just wanted a working solution and that&#x27;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.<p>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.
评论 #30897561 未加载
评论 #30899097 未加载
评论 #30897575 未加载
sam36about 3 years ago
Heh, I haven&#x27;t seen or read NR but added it to my wishlist after watching Terry Davis mention it [at 8:15] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=25hLohVZdME" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=25hLohVZdME</a> Seemed to work well enough for him.