#
# PYTHON • MyCompiler
#
# betadirichlet & zetahurwitz
# https://[Log in to view URL]
# Beta de Dirichlet & Zeta de Hurwitz
#
# 2026 Outubro Ter, 20
# 2026 Novembro Seg, 9
#
# by
# j
#
import matplotlib.pyplot as plt
import numpy as np
from numpy import pi
from numpy import angle
from numpy import sin
from numpy import cos
from scipy.special import gamma
from scipy.integrate import quad
import colorsys
import warnings
#
# W A R N I N G
#
# Para obter gráficos de melhor qualidade
# é necessário configurar a variável
# MAXRESOLUTION para valores tal qual
# 256 ou 512; no entanto haverá a
# necessidade de mudar a ambiência de
# execução deste código python para
# evitar o estouro de tempo.
#
# To obtain higher-quality graphics,
# you need to set the MAXRESOLUTION
# variable to values such as 256 or
# 512; however, you will need to
# change the execution environment
# of this Python code to avoid a
# timeout.
#
warnings.filterwarnings("ignore")
MAXRESOLUTION = 20
#
# Hurwitz Reflexão
# Re(s) < 0
#
def hurwitzreflex(s,a):
max = 1000
f = 2*gamma(1-s)/( (2*pi)**(1-s))
sn = sin(pi*s/2)
cs = cos(pi*s/2)
s1 = 0
s2 = 0
for n in range(1,max+1):
s1 += cos(2*pi*n*a)/n**(1-s)
s2 += sin(2*pi*n*a)/n**(1-s)
hrw = f*(sn*s1 + cs*s2)
return hrw
#
# Hurwitz Hermite
# 0 < Re(s) < 1
#
def hrw(x, s, a):
#
# Proteção para evitar divisão
# por zero se x for exatamente 0
#
if x == 0:
hrwtz = 0.0 + 0.0j
else:
num = np.sin(s * np.arctan(x / a))
exp_term = np.exp(2 * np.pi * x)
den = ((x**2 + a**2)**(s / 2)) * (exp_term - 1)
hrwtz = num / den
return hrwtz
def hurwitzhermite(s, a):
#
# Calcula a função zeta de Hurwitz
# para s complexo com limite
# controlado.
#
s = complex(s)
f = 1 / (2 * (a**s))
g = (a**(1 - s)) / (s - 1)
integrand_real = lambda x: np.real(hrw(x, s, a))
integrand_imag = lambda x: np.imag(hrw(x, s, a))
#
# Substituímos np.inf por 30.
# O erro residual após x=30 é menor que 10^(-80).
# Aumentamos o limite de subdivisões (limit=200)
# para melhorar a precisão com s complexo.
#
limite_inf = 30
res_real, _ = quad(integrand_real, 0, limite_inf, limit=200)
res_imag, _ = quad(integrand_imag, 0, limite_inf, limit=200)
integral_res = res_real + 1j * res_imag
hrwtz = f + g + 2 * integral_res
return hrwtz
#
# Hurwitz Clássico
# Re(s) > 1
#
def hurwitz(s,a):
max = 1000
sum = 0
for k in range(0,max+1):
sum += 1 / (k + a)**s
return sum
#
# Cálculo da Função Zeta De Hurwitz
# Em Todo O Plano Complexo
#
def hurwitzfull(s,a):
t = s.real
if (t < 0):
z = hurwitzreflex(s,a)
else:
if (t<1):
z = hurwitzhermite(s, a)
else:
if t != 1:
z = hurwitz(s,a)
else:
z = hurwitz(s+0.001,a)
return z
#
# Cálculo da Função Beta Dirichlet
# Via A Função Zeta De Hurwitz
#
def betadirichlethurwitz(s):
s = complex(s)
z1 = hurwitzfull(s, 0.25)
z2 = hurwitzfull(s, 0.75)
beta = (4**(-s)) * (z1 - z2)
return beta
#
# Análise Numérica de Alguns Resultados
#
def analisys():
print("... Zeta de Hurwitz ...")
print("")
s_complex = 2 + 0j
print(f"... ζ({s_complex},¼) ...")
print("8G+π² =",hurwitzhermite(s_complex, 0.25))
print("")
s_complex = 3 + 0j
print(f"... ζ({s_complex},¼) ...")
print("28ζ(3)+π³ =",hurwitzhermite(s_complex, 0.25))
print("")
s_complex = 0.75 + 0j
print(f"... ζ({s_complex},¼) ...")
print(hurwitzhermite(s_complex, 0.25))
print("")
s_complex = 0.99 + 10j
print(f"... ζ({s_complex},¼) ...")
print(hurwitzhermite(s_complex, 0.25))
print("")
print("... Beta de Dirichlet ...")
print("")
print("... β(1) ... ")
print("¼π ≈",betadirichlethurwitz(1))
print("")
print("... β(2) ... ")
print("G ≈",betadirichlethurwitz(2))
print("")
print(f"... β{s_complex} ...")
print(" =",betadirichlethurwitz(s_complex))
#
# Ajuste String
#
def ajstring(num,tam):
space = " "
alpha = f"{num:,.3f}"
cp = tam - len(alpha)
spc = space[:cp]
new = spc + alpha
return new
#
# Tabela Hurwitz
#
def tablehurwitz(g):
val = [ -4, 0.5, 4 ]
print("Beta Dirichlet × Hurwitz")
print("")
print("s 4s ζ(s,¼) ζ(s,¾) β(s)")
print("--------------------------------------")
for s in val:
f = 4**(-s)
z1 = hurwitzfull(s,1/4)
z2 = hurwitzfull(s,3/4)
beta = betadirichlethurwitz(s)
sa = ajstring(s,6)
fa = ajstring(f,7)
da = ajstring(z1.real,7)
db = ajstring(z2.real,6)
bt = ajstring(beta.real,5)
match g:
case 1:
print(f"{s:,.3f}&{f:,.3f}&{z1.real:,.3f}&{z2.real:,.3f}&{beta.real:,.3f}")
case 2:
print(f"{sa} {fa} {da} {db} {bt}")
print("--------------------------------------")
#
# Gera o Gráfico Real Das 2 Funções
#
def graphreal(f,xmin,xmax,n):
a = 1
plt.style.use('dark_background')
plt.figure(figsize=(6,6))
x = []
y = []
delta = (xmax - xmin)/n
t = xmin
while (t < xmax):
match f:
case 1:
z = hurwitzfull(t,a)
tit = "Hurwitz Zeta Function ζ(x,1)"
case 2:
z = betadirichlethurwitz(t)
tit = "Dirichlet Beta Function β(x)"
if t!= 1:
x.append(t)
y.append(z)
t += delta
plt.plot(x,y,'-')
# plt.axis('equal')
plt.title(tit)
match f:
case 1:
plt.scatter(-19,26.46,color="red")
plt.text(-19+0.5,26.46+0.1,"$ζ(-19)≈26.46$")
plt.scatter(-18,0,color="red")
plt.text(-18+0.5,0+1.5,"$ζ(-18)=0$")
case 2:
plt.scatter(2,0.91,color="red")
plt.text(2-0.1,0.91+0.35,"$β(2)=G$")
plt.scatter(1,0.785,color="red")
plt.text(1-1.0,0.785+0.35,"$β(1)=¼π$")
plt.scatter(-2,-0.5,color="red")
plt.text(-2-1,-0.5-0.40,"$β(-2)=-½$")
plt.scatter(-4,2.5,color="red")
plt.text(-4+0.25,2.5+0,"$β(-4)=2.5$")
# plt.legend()
# plt.xticks([])
# plt.yticks([])
# plt.xlim([-2, 4])
# plt.ylim([-30, +30])
plt.xlabel("x")
plt.ylabel("y")
plt.grid(False)
plt.show()
#
# Gera o Gráfico da Linha Crítica
#
def graphcritica(xmin,xmax,n):
print("Complex Roots of the Dirichlet Beta Function")
print("on the Critical Line z = 1/2 + it")
print("")
plt.style.use('dark_background')
plt.figure(figsize=(6,6))
x = []
y = []
delta = (xmax - xmin)/n
t = xmin
k = 1
while (t < xmax):
s = complex(1/2,t)
b = betadirichlethurwitz(s)
m = ((b.real)**2 + (b.imag)**2)**(1/2)
if (m < 0.06):
print(f"{k}⁰ :: z ≈ ½ + {t:,.1f}i")
k += 1
x.append(b.real)
y.append(b.imag)
t += delta
plt.plot(x,y,'-',color="red")
# plt.axis('equal')
plt.title("Dirichlet Beta Function | s = ½ + it")
# plt.legend()
# plt.xticks([])
# plt.yticks([])
# plt.xlim([-2, 4])
# plt.ylim([-30, +30])
plt.xlabel("Re(s)")
plt.ylabel("Im(s)")
plt.grid(False)
plt.show()
#
# Gera o gráfico complexo das 2 funções
#
def graphcomplex(g,xMIN,yMIN,xMAX,yMAX):
#
# Parametrizações
#
plt.style.use('dark_background')
xRESOLUTION = MAXRESOLUTION
yRESOLUTION = MAXRESOLUTION
H = np.zeros((xRESOLUTION, yRESOLUTION))
S = np.zeros((xRESOLUTION, yRESOLUTION))
L = np.zeros((xRESOLUTION, yRESOLUTION))
RGB = np.zeros((xRESOLUTION, yRESOLUTION, 3))
#
# Preparação
#
deltaX = (xMAX - xMIN) / xRESOLUTION
deltaY = (yMAX - yMIN) / yRESOLUTION
#
# Varredura Principal
#
for idx in range(xRESOLUTION):
x = xMIN + idx * deltaX
for idy in range(yRESOLUTION):
y = yMIN + idy * deltaY
#
# Cálculo da Função
#
try:
match g:
#
# Zeta de Hurwitz
#
case 1:
s = complex(hurwitzfull(complex(x, y),1/3))
plt.title("Hurwitz Zeta Function $ζ(s,1/3)$")
#
# Beta de Dirichlet
#
case 2:
s = complex(betadirichlethurwitz(complex(x, y)))
plt.title("Dirichet Beta Function $β(s)$")
except:
s = 0j
#
# Cálculo parâmetros cores HLS
#
H[idx, idy] = (angle(s) + pi) / (2 * pi)
L[idx, idy] = 1.0 - 1.0 / (1.0 + abs(s)**0.5)
S[idx, idy] = 1.0
#
# Converte cada pixel individualmente
# de HLS para RGB
# usando a biblioteca colorsys
#
for i in range(xRESOLUTION):
for j in range(yRESOLUTION):
RGB[i, j] = colorsys.hls_to_rgb(H[i, j], L[i, j], S[i, j])
#
# Gera o gráfico
#
plt.imshow(RGB.swapaxes(0, 1), extent=[xMIN, xMAX, yMIN, yMAX], origin='lower')
plt.xlabel("Re(s)")
plt.ylabel("Im(s)")
plt.axis('on')
plt.show()
#
# Menu Geral
#
def menu(opt,g):
match opt:
#
# Análises
#
case 0:
analisys()
#
# Tabela Hurwitz
#
case 1:
tablehurwitz(g)
#
# Gráficos Reais
#
case 2:
if (g == 1):
graphreal(1,-20.1,3,220)
if (g == 2):
graphreal(2,-5.2,+5,45)
#
# Gráfico Linha Crítica
case 3:
graphcritica(0,30,400)
#
# Gráficos Complexos
#
case 4:
if (g==1):
graphcomplex(1,-10,-10,+10,+10)
if (g==2):
graphcomplex(2,-4,-4,+4,+4)
menu(2,1)
To embed this project on your website, copy the following code and paste it into your website's HTML: