Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2009-03-19 18:06:00

MrRHQ
Member
Registered: 2009-03-15
Posts: 8

Complex statistics functions in a C.P.R

(C.P.R stands for common programming language. C, C++, Java, Python, and more.)

OK, I want to know how functions like gamma and zeta which gamma uses integrals and zeta uses something related to the harmonic series but with the denominator as an exponential function.

I've looked up statistics functions in a common programming language made using only operators and variables. This means it can be Game Maker compatible which is what I'm looking for.

The gamma function on THIS WEBSITE is written in C++. The following below is a version I rewrote for Game Maker, credit goes to original creator though.

if!(is_real(argument))return 0;
var i,k,m,g,ga,gr,r,c,z;
g[0]=1.0;
g[1]=0.5772156649015329;
g[2]=-0.6558780715202538;
g[3]=-0.0420026350340952;
g[4]=0.1665386113822915;
g[5]=-0.0421977345555443;
g[6]=-0.009621971527877;
g[7]=0.007218943246663;
g[8]=-0.0011651675918591;
g[9]=-0.0002152416741149;
g[10]=0.0001280502823882;
g[11]=-0.0000201348547807;
g[12]=-0.0000012504934821;
g[13]=0.000001133027232;
g[14]=-0.0000002056338417;
g[15]=0.000000006116095;
g[16]=0.0000000050020075;
g[17]=-0.0000000011812746;
g[18]=0.0000000001043427;
g[19]=0.0000000000077823;
g[20]=-0.0000000000036968;
g[21]=0.00000000000051;
g[22]=-0.0000000000000206;
g[23]=-0.0000000000000054;
g[24]=0.0000000000000014;
z=argument;
if(z==z div 1){
    c=1;
    z-=1;
    repeat(z-1){
        c*=z;
        z-=1;
        if(z>=9223372036854775808){
            show_error("Error in function gamma().",0);
            exit;
        }
    }
    return c-(z<=0);
}else{
    if(abs(z)>1){
        c=abs(z);
        m=floor(c);
        r=1;
        for(k=1;k<=m;k+=1){
            r*=(z-k);
        }
        c-=m;
    }else c=z;
    gr=g[24];
    for(k=23;k>=0;k-=1){
        gr*=c;
        gr+=g[k];
    }
    ga=1/(gr*c);
    if(abs(z)>1){
        ga*=r;
        if(z<0)
            ga=-pi/(z*ga*sin(pi*z));
    }
}
if(ga>=9223372036854775808){
    show_error("Error in function gamma().",0);
    exit;
}
return ga;

It works, but I want to know how.
Brief analysis says that it looks like an array of random real numbers are initialized in the beginning. We can say that gamma(z) = z! when z is a natural number. Otherwise, we do some calculations. Since this is an integral related function, we multiply when using for loops I guess.

But, have you looked at the C++ gamma(); function? Is another algorithm faster than using arithmetic calculations? Since gamma relates to factorials, can it be thought of as a function to calculate values in between factorials on a graph? Can zeta or other functions be calculated? How?

Offline

Board footer

Powered by FluxBB