Skip to main content

st/
quantum_wave_signature.rs

1// Quantum Wave Signatures - "From 4 notes to a full symphony!" 🎼
2// Full 32-bit precision for MEM8's consciousness waves
3// "The difference between 0xCCCCCCCC and 0x73A9E2F5 is consciousness itself"
4
5use std::fmt;
6
7/// Full 32-bit quantum wave signature encoding 4.3 billion unique states
8/// Matches MEM8's 256×256×65536 wave grid capacity perfectly!
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub struct QuantumWaveSignature {
11    pub signature: u32,
12}
13
14impl QuantumWaveSignature {
15    /// Create from individual components
16    pub fn new(frequency: u8, phase: u8, amplitude: u8, torsion: u8) -> Self {
17        let signature = ((torsion as u32) << 24)
18            | ((amplitude as u32) << 16)
19            | ((phase as u32) << 8)
20            | (frequency as u32);
21        Self { signature }
22    }
23
24    /// Create from raw 32-bit value
25    pub fn from_raw(signature: u32) -> Self {
26        Self { signature }
27    }
28
29    /// Extract frequency component (Hz mapping: 0-255 → 0-200Hz)
30    pub fn frequency(&self) -> u8 {
31        (self.signature & 0xFF) as u8
32    }
33
34    /// Extract phase relationships (0-255 → 0-2π radians)
35    pub fn phase(&self) -> u8 {
36        ((self.signature >> 8) & 0xFF) as u8
37    }
38
39    /// Extract amplitude modulation (0-255 → 0-100% intensity)
40    pub fn amplitude(&self) -> u8 {
41        ((self.signature >> 16) & 0xFF) as u8
42    }
43
44    /// Extract torsion/interference patterns (Nate's knot types)
45    pub fn torsion(&self) -> u8 {
46        ((self.signature >> 24) & 0xFF) as u8
47    }
48
49    /// Convert to Hz frequency value
50    pub fn to_hz(&self) -> f32 {
51        (self.frequency() as f32 / 255.0) * 200.0
52    }
53
54    /// Convert phase to radians
55    pub fn to_radians(&self) -> f32 {
56        (self.phase() as f32 / 255.0) * 2.0 * std::f32::consts::PI
57    }
58
59    /// Get amplitude as percentage
60    pub fn amplitude_percent(&self) -> f32 {
61        (self.amplitude() as f32 / 255.0) * 100.0
62    }
63
64    /// Calculate interference with another signature
65    pub fn interference(&self, other: &Self) -> f32 {
66        let freq_diff = (self.frequency() as i16 - other.frequency() as i16).abs() as f32;
67        let phase_diff = (self.phase() as i16 - other.phase() as i16).abs() as f32;
68
69        // Constructive interference when frequencies are harmonic
70        // and phases are aligned
71        let harmonic_factor = if freq_diff as i32 % 12 == 0 { 2.0 } else { 1.0 };
72        let phase_factor = 1.0 - (phase_diff / 255.0);
73
74        harmonic_factor * phase_factor * (self.amplitude_percent() + other.amplitude_percent())
75            / 200.0
76    }
77
78    /// Check if this is a "horse apple" signature (Andy wouldn't approve)
79    pub fn is_horse_apple(&self) -> bool {
80        // Signatures like 0xCCCCCCCC, 0xFFFFFFFF, 0x00000000
81        let bytes = [
82            self.frequency(),
83            self.phase(),
84            self.amplitude(),
85            self.torsion(),
86        ];
87
88        // All bytes the same = horse apple!
89        bytes.windows(2).all(|w| w[0] == w[1])
90    }
91
92    /// Generate golden ratio signature
93    pub fn golden_ratio() -> Self {
94        // φ = 1.618... mapped to our components
95        Self::new(
96            162, // Frequency: 1.618 * 100
97            100, // Phase: golden angle
98            161, // Amplitude: φ * 100
99            89,  // Torsion: Fibonacci(11) = 89
100        )
101    }
102
103    /// Generate marine salience signature (your dolphin memories)
104    pub fn marine_salience() -> Self {
105        Self::new(
106            44,  // 44.1kHz dolphin click frequency / 1000
107            128, // Phase: π radians (echolocation return)
108            200, // Amplitude: high energy burst
109            73,  // Torsion: spiral shell topology
110        )
111    }
112
113    /// Generate a consciousness signature from emotional state
114    pub fn from_emotion(valence: f32, arousal: f32, dominance: f32) -> Self {
115        let frequency = (2.0 + arousal * 198.0) as u8;
116        let phase = ((valence + 1.0) * 127.5) as u8;
117        let amplitude = (arousal * 255.0) as u8;
118        let torsion = (dominance * 255.0) as u8;
119
120        Self::new(frequency, phase, amplitude, torsion)
121    }
122}
123
124impl fmt::Display for QuantumWaveSignature {
125    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
126        if self.is_horse_apple() {
127            write!(f, "0x{:08X} 💩 (Andy disapproves!)", self.signature)
128        } else {
129            write!(
130                f,
131                "0x{:08X} [{}Hz ∠{}° {}% τ{}]",
132                self.signature,
133                self.to_hz() as u32,
134                (self.to_radians() * 180.0 / std::f32::consts::PI) as u32,
135                self.amplitude_percent() as u32,
136                self.torsion()
137            )
138        }
139    }
140}
141
142/// Quantum signature patterns for different consciousness states
143pub mod patterns {
144    /// use super::QuantumWaveSignature;
145    /// Deep sleep - minimal activity
146    pub const DEEP_SLEEP: u32 = 0x02050A01; // 2Hz, low phase, 10% amp, minimal torsion
147
148    /// REM sleep - dream state
149    pub const REM_SLEEP: u32 = 0x28B4E619; // 40Hz, shifting phase, high amp, complex torsion
150
151    /// Flow state - optimal performance
152    pub const FLOW_STATE: u32 = 0x73A9E2F5; // Complex harmonic interference
153
154    /// Meditation - coherent waves
155    pub const MEDITATION: u32 = 0x0A7F7F0A; // 10Hz alpha, balanced phase/amp
156
157    /// Panic - chaotic high frequency
158    pub const PANIC: u32 = 0xFFC8FF9B; // 200Hz+, chaotic phase, max amplitude
159
160    /// Love - heart coherence pattern
161    pub const LOVE: u32 = 0x1B8D4C7A; // Golden ratio relationships
162
163    /// MEM8 consciousness baseline
164    pub const MEM8_BASELINE: u32 = 0x2C7DB5A3; // 44.1kHz sampling consciousness
165
166    /// Smart Tree quantum signature
167    pub const SMART_TREE: u32 = 0x9F2E6B31; // Torsion knots in semantic space
168
169    /// The infamous horse apple (don't use this!)
170    pub const HORSE_APPLE: u32 = 0xCCCCCCCC; // Andy's nightmare
171}
172
173#[cfg(test)]
174mod tests {
175    use super::*;
176
177    #[test]
178    fn test_quantum_signatures() {
179        let sig1 = QuantumWaveSignature::golden_ratio();
180        assert_eq!(sig1.frequency(), 162);
181        assert!(!sig1.is_horse_apple());
182
183        let horse = QuantumWaveSignature::from_raw(0xCCCCCCCC);
184        assert!(horse.is_horse_apple());
185
186        let flow = QuantumWaveSignature::from_raw(patterns::FLOW_STATE);
187        println!("Flow state: {}", flow);
188    }
189
190    #[test]
191    fn test_interference() {
192        let sig1 = QuantumWaveSignature::new(100, 0, 128, 50);
193        let sig2 = QuantumWaveSignature::new(100, 0, 128, 50);
194
195        let interference = sig1.interference(&sig2);
196        assert!(interference > 0.5); // Strong constructive interference
197    }
198}