Stand-alone scientific code

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.

Related posts:

8 thoughts on “Stand-alone scientific code

  1. 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.

  2. 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.

  3. Manoel Galdino

    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.

  4. SteveBrooklineMA

    Very nice, thanks! I often find myself wrestling, exactly like Mark above.

  5. This is great stuff! In an ideal world I would love to see stand-alone, portable and free reference implementations of every numerical method.

  6. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>