Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
lorentz_transform.cpp
Go to the documentation of this file.
1/// @file src/lorentz/lorentz_transform.cpp
2/// @brief Lorentz Transform Engine — AGT-01 implementation.
3
5
6#include <cmath>
7
8namespace srfm::lorentz {
9
10// ─── Validation ───────────────────────────────────────────────────────────────
11
12bool LorentzTransform::isValidBeta(double beta) noexcept {
13 // Must be finite and strictly within the safe subluminal bound.
14 return std::isfinite(beta) && std::abs(beta) < constants::BETA_MAX_SAFE;
15}
16
17// ─── Core Transforms ──────────────────────────────────────────────────────────
18
19std::optional<LorentzFactor>
21 if (!isValidBeta(beta.value)) {
22 return std::nullopt;
23 }
24
25 // γ = 1 / √(1 − β²)
26 // With BETA_MAX_SAFE = 0.9999, the denominator is ≥ √(1 − 0.9999²) ≈ 0.014
27 // — no risk of division by zero.
28 const double beta2 = beta.value * beta.value;
29 const double denom = std::sqrt(1.0 - beta2);
30
31 if (denom <= 0.0) {
32 // Should never reach here given isValidBeta, but guard defensively.
33 return std::nullopt;
34 }
35
36 return LorentzFactor{1.0 / denom};
37}
38
39std::optional<double>
41 BetaVelocity beta) noexcept {
42 // Proper time must be non-negative (signal cannot have negative age).
43 if (proper_time < 0.0) {
44 return std::nullopt;
45 }
46
47 auto g = gamma(beta);
48 if (!g) {
49 return std::nullopt;
50 }
51
52 // t_dilated = γ · τ
53 // γ ≥ 1, so dilated time is always ≥ proper time.
54 return proper_time * g->value;
55}
56
57std::optional<RelativisticSignal>
59 BetaVelocity beta,
60 double effective_mass) noexcept {
61 // Effective mass is a liquidity proxy — must be strictly positive.
62 if (!std::isfinite(effective_mass) || effective_mass <= 0.0) {
63 return std::nullopt;
64 }
65
66 auto g = gamma(beta);
67 if (!g) {
68 return std::nullopt;
69 }
70
71 // p_rel = γ · m_eff · raw_signal
72 // Newtonian limit (β → 0, γ → 1): p_rel → m_eff · raw_signal (classical).
73 const double adjusted = g->value * effective_mass * raw_signal;
74
75 return RelativisticSignal{
76 .raw_value = raw_signal,
77 .gamma = *g,
78 .adjusted_value = adjusted,
79 .time = {} // caller sets timestamp if needed
80 };
81}
82
85 BetaVelocity beta2) noexcept {
86 // Relativistic velocity addition: β₁₂ = (β₁ + β₂) / (1 + β₁β₂)
87 //
88 // Properties guaranteed by the formula:
89 // - |β₁₂| < 1 whenever |β₁| < 1 and |β₂| < 1
90 // - Commutative: β₁ ⊕ β₂ = β₂ ⊕ β₁
91 // - Identity element: β ⊕ 0 = β
92 //
93 // The denominator 1 + β₁β₂ is always > 0 when both inputs are < 1 in
94 // magnitude, so there is no risk of division by zero here.
95 const double num = beta1.value + beta2.value;
96 const double denom = 1.0 + beta1.value * beta2.value;
97 // denom > 0 when both inputs are valid (|β| < 1), but clamp the result to
98 // guard against floating-point drift accumulating over many compositions.
99 constexpr double kMaxBeta = 1.0 - 1e-9;
100 const double raw = num / denom;
101 return BetaVelocity{std::max(-kMaxBeta, std::min(kMaxBeta, raw))};
102}
103
104std::optional<double>
106 BetaVelocity beta) noexcept {
107 auto g = gamma(beta);
108 if (!g) {
109 return std::nullopt;
110 }
111
112 // Inverse dilation: τ = t / γ
113 // γ > 0 always (it's a positive real), so no division by zero.
114 return dilated_value / g->value;
115}
116
117std::optional<double>
119 BetaVelocity beta) noexcept {
120 // Proper length must be strictly positive (a zero-length interval has no
121 // physical meaning in this context).
122 if (proper_length <= 0.0) {
123 return std::nullopt;
124 }
125
126 auto g = gamma(beta);
127 if (!g) {
128 return std::nullopt;
129 }
130
131 // L = L₀ / γ
132 // γ ≥ 1, so contracted length ≤ proper length. Always positive.
133 return proper_length / g->value;
134}
135
136std::optional<double>
138 if (!isValidBeta(beta.value)) {
139 return std::nullopt;
140 }
141
142 // φ = atanh(β)
143 //
144 // atanh is defined on the open interval (−1, 1).
145 // isValidBeta ensures |β| < BETA_MAX_SAFE < 1, so this is always safe.
146 //
147 // Key property: rapidity is additive under relativistic velocity addition:
148 // φ(β₁ ⊕ β₂) = φ(β₁) + φ(β₂)
149 return std::atanh(beta.value);
150}
151
152std::optional<double>
154 double effective_mass,
155 double c_market) noexcept {
156 if (!std::isfinite(effective_mass) || effective_mass <= 0.0) {
157 return std::nullopt;
158 }
159
160 auto g = gamma(beta);
161 if (!g) {
162 return std::nullopt;
163 }
164
165 // E = γ · m_eff · c²_market
166 // Rest energy E₀ = m_eff · c²_market (at β = 0, γ = 1).
167 // Kinetic energy E_k = E − E₀ = (γ − 1) · m_eff · c²_market.
168 return g->value * effective_mass * c_market * c_market;
169}
170
171} // namespace srfm::lorentz
static std::optional< LorentzFactor > gamma(BetaVelocity beta) noexcept
static std::optional< double > inverseTransform(double dilated_value, BetaVelocity beta) noexcept
static std::optional< RelativisticSignal > applyMomentumCorrection(double raw_signal, BetaVelocity beta, double effective_mass) noexcept
static std::optional< double > dilateTime(double proper_time, BetaVelocity beta) noexcept
static std::optional< double > contractLength(double proper_length, BetaVelocity beta) noexcept
static std::optional< double > totalEnergy(BetaVelocity beta, double effective_mass, double c_market=constants::SPEED_OF_INFORMATION) noexcept
static BetaVelocity composeVelocities(BetaVelocity beta1, BetaVelocity beta2) noexcept
static bool isValidBeta(double beta) noexcept
static std::optional< double > rapidity(BetaVelocity beta) noexcept
static constexpr double BETA_MAX_SAFE
Definition constants.hpp:17
Lorentz Transform Engine — AGT-01 public header.
Lorentz factor γ = 1/√(1−β²). Always ≥ 1.0 for valid beta.
Definition types.hpp:33
A financial signal with relativistic corrections applied.
Definition types.hpp:52
double raw_value
Original signal before correction.
Definition types.hpp:53