# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Riemann Zeta Functions $\zeta$

# The simplest representation is
#
# $$ \zeta(s) = \sum_{n=1}^{\infty} \frac{1}{n^s} $$
#
# Often in physics problems, $s$ will be integer. On the real line with $s>1$ we have an alternative definition:
#
# $$ \zeta(s) = \frac{1}{\Gamma(s)} \int_0^{\infty} \frac{u^{s-1}}{e^u - 1} du $$
#
# This is an integral that is needed in quite common problems such as blackbody radiation. Turning it around slightly:
#
# $$ \int_0^{\infty} \frac{x^{\alpha}}{e^x - 1} dx = \Gamma(\alpha + 1) \zeta(\alpha + 1) $$
#
# $\zeta(s)$ is defined over the complex plane, apart from some singularities (such as $s=1$). This is important in number theory and has spawned a vast literature, not immediately comprehensible to most of us.

# Does $\zeta(s)$ have a simple representation for integer $s$? Some do, some don't:

# +
from IPython.display import Math
from sympy import zeta, latex
from sympy.abc import x, s

for i in range(-7, 7):
    zeta_i = latex(zeta(i))
    display(Math('\zeta({}) = {}'.format(i, zeta_i)))
# -

# For real $s$, Python has a few issues with $s < 1$. The function `scipy.special.zeta(x)` returns `nan` for $s \le 1$. A related function `scipy.special.zetac(x)` is more flexible, but the values returned are offset to $\zeta(s) - 1$ and the documentation warns it returns `nan` for $x < -30.8148$.

# +
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams.update({'font.size': 16})

import scipy.special as sp
xlims = (-20, 20)
x = np.linspace(xlims[0], xlims[1], 500)
zetas = sp.zetac(x) + 1
# display(zetas)

plt.figure(figsize=(9, 9))
plt.plot(x, zetas)

plt.xlim(xlims)
plt.ylim((-0.5, 1.5))
plt.xlabel('$x$')
plt.ylabel('$\\zeta(x)$')
plt.title('Plot of the zetas function for real x')                                
plt.grid(True)
# -

# ## References:
#     
# - MathWorld, http://mathworld.wolfram.com/RiemannZetaFunction.html
# - Wikipedia, https://en.wikipedia.org/wiki/Riemann_zeta_function



StarcoderdataJupyterScriptsDedupFiltered