// Euler-Maclaurin summation approximates a sum by an integral. // \sum_{k=a}^{b} f(k) = \int_a^b \! f(x) \, dx - B_1 \left[ f(b) + f(a) \right] + // \sum_{j=0}^{\infty} \frac{B_{2j}}{(2j)!} \left[ f^{(2j-1)}(b) - f^{(2j-1)}(a) \right] private static Complex RiemannZeta_EulerMaclaurin(Complex z, int n) { Complex f = 0.0; // Sum terms up to (n-1)^{-z} for (int k = 1; k < n; k++) { f += ComplexMath.Pow(k, -z); } // Integral term Complex f_old = f; Complex zm1 = z - Complex.One; f += ComplexMath.Pow(n, -zm1) / zm1; if (f == f_old) { return(f); } // B_1 term f_old = f; Complex df = ComplexMath.Pow(n, -z) / 2.0; f += df; if (f == f_old) { return(f); } // B_2 term df *= z / n; f += AdvancedIntegerMath.BernoulliNumber(2) * df; if (f == f_old) { return(f); } // Higher Bernoulli terms for (int k = 4; k < 2 * AdvancedIntegerMath.Bernoulli.Length; k += 2) { f_old = f; df *= (z + (k - 2)) / n * (z + (k - 3)) / n / k / (k - 1); f += AdvancedIntegerMath.Bernoulli[k / 2] * df; if (f == f_old) { return(f); } } throw new NonconvergenceException(); }
private static double PolyLog_BernoulliSum(int n, double w) { double s = 0.0; for (int k = n; k > 1; k--) { double ds = (1.0 - MoreMath.Pow(2.0, 1 - k)) * Math.Abs(AdvancedIntegerMath.BernoulliNumber(k)) * MoreMath.Pow(Global.TwoPI, k) / AdvancedIntegerMath.Factorial(k) * MoreMath.Pow(w, n - k) / AdvancedIntegerMath.Factorial(n - k); s -= ds; } s -= MoreMath.Pow(w, n) / AdvancedIntegerMath.Factorial(n); return(s); }