Advertisement
apexsquirt

Zeta approximation over the reals

May 4th, 2020
2,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. const float precision_d = 0.0001;
  2. // the closer precision_d will be to 0, the more zeta
  3. // should theoretically be accurate in the negatives !
  4. // although, there are precision errors practically,
  5. // but i'll go further in depth in the code. ^^
  6. double zeta (double x, double z[5000], bool osef = false) {
  7.     double e_x = 2*int(x/2);
  8.     if (x >= 0 and x < 2) { z[0] = -0.5; }
  9.     else if (x >= 2 and x < 4) { z[2] = 1.644934066848226436472415166646; }
  10.     else if (x >= 4) {
  11.         double ret = 0;
  12.         double e_i;
  13.         for (int i = 1; i <= e_x/2-1; i++) {
  14.             e_i = 2*i;
  15.             ret += z[int(e_i)]*z[int(e_x-e_i)];
  16.         }
  17.         ret *= 2/(e_x+1);
  18.         z[int(e_x)] = ret;
  19.     }
  20.     if (osef) return z[int(e_x)];
  21.     else {
  22.         if (x >= 0) return ((e_x-1)*(e_x-x+2)*z[int(e_x)]+(x-e_x)*(e_x+1)*zeta(x+2,z,true))*0.5/(x-1);
  23.             // c++ is kinda shit doe precisionwise so it'll basically be 0 far enough
  24.             // in the negatives bcs he thinks it's 1 far enough in the positives... :/
  25.         else if (x < 0) {
  26.             double gamma = 0;
  27.             for (float d = precision_d; d < 1; d += precision_d) {
  28.                 gamma += precision_d/pow(log(1/d),x);
  29.             }
  30.             return pow(2,x)*pow(3.1415926535897932384626433832795,x-1)*sin(3.1415926535897932384626433832795*x/2)*gamma*zeta(1-x,z);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement