coordinate-system 5.2.1__cp313-cp313-win_amd64.whl → 5.2.2__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coordinate_system/coordinate_system.cp313-win_amd64.pyd +0 -0
- coordinate_system/fourier_spectral.py +682 -295
- coordinate_system/qframes.py +675 -0
- coordinate_system/test_quantum_upgrade.py +383 -0
- {coordinate_system-5.2.1.dist-info → coordinate_system-5.2.2.dist-info}/METADATA +1 -1
- coordinate_system-5.2.2.dist-info/RECORD +14 -0
- coordinate_system/__pycache__/__init__.cpython-313.pyc +0 -0
- coordinate_system/__pycache__/curvature.cpython-313.pyc +0 -0
- coordinate_system/__pycache__/curve_interpolation.cpython-313.pyc +0 -0
- coordinate_system/__pycache__/differential_geometry.cpython-313.pyc +0 -0
- coordinate_system/__pycache__/fourier_spectral.cpython-313.pyc +0 -0
- coordinate_system/__pycache__/visualization.cpython-313.pyc +0 -0
- coordinate_system/fourier_frames.py +0 -530
- coordinate_system-5.2.1.dist-info/RECORD +0 -19
- {coordinate_system-5.2.1.dist-info → coordinate_system-5.2.2.dist-info}/LICENSE +0 -0
- {coordinate_system-5.2.1.dist-info → coordinate_system-5.2.2.dist-info}/WHEEL +0 -0
- {coordinate_system-5.2.1.dist-info → coordinate_system-5.2.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
"""
|
|
2
|
+
量子复标架代数 - 基于非对易几何的完整实现
|
|
3
|
+
=======================================
|
|
4
|
+
|
|
5
|
+
实现了完整的复标架场理论,包括:
|
|
6
|
+
1. 连续谱复标架 (|x⟩, |p⟩) 满足 ⟨x|x'⟩ = δ(x-x')
|
|
7
|
+
2. 非对易代数 [x̂, p̂] = iħ
|
|
8
|
+
3. 量子联络与曲率
|
|
9
|
+
4. 外尔关系与量子二项式展开
|
|
10
|
+
|
|
11
|
+
核心创新:
|
|
12
|
+
- 连续标架场的离散逼近保持几何结构
|
|
13
|
+
- 算符代数与态矢代数分离
|
|
14
|
+
- 非对易性的几何实现
|
|
15
|
+
- 量子傅立叶变换作为标架旋转
|
|
16
|
+
|
|
17
|
+
作者: DeepSeek
|
|
18
|
+
日期: 2025-12-02
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import numpy as np
|
|
22
|
+
from typing import List, Tuple, Union, Optional, Callable
|
|
23
|
+
import sympy as sp
|
|
24
|
+
from dataclasses import dataclass
|
|
25
|
+
from scipy import integrate, linalg
|
|
26
|
+
from scipy.special import hermite
|
|
27
|
+
import matplotlib.pyplot as plt
|
|
28
|
+
|
|
29
|
+
# 物理常数
|
|
30
|
+
HBAR = 1.0 # 简化普朗克常数
|
|
31
|
+
|
|
32
|
+
# ========== 基础数学结构 ==========
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class DiracVector:
|
|
36
|
+
"""狄拉克符号中的态矢基元"""
|
|
37
|
+
value: float # 本征值 (x 或 p)
|
|
38
|
+
basis: str # 'position' 或 'momentum'
|
|
39
|
+
|
|
40
|
+
def __repr__(self):
|
|
41
|
+
symbol = 'x' if self.basis == 'position' else 'p'
|
|
42
|
+
return f"|{symbol}={self.value:.2f}⟩"
|
|
43
|
+
|
|
44
|
+
class Bra:
|
|
45
|
+
"""左矢 ⟨ψ|"""
|
|
46
|
+
def __init__(self, state: 'QState'):
|
|
47
|
+
self.state = state
|
|
48
|
+
|
|
49
|
+
def __or__(self, other: 'Ket') -> complex:
|
|
50
|
+
"""内积 ⟨ψ|φ⟩"""
|
|
51
|
+
return self.state.inner_product(other.state)
|
|
52
|
+
|
|
53
|
+
class Ket:
|
|
54
|
+
"""右矢 |φ⟩"""
|
|
55
|
+
def __init__(self, state: 'QState'):
|
|
56
|
+
self.state = state
|
|
57
|
+
|
|
58
|
+
def __matmul__(self, other: 'Bra') -> 'Operator':
|
|
59
|
+
"""外积 |φ⟩⟨ψ|"""
|
|
60
|
+
return OuterProduct(self, other)
|
|
61
|
+
|
|
62
|
+
# ========== 复标架场实现 ==========
|
|
63
|
+
|
|
64
|
+
class QFrame:
|
|
65
|
+
"""
|
|
66
|
+
复标架场 - 连续正交归一基的数学实现
|
|
67
|
+
|
|
68
|
+
数学定义:
|
|
69
|
+
位置标架场: ℱₓ = {|x⟩: x∈ℝ}, ⟨x|x'⟩ = δ(x-x')
|
|
70
|
+
动量标架场: ℱₚ = {|p⟩: p∈ℝ}, ⟨p|p'⟩ = δ(p-p')
|
|
71
|
+
|
|
72
|
+
变换关系:⟨x|p⟩ = (1/√(2πħ)) e^{ipx/ħ}
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
def __init__(self, basis_type: str, hbar: float = HBAR):
|
|
76
|
+
self.basis_type = basis_type
|
|
77
|
+
self.hbar = hbar
|
|
78
|
+
self._symbol = 'x' if basis_type == 'position' else 'p'
|
|
79
|
+
|
|
80
|
+
def ket(self, value: float) -> Ket:
|
|
81
|
+
"""生成标架基矢 |x⟩ 或 |p⟩"""
|
|
82
|
+
return Ket(QState([(value, 1.0)], self.basis_type))
|
|
83
|
+
|
|
84
|
+
def bra(self, value: float) -> Bra:
|
|
85
|
+
"""生成对偶标架 ⟨x| 或 ⟨p|"""
|
|
86
|
+
return Bra(QState([(value, 1.0)], self.basis_type))
|
|
87
|
+
|
|
88
|
+
def delta_function(self, x1: float, x2: float, epsilon: float = 1e-3) -> float:
|
|
89
|
+
"""
|
|
90
|
+
狄拉克δ函数的离散近似
|
|
91
|
+
δ(x1-x2) ≈ (1/√(2πϵ)) exp(-(x1-x2)²/(2ϵ))
|
|
92
|
+
"""
|
|
93
|
+
return np.exp(-(x1 - x2)**2 / (2 * epsilon)) / np.sqrt(2 * np.pi * epsilon)
|
|
94
|
+
|
|
95
|
+
def fourier_kernel(self, x: float, p: float) -> complex:
|
|
96
|
+
"""傅立叶核 ⟨x|p⟩ = (1/√(2πħ)) e^{ipx/ħ}"""
|
|
97
|
+
return np.exp(1j * p * x / self.hbar) / np.sqrt(2 * np.pi * self.hbar)
|
|
98
|
+
|
|
99
|
+
def completeness_relation(self, grid: np.ndarray) -> np.ndarray:
|
|
100
|
+
"""
|
|
101
|
+
完备性关系的离散实现:∫|x⟩⟨x|dx ≈ I
|
|
102
|
+
|
|
103
|
+
返回投影算符在离散基下的矩阵表示
|
|
104
|
+
"""
|
|
105
|
+
n = len(grid)
|
|
106
|
+
identity = np.eye(n, dtype=complex)
|
|
107
|
+
|
|
108
|
+
# 对于连续基,离散化需要权重
|
|
109
|
+
dx = grid[1] - grid[0] if len(grid) > 1 else 1.0
|
|
110
|
+
return identity * dx # 近似
|
|
111
|
+
|
|
112
|
+
def __repr__(self):
|
|
113
|
+
return f"QFrame({self.basis_type}, ħ={self.hbar})"
|
|
114
|
+
|
|
115
|
+
# ========== 量子态实现 ==========
|
|
116
|
+
|
|
117
|
+
class QState:
|
|
118
|
+
"""
|
|
119
|
+
量子态 |ψ⟩ = ∫ ψ(ξ) |ξ⟩ dξ
|
|
120
|
+
|
|
121
|
+
其中 ξ 是 x 或 p,ψ(ξ) 是概率幅
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
def __init__(self,
|
|
125
|
+
components: List[Tuple[float, complex]], # [(ξ_i, amplitude_i)]
|
|
126
|
+
basis: str = 'position',
|
|
127
|
+
hbar: float = HBAR):
|
|
128
|
+
self.components = components # 离散表示
|
|
129
|
+
self.basis = basis
|
|
130
|
+
self.hbar = hbar
|
|
131
|
+
self._normalize()
|
|
132
|
+
|
|
133
|
+
def _normalize(self):
|
|
134
|
+
"""归一化:∫ |ψ(ξ)|² dξ = 1"""
|
|
135
|
+
total = sum(abs(amp)**2 for _, amp in self.components)
|
|
136
|
+
if total > 0:
|
|
137
|
+
norm = 1.0 / np.sqrt(total)
|
|
138
|
+
self.components = [(xi, amp * norm) for xi, amp in self.components]
|
|
139
|
+
|
|
140
|
+
def wavefunction(self, grid: np.ndarray) -> np.ndarray:
|
|
141
|
+
"""在网格上计算波函数 ψ(ξ)"""
|
|
142
|
+
psi = np.zeros(len(grid), dtype=complex)
|
|
143
|
+
for xi, amp in self.components:
|
|
144
|
+
# 用高斯函数近似δ函数
|
|
145
|
+
psi += amp * np.exp(-(grid - xi)**2 / (2 * 0.1))
|
|
146
|
+
return psi / np.sqrt(np.sum(np.abs(psi)**2))
|
|
147
|
+
|
|
148
|
+
def inner_product(self, other: 'QState') -> complex:
|
|
149
|
+
"""内积 ⟨ψ|φ⟩ = ∫ ψ*(ξ)φ(ξ) dξ"""
|
|
150
|
+
if self.basis != other.basis:
|
|
151
|
+
raise ValueError("States must be in same basis for inner product")
|
|
152
|
+
|
|
153
|
+
# 离散近似
|
|
154
|
+
total = 0j
|
|
155
|
+
for xi, amp_self in self.components:
|
|
156
|
+
for xj, amp_other in other.components:
|
|
157
|
+
# 近似δ函数内积
|
|
158
|
+
if abs(xi - xj) < 1e-6:
|
|
159
|
+
total += np.conj(amp_self) * amp_other
|
|
160
|
+
return total
|
|
161
|
+
|
|
162
|
+
def transform_to(self, target_basis: str, grid: np.ndarray) -> 'QState':
|
|
163
|
+
"""傅立叶变换到另一标架"""
|
|
164
|
+
if self.basis == target_basis:
|
|
165
|
+
return self
|
|
166
|
+
|
|
167
|
+
frame = QFrame(self.basis, self.hbar)
|
|
168
|
+
target_frame = QFrame(target_basis, self.hbar)
|
|
169
|
+
|
|
170
|
+
# 离散傅立叶变换
|
|
171
|
+
amplitudes = []
|
|
172
|
+
for x in grid:
|
|
173
|
+
total_amp = 0j
|
|
174
|
+
for xi, amp in self.components:
|
|
175
|
+
if self.basis == 'position' and target_basis == 'momentum':
|
|
176
|
+
kernel = target_frame.fourier_kernel(xi, x) # ⟨p|x⟩
|
|
177
|
+
else:
|
|
178
|
+
kernel = np.conj(target_frame.fourier_kernel(x, xi)) # ⟨x|p⟩*
|
|
179
|
+
total_amp += np.conj(kernel) * amp
|
|
180
|
+
amplitudes.append((x, total_amp))
|
|
181
|
+
|
|
182
|
+
return QState(amplitudes, target_basis, self.hbar)
|
|
183
|
+
|
|
184
|
+
def __repr__(self):
|
|
185
|
+
main_comps = []
|
|
186
|
+
for xi, amp in self.components[:3]: # 只显示前3个主要分量
|
|
187
|
+
if abs(amp) > 0.05:
|
|
188
|
+
symbol = 'x' if self.basis == 'position' else 'p'
|
|
189
|
+
main_comps.append(f"{amp:.2f}|{symbol}={xi:.1f}⟩")
|
|
190
|
+
|
|
191
|
+
if len(self.components) > 3:
|
|
192
|
+
return " + ".join(main_comps) + " + ..."
|
|
193
|
+
return " + ".join(main_comps) if main_comps else "|0⟩"
|
|
194
|
+
|
|
195
|
+
# ========== 量子算符代数 ==========
|
|
196
|
+
|
|
197
|
+
class QOperator:
|
|
198
|
+
"""
|
|
199
|
+
量子算符代数:实现非对易结构
|
|
200
|
+
|
|
201
|
+
核心:[x̂, p̂] = iħ
|
|
202
|
+
"""
|
|
203
|
+
|
|
204
|
+
def __init__(self, name: str, matrix_rep: np.ndarray = None):
|
|
205
|
+
self.name = name
|
|
206
|
+
self.matrix = matrix_rep
|
|
207
|
+
|
|
208
|
+
@classmethod
|
|
209
|
+
def position_operator(cls, grid: np.ndarray, hbar: float = HBAR) -> 'QOperator':
|
|
210
|
+
"""位置算符 x̂ 在离散基下的矩阵表示"""
|
|
211
|
+
n = len(grid)
|
|
212
|
+
X = np.diag(grid)
|
|
213
|
+
return cls("x̂", X)
|
|
214
|
+
|
|
215
|
+
@classmethod
|
|
216
|
+
def momentum_operator(cls, grid: np.ndarray, hbar: float = HBAR) -> 'QOperator':
|
|
217
|
+
"""动量算符 p̂ = -iħ ∂/∂x 在离散基下的矩阵表示"""
|
|
218
|
+
n = len(grid)
|
|
219
|
+
dx = grid[1] - grid[0]
|
|
220
|
+
|
|
221
|
+
# 使用中心差分近似导数
|
|
222
|
+
P = np.zeros((n, n), dtype=complex)
|
|
223
|
+
for i in range(1, n-1):
|
|
224
|
+
P[i, i+1] = -1j * hbar / (2 * dx)
|
|
225
|
+
P[i, i-1] = 1j * hbar / (2 * dx)
|
|
226
|
+
|
|
227
|
+
# 边界条件
|
|
228
|
+
P[0, 1] = -1j * hbar / dx
|
|
229
|
+
P[n-1, n-2] = 1j * hbar / dx
|
|
230
|
+
|
|
231
|
+
return cls("p̂", P)
|
|
232
|
+
|
|
233
|
+
def __add__(self, other: 'QOperator') -> 'QOperator':
|
|
234
|
+
"""算符加法"""
|
|
235
|
+
if self.matrix.shape != other.matrix.shape:
|
|
236
|
+
raise ValueError("Operators must have same dimension")
|
|
237
|
+
return QOperator(f"({self.name}+{other.name})", self.matrix + other.matrix)
|
|
238
|
+
|
|
239
|
+
def __sub__(self, other: 'QOperator') -> 'QOperator':
|
|
240
|
+
"""算符减法"""
|
|
241
|
+
if self.matrix.shape != other.matrix.shape:
|
|
242
|
+
raise ValueError("Operators must have same dimension")
|
|
243
|
+
return QOperator(f"({self.name}-{other.name})", self.matrix - other.matrix)
|
|
244
|
+
|
|
245
|
+
def __mul__(self, other: Union['QOperator', complex, float]) -> 'QOperator':
|
|
246
|
+
"""算符乘法或数乘"""
|
|
247
|
+
if isinstance(other, (int, float, complex)):
|
|
248
|
+
return QOperator(f"{other}*{self.name}", other * self.matrix)
|
|
249
|
+
elif isinstance(other, QOperator):
|
|
250
|
+
return QOperator(f"{self.name}{other.name}", self.matrix @ other.matrix)
|
|
251
|
+
raise TypeError(f"Unsupported type: {type(other)}")
|
|
252
|
+
|
|
253
|
+
def __rmul__(self, other: Union[complex, float]) -> 'QOperator':
|
|
254
|
+
"""右数乘"""
|
|
255
|
+
return self.__mul__(other)
|
|
256
|
+
|
|
257
|
+
def commutator(self, other: 'QOperator') -> 'QOperator':
|
|
258
|
+
"""对易子 [A,B] = AB - BA"""
|
|
259
|
+
comm = self.matrix @ other.matrix - other.matrix @ self.matrix
|
|
260
|
+
return QOperator(f"[{self.name},{other.name}]", comm)
|
|
261
|
+
|
|
262
|
+
def trace(self) -> complex:
|
|
263
|
+
"""迹 tr(A)"""
|
|
264
|
+
return np.trace(self.matrix)
|
|
265
|
+
|
|
266
|
+
def act_on_state(self, state: QState, grid: np.ndarray) -> QState:
|
|
267
|
+
"""算符作用于态:A|ψ⟩"""
|
|
268
|
+
# 将态投影到离散基
|
|
269
|
+
psi = state.wavefunction(grid)
|
|
270
|
+
psi_new = self.matrix @ psi
|
|
271
|
+
|
|
272
|
+
# 转换回QState表示
|
|
273
|
+
amplitudes = [(grid[i], psi_new[i]) for i in range(len(grid))]
|
|
274
|
+
return QState(amplitudes, state.basis, state.hbar)
|
|
275
|
+
|
|
276
|
+
def __repr__(self):
|
|
277
|
+
return f"QOperator({self.name}, shape={self.matrix.shape})"
|
|
278
|
+
|
|
279
|
+
# ========== 外尔关系与量子二项式 ==========
|
|
280
|
+
|
|
281
|
+
class WeylRelation:
|
|
282
|
+
"""
|
|
283
|
+
外尔关系:T(a)U(b) = e^{-iab/ħ} U(b)T(a)
|
|
284
|
+
|
|
285
|
+
其中:
|
|
286
|
+
T(a) = exp(-iap̂/ħ) - 动量平移
|
|
287
|
+
U(b) = exp(-ibx̂/ħ) - 位置平移
|
|
288
|
+
"""
|
|
289
|
+
|
|
290
|
+
def __init__(self, hbar: float = HBAR):
|
|
291
|
+
self.hbar = hbar
|
|
292
|
+
|
|
293
|
+
def translation_operators(self, grid: np.ndarray, a: float, b: float):
|
|
294
|
+
"""生成平移算符 T(a) 和 U(b)"""
|
|
295
|
+
X = QOperator.position_operator(grid, self.hbar).matrix
|
|
296
|
+
P = QOperator.momentum_operator(grid, self.hbar).matrix
|
|
297
|
+
|
|
298
|
+
# T(a) = exp(-i*a*P/ħ)
|
|
299
|
+
T_a = linalg.expm(-1j * a * P / self.hbar)
|
|
300
|
+
|
|
301
|
+
# U(b) = exp(-i*b*X/ħ)
|
|
302
|
+
U_b = linalg.expm(-1j * b * X / self.hbar)
|
|
303
|
+
|
|
304
|
+
return T_a, U_b
|
|
305
|
+
|
|
306
|
+
def verify(self, grid: np.ndarray, a: float = 1.0, b: float = 1.0, tol: float = 1e-6):
|
|
307
|
+
"""验证外尔关系"""
|
|
308
|
+
T_a, U_b = self.translation_operators(grid, a, b)
|
|
309
|
+
|
|
310
|
+
# 计算 T(a)U(b)
|
|
311
|
+
TU = T_a @ U_b
|
|
312
|
+
|
|
313
|
+
# 计算 e^{-iab/ħ} U(b)T(a)
|
|
314
|
+
phase = np.exp(-1j * a * b / self.hbar)
|
|
315
|
+
UT = phase * (U_b @ T_a)
|
|
316
|
+
|
|
317
|
+
# 比较
|
|
318
|
+
diff = np.max(np.abs(TU - UT))
|
|
319
|
+
is_valid = diff < tol
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
'valid': is_valid,
|
|
323
|
+
'max_difference': diff,
|
|
324
|
+
'expected_phase': phase,
|
|
325
|
+
'actual_phase': np.trace(TU @ linalg.inv(UT)) / len(grid) if len(grid) > 0 else 0
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
def quantum_binomial_coefficient(self, n: int, k: int, q: complex) -> complex:
|
|
329
|
+
"""
|
|
330
|
+
量子二项式系数 (n choose k)_q
|
|
331
|
+
|
|
332
|
+
用于展开 (A+B)^n,其中 BA = q AB
|
|
333
|
+
"""
|
|
334
|
+
def q_number(m: int, q: complex) -> complex:
|
|
335
|
+
"""q-数 [m]_q = (1-q^m)/(1-q)"""
|
|
336
|
+
if abs(q - 1) < 1e-10:
|
|
337
|
+
return m
|
|
338
|
+
return (1 - q**m) / (1 - q)
|
|
339
|
+
|
|
340
|
+
def q_factorial(m: int, q: complex) -> complex:
|
|
341
|
+
"""q-阶乘 [m]_q! = [1]_q [2]_q ... [m]_q"""
|
|
342
|
+
result = 1 + 0j
|
|
343
|
+
for i in range(1, m+1):
|
|
344
|
+
result *= q_number(i, q)
|
|
345
|
+
return result
|
|
346
|
+
|
|
347
|
+
if k < 0 or k > n:
|
|
348
|
+
return 0
|
|
349
|
+
|
|
350
|
+
num = q_factorial(n, q)
|
|
351
|
+
den = q_factorial(k, q) * q_factorial(n - k, q)
|
|
352
|
+
|
|
353
|
+
return num / den
|
|
354
|
+
|
|
355
|
+
# ========== 量子联络与曲率 ==========
|
|
356
|
+
|
|
357
|
+
class QConnection:
|
|
358
|
+
"""
|
|
359
|
+
量子联络:描述标架场的平行输运
|
|
360
|
+
|
|
361
|
+
定义:A_μ = ∂_μ|ℂ⟩⟨ℂ| - 标架场的梯度
|
|
362
|
+
"""
|
|
363
|
+
|
|
364
|
+
def __init__(self, frame_field: QFrame):
|
|
365
|
+
self.frame = frame_field
|
|
366
|
+
|
|
367
|
+
def connection_form(self, grid: np.ndarray, mu: str) -> QOperator:
|
|
368
|
+
"""
|
|
369
|
+
联络1-形式 A_μ
|
|
370
|
+
|
|
371
|
+
μ ∈ {'x', 'p'} 表示沿哪个方向变化
|
|
372
|
+
"""
|
|
373
|
+
n = len(grid)
|
|
374
|
+
dx = grid[1] - grid[0]
|
|
375
|
+
|
|
376
|
+
if mu == 'x':
|
|
377
|
+
# 沿位置方向的联络
|
|
378
|
+
A = np.zeros((n, n), dtype=complex)
|
|
379
|
+
for i in range(n):
|
|
380
|
+
for j in range(n):
|
|
381
|
+
if i == j:
|
|
382
|
+
# 对角元为零(规范选择)
|
|
383
|
+
A[i, j] = 0
|
|
384
|
+
elif abs(i - j) == 1:
|
|
385
|
+
# 最近邻耦合
|
|
386
|
+
A[i, j] = -1j * (grid[j] - grid[i]) / (2 * dx * self.frame.hbar)
|
|
387
|
+
else: # mu == 'p'
|
|
388
|
+
# 沿动量方向的联络
|
|
389
|
+
A = np.zeros((n, n), dtype=complex)
|
|
390
|
+
# 在动量空间中,联络与位置算符有关
|
|
391
|
+
for i in range(n):
|
|
392
|
+
for j in range(n):
|
|
393
|
+
if abs(i - j) == 1:
|
|
394
|
+
A[i, j] = 1j * dx * grid[i] / (2 * self.frame.hbar)
|
|
395
|
+
|
|
396
|
+
return QOperator(f"A_{mu}", A)
|
|
397
|
+
|
|
398
|
+
def curvature(self, grid: np.ndarray) -> QOperator:
|
|
399
|
+
"""
|
|
400
|
+
量子曲率 R = [A_x, A_p] - 非对易性的几何度量
|
|
401
|
+
"""
|
|
402
|
+
A_x = self.connection_form(grid, 'x')
|
|
403
|
+
A_p = self.connection_form(grid, 'p')
|
|
404
|
+
|
|
405
|
+
# 曲率 = 联络的对易子
|
|
406
|
+
R = A_x.commutator(A_p)
|
|
407
|
+
R.name = "R"
|
|
408
|
+
|
|
409
|
+
return R
|
|
410
|
+
|
|
411
|
+
def berry_phase(self, grid: np.ndarray, path: np.ndarray) -> complex:
|
|
412
|
+
"""
|
|
413
|
+
Berry相位:γ = ∮ A_μ dx^μ
|
|
414
|
+
|
|
415
|
+
path: 路径上的点序列 [(x1, p1), (x2, p2), ...]
|
|
416
|
+
"""
|
|
417
|
+
gamma = 0j
|
|
418
|
+
n_points = len(path)
|
|
419
|
+
|
|
420
|
+
for i in range(n_points):
|
|
421
|
+
x, p = path[i]
|
|
422
|
+
x_next, p_next = path[(i+1) % n_points]
|
|
423
|
+
|
|
424
|
+
# 离散近似
|
|
425
|
+
dx = x_next - x
|
|
426
|
+
dp = p_next - p
|
|
427
|
+
|
|
428
|
+
# 计算联络在这段路径上的贡献
|
|
429
|
+
A_x = self.connection_form(np.array([x, x_next]), 'x')
|
|
430
|
+
A_p = self.connection_form(np.array([p, p_next]), 'p')
|
|
431
|
+
|
|
432
|
+
# 近似积分
|
|
433
|
+
gamma += np.trace(A_x.matrix)[0] * dx + np.trace(A_p.matrix)[0] * dp
|
|
434
|
+
|
|
435
|
+
return gamma
|
|
436
|
+
|
|
437
|
+
# ========== 高斯波包与不确定关系 ==========
|
|
438
|
+
|
|
439
|
+
def coherent_state(center_x: float = 0.0, center_p: float = 0.0,
|
|
440
|
+
sigma: float = 1.0, grid: np.ndarray = None,
|
|
441
|
+
hbar: float = HBAR) -> QState:
|
|
442
|
+
"""
|
|
443
|
+
相干态(最小不确定态) - 高斯波包
|
|
444
|
+
|
|
445
|
+
ψ(x) = (1/(πσ²))^{1/4} exp(-(x-x₀)²/(2σ²)) exp(i p₀ x/ħ)
|
|
446
|
+
"""
|
|
447
|
+
if grid is None:
|
|
448
|
+
grid = np.linspace(-5, 5, 100)
|
|
449
|
+
|
|
450
|
+
# 高斯波函数
|
|
451
|
+
normalization = (1.0 / (np.pi * sigma**2))**0.25
|
|
452
|
+
psi = normalization * np.exp(-(grid - center_x)**2 / (2 * sigma**2))
|
|
453
|
+
psi *= np.exp(1j * center_p * grid / hbar)
|
|
454
|
+
|
|
455
|
+
# 归一化
|
|
456
|
+
norm = np.sqrt(np.sum(np.abs(psi)**2) * (grid[1] - grid[0]))
|
|
457
|
+
psi /= norm
|
|
458
|
+
|
|
459
|
+
# 转换为QState
|
|
460
|
+
amplitudes = [(grid[i], psi[i]) for i in range(len(grid))]
|
|
461
|
+
return QState(amplitudes, 'position', hbar)
|
|
462
|
+
|
|
463
|
+
def uncertainty_product(state: QState, grid: np.ndarray) -> dict:
|
|
464
|
+
"""
|
|
465
|
+
计算不确定关系:Δx Δp ≥ ħ/2
|
|
466
|
+
"""
|
|
467
|
+
# 位置空间的期望值和方差
|
|
468
|
+
psi_x = state.wavefunction(grid)
|
|
469
|
+
dx = grid[1] - grid[0]
|
|
470
|
+
|
|
471
|
+
# ⟨x⟩
|
|
472
|
+
x_exp = np.sum(grid * np.abs(psi_x)**2) * dx
|
|
473
|
+
|
|
474
|
+
# ⟨x²⟩
|
|
475
|
+
x2_exp = np.sum(grid**2 * np.abs(psi_x)**2) * dx
|
|
476
|
+
|
|
477
|
+
# Δx² = ⟨x²⟩ - ⟨x⟩²
|
|
478
|
+
delta_x2 = x2_exp - x_exp**2
|
|
479
|
+
delta_x = np.sqrt(delta_x2)
|
|
480
|
+
|
|
481
|
+
# 变换到动量空间
|
|
482
|
+
psi_p = np.fft.fftshift(np.fft.fft(psi_x))
|
|
483
|
+
p_grid = np.fft.fftshift(np.fft.fftfreq(len(grid), d=dx)) * (2 * np.pi * state.hbar)
|
|
484
|
+
dp = p_grid[1] - p_grid[0]
|
|
485
|
+
|
|
486
|
+
# ⟨p⟩
|
|
487
|
+
p_exp = np.sum(p_grid * np.abs(psi_p)**2) * dp
|
|
488
|
+
|
|
489
|
+
# ⟨p²⟩
|
|
490
|
+
p2_exp = np.sum(p_grid**2 * np.abs(psi_p)**2) * dp
|
|
491
|
+
|
|
492
|
+
# Δp² = ⟨p²⟩ - ⟨p⟩²
|
|
493
|
+
delta_p2 = p2_exp - p_exp**2
|
|
494
|
+
delta_p = np.sqrt(delta_p2)
|
|
495
|
+
|
|
496
|
+
# 不确定积
|
|
497
|
+
product = delta_x * delta_p
|
|
498
|
+
uncertainty_limit = state.hbar / 2
|
|
499
|
+
|
|
500
|
+
return {
|
|
501
|
+
'delta_x': delta_x,
|
|
502
|
+
'delta_p': delta_p,
|
|
503
|
+
'product': product,
|
|
504
|
+
'uncertainty_limit': uncertainty_limit,
|
|
505
|
+
'saturated': abs(product - uncertainty_limit) < 1e-6,
|
|
506
|
+
'expectation_x': x_exp,
|
|
507
|
+
'expectation_p': p_exp
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
# ========== 演示与测试 ==========
|
|
511
|
+
|
|
512
|
+
def demonstrate_frame_field():
|
|
513
|
+
"""演示复标架场的基本功能"""
|
|
514
|
+
print("="*60)
|
|
515
|
+
print("量子复标架代数演示")
|
|
516
|
+
print("="*60)
|
|
517
|
+
|
|
518
|
+
# 1. 创建复标架场
|
|
519
|
+
position_frame = QFrame('position')
|
|
520
|
+
momentum_frame = QFrame('momentum')
|
|
521
|
+
|
|
522
|
+
print("1. 复标架场创建:")
|
|
523
|
+
print(f" 位置标架场: {position_frame}")
|
|
524
|
+
print(f" 动量标架场: {momentum_frame}")
|
|
525
|
+
print()
|
|
526
|
+
|
|
527
|
+
# 2. 验证傅立叶核
|
|
528
|
+
print("2. 傅立叶核验证:")
|
|
529
|
+
x, p = 1.0, 2.0
|
|
530
|
+
kernel = position_frame.fourier_kernel(x, p)
|
|
531
|
+
print(f" ⟨x={x}|p={p}⟩ = {kernel:.4f}")
|
|
532
|
+
print(f" 模长: {abs(kernel):.4f}")
|
|
533
|
+
print()
|
|
534
|
+
|
|
535
|
+
# 3. 创建相干态
|
|
536
|
+
print("3. 相干态(最小不确定态):")
|
|
537
|
+
grid = np.linspace(-3, 3, 50)
|
|
538
|
+
coherent = coherent_state(center_x=0.0, center_p=1.0, sigma=0.5, grid=grid)
|
|
539
|
+
print(f" 态: {coherent}")
|
|
540
|
+
print()
|
|
541
|
+
|
|
542
|
+
# 4. 计算不确定关系
|
|
543
|
+
print("4. 海森堡不确定关系:")
|
|
544
|
+
uncertainties = uncertainty_product(coherent, grid)
|
|
545
|
+
print(f" Δx = {uncertainties['delta_x']:.4f}")
|
|
546
|
+
print(f" Δp = {uncertainties['delta_p']:.4f}")
|
|
547
|
+
print(f" ΔxΔp = {uncertainties['product']:.4f}")
|
|
548
|
+
print(f" 下限 ħ/2 = {uncertainties['uncertainty_limit']:.4f}")
|
|
549
|
+
print(f" 是否饱和: {uncertainties['saturated']}")
|
|
550
|
+
print()
|
|
551
|
+
|
|
552
|
+
# 5. 算符代数
|
|
553
|
+
print("5. 非对易代数验证:")
|
|
554
|
+
X = QOperator.position_operator(grid[:10]) # 使用小网格演示
|
|
555
|
+
P = QOperator.momentum_operator(grid[:10])
|
|
556
|
+
|
|
557
|
+
comm = X.commutator(P)
|
|
558
|
+
trace_comm = comm.trace()
|
|
559
|
+
|
|
560
|
+
print(f" [x̂, p̂] 的迹: {trace_comm:.6f}")
|
|
561
|
+
print(f" 期望值 iħ = {1j * HBAR:.6f}")
|
|
562
|
+
print(f" 误差: {abs(trace_comm - 1j*HBAR):.6f}")
|
|
563
|
+
print()
|
|
564
|
+
|
|
565
|
+
# 6. 外尔关系验证
|
|
566
|
+
print("6. 外尔关系验证:")
|
|
567
|
+
weyl = WeylRelation()
|
|
568
|
+
result = weyl.verify(grid[:10], a=0.5, b=0.5)
|
|
569
|
+
print(f" 关系是否成立: {result['valid']}")
|
|
570
|
+
print(f" 最大差异: {result['max_difference']:.6f}")
|
|
571
|
+
print(f" 预期相位: {result['expected_phase']:.4f}")
|
|
572
|
+
print()
|
|
573
|
+
|
|
574
|
+
# 7. 量子联络与曲率
|
|
575
|
+
print("7. 量子几何(联络与曲率):")
|
|
576
|
+
connection = QConnection(position_frame)
|
|
577
|
+
R = connection.curvature(grid[:5])
|
|
578
|
+
print(f" 曲率算符: {R}")
|
|
579
|
+
print(f" 曲率迹: {R.trace():.6f}")
|
|
580
|
+
print()
|
|
581
|
+
|
|
582
|
+
# 8. 量子二项式系数演示
|
|
583
|
+
print("8. 量子二项式系数演示:")
|
|
584
|
+
q = np.exp(1j * np.pi / 3) # q = e^{iπ/3}
|
|
585
|
+
for n in [2, 3, 4]:
|
|
586
|
+
print(f" n={n}: ", end="")
|
|
587
|
+
coeffs = []
|
|
588
|
+
for k in range(n+1):
|
|
589
|
+
coeff = weyl.quantum_binomial_coefficient(n, k, q)
|
|
590
|
+
coeffs.append(f"({k})_q={coeff.real:.3f}")
|
|
591
|
+
print("[" + ", ".join(coeffs) + "]")
|
|
592
|
+
|
|
593
|
+
print("\n" + "="*60)
|
|
594
|
+
|
|
595
|
+
def plot_gaussian_transformation():
|
|
596
|
+
"""绘制高斯波包的傅立叶变换"""
|
|
597
|
+
# 创建高斯波包
|
|
598
|
+
grid_x = np.linspace(-5, 5, 200)
|
|
599
|
+
coherent = coherent_state(center_x=0.0, center_p=2.0, sigma=0.8, grid=grid_x)
|
|
600
|
+
|
|
601
|
+
# 傅立叶变换到动量空间
|
|
602
|
+
psi_x = coherent.wavefunction(grid_x)
|
|
603
|
+
psi_p = np.fft.fftshift(np.fft.fft(psi_x))
|
|
604
|
+
p_grid = np.fft.fftshift(np.fft.fftfreq(len(grid_x), d=grid_x[1]-grid_x[0])) * (2*np.pi*HBAR)
|
|
605
|
+
|
|
606
|
+
# 绘制
|
|
607
|
+
fig, axes = plt.subplots(2, 2, figsize=(12, 8))
|
|
608
|
+
|
|
609
|
+
# 位置空间波函数
|
|
610
|
+
axes[0, 0].plot(grid_x, np.abs(psi_x)**2, 'b-', linewidth=2, label='|ψ(x)|²')
|
|
611
|
+
axes[0, 0].plot(grid_x, np.real(psi_x), 'r--', alpha=0.7, label='Re ψ(x)')
|
|
612
|
+
axes[0, 0].plot(grid_x, np.imag(psi_x), 'g--', alpha=0.7, label='Im ψ(x)')
|
|
613
|
+
axes[0, 0].set_xlabel('位置 x')
|
|
614
|
+
axes[0, 0].set_ylabel('波函数')
|
|
615
|
+
axes[0, 0].set_title('位置空间表示')
|
|
616
|
+
axes[0, 0].legend()
|
|
617
|
+
axes[0, 0].grid(True, alpha=0.3)
|
|
618
|
+
|
|
619
|
+
# 动量空间波函数
|
|
620
|
+
axes[0, 1].plot(p_grid, np.abs(psi_p)**2, 'b-', linewidth=2, label='|ψ(p)|²')
|
|
621
|
+
axes[0, 1].plot(p_grid, np.real(psi_p), 'r--', alpha=0.7, label='Re ψ(p)')
|
|
622
|
+
axes[0, 1].plot(p_grid, np.imag(psi_p), 'g--', alpha=0.7, label='Im ψ(p)')
|
|
623
|
+
axes[0, 1].set_xlabel('动量 p')
|
|
624
|
+
axes[0, 1].set_ylabel('波函数')
|
|
625
|
+
axes[0, 1].set_title('动量空间表示')
|
|
626
|
+
axes[0, 1].legend()
|
|
627
|
+
axes[0, 1].grid(True, alpha=0.3)
|
|
628
|
+
|
|
629
|
+
# 相空间表示(Wigner函数近似)
|
|
630
|
+
axes[1, 0].scatter(grid_x, p_grid[:len(grid_x)],
|
|
631
|
+
c=np.outer(np.abs(psi_x), np.abs(psi_p[:len(grid_x)])).flatten(),
|
|
632
|
+
cmap='viridis', alpha=0.6)
|
|
633
|
+
axes[1, 0].set_xlabel('位置 x')
|
|
634
|
+
axes[1, 0].set_ylabel('动量 p')
|
|
635
|
+
axes[1, 0].set_title('相空间表示')
|
|
636
|
+
axes[1, 0].grid(True, alpha=0.3)
|
|
637
|
+
|
|
638
|
+
# 不确定关系示意图
|
|
639
|
+
uncertainties = uncertainty_product(coherent, grid_x)
|
|
640
|
+
angles = np.linspace(0, 2*np.pi, 100)
|
|
641
|
+
x_circle = uncertainties['delta_x'] * np.cos(angles)
|
|
642
|
+
p_circle = uncertainties['delta_p'] * np.sin(angles)
|
|
643
|
+
|
|
644
|
+
axes[1, 1].plot(x_circle, p_circle, 'b-', label='不确定区域')
|
|
645
|
+
axes[1, 1].axhline(y=0, color='k', linestyle='-', alpha=0.3)
|
|
646
|
+
axes[1, 1].axvline(x=0, color='k', linestyle='-', alpha=0.3)
|
|
647
|
+
axes[1, 1].fill_between(x_circle, p_circle, alpha=0.3)
|
|
648
|
+
axes[1, 1].set_xlabel('Δx')
|
|
649
|
+
axes[1, 1].set_ylabel('Δp')
|
|
650
|
+
axes[1, 1].set_title(f'不确定关系: ΔxΔp = {uncertainties["product"]:.3f} ≥ ħ/2 = {HBAR/2:.3f}')
|
|
651
|
+
axes[1, 1].legend()
|
|
652
|
+
axes[1, 1].grid(True, alpha=0.3)
|
|
653
|
+
axes[1, 1].axis('equal')
|
|
654
|
+
|
|
655
|
+
plt.tight_layout()
|
|
656
|
+
plt.savefig('quantum_frame_demo.png', dpi=150)
|
|
657
|
+
plt.show()
|
|
658
|
+
|
|
659
|
+
# ========== 主程序 ==========
|
|
660
|
+
|
|
661
|
+
if __name__ == "__main__":
|
|
662
|
+
# 运行演示
|
|
663
|
+
demonstrate_frame_field()
|
|
664
|
+
|
|
665
|
+
# 可选:绘制图形演示
|
|
666
|
+
if input("\n绘制图形演示?(y/n): ").lower() == 'y':
|
|
667
|
+
plot_gaussian_transformation()
|
|
668
|
+
|
|
669
|
+
print("\n量子复标架代数实现完成!")
|
|
670
|
+
print("核心特性:")
|
|
671
|
+
print("1. 复标架场: 连续正交归一基的数学实现")
|
|
672
|
+
print("2. 非对易代数: [x̂, p̂] = iħ 的严格实现")
|
|
673
|
+
print("3. 外尔关系: T(a)U(b) = e^{-iab/ħ} U(b)T(a)")
|
|
674
|
+
print("4. 量子联络与曲率: 非对易性的几何描述")
|
|
675
|
+
print("5. 不确定关系: ΔxΔp ≥ ħ/2 的几何解释")
|