This repository was archived by the owner on Feb 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssz_core.py
More file actions
430 lines (341 loc) · 12.8 KB
/
ssz_core.py
File metadata and controls
430 lines (341 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SSZ Core Calculations Module
Segmented Spacetime Unified Calculations
© 2025 Carmen Wrede & Lino Casu
"""
import numpy as np
from typing import Tuple, Dict, Any, Optional
from dataclasses import dataclass
# Physical Constants
G = 6.67430e-11 # Gravitational constant [m³/(kg·s²)]
c = 299792458.0 # Speed of light [m/s]
M_SUN = 1.98847e30 # Solar mass [kg]
PHI = (1 + np.sqrt(5)) / 2 # Golden ratio ≈ 1.618034
H_PLANCK = 6.62607015e-34 # Planck constant [J·s]
K_B = 1.380649e-23 # Boltzmann constant [J/K]
@dataclass
class SSZResult:
"""Container for SSZ calculation results"""
name: str
value: float
unit: str
formula: str
description: str
# =============================================================================
# SCHWARZSCHILD CALCULATIONS
# =============================================================================
def schwarzschild_radius(M: float) -> float:
"""
Calculate Schwarzschild radius.
r_s = 2GM/c²
Args:
M: Mass in kg
Returns:
Schwarzschild radius in meters
"""
return 2 * G * M / (c * c)
def schwarzschild_radius_solar(M_solar: float) -> float:
"""Schwarzschild radius for mass in solar masses"""
return schwarzschild_radius(M_solar * M_SUN)
# =============================================================================
# SEGMENT DENSITY Xi(r)
# =============================================================================
def xi_weak_field(r: float, r_s: float) -> float:
"""
Weak field segment density.
Ξ(r) = r_s / (2r) for r >> r_s
"""
return r_s / (2 * r)
def xi_strong_field(r: float, r_s: float, xi_max: float = 1.0) -> float:
"""
Strong field segment density (exponential model).
Ξ(r) = ξ_max × (1 - exp(-φ × r/r_s))
"""
return xi_max * (1 - np.exp(-PHI * r / r_s))
def xi_blended(r: float, r_s: float, xi_max: float = 1.0,
r_weak: float = 110, r_strong: float = 90) -> float:
"""
Blended Xi with smooth transition between weak and strong field.
Uses Hermite C² interpolation in blend zone.
"""
ratio = r / r_s
if ratio > r_weak:
return xi_weak_field(r, r_s)
elif ratio < r_strong:
return xi_strong_field(r, r_s, xi_max)
else:
# Hermite blend
t = (ratio - r_strong) / (r_weak - r_strong)
h = 3*t*t - 2*t*t*t # Smooth step
xi_w = xi_weak_field(r, r_s)
xi_s = xi_strong_field(r, r_s, xi_max)
return xi_s * (1 - h) + xi_w * h
# =============================================================================
# TIME DILATION
# =============================================================================
def time_dilation_gr(r: float, r_s: float) -> float:
"""
GR time dilation factor.
D_GR = √(1 - r_s/r)
"""
if r <= r_s:
return 0.0
return np.sqrt(1 - r_s / r)
def time_dilation_ssz(r: float, r_s: float, xi_max: float = 1.0) -> float:
"""
SSZ time dilation factor.
D_SSZ = 1 / (1 + Ξ)
"""
xi = xi_strong_field(r, r_s, xi_max)
return 1.0 / (1.0 + xi)
# =============================================================================
# REDSHIFT
# =============================================================================
def redshift_from_dilation(D: float) -> float:
"""
Redshift from time dilation factor.
z = 1/D - 1
"""
if D <= 0:
return np.inf
return 1.0 / D - 1.0
def redshift_gr(r: float, r_s: float) -> float:
"""GR gravitational redshift"""
D = time_dilation_gr(r, r_s)
return redshift_from_dilation(D)
def redshift_ssz(r: float, r_s: float, xi_max: float = 1.0) -> float:
"""SSZ gravitational redshift"""
D = time_dilation_ssz(r, r_s, xi_max)
return redshift_from_dilation(D)
# =============================================================================
# LORENTZ FACTOR (Special Relativity)
# =============================================================================
def lorentz_factor(v: float) -> float:
"""
Lorentz factor γ.
γ = 1 / √(1 - v²/c²)
"""
beta = v / c
if beta >= 1:
return np.inf
return 1.0 / np.sqrt(1 - beta * beta)
def lorentz_factor_beta(beta: float) -> float:
"""Lorentz factor from velocity ratio β = v/c"""
if beta >= 1:
return np.inf
return 1.0 / np.sqrt(1 - beta * beta)
# =============================================================================
# ENERGY CALCULATIONS
# =============================================================================
def rest_energy(m: float) -> float:
"""Rest energy E = mc²"""
return m * c * c
def observed_energy_gr(m: float, M: float, r: float, v: float) -> float:
"""
GR observed energy.
E_obs = E_rest × γ_SR × γ_GR
"""
r_s = schwarzschild_radius(M)
E_rest = rest_energy(m)
gamma_sr = lorentz_factor(v)
gamma_gr = 1.0 / time_dilation_gr(r, r_s) if time_dilation_gr(r, r_s) > 0 else np.inf
return E_rest * gamma_sr * gamma_gr
def observed_energy_ssz(m: float, M: float, r: float, v: float, xi_max: float = 1.0) -> float:
"""
SSZ observed energy.
E_obs = E_rest × γ_SR × γ_GR × F(Ξ)
where F(Ξ) = 1/(1+Ξ)
"""
r_s = schwarzschild_radius(M)
E_rest = rest_energy(m)
gamma_sr = lorentz_factor(v)
gamma_gr = 1.0 / time_dilation_gr(r, r_s) if time_dilation_gr(r, r_s) > 0 else np.inf
xi = xi_strong_field(r, r_s, xi_max)
F = 1.0 / (1.0 + xi)
return E_rest * gamma_sr * gamma_gr * F
# =============================================================================
# PPN PARAMETERS
# =============================================================================
def ppn_metric_A(U: float, eps3: float = -24.0/5.0) -> float:
"""
PPN metric component A(U).
A(U) = 1 - 2U + 2U² + ε₃U³
"""
return 1.0 - 2.0*U + 2.0*(U*U) + eps3*(U**3)
def ppn_potential_U(r: float, M: float) -> float:
"""Newtonian potential U = GM/(rc²)"""
return G * M / (r * c * c)
# =============================================================================
# SHAPIRO DELAY
# =============================================================================
def shapiro_delay_gr(M: float, r_E: float, r_R: float, b: float) -> float:
"""
GR Shapiro time delay.
Δt = (2GM/c³) × ln(4·r_E·r_R/b²)
"""
if b <= 0:
return np.nan
return (2 * G * M / (c**3)) * np.log((4.0 * r_E * r_R) / (b * b))
def shapiro_delay_ssz(M: float, r_E: float, r_R: float, b: float,
xi_max: float = 1.0, N: int = 10000) -> float:
"""
SSZ Shapiro delay via path integral.
Uses effective refractive index n(r) = 1/D(r)
"""
r_s = schwarzschild_radius(M)
x_max = max(r_E, r_R)
x = np.linspace(-x_max, x_max, N)
r = np.sqrt(x*x + b*b)
D = np.array([time_dilation_ssz(ri, r_s, xi_max) for ri in r])
D = np.clip(D, 1e-15, None)
n_eff = 1.0 / D
return np.trapz(n_eff - 1.0, x) / c
# =============================================================================
# UNIVERSAL INTERSECTION POINT
# =============================================================================
def find_intersection(r_s: float = 1.0, xi_max: float = 1.0,
tol: float = 1e-10) -> Dict[str, float]:
"""
Find r* where D_SSZ = D_GR.
Returns dict with r*/r_s, D*, Ξ*
"""
from scipy.optimize import brentq
def diff(r):
return time_dilation_ssz(r, r_s, xi_max) - time_dilation_gr(r, r_s)
try:
r_star = brentq(diff, r_s * 1.01, r_s * 2.0, xtol=tol)
D_star = time_dilation_ssz(r_star, r_s, xi_max)
xi_star = xi_strong_field(r_star, r_s, xi_max)
return {
'r_star': r_star,
'r_over_rs': r_star / r_s,
'D_star': D_star,
'xi_star': xi_star
}
except:
return {'r_star': np.nan, 'r_over_rs': np.nan, 'D_star': np.nan, 'xi_star': np.nan}
# =============================================================================
# POWER LAW
# =============================================================================
def energy_power_law(r_s_over_R: float, A: float = 0.3187, alpha: float = 0.9821) -> float:
"""
Universal power law for energy ratio.
E/E_rest = 1 + A × (r_s/R)^α
"""
return 1.0 + A * (r_s_over_R ** alpha)
# =============================================================================
# Q-FACTOR AND VELOCITY PROPAGATION
# =============================================================================
def q_factor(T_curr: float, T_prev: float, beta: float = 1.0,
n_curr: float = 1.0, n_prev: float = 1.0, eta: float = 0.0) -> float:
"""
Segment Q-factor.
q_k = (T_curr/T_prev)^β × (n_curr/n_prev)^η
"""
return (T_curr / T_prev)**beta * (n_curr / n_prev)**eta
def velocity_propagation(v_prev: float, q: float, alpha: float = 1.0) -> float:
"""
Velocity propagation through segments.
v_k = v_{k-1} × q^(-α/2)
"""
return v_prev * (q ** (-alpha / 2))
def cumulative_gamma(q_series: np.ndarray) -> np.ndarray:
"""Cumulative gamma from Q-factors: γ = ∏ q_k"""
return np.cumprod(q_series)
# =============================================================================
# FREQUENCY SHIFT
# =============================================================================
def frequency_shift(nu_in: float, gamma: float) -> float:
"""
Frequency shift through segment field.
ν_out = ν_in × γ^(-0.5)
"""
return nu_in * (gamma ** (-0.5))
# =============================================================================
# ROTATION CURVE
# =============================================================================
def rotation_modifier(gamma: float, p: float = 0.5) -> float:
"""
Rotation curve velocity modifier.
v_mod = γ^(-p)
"""
return gamma ** (-p)
# =============================================================================
# GRAVITATIONAL LENSING
# =============================================================================
def deflection_angle_gr(M: float, b: float) -> float:
"""
GR light deflection angle.
α = 4GM/(bc²) = 2r_s/b
"""
r_s = schwarzschild_radius(M)
return 2 * r_s / b
def deflection_angle_ppn(M: float, b: float, gamma_ppn: float = 1.0) -> float:
"""
PPN light deflection angle.
α = (1+γ) × 2GM/(bc²) = (1+γ) × r_s/b
"""
r_s = schwarzschild_radius(M)
return (1 + gamma_ppn) * r_s / b
# =============================================================================
# COMPARISON METRICS
# =============================================================================
def rmse(predicted: np.ndarray, observed: np.ndarray) -> float:
"""Root Mean Square Error"""
return np.sqrt(np.mean((predicted - observed) ** 2))
def mae(predicted: np.ndarray, observed: np.ndarray) -> float:
"""Mean Absolute Error"""
return np.mean(np.abs(predicted - observed))
def relative_error(predicted: float, observed: float) -> float:
"""Relative error in percent"""
if observed == 0:
return np.inf
return abs(predicted - observed) / abs(observed) * 100
# =============================================================================
# BATCH CALCULATIONS
# =============================================================================
def calculate_all(M: float, r: float, v: float = 0.0,
m_test: float = 1.0, xi_max: float = 1.0) -> Dict[str, Any]:
"""
Calculate all SSZ quantities for given parameters.
Args:
M: Central mass [kg]
r: Distance [m]
v: Velocity [m/s]
m_test: Test particle mass [kg]
xi_max: Maximum segment density
Returns:
Dictionary with all calculated quantities
"""
r_s = schwarzschild_radius(M)
results = {
# Basic parameters
'M': M,
'M_solar': M / M_SUN,
'r': r,
'r_s': r_s,
'r_over_rs': r / r_s,
# Segment density
'xi_weak': xi_weak_field(r, r_s),
'xi_strong': xi_strong_field(r, r_s, xi_max),
# Time dilation
'D_gr': time_dilation_gr(r, r_s),
'D_ssz': time_dilation_ssz(r, r_s, xi_max),
# Redshift
'z_gr': redshift_gr(r, r_s),
'z_ssz': redshift_ssz(r, r_s, xi_max),
# Special relativity
'gamma_sr': lorentz_factor(v) if v > 0 else 1.0,
# Energy
'E_rest': rest_energy(m_test),
'E_gr': observed_energy_gr(m_test, M, r, v),
'E_ssz': observed_energy_ssz(m_test, M, r, v, xi_max),
# PPN
'U': ppn_potential_U(r, M),
'A_U': ppn_metric_A(ppn_potential_U(r, M)),
# Intersection
**find_intersection(r_s, xi_max),
}
return results