code: public static double regularizedIncompleteGamma(double s, double x) {
          if (s < 0.0) {
              throw new IllegalArgumentException("Invalid s: " + s);
          }
  
          if (x < 0.0) {
              throw new IllegalArgumentException("Invalid x: " + x);
          }
  
          double igf = 0.0;
  
          if (x < s + 1.0) {
              // Series representation
              igf = regularizedIncompleteGammaSeries(s, x);
          } else {
              // Continued fraction representation
              igf = regularizedIncompleteGammaFraction(s, x);
          }
  
          return igf;
      }
docs: Regularized Incomplete Gamma Function
  P(s,x) = <i><big>&#8747;</big><sub><small>0</small></sub><sup><small>x</small></sup> e<sup>-t</sup> t<sup>(s-1)</sup> dt</i>