Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
christoffel_n.hpp
Go to the documentation of this file.
1#pragma once
2/**
3 * @file christoffel_n.hpp
4 * @brief Christoffel symbol computation for an NAssetManifold.
5 *
6 * Module: include/srfm/tensor/
7 * Stage: 4 — N-Asset Manifold
8 *
9 * ## Responsibility
10 * Compute the Christoffel symbols of the second kind,
11 *
12 * Γ^λ_μν = ½ g^λσ (∂_μ g_νσ + ∂_ν g_μσ - ∂_σ g_μν)
13 *
14 * for an arbitrary NAssetManifold via central finite-differences on the
15 * metric tensor.
16 *
17 * ## Guarantees
18 * - Thread-safe: ChristoffelN is stateless beyond holding a const reference
19 * to the manifold.
20 * - All fallible operations return std::optional.
21 * - All public methods are noexcept.
22 * - For a constant metric (flat manifold) all symbols are exactly zero.
23 *
24 * ## NOT Responsible For
25 * - Second derivatives / Riemann tensor.
26 * - Geodesic integration (see geodesic_n.hpp).
27 */
28
29#include "n_asset_manifold.hpp"
30
31#include <optional>
32#include <vector>
33#include <Eigen/Dense>
34
35namespace srfm::tensor {
36
37/**
38 * @brief Computes Christoffel symbols Γ^λ_μν for an NAssetManifold.
39 *
40 * Metric derivatives are approximated by central finite differences with
41 * step size FD_STEP. For a constant metric all derivatives vanish and every
42 * Christoffel symbol is exactly zero.
43 */
45public:
46 /// Central finite-difference step size used for metric derivatives.
47 static constexpr double FD_STEP = 1e-5;
48
49 // ── Construction ─────────────────────────────────────────────────────────
50
51 /**
52 * @brief Construct from a manifold reference.
53 *
54 * The manifold must remain valid for the lifetime of this object.
55 *
56 * @param manifold The NAssetManifold providing the metric.
57 */
58 explicit ChristoffelN(const NAssetManifold& manifold) noexcept;
59
60 // ── Symbol accessors ──────────────────────────────────────────────────────
61
62 /**
63 * @brief Compute a single Christoffel symbol Γ^lambda_mu_nu at point x.
64 *
65 * Uses the formula:
66 * Γ^λ_μν = ½ g^λσ (∂_μ g_νσ + ∂_ν g_μσ - ∂_σ g_μν)
67 *
68 * Metric derivatives are approximated by central FD with step FD_STEP.
69 *
70 * @param lambda Contravariant index, in [0, dim).
71 * @param mu First covariant index, in [0, dim).
72 * @param nu Second covariant index, in [0, dim).
73 * @param x Coordinate point, must have length dim().
74 * @return Γ^lambda_mu_nu, or std::nullopt on dimension mismatch or
75 * metric inversion failure.
76 */
77 [[nodiscard]] std::optional<double>
78 symbol(int lambda, int mu, int nu,
79 const Eigen::VectorXd& x) const noexcept;
80
81 /**
82 * @brief Compute all Christoffel symbols at point x.
83 *
84 * Returns a dim() × dim() × dim() tensor stored as nested std::vector:
85 * result[lambda][mu][nu] = Γ^lambda_mu_nu
86 *
87 * @param x Coordinate point of length dim().
88 * @return Full tensor, or std::nullopt on failure.
89 */
90 [[nodiscard]] std::optional<std::vector<std::vector<std::vector<double>>>>
91 all_symbols(const Eigen::VectorXd& x) const noexcept;
92
93 /**
94 * @brief Verify that Γ^λ_μν = Γ^λ_νμ for all indices at point x.
95 *
96 * Checks the symmetry of the lower two indices, which holds for
97 * torsion-free connections.
98 *
99 * @param x Coordinate point of length dim().
100 * @param tol Tolerance for the symmetry check (default 1e-10).
101 * @return true if symmetric within tolerance, false otherwise.
102 * Returns false (not nullopt) on dimension mismatch.
103 */
104 [[nodiscard]] bool
105 verify_symmetry(const Eigen::VectorXd& x,
106 double tol = 1e-10) const noexcept;
107
108 /**
109 * @brief Return the dimension of the manifold.
110 *
111 * @return manifold_.dim().
112 */
113 [[nodiscard]] int dim() const noexcept;
114
115private:
116 // ── Internal helpers ──────────────────────────────────────────────────────
117
118 /**
119 * @brief Compute ∂_alpha g_mu_nu at x via central finite differences.
120 *
121 * ∂_α g_μν ≈ [g_μν(x + h·e_α) - g_μν(x - h·e_α)] / (2h)
122 *
123 * @param alpha Direction index for differentiation.
124 * @param mu Row index of the metric component.
125 * @param nu Column index of the metric component.
126 * @param x Base point.
127 * @return Finite-difference approximation, or std::nullopt on failure.
128 */
129 [[nodiscard]] std::optional<double>
130 metric_deriv(int alpha, int mu, int nu,
131 const Eigen::VectorXd& x) const noexcept;
132
133 /**
134 * @brief Return the inverse metric at x, computing it if needed.
135 *
136 * For a constant metric this always returns the pre-built inverse.
137 *
138 * @param x Coordinate point.
139 * @return Inverse metric matrix or std::nullopt on failure.
140 */
141 [[nodiscard]] std::optional<Eigen::MatrixXd>
142 inv_metric_at(const Eigen::VectorXd& x) const noexcept;
143
144 // ── Data members ──────────────────────────────────────────────────────────
145
146 const NAssetManifold& manifold_; ///< Reference to the underlying manifold.
147};
148
149// ── Inline trivial accessors ──────────────────────────────────────────────────
150
151inline int ChristoffelN::dim() const noexcept {
152 return manifold_.dim();
153}
154
155} // namespace srfm::tensor
Computes Christoffel symbols Γ^λ_μν for an NAssetManifold.
int dim() const noexcept
Return the dimension of the manifold.
static constexpr double FD_STEP
Central finite-difference step size used for metric derivatives.
bool verify_symmetry(const Eigen::VectorXd &x, double tol=1e-10) const noexcept
Verify that Γ^λ_μν = Γ^λ_νμ for all indices at point x.
std::optional< std::vector< std::vector< std::vector< double > > > > all_symbols(const Eigen::VectorXd &x) const noexcept
Compute all Christoffel symbols at point x.
std::optional< double > symbol(int lambda, int mu, int nu, const Eigen::VectorXd &x) const noexcept
Compute a single Christoffel symbol Γ^lambda_mu_nu at point x.
(N+1)-dimensional Lorentzian manifold for N financial assets.
int dim() const noexcept
Returns the full manifold dimension = n_assets + 1.
N-Asset Lorentzian Manifold for Special Relativistic Financial Mechanics.