Skip to main content

qualia_core_db/sparql_library/immersive/
profile.rs

1//! QISP Tensor10D profile — the fixed ordered dimensions and their honest
2//! classification, plus inline-value validation (plan §3.5, §3.6).
3//!
4//! The Qualia profile fixes the ordered dimensions as
5//! `[q, v, w, x, y, z, t, alpha, mu, sigma]`. **Not all ten are physical
6//! dimensions.** `x, y, z` are spatial and `t` is temporal, but `q, v, w, alpha,
7//! mu, sigma` carry Qualia-specific semantics and are only meaningful under an
8//! explicit profile IRI ([`TENSOR10D_PROFILE_IRI`]) — an external system may treat
9//! the payload as an opaque asset while still reading this profile metadata.
10//!
11//! The `alpha`/`mu`/`sigma` triad is the EMF-signal payload (amplitude / modulation /
12//! spectral-signature) — the substrate is the **entire EM spectrum + amplitude,
13//! addressable over time**, not "colour or sound" (those are perceptual projections;
14//! q42-10d-tensor-standard.md §1.2–§1.3). Axis semantics here follow that standard.
15
16use super::value::QispError;
17
18/// Absolute IRI of the Qualia Tensor10D profile. Any inline Tensor10D value MUST be
19/// accompanied by this profile IRI to be interpreted (plan §3.5, §3.6).
20pub const TENSOR10D_PROFILE_IRI: &str = "https://webizen.org/immersive/0.1#Tensor10DProfile";
21
22/// How a Tensor10D dimension is classified. This governs how a dimension is
23/// interpreted and rendered; it deliberately does **not** claim all ten axes are
24/// physical (plan §3.5).
25#[repr(u8)]
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
27pub enum DimClass {
28    /// A physical spatial axis (metres in the declared coordinate frame).
29    Spatial = 0,
30    /// A physical temporal axis.
31    Temporal = 1,
32    /// A Qualia-specific epistemic quantity (belief/quality/uncertainty-like).
33    Epistemic = 2,
34    /// An EMF-signal parameter — amplitude (`alpha`), modulation/phase (`mu`), or
35    /// spectral signature (`sigma`) across the **full EM spectrum**. Human-visible
36    /// colour and audible sound are projections of these, never their range
37    /// (q42-10d-tensor-standard.md §1.2–§1.3).
38    Spectral = 3,
39    /// A categorical / discriminant label dimension.
40    Categorical = 4,
41}
42
43/// The fixed ordered Tensor10D dimensions with their classification.
44///
45/// **Canonical source of truth: `docs/manuals/standards/q42-10d-tensor-standard.md`
46/// §1.2** (Draft Standard v1.2). These are NOT provisional guesses — every axis is
47/// defined there. Order is normative: `[q, v, w, x, y, z, t, alpha, mu, sigma]`.
48///
49/// - `q`  — Quantum Context / epistemic superposition index (`q=0` collapsed ground
50///   truth; `q>0` parallel epistemic contexts). → `Epistemic`.
51/// - `v`  — Topological class; selects the volume-search metric (euclidean / cyclic /
52///   hyperbolic / boundary-clique). → `Categorical` (a discrete topology-class index).
53/// - `w`  — Manifold / domain index (biological, legal, personal, environmental,
54///   socioeconomic …). → `Categorical`.
55/// - `x`,`y`,`z` — semantic-topology spatial coordinates. → `Spatial`.
56/// - `t`  — temporal state / provenance ledger. → `Temporal`.
57/// - `alpha`,`mu`,`sigma` — the **Spectral-Logical Payload**: parameters of the EMF
58///   signal, **NOT "colour/sound"** (those are only human-perceptual PROJECTIONS —
59///   standard §1.3). `alpha` = amplitude / intensity / energy density; `mu` =
60///   modulation (phase / FM / bit-packed provenance); `sigma` = spectral signature
61///   (multi-band profile across the EM spectrum; the full SPD/STFT live in mmap
62///   sidecars, of which the visible/audible bands are one window). All three →
63///   `Spectral`. The **entire EM spectrum is addressable via `sigma` × the `t` axis.**
64pub const TENSOR10D_DIMS: [(&str, DimClass); 10] = [
65    ("q", DimClass::Epistemic),
66    ("v", DimClass::Categorical),
67    ("w", DimClass::Categorical),
68    ("x", DimClass::Spatial),
69    ("y", DimClass::Spatial),
70    ("z", DimClass::Spatial),
71    ("t", DimClass::Temporal),
72    ("alpha", DimClass::Spectral),
73    ("mu", DimClass::Spectral),
74    ("sigma", DimClass::Spectral),
75];
76
77/// Validate an inline Tensor10D value: it must be **exactly ten finite values**
78/// (plan §3.6 "exactly ten finite values plus a profile IRI"). Wrong arity or any
79/// non-finite (NaN/±Inf) component is rejected with [`QispError::ProfileMismatch`]
80/// before any native dispatch (plan §3.6 "Reject non-canonical, non-finite,
81/// mixed-profile, or ambiguous-unit values before native dispatch").
82///
83/// The caller is responsible for supplying the accompanying profile IRI; this
84/// function validates the numeric payload shape and finiteness.
85pub fn validate_inline_tensor10d(values: &[f64]) -> Result<[f64; 10], QispError> {
86    if values.len() != 10 {
87        return Err(QispError::ProfileMismatch);
88    }
89    let mut out = [0.0f64; 10];
90    for (i, &v) in values.iter().enumerate() {
91        if !v.is_finite() {
92            return Err(QispError::ProfileMismatch);
93        }
94        out[i] = v;
95    }
96    Ok(out)
97}
98
99#[cfg(test)]
100mod tests {
101    use super::*;
102
103    #[test]
104    fn dim_order_is_fixed_and_normative() {
105        let names: [&str; 10] = TENSOR10D_DIMS.map(|(n, _)| n);
106        assert_eq!(
107            names,
108            ["q", "v", "w", "x", "y", "z", "t", "alpha", "mu", "sigma"]
109        );
110    }
111
112    #[test]
113    fn physical_axes_are_classified_honestly() {
114        // x, y, z spatial; t temporal.
115        assert_eq!(TENSOR10D_DIMS[3], ("x", DimClass::Spatial));
116        assert_eq!(TENSOR10D_DIMS[4], ("y", DimClass::Spatial));
117        assert_eq!(TENSOR10D_DIMS[5], ("z", DimClass::Spatial));
118        assert_eq!(TENSOR10D_DIMS[6], ("t", DimClass::Temporal));
119        // sigma is the shared-EMF-truth spectral axis.
120        assert_eq!(TENSOR10D_DIMS[9], ("sigma", DimClass::Spectral));
121        // The Qualia-specific axes are NOT presented as physical (spatial/temporal).
122        for &(name, class) in &[
123            TENSOR10D_DIMS[0], // q
124            TENSOR10D_DIMS[1], // v
125            TENSOR10D_DIMS[2], // w
126            TENSOR10D_DIMS[7], // alpha
127            TENSOR10D_DIMS[8], // mu
128        ] {
129            assert!(
130                class != DimClass::Spatial && class != DimClass::Temporal,
131                "Qualia-specific dim {name} must not be classified physical"
132            );
133        }
134    }
135
136    #[test]
137    fn spectral_payload_triad_is_emf_signal() {
138        // alpha (amplitude), mu (modulation/phase), sigma (spectral signature) are the
139        // EMF-signal payload — ALL Spectral (q42-10d-tensor-standard.md §1.2). This locks
140        // the 2026-07-13 correction: mu was previously misclassified Epistemic.
141        assert_eq!(TENSOR10D_DIMS[7], ("alpha", DimClass::Spectral));
142        assert_eq!(TENSOR10D_DIMS[8], ("mu", DimClass::Spectral));
143        assert_eq!(TENSOR10D_DIMS[9], ("sigma", DimClass::Spectral));
144        // q is the epistemic/quantum context; the spatial/temporal axes are physical.
145        assert_eq!(TENSOR10D_DIMS[0], ("q", DimClass::Epistemic));
146    }
147
148    #[test]
149    fn profile_iri_is_the_provisional_tensor10d_iri() {
150        assert_eq!(
151            TENSOR10D_PROFILE_IRI,
152            "https://webizen.org/immersive/0.1#Tensor10DProfile"
153        );
154    }
155
156    #[test]
157    fn validate_accepts_ten_finite_values() {
158        let v = [0.0, 1.0, -2.5, 3.0, 4.0, 5.0, 6.0, 0.25, -0.75, 100.0];
159        let out = validate_inline_tensor10d(&v).unwrap();
160        assert_eq!(out, v);
161    }
162
163    #[test]
164    fn validate_rejects_wrong_arity() {
165        assert_eq!(
166            validate_inline_tensor10d(&[1.0, 2.0, 3.0]),
167            Err(QispError::ProfileMismatch)
168        );
169        let eleven = [1.0f64; 11];
170        assert_eq!(
171            validate_inline_tensor10d(&eleven),
172            Err(QispError::ProfileMismatch)
173        );
174        assert_eq!(
175            validate_inline_tensor10d(&[]),
176            Err(QispError::ProfileMismatch)
177        );
178    }
179
180    #[test]
181    fn validate_rejects_non_finite() {
182        let mut nan_v = [0.0f64; 10];
183        nan_v[4] = f64::NAN;
184        assert_eq!(
185            validate_inline_tensor10d(&nan_v),
186            Err(QispError::ProfileMismatch)
187        );
188
189        let mut inf_v = [0.0f64; 10];
190        inf_v[9] = f64::INFINITY;
191        assert_eq!(
192            validate_inline_tensor10d(&inf_v),
193            Err(QispError::ProfileMismatch)
194        );
195
196        let mut neg_inf_v = [0.0f64; 10];
197        neg_inf_v[0] = f64::NEG_INFINITY;
198        assert_eq!(
199            validate_inline_tensor10d(&neg_inf_v),
200            Err(QispError::ProfileMismatch)
201        );
202    }
203}