Skip to main content

deep_causality_multivector/alias/
alias_real.rs

1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5use crate::{Metric, RealMultiVector};
6
7// Generic Algebras
8impl RealMultiVector {
9    /// Cl(N, 0): Generic N-dimensional Euclidean algebra.
10    /// All basis vectors square to +1.
11    pub fn new_euclidean(data: Vec<f64>, dim: usize) -> Self {
12        Self::new(data, Metric::Euclidean(dim)).unwrap()
13    }
14}
15
16// Division Algebras (Standard Math)
17impl RealMultiVector {
18    /// Cl(0, 1): Isomorphic to Complex Numbers C
19    /// Basis: {1, e1} where e1^2 = -1 (acts as i)
20    pub fn new_complex_number(real: f64, imag: f64) -> Self {
21        let data = vec![real, imag];
22        Self::new(data, Metric::NonEuclidean(1)).unwrap()
23    }
24
25    /// Cl(1, 0): Isomorphic to Split-Complex (Hyperbolic) Numbers
26    /// Basis: {1, e1} where e1^2 = +1 (acts as j)
27    pub fn new_split_complex(a: f64, b: f64) -> Self {
28        let data = vec![a, b];
29        Self::new(data, Metric::Euclidean(1)).unwrap()
30    }
31
32    /// Cl(0, 2): Isomorphic to Quaternions H
33    /// Basis: {1, e1, e2, e12}. e1^2 = e2^2 = -1.
34    pub fn new_quaternion(w: f64, x: f64, y: f64, z: f64) -> Self {
35        let data = vec![w, x, y, z];
36        Self::new(data, Metric::NonEuclidean(2)).unwrap()
37    }
38
39    /// Cl(2, 0): Isomorphic to Split-Quaternions (Coquaternions) or M(2,R)
40    /// Basis: {1, e1, e2, e12} where e1^2 = 1, e2^2 = 1.
41    ///
42    /// This algebra is often used in representing 2D isometries.
43    pub fn new_split_quaternion(a: f64, b: f64, c: f64, d: f64) -> Self {
44        let data = vec![a, b, c, d];
45        // 2 dimensions, 4 coefficients for scalar, v1, v2, bivector
46        Self::new(data, Metric::Euclidean(2)).unwrap()
47    }
48}
49
50// The Physics Algebras (Spacetime)
51
52impl RealMultiVector {
53    /// Cl(3, 0): Algebra of Physical Space (APS) / Pauli Algebra
54    /// Used for non-relativistic quantum mechanics (Pauli Matrices).
55    pub fn new_aps_vector(data: Vec<f64>) -> Self {
56        // Dimension 3, Euclidean Metric (+ + +)
57        Self::new(data, Metric::Euclidean(3)).unwrap()
58    }
59
60    /// Cl(1, 3): Space-Time Algebra (STA) / Dirac Algebra
61    /// Physics Convention: Time-like vector is positive. Metric: (+ - - -)
62    /// This is a specialized case of Metric::Generic { p: 1, q: 3, r: 0 }.
63    pub fn new_spacetime_algebra_1_3(data: Vec<f64>) -> Self {
64        // Dimension 4, Minkowski Metric (+ - - -)
65        Self::new(data, Metric::Minkowski(4)).unwrap()
66    }
67
68    /// Cl(3, 1): Spacetime Algebra (STA) / Dirac Algebra
69    /// Mathematics/GR Convention: Space-like vectors are positive. Metric: (- + + +)
70    /// This is a specialized case of Metric::Generic { p: 3, q: 1, r: 0 }.
71    pub fn new_spacetime_algebra_3_1(data: Vec<f64>) -> Self {
72        // The Minkowski definition is a special case that handles this:
73        // We will use Custom for clarity since Minkowski is hardcoded to (+---).
74
75        // Custom Metric: 4 dimensions. e0^2=-1, e1^2=+1, e2^2=+1, e3^2=+1.
76        // neg_mask: bit 0 (e0) = 1.
77        Self::new(
78            data,
79            Metric::Custom {
80                dim: 4,
81                neg_mask: 1,
82                zero_mask: 0,
83            },
84        )
85        .unwrap()
86    }
87
88    /// Cl(4, 1): Conformal Geometric Algebra (CGA)
89    /// Used for computer graphics and advanced robotics.
90    /// 5 Dimensions. Metric (+ + + + -).
91    ///
92    /// Basis: e1, e2, e3, e+ (e4), e- (e5).
93    /// e5^2 = -1.
94    pub fn new_cga_vector(data: Vec<f64>) -> Self {
95        // Metric (+ + + + -) = Generic { p: 4, q: 1, r: 0 }
96        Self::new(data, Metric::Generic { p: 4, q: 1, r: 0 }).unwrap()
97    }
98}