zetac.py 591 B

123456789101112131415161718192021222324252627
  1. """Compute the Taylor series for zeta(x) - 1 around x = 0."""
  2. try:
  3. import mpmath
  4. except ImportError:
  5. pass
  6. def zetac_series(N):
  7. coeffs = []
  8. with mpmath.workdps(100):
  9. coeffs.append(-1.5)
  10. for n in range(1, N):
  11. coeff = mpmath.diff(mpmath.zeta, 0, n)/mpmath.factorial(n)
  12. coeffs.append(coeff)
  13. return coeffs
  14. def main():
  15. print(__doc__)
  16. coeffs = zetac_series(10)
  17. coeffs = [mpmath.nstr(x, 20, min_fixed=0, max_fixed=0)
  18. for x in coeffs]
  19. print("\n".join(coeffs[::-1]))
  20. if __name__ == '__main__':
  21. main()