public static double trigamma(double x){
  if (Double.isNaN(x) || Double.isInfinite(x)) {
    return x;
  }
  if (x > 0 && x <= S_LIMIT) {
    return 1 / (x * x);
  }
  if (x >= C_LIMIT) {
    double inv=1 / (x * x);
    return 1 / x + inv / 2 + inv / x * (1.0 / 6 - inv * (1.0 / 30 + inv / 42));
  }
  return trigamma(x + 1) + 1 / (x * x);
}

public static double trigamma ( double x ) { if ( Double . isNaN ( x ) || Double . isInfinite ( x ) ) { return x ; } if ( x > 0 && x <= S_LIMIT ) { return 1 / ( x * x ) ; } if ( x >= C_LIMIT ) { double inv = 1 / ( x * x ) ; return 1 / x + inv / 2 + inv / x * ( 1.0 / 6 - inv * ( 1.0 / 30 + inv / 42 ) ) ; } return trigamma ( x + 1 ) + 1 / ( x * x ) ; }
computes the trigamma function of x . this function is derived by taking the derivative of the implementation of digamma .
