Sometimes you need one or two scientific functions not included in your programming environment. For a number of possible reasons, you do not want to depend on an external library. For example, maybe you don’t want to take the time to evaluate libraries. Or maybe you want to give someone else a small amount of self-contained code. Here is a collection of code for these situations.
Stand-alone code for numerical computing
This page contains C++, Python, and C# code for special functions and random number generation with no external dependencies. Do whatever you want with it, no strings attached. Use at your own risk. I recently added software for gamma and log gamma functions, as well as a few random number generators. (Why separate functions for the gamma function and its logarithm? See explanation here.)
I don’t recommend using this code as a way to avoid learning a good library. If you’re writing Python, for example, I’d recommend using SciPy. But there are times when the advantages of being self-contained outweigh the advantages of using high-quality libraries.
7 thoughts on “Stand-alone scientific code”
This is very cool John. Thanks for sharing the tools, I’ve been wrestling with licensed math functions (Numerical Recipes) or big libraries (Boost) recently so I can appreciate portable solutions.
Thanks very much! Although I’ve written my own versions that I’ve needed for numerical computing in C, it’s great to know this is out there.
Yep, ti’s great. Btw, do you know of some code to generate random number from Wishart distributions? I need it for some Bayesian hierarchical models of my own.
Thanks anyay for sharing these codes.
Very nice, thanks! I often find myself wrestling, exactly like Mark above.
This is great stuff! In an ideal world I would love to see stand-alone, portable and free reference implementations of every numerical method.
Hi Dr. Cook,
I hope your spam filter didn’t trap the email I sent you on this topic. (I would have posted it to the blog but I wanted to stuff in a bunch of hyperlinks; now I realize that I might as well put them here) In a nutshell, what you’re doing is valuable enough, and the code useful enough, that the world would be a better place if you put the code in GitHub Gists and the index page in a wiki (also free). If GitHub doesn’t support this outright as one of the best possible uses for their system, everyone can boycott them ;-)
The inspiration basically comes from Hadley Wickham’s R development class materials, which use one of Dirk’s now-classic examples of prototyping C++ extensions from within R using the ‘inline’ package. I cannot imagine a better resource for that sort of thing than what you’ve created. Using a wiki-style resource would mean you could farm out some of the maintenance, and using GitHub Gists as the backing store means that the individual snippets become versioned, so the entire enterprise ends up version-controlled and downloadable.
Thanks for your help individually (you can of course expect a citation from me) and, as with this project, in general. The world is a better place because of people like you.
Very useful, thanks for sharing this.