home


The following code is provided as is with no warranties express or implied or statutory or whatever, standard disclaimers apply, use at your own risk, yatta, yatta, yatta. If you find any problems, please make a comment here.

Approximations for the Gaussian Integral

Following are a few useful approximations for the Gaussian Integral. 

Stegun and Abramowitz provide tables to 15 decimal places in Table 26.1 of Handbook of Mathematical Functions. The book is available online here, but unfortunately, the table is missing from the PDF.

-----------------------------------------------------------

double Z(double x)
{
    // This is a supporting function called by P_1() and P_2()
    // Z(x) = 1.0/sqrt(2*pi) * e^(-x*x/2)
    const double s = 1.0 / sqrt(2.0 * pi);
    return s*exp(-x*x*0.5);
}

-----------------------------------------------------------

double P_1(double x)
{
    // Based on Abramowitz and Stegun, 26.2.16, p. 932
    // from C. Hastings, Approximations for Digital Computers
    // |e(x)| < 1.0 * 10^-5

    const double a1 = 0.4361836;
    const double a2 = -0.1201676;
    const double a3 = 0.9372980;
    const double p = 0.3326700;
    const double t = 1.0 / (1.0 + p*x);

    // return 1-Z(x) * (a1*t + a2*t*t + a3*t*t*t);
    return 1-Z(x) * (t*(a1 + t*(a2 + a3*t)));
}

-----------------------------------------------------------

double P_2(double x)
{
    // Based on Abramowitz and Stegun, 26.2.17, p. 932
    // from C. Hastings, Approximations for Digital Computers
    // |e(x)| < 7.5 * 10^-8

    const double b1 = 0.3193815300;
    const double b2 = -0.356563782;
    const double b3 = 1.781479370;
    const double b4 = -1.821255978;
    const double b5 = 1.330274429;
    const double p = 0.231641900;
    const double t = 1.0 / (1.0 + p*x);

    // return 1-Z(x)*(b1*t^1 + b2*t^2 + b3*t^3 + b4*t^4 + b5*t^5);
    return 1-Z(x)*(t*(b1 + t*(b2 + t*(b3 + t * (b4 + b5*t)))));
}

-----------------------------------------------------------

double factorial(int i)
{
    double f = 1.0;

    for(; i > 1; i--)
        f *= i;

    return f;
}

double ERF(double x, int ilevel)
{
    // ERF Taylor series expansion
    // Based on Abramowitz and Stegun, 7.1.5, p. 297

    double r = 0.0;
    double sign = 1.0;

    for(int i=0; i<=ilevel; i++)
    {
        r += sign * pow(x, 2*i+1) / ((2*i+1)*factorial(i));
        sign *= -1.0;
    }

    return 2.0 / sqrt(pi) * r;
}

double P_TAY(double x, int ilevel)
{
    // Taylor series expansion to specified term
    return 0.5 * (1.0 + ERF(x / sqrt(2.0), ilevel));
}

----------------------------------------------------------

double P_WJC(double x)
{
    // This function calls my port of W. J. Cody's CALERF
    // in TOMS 462 (http://www.netlib.org/toms/462)
    // My port is here: http://metamerist.com/gaussian/calerf.cpp
    // Assuming it's ported correctly, this is the
    // most accurate implementation--although calling P_TAY with
    // ilevel set sufficiently high seems to return good results
    // as well.

    double CALERF(double ARG);
    return 0.5 * (1.0 + CALERF(x / sqrt(2.0)));
}

----------------------------------------------------------

int main(int argc, char* argv[])
{
    int z=0;
    for(double x = 0.0; x<=4.0; x += 0.05)
    {
        printf("P(%4.2f) = %18.16f %18.16f %18.16f %18.16f\n", x, P_1(x), P_2(x), P_TAY(x, 100), P_WJC(x));
        if (++z%5==0)
            printf("\n");
    }

    return 0;
}
 

----------------------------output----------------------------

Column 1 = P_1(x)
Column 2 = P_2(x)
Column 3 = P_TAY(x, 100)
Column 4 = P_WJC(x)

P(0.00) = 0.5000000547809588 0.4999994288405208 0.5000000000000000 0.5000000000000000
P(0.05) = 0.5199469161544477 0.5199383224583177 0.5199388058383725 0.5199388058383725
P(0.10) = 0.5398383891580654 0.5398273651419756 0.5398278372770290 0.5398278372770290
P(0.15) = 0.5596271089075562 0.5596172019093885 0.5596176923702425 0.5596176923702425
P(0.20) = 0.5792659611525850 0.5792591985970543 0.5792597094391030 0.5792597094391030

P(0.25) = 0.5987085240649315 0.5987058063628732 0.5987063256829237 0.5987063256829237
P(0.30) = 0.6179094866649222 0.6179109112500504 0.6179114221889526 0.6179114221889526
P(0.35) = 0.6368250403995147 0.6368301648678466 0.6368306511756190 0.6368306511756190
P(0.40) = 0.6554132406744477 0.6554212925281566 0.6554217416103242 0.6554217416103241
P(0.45) = 0.6736343354998582 0.6736443755238164 0.6736447797120799 0.6736447797120799

P(0.50) = 0.6914510588231457 0.6914621046374387 0.6914624612740131 0.6914624612740130
P(0.55) = 0.7088288865833992 0.7088400024195181 0.7088403132116536 0.7088403132116535
P(0.60) = 0.7257362540168003 0.7257466122617116 0.7257468822499265 0.7257468822499263
P(0.65) = 0.7421447332603093 0.7421536528051094 0.7421538891941353 0.7421538891941353
P(0.70) = 0.7580291708298861 0.7580361367530554 0.7580363477769270 0.7580363477769270

P(0.75) = 0.7733677850780215 0.7733724536926904 0.7733726476231317 0.7733726476231317
P(0.80) = 0.7881422242525100 0.7881444170580264 0.7881446014166034 0.7881446014166034
P(0.85) = 0.8023375862739011 0.8023372758796175 0.8023374568773076 0.8023374568773076
P(0.90) = 0.8159424018135768 0.8159396924520643 0.8159398746532405 0.8159398746532405
P(0.95) = 0.8289485826796508 0.8289436875018292 0.8289438736915182 0.8289438736915182

P(1.00) = 0.8413513378967856 0.8413445548464076 0.8413447460685428 0.8413447460685430
P(1.05) = 0.8531490601928702 0.8531407478953090 0.8531409436241040 0.8531409436241041
P(1.10) = 0.8643431858759271 0.8643337406483638 0.8643339390536173 0.8643339390536173
P(1.15) = 0.8749380312957473 0.8749278660938815 0.8749280643628500 0.8749280643628498
P(1.20) = 0.8849406092350832 0.8849301350958492 0.8849303297782918 0.8849303297782918

P(1.25) = 0.8943604286647016 0.8943500389848283 0.8943502263331448 0.8943502263331449
P(1.30) = 0.9032092813264522 0.9031993391320629 0.9031995154143897 0.9031995154143897
P(1.35) = 0.9115010185811969 0.9114918467923813 0.9114920085625980 0.9114920085625980
P(1.40) = 0.9192513218775502 0.9192431964518465 0.9192433407662290 0.9192433407662290
P(1.45) = 0.9264774700673977 0.9264706158148709 0.9264707403903516 0.9264707403903517

P(1.50) = 0.9331981066204084 0.9331926954176812 0.9331927987311419 0.9331927987311420
P(1.55) = 0.9394330095781189 0.9394291606663081 0.9394292419979411 0.9394292419979411
P(1.60) = 0.9452028668450281 0.9452006488739331 0.9452007083004421 0.9452007083004421
P(1.65) = 0.9505290591460667 0.9505284936210636 0.9505285319663519 0.9505285319663520
P(1.70) = 0.9554334526935129 0.9554345184893660 0.9554345372414570 0.9554345372414570

P(1.75) = 0.9599382033084982 0.9599408419328428 0.9599408431361831 0.9599408431361830
P(1.80) = 0.9640655734390776 0.9640696947549425 0.9640696808870742 0.9640696808870742
P(1.85) = 0.9678377632144323 0.9678432513634167 0.9678432252043862 0.9678432252043864
P(1.90) = 0.9712767563786688 0.9712834756820810 0.9712834401839983 0.9712834401839983
P(1.95) = 0.9744041816628479 0.9744119823153700 0.9744119404783616 0.9744119404783614

P(2.00) = 0.9772411898846422 0.9772499132923079 0.9772498680518207 0.9772498680518209
P(2.05) = 0.9798083468150315 0.9798178304652006 0.9798177845942955 0.9798177845942957
P(2.10) = 0.9821255416236181 0.9821356234081859 0.9821355794371834 0.9821355794371834
P(2.15) = 0.9842119105106846 0.9842224324542387 0.9842223926089094 0.9842223926089095
P(2.20) = 0.9860857749565328 0.9860965863280439 0.9860965524865015 0.9860965524865014

P(2.25) = 0.9877645938677331 0.9877755536773724 0.9877755273449553 0.9877755273449553
P(2.30) = 0.9892649287758847 0.9892759076775808 0.9892758899783241 0.9892758899783242
P(2.35) = 0.9906024211469301 0.9906133027823781 0.9906132944651613 0.9906132944651614
P(2.40) = 0.9917917807870923 0.9918024626182828 0.9918024640754040 0.9918024640754038
P(2.45) = 0.9928467842837576 0.9928571779689847 0.9928571892647283 0.9928571892647286

P(2.50) = 0.9937802823944153 0.9937903137674966 0.9937903346742236 0.9937903346742238
P(2.55) = 0.9946042152920921 0.9946138240065824 0.9946138540459334 0.9946138540459333
P(2.60) = 0.9953296345893866 0.9953387734893030 0.9953388119762812 0.9953388119762813
P(2.65) = 0.9959667310928881 0.9959753653693143 0.9959754114572419 0.9959754114572417
P(2.70) = 0.9965248672830424 0.9965329734723424 0.9965330261969589 0.9965330261969594

P(2.75) = 0.9970126135690207 0.9970201784436595 0.9970202367649452 0.9970202367649454
P(2.80) = 0.9974377874314856 0.9974448068289697 0.9974448696695724 0.9974448696695720
P(2.85) = 0.9978074946360842 0.9978139722656235 0.9978140385450867 0.9978140385450868
P(2.90) = 0.9981281717749367 0.9981341180353438 0.9981341866996164 0.9981341866996160
P(2.95) = 0.9984056294703571 0.9984110603066843 0.9984111303526349 0.9984111303526351

P(3.00) = 0.9986450956528223 0.9986500314734600 0.9986501019683698 0.9986501019683699
P(3.05) = 0.9988512584022490 0.9988557230728125 0.9988557931689776 0.9988557931689773
P(3.10) = 0.9990283079166090 0.9990323278420333 0.9990323967867818 0.9990323967867816
P(3.15) = 0.9991799772437424 0.9991835805456438 0.9991836476871727 0.9991836476871714
P(3.20) = 0.9993095814799907 0.9993127972725765 0.9993128620620829 0.9993128620620841

P(3.25) = 0.9994200552023220 0.9994229129669471 0.9994229749576091 0.9994229749576092
P(3.30) = 0.9995139879584353 0.9995165170143038 0.9995165758576154 0.9995165758576162
P(3.35) = 0.9995936576916281 0.9995958867580891 0.9995959421981384 0.9995959421981360
P(3.40) = 0.9996610620238206 0.9996630188681654 0.9996630707343225 0.9996630707343231
P(3.45) = 0.9997179473610334 0.9997196585246279 0.9997197067231841 0.9997197067231838

P(3.50) = 0.9997658358209424 0.9997673264158479 0.9997673709209674 0.9997673709209645
P(3.55) = 0.9998060500120499 0.9998073435799666 0.9998073844243658 0.9998073844243643
P(3.60) = 0.9998397357188429 0.9998408541441656 0.9998408914098418 0.9998408914098425
P(3.65) = 0.9998678825673570 0.9998688460363341 0.9998688798455797 0.9998688798455795
P(3.70) = 0.9998913427612540 0.9998921697596170 0.9998922002665283 0.9998922002665226

P(3.75) = 0.9999108479902378 0.9999115553321825 0.9999115827148019 0.9999115827147992
P(3.80) = 0.9999270246208258 0.9999276275028314 0.9999276519560691 0.9999276519560749
P(3.85) = 0.9999404072845813 0.9999409193582174 0.9999409410875930 0.9999409410875810
P(3.90) = 0.9999514509813269 0.9999518844398816 0.9999519036559876 0.9999519036559824
P(3.95) = 0.9999605418149977 0.9999609074894517 0.9999609244034002 0.9999609244034022

P(4.00) = 0.9999680064780536 0.9999683139385895 0.9999683287581589 0.9999683287581669