26th September 2018
A lot of the mathematical implementations we do at NearForm depends on so-called mathematical special functions. There is no clearly defined criteria for what a special function is, but suffice to say they are functions that often turn up in mathematics and most of them are notoriously hard to compute. Often they are defined as the solution to a well-posed problem. However the solution itself is not easy to compute.
In R these functions are often built-in, and in Python, SciPy implements these functions.
Deep within the SciPy source code, we find the Cephes library which is what implements many of these functions.
We have released the WebAssembly version of Cephes on npm, see https://www.npmjs.com/package/cephes.
So all you need to do is to install it with
npm install cephes.
const cephes = require('cephes'); const value = cephes.gamma(2);
Below are just a few examples of the 125 available functions. You can see all of them in our README file.
All of the values that make up the graph are calculated dynamically in your browser. This gives you an idea of just how fast Cephes in WebAssembly is.
Cephes as an Open Source project
Whilst Cephes lacks a general license, its author, Stephen L. Moshier, has kindly granted us permission to license it as BSD-3-Clause. Whilst the library continues to be maintained, it doesn’t use some of the more modern approximation methods for many of the special functions.
The good news is that R and SciPy are working together on making a better Open Source library of these special functions. But it will take a while before that library is ready and until then Cephes is by far the best choice.
The mathematical special functions have so many use cases. If you think your business could benefit from math, such as statistics, logistics, or something else. Then please feel free to contact us.