zetac.py 657 B

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