docs: function bgrat(a, b, x) {
        var T, fTs, u, logH, logM, lnx2s, lnx2sn, ps, cs, j, ser;
  
        T = a + 0.5 * (b - 1);
        fTs = 1 / (4 * T * T);
        u = -T * Math.log(x);
        logH = Math.log(b) + log1p(gam1(b)) + b * Math.log(u) - u;
        logM = logH - (algdiv(b, a) + b * Math.log(T));
        cs = [1];   // cs[n] = 1 / (2n + 1)!
        ps = [1];   // ps[n] = p_n in (9.3)
        lnx2s = Math.log(x) * 0.5;   // (ln(x) / 2) ^ 2
        lnx2s *= lnx2s;
        lnx2sn = 1;   // lnx2s ^ n
        j = gratR(b, u, logH);
        ser =
        Math.log(
           series(function(n) {
              var mbmn; // holds m*b - n
  
              mbmn = -n;
              if (n > 0) {
                 j = (b + 2 * n - 2) * (b + 2 * n - 2 + 1) * j +
                       (u + b + 2 * n - 2 + 1) * lnx2sn;
                 j *= fTs;
                 cs[n] = cs[n - 1] / (2 * n) / (2 * n + 1);
                 ps[n] = (b - 1) * cs[n] + 1 / n * series(function(m) {
                    if (m === 0) { return 0; }
                    mbmn += b;
                    return mbmn * cs[m] * ps[n - m];
                 }, n);
                 lnx2sn *= lnx2s;
              }
              return ps[n] * j;
           })
        );
        return logM + ser;
     }