-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add inverse error functions erfinv and erfcinv #2987
Conversation
Awesome! Major bonus points for including a reference. |
add inverse error functions erfinv and erfcinv
Thanks Jeff! PS. In a quick benchmark ( |
This is also a really good example of a non-trivial macro that is useful to and accessible to those more mathematically-inclined than programming-inclined. |
Yes, it was pleasant to be able to use a macro for this; might be nice to have an example of this sort in the manual to illustrate expression generation. |
This is one of my favorite pull requests ever. |
Hmm, also seems to be almost 3× faster than the |
It may be because it loops over arrays of coefficients, instead of unrolling everything like your macro does. |
Here is an oddity: the single-precision version is slower than the double-precision version.
It looks like the culprit is that |
@JeffBezanson, fixing the |
This patch adds functions
erfinv
anderfcinv
that compute the inverse of the error function (erf
) and the complementary error function (erfc
) for real arguments, respectively.It uses the rational approximants described by Blair et al.. This is an independent, from-scratch implementation, so there should be no copyright concerns. (I use the tables of coefficients from Blair, but mathematical data of this sort is not generally subject to copyright.)
There are separate double- and single-precision versions, since the latter can be computed more cheaply using lower-degree approximants. Complex arguments are not supported (this would be a much harder problem and I'm not sure if it has been addressed in the literature).