Skip to content

Commit c50ad14

Browse files
authored
binder-lubon.ipynb
1 parent e8e7f8c commit c50ad14

1 file changed

Lines changed: 300 additions & 0 deletions

File tree

binder-lubon.ipynb

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"!pip install numpy==1.26.4 matplotlib==3.9.2 mpmath==1.3.0 scipy==1.14.1 plotly==5.24.1 sympy==1.13.3"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"import numpy as np\n",
19+
"import plotly.graph_objects as go\n",
20+
"from mpmath import mp, chi\n",
21+
"from sympy import zeta as sympy_zeta\n",
22+
"from functools import lru_cache\n",
23+
"from scipy.interpolate import interp1d\n",
24+
"\n",
25+
"# Настройки mpmath\n",
26+
"mp.dps = 30\n",
27+
"\n",
28+
"# Параметры\n",
29+
"T = 50\n",
30+
"t = np.linspace(-T, T, 300)\n",
31+
"gamma_n = [14.1347, 21.0220, 25.0108]\n",
32+
"k = 1.0\n",
33+
"epsilon = 1e-8\n",
34+
"omega = 1e12\n",
35+
"hbar = 6.582e-16\n",
36+
"dt_avg = 2 * T / len(t)\n",
37+
"\n",
38+
"# Кэширование zeta и chi\n",
39+
"@lru_cache(maxsize=1000)\n",
40+
"def cached_zeta(s_real, s_imag):\n",
41+
" try:\n",
42+
" return complex(sympy_zeta(complex(s_real, s_imag)))\n",
43+
" except:\n",
44+
" return 0.0\n",
45+
"\n",
46+
"@lru_cache(maxsize=1000)\n",
47+
"def cached_chi(s_real, s_imag):\n",
48+
" try:\n",
49+
" return complex(chi(complex(s_real, s_imag)))\n",
50+
" except:\n",
51+
" return 0.0\n",
52+
"\n",
53+
"# Модуль |zeta(1/2 + it)|^2\n",
54+
"def zeta_squared(u):\n",
55+
" z = cached_zeta(0.5, u)\n",
56+
" result = z * z.conjugate()\n",
57+
" return float(result.real) if not np.isnan(result) and not np.isinf(result) else 0.0\n",
58+
"\n",
59+
"# Функция psi\n",
60+
"def psi(s, u, epsilon):\n",
61+
" denom = (s - 0.5 - 1j*u)**2 * (1 - s - 0.5 - 1j*u)**2 + epsilon**2\n",
62+
" result = 1 / denom\n",
63+
" zeta_s = cached_zeta(s.real, s.imag)\n",
64+
" chi_s = cached_chi(s.real, s.imag)\n",
65+
" chi_zeta = abs(chi_s * zeta_s)**2\n",
66+
" if chi_zeta > 1e10:\n",
67+
" chi_zeta = 1e10\n",
68+
" result *= chi_zeta\n",
69+
" return result if not np.isnan(result) and not np.isinf(result) else 0.0\n",
70+
"\n",
71+
"# Вычисление ядра K_sym\n",
72+
"def compute_kernel(epsilon):\n",
73+
" N = len(t)\n",
74+
" K = np.zeros((N, N), dtype=complex)\n",
75+
" for i in range(N):\n",
76+
" for j in range(N):\n",
77+
" s = 0.5 + 1j * t[i]\n",
78+
" u = t[j]\n",
79+
" psi_val = psi(s, u, epsilon)\n",
80+
" zeta_val = zeta_squared(u)\n",
81+
" K[i, j] = psi_val * zeta_val\n",
82+
" K = (K + K.conj().T) / 2\n",
83+
" return K\n",
84+
"\n",
85+
"# Потенциал\n",
86+
"V_eff = -k * np.array([zeta_squared(ti) for ti in t])\n",
87+
"\n",
88+
"# Вычисление собственных функций\n",
89+
"K_sym = compute_kernel(epsilon) * dt_avg\n",
90+
"eigvals, eigvecs = np.linalg.eigh(K_sym)\n",
91+
"idx = np.argsort(eigvals)[::-1]\n",
92+
"eigvals = eigvals[idx]\n",
93+
"eigvecs = eigvecs[:, idx]\n",
94+
"\n",
95+
"# Выбор трёх собственных функций\n",
96+
"selected_indices = [np.argmin(np.abs(eigvals - gamma)) for gamma in gamma_n]\n",
97+
"fn_data = [np.abs(eigvecs[:, idx])**2 for idx in selected_indices]\n",
98+
"\n",
99+
"# Интерполяция\n",
100+
"fn_interps = [interp1d(t, fn, kind='cubic') for fn in fn_data]\n",
101+
"\n",
102+
"# Плотности вероятности с фазой\n",
103+
"psi_data = []\n",
104+
"for i, gamma in enumerate(gamma_n):\n",
105+
" frames = []\n",
106+
" for time in np.linspace(0, 1e-12, 20):\n",
107+
" phase = omega * gamma * time\n",
108+
" psi = fn_interps[i](t) * np.exp(1j * phase)\n",
109+
" psi_squared = np.abs(psi)**2\n",
110+
" frames.append(psi_squared)\n",
111+
" psi_data.append(frames)\n",
112+
"\n",
113+
"# Описание в виде цитаты\n",
114+
"print(\"\"\"\n",
115+
"> * Любо́н (Lub): Описание и цвета графика *\n",
116+
"> ----------------------------------------\n",
117+
"> @ Тип: Скалярный бозон (спин-0)\n",
118+
"> # Масса: ~10^-3 эВ/c^2 (легче нейтрино)\n",
119+
"> ~ Энергия: E_n = ℏωγ_n, где γ_n — нули ζ(1/2 + iγ_n)\n",
120+
"> & Природа: Резонанс квантовой системы с хаотической динамикой\n",
121+
"> = Связь: Дзета-функция Римана ζ(s)\n",
122+
"> ? Где искать: Квантовые точки, фотонные кристаллы, космос\n",
123+
"> % Тёмная материя?: Возможный кандидат\n",
124+
"> $ Статистика: GUE (хаотический спектр)\n",
125+
"> ! Значение: Мост между математикой и физикой\n",
126+
">\n",
127+
"> + Цвета линий на графике:\n",
128+
"> - # Синий: |lub_1(t)|^2 (γ_1 = 14.1347)\n",
129+
"> - # Зелёный: |lub_2(t)|^2 (γ_2 = 21.0220)\n",
130+
"> - # Фиолетовый: |lub_3(t)|^2 (γ_3 = 25.0108)\n",
131+
"> - # Красный (пунктир): Потенциал V_eff(t) = -|ζ(1/2 + it)|^2\n",
132+
"> - # Полупрозрачная красная поверхность: Потенциал V_eff(t)\n",
133+
"> ----------------------------------------\n",
134+
"\"\"\")\n",
135+
"\n",
136+
"# Создание графика\n",
137+
"fig = go.Figure()\n",
138+
"\n",
139+
"# Волновые функции\n",
140+
"colors = ['blue', 'green', 'purple']\n",
141+
"for i, gamma in enumerate(gamma_n):\n",
142+
" fig.add_trace(go.Scatter3d(\n",
143+
" x=t,\n",
144+
" y=psi_data[i][0],\n",
145+
" z=V_eff,\n",
146+
" mode='lines',\n",
147+
" line=dict(width=5, color=colors[i]),\n",
148+
" name=f'|lub_{i+1}(t)|^2 (γ_{i+1} = {gamma})',\n",
149+
" visible=(i == 0)\n",
150+
" ))\n",
151+
"\n",
152+
"# Потенциал\n",
153+
"fig.add_trace(go.Scatter3d(\n",
154+
" x=t,\n",
155+
" y=np.zeros_like(t),\n",
156+
" z=V_eff,\n",
157+
" mode='lines',\n",
158+
" line=dict(width=4, color='red', dash='dash'),\n",
159+
" name='V_eff(t)'\n",
160+
"))\n",
161+
"\n",
162+
"# Поверхностный график\n",
163+
"X, Y = np.meshgrid(t, np.linspace(0, max(psi_data[0][0]) * 1.1, 20))\n",
164+
"Z = np.tile(V_eff, (20, 1))\n",
165+
"fig.add_trace(go.Surface(\n",
166+
" x=X,\n",
167+
" y=Y,\n",
168+
" z=Z,\n",
169+
" opacity=0.3,\n",
170+
" colorscale='Reds',\n",
171+
" showscale=False,\n",
172+
" name='Потенциал (поверхность)'\n",
173+
"))\n",
174+
"\n",
175+
"# Аннотации\n",
176+
"for gamma in gamma_n:\n",
177+
" fig.add_trace(go.Scatter3d(\n",
178+
" x=[gamma],\n",
179+
" y=[max(psi_data[0][0]) * 0.5],\n",
180+
" z=[min(V_eff)],\n",
181+
" mode='text',\n",
182+
" text=[f'γ_{gamma}'],\n",
183+
" textposition='top center',\n",
184+
" showlegend=False\n",
185+
" ))\n",
186+
"\n",
187+
"# Анимация\n",
188+
"frames = []\n",
189+
"for f in range(20):\n",
190+
" frame_data = []\n",
191+
" for i, gamma in enumerate(gamma_n):\n",
192+
" frame_data.append(go.Scatter3d(\n",
193+
" x=t,\n",
194+
" y=psi_data[i][f],\n",
195+
" z=V_eff,\n",
196+
" mode='lines',\n",
197+
" line=dict(width=5, color=colors[i]),\n",
198+
" name=f'|lub_{i+1}(t)|^2',\n",
199+
" visible=(i == 0)\n",
200+
" ))\n",
201+
" frame_data.append(fig.data[len(gamma_n)])\n",
202+
" frame_data.append(fig.data[len(gamma_n) + 1])\n",
203+
" for j in range(len(gamma_n)):\n",
204+
" frame_data.append(fig.data[len(gamma_n) + 2 + j])\n",
205+
" frames.append(go.Frame(data=frame_data, name=f'frame{f}'))\n",
206+
"\n",
207+
"fig.frames = frames\n",
208+
"\n",
209+
"# Слайдеры\n",
210+
"sliders = [\n",
211+
" dict(\n",
212+
" steps=[\n",
213+
" dict(\n",
214+
" method='update',\n",
215+
" args=[{'visible': [k == i for k in range(len(gamma_n))] + [True, True] + [True]*len(gamma_n)},\n",
216+
" {'title': f'Любо́н: |lub_{i+1}(t)|^2 (γ_{i+1} = {gamma_n[i]})'}],\n",
217+
" label=f'γ_{i+1}'\n",
218+
" ) for i in range(len(gamma_n))\n",
219+
" ],\n",
220+
" active=0,\n",
221+
" currentvalue={'prefix': 'Выбор нуля: '},\n",
222+
" pad={'t': 50}\n",
223+
" )\n",
224+
"]\n",
225+
"\n",
226+
"# Кнопки анимации\n",
227+
"fig.update_layout(\n",
228+
" updatemenus=[\n",
229+
" dict(\n",
230+
" type='buttons',\n",
231+
" showactive=True,\n",
232+
" buttons=[\n",
233+
" dict(\n",
234+
" label='Играть',\n",
235+
" method='animate',\n",
236+
" args=[None, {'frame': {'duration': 50, 'redraw': True}, 'fromcurrent': True}]\n",
237+
" ),\n",
238+
" dict(\n",
239+
" label='Пауза',\n",
240+
" method='animate',\n",
241+
" args=[[None], {'frame': {'duration': 0, 'redraw': False}, 'mode': 'immediate'}]\n",
242+
" )\n",
243+
" ],\n",
244+
" pad={'r': 10, 't': 10}\n",
245+
" )\n",
246+
" ],\n",
247+
" sliders=sliders,\n",
248+
" title='Анимированная 3D-визуализация Любо́на (Lub)',\n",
249+
" scene=dict(\n",
250+
" xaxis_title='t',\n",
251+
" yaxis_title='|lub(t)|^2',\n",
252+
" zaxis_title='V_eff(t)',\n",
253+
" xaxis=dict(range=[-T, T]),\n",
254+
" yaxis=dict(range=[0, max(psi_data[0][0]) * 1.1]),\n",
255+
" zaxis=dict(range=[min(V_eff) * 1.1, max(V_eff) * 1.1])\n",
256+
" ),\n",
257+
" showlegend=True,\n",
258+
" width=800,\n",
259+
" height=600,\n",
260+
" margin=dict(l=0, r=0, t=50, b=50),\n",
261+
" scene_aspectmode='manual',\n",
262+
" scene_aspectratio=dict(x=1, y=1, z=0.5),\n",
263+
" template='plotly_white',\n",
264+
" paper_bgcolor='rgba(0,0,0,0)',\n",
265+
" plot_bgcolor='rgba(0,0,0,0)',\n",
266+
" autosize=False,\n",
267+
" scene_camera=dict(eye=dict(x=1.5, y=1.5, z=0.8))\n",
268+
")\n",
269+
"\n",
270+
"# Показать график\n",
271+
"fig.show()\n",
272+
"\n",
273+
"# Экспорт в HTML\n",
274+
"fig.write_html(\"lubon_visualization.html\")\n",
275+
"print(\"* График сохранён как lubon_visualization.html\")"
276+
]
277+
}
278+
],
279+
"metadata": {
280+
"kernelspec": {
281+
"display_name": "Python 3",
282+
"language": "python",
283+
"name": "python3"
284+
},
285+
"language_info": {
286+
"codemirror_mode": {
287+
"name": "ipython",
288+
"version": 3
289+
},
290+
"file_extension": ".py",
291+
"mimetype": "text/x-python",
292+
"name": "python",
293+
"nbconvert_exporter": "python",
294+
"pygments_lexer": "ipython3",
295+
"version": "3.11.0"
296+
}
297+
},
298+
"nbformat": 4,
299+
"nbformat_minor": 4
300+
}

0 commit comments

Comments
 (0)