coordinate-system 7.0.0__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.
@@ -0,0 +1,885 @@
1
+ """
2
+ U(3) Complex Frame and Gauge Field Unification Framework
3
+ ================================================================================
4
+
5
+ Complete implementation based on "Complex Frame and Gauge Field Unification Program"
6
+
7
+ Core Theory:
8
+ - Complex frame U(x) ∈ U(3) as unified structure of spacetime and gauge fields
9
+ - Symmetry breaking chain: SU(4) → SU(3) × SU(2) × U(1)
10
+ - Imaginary time embedding: ℝ³ × iℝ → internal rotational degrees of freedom
11
+ - Gauge field as complex frame connection: A_μ ∈ 𝔲(3)
12
+ - Three phase angles corresponding to color degrees of freedom (red, green, blue)
13
+
14
+ Author: Enhanced by AI following theoretical framework
15
+ Date: 2025-12-04
16
+ Version: 7.0.0-alpha
17
+ """
18
+
19
+ __version__ = '7.0.0-alpha'
20
+
21
+ import numpy as np
22
+ from typing import Tuple, Optional, List, Dict, Any
23
+ from dataclasses import dataclass
24
+ import warnings
25
+
26
+ # Attempt to import basic coordinate system
27
+ try:
28
+ from .coordinate_system import coord3, vec3, quat
29
+ except ImportError:
30
+ try:
31
+ from coordinate_system import coord3, vec3, quat
32
+ except ImportError:
33
+ coord3 = None
34
+ vec3 = None
35
+ quat = None
36
+
37
+ # Physical constants
38
+ HBAR = 1.0 # Reduced Planck constant (natural units)
39
+ C_SPEED = 1.0 # Speed of light (natural units)
40
+
41
+
42
+ # ============================================================
43
+ # U(3) Complex Frame Class
44
+ # ============================================================
45
+
46
+ class U3Frame:
47
+ """
48
+ U(3) Complex Frame - Complete three-dimensional unitary matrix frame
49
+
50
+ Mathematical form:
51
+ U(x) = [e₁(x), e₂(x), e₃(x)] ∈ U(3)
52
+
53
+ Each basis vector eₖ = aₖ + ibₖ ∈ ℂ³ satisfies:
54
+ ⟨eⱼ, eₖ⟩ = δⱼₖ (complex inner product)
55
+ det(U) = e^{iφ} (phase degree of freedom)
56
+
57
+ Symmetry decomposition:
58
+ U(3) ⊃ SU(3) × U(1)
59
+ SU(3) ⊃ SU(2) × U(1)
60
+
61
+ Physical interpretation:
62
+ - Real part Re(eₖ): spatial direction vectors
63
+ - Imaginary part Im(eₖ): imaginary time evolution direction
64
+ - Three phase angles (θ₁, θ₂, θ₃): color degrees of freedom (red, green, blue)
65
+ """
66
+
67
+ def __init__(self,
68
+ e1: Optional[np.ndarray] = None,
69
+ e2: Optional[np.ndarray] = None,
70
+ e3: Optional[np.ndarray] = None,
71
+ ensure_unitary: bool = True):
72
+ """
73
+ Initialize U(3) complex frame
74
+
75
+ Args:
76
+ e1, e2, e3: Three complex basis vectors, each a complex array of shape (3,)
77
+ ensure_unitary: Whether to ensure unitarity
78
+ """
79
+ if e1 is None:
80
+ # Default: identity frame
81
+ self.e1 = np.array([1.0+0j, 0.0+0j, 0.0+0j], dtype=complex)
82
+ self.e2 = np.array([0.0+0j, 1.0+0j, 0.0+0j], dtype=complex)
83
+ self.e3 = np.array([0.0+0j, 0.0+0j, 1.0+0j], dtype=complex)
84
+ else:
85
+ self.e1 = np.array(e1, dtype=complex)
86
+ self.e2 = np.array(e2, dtype=complex)
87
+ self.e3 = np.array(e3, dtype=complex)
88
+
89
+ if ensure_unitary:
90
+ self._gram_schmidt_orthonormalize()
91
+
92
+ # -------------------- Basic Properties --------------------
93
+
94
+ @property
95
+ def matrix(self) -> np.ndarray:
96
+ """
97
+ U(3) matrix representation
98
+
99
+ Returns:
100
+ 3×3 complex matrix [e₁ | e₂ | e₃]
101
+ """
102
+ return np.column_stack([self.e1, self.e2, self.e3])
103
+
104
+ @property
105
+ def determinant(self) -> complex:
106
+ """
107
+ Determinant det(U) = e^{iφ}
108
+
109
+ For U(3): |det(U)| = 1
110
+ """
111
+ return np.linalg.det(self.matrix)
112
+
113
+ @property
114
+ def global_phase(self) -> float:
115
+ """
116
+ Global phase φ = arg(det(U))
117
+
118
+ Corresponds to U(1) global gauge transformation
119
+ """
120
+ return np.angle(self.determinant)
121
+
122
+ @property
123
+ def real_part(self) -> np.ndarray:
124
+ """Real part: spatial frame"""
125
+ return np.column_stack([self.e1.real, self.e2.real, self.e3.real])
126
+
127
+ @property
128
+ def imag_part(self) -> np.ndarray:
129
+ """Imaginary part: imaginary time direction"""
130
+ return np.column_stack([self.e1.imag, self.e2.imag, self.e3.imag])
131
+
132
+ # -------------------- Symmetry Decomposition --------------------
133
+
134
+ def to_su3_u1(self) -> Tuple['SU3Component', complex]:
135
+ """
136
+ Decompose into SU(3) × U(1)
137
+
138
+ U(3) = SU(3) × U(1)
139
+ U = (det U)^{1/3} · V
140
+
141
+ where V ∈ SU(3), det(V) = 1
142
+
143
+ Returns:
144
+ (su3_component, u1_phase)
145
+ """
146
+ det_u = self.determinant
147
+ u1_phase = det_u ** (1/3) # ∛det(U)
148
+
149
+ # Normalize to SU(3)
150
+ V_matrix = self.matrix / u1_phase
151
+
152
+ return SU3Component(V_matrix), u1_phase
153
+
154
+ def color_phases(self) -> Tuple[float, float, float]:
155
+ """
156
+ Extract color phase angles (θ₁, θ₂, θ₃)
157
+
158
+ For diagonalized complex frame:
159
+ U = diag(e^{iθ₁}, e^{iθ₂}, e^{iθ₃})
160
+
161
+ Constraint: θ₁ + θ₂ + θ₃ = φ (global phase)
162
+
163
+ Returns:
164
+ (θ_red, θ_green, θ_blue)
165
+ """
166
+ # Extract phases of diagonal elements
167
+ diag = np.diag(self.matrix)
168
+ phases = np.angle(diag)
169
+
170
+ return tuple(phases)
171
+
172
+ def to_quaternion_representation(self) -> Tuple[complex, complex, complex, complex]:
173
+ """
174
+ Convert to quaternion representation (SU(2) subgroup only)
175
+
176
+ SU(2) ⊂ SU(3) corresponds to quaternion q = a + bi + cj + dk
177
+
178
+ Returns:
179
+ (q0, q1, q2, q3) quaternion components
180
+ """
181
+ # Extract upper-left 2×2 submatrix (corresponding to SU(2))
182
+ su2_block = self.matrix[:2, :2]
183
+
184
+ # SU(2) → quaternion
185
+ # U = [[a+ib, -c+id], [c+id, a-ib]]
186
+ a = su2_block[0, 0].real
187
+ b = su2_block[0, 0].imag
188
+ c = su2_block[1, 0].real
189
+ d = su2_block[1, 0].imag
190
+
191
+ # Normalize
192
+ norm = np.sqrt(a**2 + b**2 + c**2 + d**2)
193
+ if norm > 1e-10:
194
+ return (a/norm, b/norm, c/norm, d/norm)
195
+ else:
196
+ return (1.0, 0.0, 0.0, 0.0)
197
+
198
+ # -------------------- Gauge Transformations --------------------
199
+
200
+ def gauge_transform_u1(self, phi: float) -> 'U3Frame':
201
+ """
202
+ U(1) global gauge transformation
203
+
204
+ U → e^{iφ} U
205
+
206
+ Args:
207
+ phi: Gauge phase
208
+
209
+ Returns:
210
+ Transformed frame
211
+ """
212
+ factor = np.exp(1j * phi)
213
+ return U3Frame(
214
+ e1=self.e1 * factor,
215
+ e2=self.e2 * factor,
216
+ e3=self.e3 * factor,
217
+ ensure_unitary=False
218
+ )
219
+
220
+ def gauge_transform_su2(self, pauli_vector: Tuple[float, float, float]) -> 'U3Frame':
221
+ """
222
+ SU(2) gauge transformation (acting on first two basis vectors)
223
+
224
+ Corresponds to weak interaction gauge group
225
+
226
+ Args:
227
+ pauli_vector: (θ_x, θ_y, θ_z) Pauli vector parameters
228
+
229
+ Returns:
230
+ Transformed frame
231
+ """
232
+ θ_x, θ_y, θ_z = pauli_vector
233
+ θ = np.sqrt(θ_x**2 + θ_y**2 + θ_z**2)
234
+
235
+ if θ < 1e-10:
236
+ return self
237
+
238
+ # SU(2) matrix: exp(i θ·σ/2)
239
+ n = np.array([θ_x, θ_y, θ_z]) / θ
240
+ cos_half = np.cos(θ/2)
241
+ sin_half = np.sin(θ/2)
242
+
243
+ # Construct SU(2) matrix
244
+ su2_matrix = np.array([
245
+ [cos_half + 1j*n[2]*sin_half, (1j*n[0] + n[1])*sin_half],
246
+ [(1j*n[0] - n[1])*sin_half, cos_half - 1j*n[2]*sin_half]
247
+ ], dtype=complex)
248
+
249
+ # Apply to first two basis vectors
250
+ e12_block = np.column_stack([self.e1[:2], self.e2[:2]])
251
+ e12_transformed = e12_block @ su2_matrix
252
+
253
+ new_e1 = np.concatenate([e12_transformed[:, 0], [self.e1[2]]])
254
+ new_e2 = np.concatenate([e12_transformed[:, 1], [self.e2[2]]])
255
+
256
+ return U3Frame(e1=new_e1, e2=new_e2, e3=self.e3, ensure_unitary=False)
257
+
258
+ def gauge_transform_su3(self, gell_mann_params: np.ndarray) -> 'U3Frame':
259
+ """
260
+ SU(3) gauge transformation (gluon transformation)
261
+
262
+ Corresponds to strong interaction gauge group (QCD)
263
+
264
+ Args:
265
+ gell_mann_params: 8 Gell-Mann matrix parameters (θ₁, ..., θ₈)
266
+
267
+ Returns:
268
+ Transformed frame
269
+ """
270
+ if len(gell_mann_params) != 8:
271
+ raise ValueError("SU(3) requires 8 parameters (Gell-Mann matrices)")
272
+
273
+ # Construct SU(3) matrix: exp(i Σₐ θₐ λₐ/2)
274
+ su3_matrix = self._build_su3_matrix(gell_mann_params)
275
+
276
+ # Apply transformation
277
+ new_matrix = self.matrix @ su3_matrix
278
+
279
+ return U3Frame(
280
+ e1=new_matrix[:, 0],
281
+ e2=new_matrix[:, 1],
282
+ e3=new_matrix[:, 2],
283
+ ensure_unitary=False
284
+ )
285
+
286
+ # -------------------- Imaginary Time Evolution --------------------
287
+
288
+ def imaginary_time_evolution(self, tau: float, hamiltonian: Optional[np.ndarray] = None) -> 'U3Frame':
289
+ """
290
+ Imaginary time evolution operator: exp(-τĤ)
291
+
292
+ Corresponds to Wick rotation: t → -iτ
293
+
294
+ Mathematical form:
295
+ U(τ) = exp(-τĤ) U(0)
296
+
297
+ Physical meaning:
298
+ - τ > 0: Imaginary time parameter (thermodynamic β = 1/kT)
299
+ - Ĥ: Hamiltonian operator (energy operator)
300
+ - Connection to path integral: Z = Tr[exp(-βĤ)]
301
+
302
+ Args:
303
+ tau: Imaginary time parameter
304
+ hamiltonian: 3×3 Hermitian matrix (default uses standard Laplacian)
305
+
306
+ Returns:
307
+ Evolved frame
308
+ """
309
+ if hamiltonian is None:
310
+ # Default: use simple diagonal Hamiltonian
311
+ hamiltonian = np.diag([1.0, 1.0, 1.0])
312
+
313
+ # Evolution operator: exp(-τĤ)
314
+ evolution_op = scipy_expm(-tau * hamiltonian)
315
+
316
+ # Apply to frame
317
+ new_matrix = evolution_op @ self.matrix
318
+
319
+ return U3Frame(
320
+ e1=new_matrix[:, 0],
321
+ e2=new_matrix[:, 1],
322
+ e3=new_matrix[:, 2],
323
+ ensure_unitary=False
324
+ )
325
+
326
+ def wick_rotation(self, real_time: float) -> 'U3Frame':
327
+ """
328
+ Wick rotation: t → -iτ
329
+
330
+ Convert real time evolution to imaginary time evolution
331
+
332
+ Args:
333
+ real_time: Real time t
334
+
335
+ Returns:
336
+ Frame after Wick rotation (imaginary time τ = it)
337
+ """
338
+ tau = -1j * real_time
339
+ return self.imaginary_time_evolution(tau.imag)
340
+
341
+ # -------------------- Internal Methods --------------------
342
+
343
+ def _gram_schmidt_orthonormalize(self):
344
+ """Gram-Schmidt orthonormalization"""
345
+ # Normalize e1
346
+ norm1 = np.sqrt(np.vdot(self.e1, self.e1).real)
347
+ if norm1 > 1e-10:
348
+ self.e1 = self.e1 / norm1
349
+
350
+ # Orthogonalize and normalize e2
351
+ self.e2 = self.e2 - np.vdot(self.e1, self.e2) * self.e1
352
+ norm2 = np.sqrt(np.vdot(self.e2, self.e2).real)
353
+ if norm2 > 1e-10:
354
+ self.e2 = self.e2 / norm2
355
+
356
+ # Orthogonalize and normalize e3
357
+ self.e3 = self.e3 - np.vdot(self.e1, self.e3) * self.e1 - np.vdot(self.e2, self.e3) * self.e2
358
+ norm3 = np.sqrt(np.vdot(self.e3, self.e3).real)
359
+ if norm3 > 1e-10:
360
+ self.e3 = self.e3 / norm3
361
+
362
+ def _build_su3_matrix(self, params: np.ndarray) -> np.ndarray:
363
+ """Construct SU(3) matrix"""
364
+ # Gell-Mann matrices (λ₁ to λ₈)
365
+ lambda_matrices = self._gell_mann_matrices()
366
+
367
+ # Linear combination
368
+ generator = sum(params[i] * lambda_matrices[i] for i in range(8))
369
+
370
+ # Exponential map
371
+ return scipy_expm(1j * generator)
372
+
373
+ @staticmethod
374
+ def _gell_mann_matrices() -> List[np.ndarray]:
375
+ """Gell-Mann 矩阵(SU(3) 生成元)"""
376
+ λ = [
377
+ # λ₁
378
+ np.array([[0, 1, 0], [1, 0, 0], [0, 0, 0]], dtype=complex),
379
+ # λ₂
380
+ np.array([[0, -1j, 0], [1j, 0, 0], [0, 0, 0]], dtype=complex),
381
+ # λ₃
382
+ np.array([[1, 0, 0], [0, -1, 0], [0, 0, 0]], dtype=complex),
383
+ # λ₄
384
+ np.array([[0, 0, 1], [0, 0, 0], [1, 0, 0]], dtype=complex),
385
+ # λ₅
386
+ np.array([[0, 0, -1j], [0, 0, 0], [1j, 0, 0]], dtype=complex),
387
+ # λ₆
388
+ np.array([[0, 0, 0], [0, 0, 1], [0, 1, 0]], dtype=complex),
389
+ # λ₇
390
+ np.array([[0, 0, 0], [0, 0, -1j], [0, 1j, 0]], dtype=complex),
391
+ # λ₈
392
+ np.array([[1, 0, 0], [0, 1, 0], [0, 0, -2]], dtype=complex) / np.sqrt(3),
393
+ ]
394
+ return λ
395
+
396
+ # -------------------- Operator Overloading --------------------
397
+
398
+ def __mul__(self, other):
399
+ """Frame multiplication or scalar multiplication"""
400
+ if isinstance(other, (int, float, complex)):
401
+ # Scalar multiplication
402
+ return U3Frame(
403
+ e1=self.e1 * other,
404
+ e2=self.e2 * other,
405
+ e3=self.e3 * other,
406
+ ensure_unitary=False
407
+ )
408
+ elif isinstance(other, U3Frame):
409
+ # Matrix multiplication
410
+ new_matrix = self.matrix @ other.matrix
411
+ return U3Frame(
412
+ e1=new_matrix[:, 0],
413
+ e2=new_matrix[:, 1],
414
+ e3=new_matrix[:, 2],
415
+ ensure_unitary=False
416
+ )
417
+ return NotImplemented
418
+
419
+ def __repr__(self):
420
+ phases = self.color_phases()
421
+ return f"U3Frame(phases=(R:{phases[0]:.3f}, G:{phases[1]:.3f}, B:{phases[2]:.3f}), φ={self.global_phase:.3f})"
422
+
423
+
424
+ # ============================================================
425
+ # SU(3) Component Class
426
+ # ============================================================
427
+
428
+ @dataclass
429
+ class SU3Component:
430
+ """
431
+ SU(3) component (strong interaction gauge group)
432
+
433
+ Properties:
434
+ - det(V) = 1
435
+ - V† V = I
436
+ - 8 generators (Gell-Mann matrices)
437
+
438
+ Physical meaning:
439
+ - Corresponds to Quantum Chromodynamics (QCD)
440
+ - 8 gluon fields
441
+ - Color charge conservation
442
+ """
443
+ matrix: np.ndarray # 3×3 SU(3) matrix
444
+
445
+ def __post_init__(self):
446
+ """Verify SU(3) properties"""
447
+ det = np.linalg.det(self.matrix)
448
+ if not np.isclose(abs(det), 1.0, atol=1e-6):
449
+ warnings.warn(f"SU(3) matrix determinant is not 1: |det|={abs(det):.6f}")
450
+
451
+ def to_gell_mann_params(self) -> np.ndarray:
452
+ """
453
+ Decompose into Gell-Mann matrix parameters
454
+
455
+ V = exp(i Σₐ θₐ λₐ)
456
+
457
+ Returns:
458
+ 8 parameters (θ₁, ..., θ₈)
459
+ """
460
+ # Take logarithm
461
+ log_v = scipy_logm(self.matrix)
462
+
463
+ # Extract Hermitian part
464
+ log_v_herm = (log_v - log_v.T.conj()) / (2j)
465
+
466
+ # Project onto Gell-Mann matrices
467
+ lambda_matrices = U3Frame._gell_mann_matrices()
468
+ params = np.array([
469
+ np.trace(log_v_herm @ lam).real / 2
470
+ for lam in lambda_matrices
471
+ ])
472
+
473
+ return params
474
+
475
+ def color_charge(self) -> Tuple[float, float]:
476
+ """
477
+ Color charge (corresponding to two Casimir operators of SU(3))
478
+
479
+ Returns:
480
+ (C₁, C₂) - First and second Casimir invariants
481
+ """
482
+ # First Casimir: C₁ = Tr(T) (always 0 for SU(3))
483
+ C1 = np.trace(self.matrix).real
484
+
485
+ # Second Casimir: C₂ = Tr(T²)
486
+ C2 = np.trace(self.matrix @ self.matrix).real
487
+
488
+ return (C1, C2)
489
+
490
+
491
+ # ============================================================
492
+ # Gauge Field Class
493
+ # ============================================================
494
+
495
+ class GaugeConnection:
496
+ """
497
+ Gauge field connection A_μ ∈ 𝔲(3)
498
+
499
+ Mathematical form:
500
+ A_μ = A_μ^{SU(3)} + A_μ^{SU(2)} + A_μ^{U(1)}
501
+
502
+ Covariant derivative:
503
+ D_μ U = ∂_μ U + A_μ U
504
+
505
+ Field strength tensor (curvature):
506
+ F_μν = ∂_μ A_ν - ∂_ν A_μ + [A_μ, A_ν]
507
+
508
+ Physical interpretation:
509
+ - A_μ^{SU(3)}: Gluon field (8 components)
510
+ - A_μ^{SU(2)}: W/Z boson field (3 components)
511
+ - A_μ^{U(1)}: Photon field (1 component)
512
+ """
513
+
514
+ def __init__(self,
515
+ su3_component: Optional[np.ndarray] = None,
516
+ su2_component: Optional[np.ndarray] = None,
517
+ u1_component: Optional[complex] = None):
518
+ """
519
+ Initialize gauge connection
520
+
521
+ Args:
522
+ su3_component: 8×1 real array (Gell-Mann components)
523
+ su2_component: 3×1 real array (Pauli components)
524
+ u1_component: Complex number (U(1) component)
525
+ """
526
+ self.su3 = su3_component if su3_component is not None else np.zeros(8)
527
+ self.su2 = su2_component if su2_component is not None else np.zeros(3)
528
+ self.u1 = u1_component if u1_component is not None else 0.0+0j
529
+
530
+ def connection_matrix(self) -> np.ndarray:
531
+ """
532
+ Matrix representation of connection A_μ ∈ 𝔲(3)
533
+
534
+ Returns:
535
+ 3×3 anti-Hermitian matrix
536
+ """
537
+ # SU(3) part
538
+ lambda_matrices = U3Frame._gell_mann_matrices()
539
+ A_su3 = sum(self.su3[i] * lambda_matrices[i] for i in range(8))
540
+
541
+ # SU(2) part (embedded in upper-left 2×2 block)
542
+ pauli_matrices = self._pauli_matrices()
543
+ A_su2_block = sum(self.su2[i] * pauli_matrices[i] for i in range(3))
544
+ A_su2 = np.zeros((3, 3), dtype=complex)
545
+ A_su2[:2, :2] = A_su2_block
546
+
547
+ # U(1) part
548
+ A_u1 = self.u1 * np.eye(3)
549
+
550
+ return 1j * (A_su3 + A_su2 + A_u1)
551
+
552
+ def field_strength(self, other: 'GaugeConnection') -> 'FieldStrength':
553
+ """
554
+ Calculate field strength tensor F_μν = [D_μ, D_ν]
555
+
556
+ Args:
557
+ other: Connection in another direction A_ν
558
+
559
+ Returns:
560
+ FieldStrength object
561
+ """
562
+ A_mu = self.connection_matrix()
563
+ A_nu = other.connection_matrix()
564
+
565
+ # F_μν = [A_μ, A_ν] (simplified version, ignoring derivative terms)
566
+ F_matrix = A_mu @ A_nu - A_nu @ A_mu
567
+
568
+ return FieldStrength(F_matrix)
569
+
570
+ @staticmethod
571
+ def _pauli_matrices() -> List[np.ndarray]:
572
+ """Pauli 矩阵(SU(2) 生成元)"""
573
+ σ = [
574
+ np.array([[0, 1], [1, 0]], dtype=complex), # σ₁
575
+ np.array([[0, -1j], [1j, 0]], dtype=complex), # σ₂
576
+ np.array([[1, 0], [0, -1]], dtype=complex), # σ₃
577
+ ]
578
+ return σ
579
+
580
+ def __repr__(self):
581
+ return f"GaugeConnection(SU(3): {np.linalg.norm(self.su3):.3f}, SU(2): {np.linalg.norm(self.su2):.3f}, U(1): {abs(self.u1):.3f})"
582
+
583
+
584
+ @dataclass
585
+ class FieldStrength:
586
+ """
587
+ Field strength tensor F_μν (curvature of gauge field)
588
+
589
+ Physical meaning:
590
+ - Electromagnetic field: F_μν corresponds to electric and magnetic fields
591
+ - Non-Abelian gauge field: Field strength of gluons/W bosons
592
+ """
593
+ matrix: np.ndarray # 3×3 anti-Hermitian matrix
594
+
595
+ def yang_mills_action(self) -> float:
596
+ """
597
+ Yang-Mills action: S = -1/(4g²) Tr(F_μν F^μν)
598
+
599
+ Returns:
600
+ Action (real number)
601
+ """
602
+ return -0.25 * np.trace(self.matrix @ self.matrix.T.conj()).real
603
+
604
+ def topological_charge(self) -> float:
605
+ """
606
+ Topological charge: Q = (1/32π²) ∫ Tr(F ∧ F)
607
+
608
+ Returns:
609
+ Topological charge (instanton number)
610
+ """
611
+ # Simplified version: using matrix trace
612
+ return (1.0 / (32 * np.pi**2)) * np.trace(self.matrix @ self.matrix).real
613
+
614
+
615
+ # ============================================================
616
+ # Symmetry Breaking Potential
617
+ # ============================================================
618
+
619
+ class SymmetryBreakingPotential:
620
+ """
621
+ Symmetry breaking potential function
622
+
623
+ Mathematical form:
624
+ V(U) = -μ² Tr(U†U) + λ [Tr(U†U)]² + γ Tr([U†,U]²)
625
+
626
+ Minimum determines symmetry breaking pattern:
627
+ - SU(4) → SU(3) × U(1)
628
+ - SU(3) → SU(2) × U(1)
629
+
630
+ Physical analogy:
631
+ - Similar to Higgs potential
632
+ - Vacuum expectation value breaks symmetry
633
+ """
634
+
635
+ def __init__(self, mu_squared: float = -1.0, lambda_coupling: float = 0.5, gamma_coupling: float = 0.1):
636
+ """
637
+ Initialize potential parameters
638
+
639
+ Args:
640
+ mu_squared: Mass squared term (negative value triggers symmetry breaking)
641
+ lambda_coupling: Quartic coupling constant
642
+ gamma_coupling: Non-Abelian coupling constant
643
+ """
644
+ self.mu2 = mu_squared
645
+ self.lambda_ = lambda_coupling
646
+ self.gamma = gamma_coupling
647
+
648
+ def potential(self, frame: U3Frame) -> float:
649
+ """
650
+ Calculate potential V(U)
651
+
652
+ Args:
653
+ frame: U(3) frame
654
+
655
+ Returns:
656
+ Potential value
657
+ """
658
+ U = frame.matrix
659
+ U_dag = U.T.conj()
660
+
661
+ # First term: -μ² Tr(U†U)
662
+ term1 = -self.mu2 * np.trace(U_dag @ U).real
663
+
664
+ # Second term: λ [Tr(U†U)]²
665
+ tr_UdagU = np.trace(U_dag @ U)
666
+ term2 = self.lambda_ * (tr_UdagU * tr_UdagU.conj()).real
667
+
668
+ # Third term: γ Tr([U†,U]²)
669
+ commutator = U_dag @ U - U @ U_dag
670
+ term3 = self.gamma * np.trace(commutator @ commutator).real
671
+
672
+ return term1 + term2 + term3
673
+
674
+ def gradient(self, frame: U3Frame) -> np.ndarray:
675
+ """
676
+ Calculate potential gradient ∇V(U)
677
+
678
+ Used to minimize potential and find symmetry breaking vacuum
679
+
680
+ Returns:
681
+ 3×3 complex matrix gradient
682
+ """
683
+ U = frame.matrix
684
+ U_dag = U.T.conj()
685
+
686
+ # Numerical gradient (simplified implementation)
687
+ epsilon = 1e-6
688
+ grad = np.zeros((3, 3), dtype=complex)
689
+
690
+ V0 = self.potential(frame)
691
+
692
+ for i in range(3):
693
+ for j in range(3):
694
+ # Real part direction
695
+ U_perturb = U.copy()
696
+ U_perturb[i, j] += epsilon
697
+ frame_perturb = U3Frame(U_perturb[:, 0], U_perturb[:, 1], U_perturb[:, 2], ensure_unitary=False)
698
+ grad[i, j] = (self.potential(frame_perturb) - V0) / epsilon
699
+
700
+ # Imaginary part direction
701
+ U_perturb = U.copy()
702
+ U_perturb[i, j] += 1j * epsilon
703
+ frame_perturb = U3Frame(U_perturb[:, 0], U_perturb[:, 1], U_perturb[:, 2], ensure_unitary=False)
704
+ grad[i, j] += 1j * (self.potential(frame_perturb) - V0) / epsilon
705
+
706
+ return grad
707
+
708
+ def find_vacuum(self, initial_frame: Optional[U3Frame] = None,
709
+ max_iterations: int = 100, tolerance: float = 1e-6) -> U3Frame:
710
+ """
711
+ Find vacuum state (potential minimum)
712
+
713
+ Using gradient descent method
714
+
715
+ Args:
716
+ initial_frame: Initial guess
717
+ max_iterations: Maximum number of iterations
718
+ tolerance: Convergence tolerance
719
+
720
+ Returns:
721
+ Vacuum state frame
722
+ """
723
+ if initial_frame is None:
724
+ initial_frame = U3Frame() # Start from identity frame
725
+
726
+ current_frame = initial_frame
727
+ learning_rate = 0.01
728
+
729
+ for iteration in range(max_iterations):
730
+ grad = self.gradient(current_frame)
731
+ grad_norm = np.linalg.norm(grad)
732
+
733
+ if grad_norm < tolerance:
734
+ print(f"Converged at iteration {iteration}, |∇V| = {grad_norm:.2e}")
735
+ break
736
+
737
+ # Gradient descent step
738
+ U_new = current_frame.matrix - learning_rate * grad
739
+ current_frame = U3Frame(U_new[:, 0], U_new[:, 1], U_new[:, 2], ensure_unitary=True)
740
+
741
+ return current_frame
742
+
743
+
744
+ # ============================================================
745
+ # Auxiliary Functions
746
+ # ============================================================
747
+
748
+ def scipy_expm(matrix: np.ndarray) -> np.ndarray:
749
+ """Matrix exponential function (depends on scipy)"""
750
+ try:
751
+ from scipy.linalg import expm
752
+ return expm(matrix)
753
+ except ImportError:
754
+ # Simplified implementation: Taylor expansion
755
+ return _matrix_exp_taylor(matrix, order=10)
756
+
757
+ def scipy_logm(matrix: np.ndarray) -> np.ndarray:
758
+ """Matrix logarithm function (depends on scipy)"""
759
+ try:
760
+ from scipy.linalg import logm
761
+ return logm(matrix)
762
+ except ImportError:
763
+ raise NotImplementedError("Requires scipy.linalg.logm")
764
+
765
+ def _matrix_exp_taylor(A: np.ndarray, order: int = 10) -> np.ndarray:
766
+ """Calculate matrix exponential using Taylor expansion"""
767
+ result = np.eye(A.shape[0], dtype=A.dtype)
768
+ term = np.eye(A.shape[0], dtype=A.dtype)
769
+
770
+ for k in range(1, order + 1):
771
+ term = term @ A / k
772
+ result += term
773
+
774
+ return result
775
+
776
+
777
+ # ============================================================
778
+ # Exports
779
+ # ============================================================
780
+
781
+ __all__ = [
782
+ 'U3Frame',
783
+ 'SU3Component',
784
+ 'GaugeConnection',
785
+ 'FieldStrength',
786
+ 'SymmetryBreakingPotential',
787
+ 'HBAR',
788
+ 'C_SPEED',
789
+ ]
790
+
791
+
792
+ # ============================================================
793
+ # Demonstration
794
+ # ============================================================
795
+
796
+ def demonstrate():
797
+ """Demonstrate U(3) complex frame and gauge field"""
798
+ print("=" * 70)
799
+ print("U(3) Complex Frame and Gauge Field Unification Framework Demo")
800
+ print("=" * 70)
801
+
802
+ # 1. Create U(3) frame
803
+ print("\n1. Create U(3) complex frame")
804
+ frame = U3Frame()
805
+ print(f" {frame}")
806
+ print(f" det(U) = {frame.determinant:.6f}")
807
+ print(f" Global phase φ = {frame.global_phase:.4f} rad")
808
+
809
+ # 2. Color phases
810
+ print("\n2. Color phases (RGB)")
811
+ phases = frame.color_phases()
812
+ print(f" θ_R (red) = {phases[0]:.4f} rad")
813
+ print(f" θ_G (green) = {phases[1]:.4f} rad")
814
+ print(f" θ_B (blue) = {phases[2]:.4f} rad")
815
+ print(f" Constraint check: θ_R + θ_G + θ_B = {sum(phases):.4f} (should equal φ)")
816
+
817
+ # 3. Symmetry decomposition
818
+ print("\n3. U(3) → SU(3) × U(1) decomposition")
819
+ su3_comp, u1_phase = frame.to_su3_u1()
820
+ print(f" SU(3) component det = {np.linalg.det(su3_comp.matrix):.6f} (should be 1)")
821
+ print(f" U(1) phase = {u1_phase:.6f}")
822
+
823
+ # 4. Quaternion representation
824
+ print("\n4. Quaternion representation (SU(2) subgroup)")
825
+ q = frame.to_quaternion_representation()
826
+ print(f" q = ({q[0]:.4f}, {q[1]:.4f}, {q[2]:.4f}, {q[3]:.4f})")
827
+ print(f" |q| = {np.sqrt(sum(abs(x)**2 for x in q)):.6f}")
828
+
829
+ # 5. Gauge transformations
830
+ print("\n5. Gauge transformations")
831
+ # U(1) transformation
832
+ frame_u1 = frame.gauge_transform_u1(np.pi/4)
833
+ print(f" After U(1) transformation: {frame_u1}")
834
+
835
+ # SU(2) transformation
836
+ frame_su2 = frame.gauge_transform_su2((0.1, 0.2, 0.3))
837
+ print(f" After SU(2) transformation: {frame_su2}")
838
+
839
+ # 6. Gauge field connection
840
+ print("\n6. Gauge field connection")
841
+ connection = GaugeConnection(
842
+ su3_component=np.random.randn(8) * 0.1,
843
+ su2_component=np.random.randn(3) * 0.1,
844
+ u1_component=0.05+0.02j
845
+ )
846
+ print(f" {connection}")
847
+ A_matrix = connection.connection_matrix()
848
+ print(f" ||A_μ|| = {np.linalg.norm(A_matrix):.4f}")
849
+
850
+ # 7. Field strength tensor
851
+ print("\n7. Field strength tensor (curvature)")
852
+ connection2 = GaugeConnection(
853
+ su3_component=np.random.randn(8) * 0.1,
854
+ su2_component=np.random.randn(3) * 0.1,
855
+ u1_component=0.03+0.01j
856
+ )
857
+ F = connection.field_strength(connection2)
858
+ print(f" ||F_μν|| = {np.linalg.norm(F.matrix):.4f}")
859
+ print(f" Yang-Mills action S = {F.yang_mills_action():.6f}")
860
+ print(f" Topological charge Q = {F.topological_charge():.6f}")
861
+
862
+ # 8. Symmetry breaking
863
+ print("\n8. Symmetry breaking potential")
864
+ potential = SymmetryBreakingPotential(mu_squared=-1.0, lambda_coupling=0.5)
865
+ V = potential.potential(frame)
866
+ print(f" V(U) = {V:.6f}")
867
+ print(f" Finding vacuum state...")
868
+ vacuum = potential.find_vacuum(max_iterations=50)
869
+ V_vacuum = potential.potential(vacuum)
870
+ print(f" V(U_vacuum) = {V_vacuum:.6f}")
871
+ print(f" Vacuum state: {vacuum}")
872
+
873
+ print("\n" + "=" * 70)
874
+ print("Core Theory Summary:")
875
+ print(" • U(3) = [e₁, e₂, e₃] ∈ U(3) [Complete unitary frame]")
876
+ print(" • U(3) = SU(3) × U(1) [Symmetry decomposition]")
877
+ print(" • (θ_R, θ_G, θ_B) [Color phases]")
878
+ print(" • A_μ = A_μ^{SU(3)} + A_μ^{SU(2)} + A_μ^{U(1)} [Gauge connection]")
879
+ print(" • F_μν = [D_μ, D_ν] [Field strength tensor]")
880
+ print(" • V(U) minimization → Symmetry breaking pattern")
881
+ print("=" * 70)
882
+
883
+
884
+ if __name__ == "__main__":
885
+ demonstrate()