code: private static double regularizedIncompleteGammaSeries(double a, double x) {
          if (a < 0.0 || x < 0.0 || x >= a + 1) {
              throw new IllegalArgumentException(String.format("Invalid a = %f, x = %f", a, x));
          }
  
          int i = 0;
          double igf = 0.0;
          boolean check = true;
  
          double acopy = a;
          double sum = 1.0 / a;
          double incr = sum;
          double loggamma = lgamma(a);
  
          while (check) {
              ++i;
              ++a;
              incr *= x / a;
              sum += incr;
              if (Math.abs(incr) < Math.abs(sum) * INCOMPLETE_GAMMA_EPSILON) {
                  igf = sum * Math.exp(-x + acopy * Math.log(x) - loggamma);
                  check = false;
              }
              if (i >= INCOMPLETE_GAMMA_MAX_ITERATIONS) {
                  check = false;
                  igf = sum * Math.exp(-x + acopy * Math.log(x) - loggamma);
                  logger.error("Gamma.regularizedIncompleteGammaSeries: Maximum number of iterations wes exceeded");
              }
          }
          return igf;
      }
docs: Regularized Incomplete Gamma Function P(a,x) = <i><big>&#8747;</big><sub><small>0</small></sub><sup><small>x</small></sup> e<sup>-t</sup> t<sup>(a-1)</sup> dt</i>.
  Series representation of the function - valid for x < a + 1