sublinear_solver/temporal_nexus/quantum/
validators.rs1use crate::temporal_nexus::quantum::{constants, QuantumError, QuantumResult};
23
24#[derive(Debug, Clone)]
26pub struct UncertaintyValidator {
27 hbar: f64,
29 min_consciousness_energy: f64,
31 temperature: f64,
33}
34
35impl UncertaintyValidator {
36 pub fn new() -> Self {
38 Self {
39 hbar: constants::PLANCK_HBAR,
40 min_consciousness_energy: 1e-18, temperature: constants::ROOM_TEMPERATURE_K,
42 }
43 }
44
45 pub fn with_temperature(temperature_k: f64) -> Self {
47 Self {
48 hbar: constants::PLANCK_HBAR,
49 min_consciousness_energy: 1e-18,
50 temperature: temperature_k,
51 }
52 }
53
54 pub fn minimum_uncertainty_product(&self) -> f64 {
56 self.hbar / 2.0
57 }
58
59 pub fn thermal_energy(&self) -> f64 {
61 constants::BOLTZMANN_K * self.temperature
62 }
63
64 pub fn validate_energy_time_product(
66 &self,
67 energy_j: f64,
68 time_s: f64,
69 ) -> QuantumResult<UncertaintyResult> {
70 let product = energy_j * time_s;
71 let min_product = self.minimum_uncertainty_product();
72 let is_valid = product >= min_product;
73
74 let energy_ev = energy_j / constants::EV_TO_JOULES;
76 let thermal_energy_j = self.thermal_energy();
77 let thermal_energy_ev = thermal_energy_j / constants::EV_TO_JOULES;
78
79 if !is_valid {
80 return Err(QuantumError::UncertaintyViolation {
81 product,
82 hbar_half: min_product,
83 });
84 }
85
86 Ok(UncertaintyResult {
87 is_valid,
88 energy_j,
89 energy_ev,
90 time_s,
91 uncertainty_product: product,
92 minimum_product: min_product,
93 margin: product / min_product,
94 thermal_energy_j,
95 thermal_energy_ev,
96 temperature_k: self.temperature,
97 energy_scale_classification: self.classify_energy_scale(energy_j),
98 })
99 }
100
101 pub fn classify_energy_scale(&self, energy_j: f64) -> EnergyScale {
103 let energy_ev = energy_j / constants::EV_TO_JOULES;
104 let _thermal_ev = self.thermal_energy() / constants::EV_TO_JOULES;
105
106 if energy_ev < 1e-6 {
107 EnergyScale::SubAttoElectronVolt
108 } else if energy_ev < 1e-3 {
109 EnergyScale::AttoElectronVolt
110 } else if energy_ev < 1.0 {
111 EnergyScale::MilliElectronVolt
112 } else if energy_ev < 1000.0 {
113 EnergyScale::ElectronVolt
114 } else if energy_ev < 1e6 {
115 EnergyScale::KiloElectronVolt
116 } else {
117 EnergyScale::MegaElectronVolt
118 }
119 }
120
121 pub fn calculate_required_energy(&self, time_constraint_s: f64) -> f64 {
123 self.minimum_uncertainty_product() / time_constraint_s
124 }
125
126 pub fn calculate_maximum_time(&self, energy_budget_j: f64) -> f64 {
133 if energy_budget_j <= 0.0 {
134 return 0.0;
135 }
136 self.minimum_uncertainty_product() / energy_budget_j
137 }
138
139 pub fn validate_nanosecond_consciousness(&self) -> UncertaintyResult {
141 let nanosecond = 1e-9;
142 let required_energy = self.calculate_required_energy(nanosecond);
143
144 self.validate_energy_time_product(required_energy, nanosecond)
145 .unwrap_or_else(|_| UncertaintyResult {
146 is_valid: false,
147 energy_j: required_energy,
148 energy_ev: required_energy / constants::EV_TO_JOULES,
149 time_s: nanosecond,
150 uncertainty_product: required_energy * nanosecond,
151 minimum_product: self.minimum_uncertainty_product(),
152 margin: 1.0,
153 thermal_energy_j: self.thermal_energy(),
154 thermal_energy_ev: self.thermal_energy() / constants::EV_TO_JOULES,
155 temperature_k: self.temperature,
156 energy_scale_classification: self.classify_energy_scale(required_energy),
157 })
158 }
159
160 pub fn analyze_time_scales(&self) -> UncertaintyAnalysis {
162 let scales = vec![
163 ("attosecond", 1e-18),
164 ("femtosecond", 1e-15),
165 ("picosecond", 1e-12),
166 ("nanosecond", 1e-9),
167 ("microsecond", 1e-6),
168 ("millisecond", 1e-3),
169 ];
170
171 let mut constraints = Vec::new();
172
173 for (name, time_s) in scales {
174 let required_energy_j = self.calculate_required_energy(time_s);
175 let required_energy_ev = required_energy_j / constants::EV_TO_JOULES;
176 let thermal_ratio = required_energy_j / self.thermal_energy();
177
178 constraints.push(UncertaintyConstraint {
179 scale_name: name.to_string(),
180 time_s,
181 required_energy_j,
182 required_energy_ev,
183 thermal_energy_ratio: thermal_ratio,
184 is_above_thermal: thermal_ratio > 1.0,
185 is_feasible: required_energy_ev < 1000.0, energy_scale: self.classify_energy_scale(required_energy_j),
187 });
188 }
189
190 UncertaintyAnalysis {
191 temperature_k: self.temperature,
192 thermal_energy_j: self.thermal_energy(),
193 thermal_energy_ev: self.thermal_energy() / constants::EV_TO_JOULES,
194 hbar: self.hbar,
195 minimum_product: self.minimum_uncertainty_product(),
196 constraints,
197 recommended_scale: "nanosecond".to_string(),
198 }
199 }
200}
201
202impl Default for UncertaintyValidator {
203 fn default() -> Self {
204 Self::new()
205 }
206}
207
208#[derive(Debug, Clone)]
210pub struct UncertaintyResult {
211 pub is_valid: bool,
212 pub energy_j: f64,
213 pub energy_ev: f64,
214 pub time_s: f64,
215 pub uncertainty_product: f64,
216 pub minimum_product: f64,
217 pub margin: f64,
218 pub thermal_energy_j: f64,
219 pub thermal_energy_ev: f64,
220 pub temperature_k: f64,
221 pub energy_scale_classification: EnergyScale,
222}
223
224impl UncertaintyResult {
225 pub fn summary(&self) -> String {
227 format!(
228 "Uncertainty Check: {} (ΔE·Δt = {:.2e}, min = {:.2e}, margin = {:.1}x)",
229 if self.is_valid { "PASS" } else { "FAIL" },
230 self.uncertainty_product,
231 self.minimum_product,
232 self.margin
233 )
234 }
235}
236
237#[derive(Debug, Clone, PartialEq)]
239pub enum EnergyScale {
240 SubAttoElectronVolt, AttoElectronVolt, MilliElectronVolt, ElectronVolt, KiloElectronVolt, MegaElectronVolt, }
247
248impl EnergyScale {
249 pub fn description(&self) -> &'static str {
250 match self {
251 EnergyScale::SubAttoElectronVolt => "Sub-atto-eV (quantum vacuum scale)",
252 EnergyScale::AttoElectronVolt => "Atto-eV (ultra-low energy)",
253 EnergyScale::MilliElectronVolt => "Milli-eV (molecular vibrations)",
254 EnergyScale::ElectronVolt => "eV (atomic scale)",
255 EnergyScale::KiloElectronVolt => "keV (X-ray scale)",
256 EnergyScale::MegaElectronVolt => "MeV (nuclear scale)",
257 }
258 }
259}
260
261#[derive(Debug, Clone)]
263pub struct UncertaintyAnalysis {
264 pub temperature_k: f64,
265 pub thermal_energy_j: f64,
266 pub thermal_energy_ev: f64,
267 pub hbar: f64,
268 pub minimum_product: f64,
269 pub constraints: Vec<UncertaintyConstraint>,
270 pub recommended_scale: String,
271}
272
273#[derive(Debug, Clone)]
275pub struct UncertaintyConstraint {
276 pub scale_name: String,
277 pub time_s: f64,
278 pub required_energy_j: f64,
279 pub required_energy_ev: f64,
280 pub thermal_energy_ratio: f64,
281 pub is_above_thermal: bool,
282 pub is_feasible: bool,
283 pub energy_scale: EnergyScale,
284}
285
286#[cfg(test)]
287mod tests {
288 use super::*;
289 use approx::assert_relative_eq;
290
291 #[test]
292 fn test_uncertainty_principle_validation() {
293 let validator = UncertaintyValidator::new();
294
295 let result = validator.validate_energy_time_product(1e-15, 1e-9).unwrap();
297 assert!(result.is_valid);
298 assert!(result.margin > 1.0);
299
300 let min_product = validator.minimum_uncertainty_product();
302 let small_energy = 1e-40;
303 let small_time = 1e-40;
304 assert!(small_energy * small_time < min_product);
305 }
306
307 #[test]
308 fn test_nanosecond_consciousness_validation() {
309 let validator = UncertaintyValidator::new();
310 let result = validator.validate_nanosecond_consciousness();
311
312 assert_eq!(result.time_s, 1e-9);
313 assert!(result.energy_ev < 1000.0); }
316
317 #[test]
318 fn test_energy_scale_classification() {
319 let validator = UncertaintyValidator::new();
320
321 let sub_atto_energy = constants::EV_TO_JOULES * 1e-18; let ev_energy = constants::EV_TO_JOULES; let kev_energy = 1000.0 * constants::EV_TO_JOULES; assert_eq!(
332 validator.classify_energy_scale(sub_atto_energy),
333 EnergyScale::SubAttoElectronVolt,
334 );
335 assert_eq!(
336 validator.classify_energy_scale(ev_energy),
337 EnergyScale::ElectronVolt,
338 );
339 assert_eq!(
340 validator.classify_energy_scale(kev_energy),
341 EnergyScale::KiloElectronVolt,
342 );
343 }
344
345 #[test]
346 fn test_time_scale_analysis() {
347 let validator = UncertaintyValidator::new();
348 let analysis = validator.analyze_time_scales();
349
350 assert_eq!(analysis.constraints.len(), 6);
351 assert_eq!(analysis.recommended_scale, "nanosecond");
352
353 let mut prev_energy = 0.0;
355 for constraint in analysis.constraints.iter().rev() {
356 assert!(constraint.required_energy_j > prev_energy);
357 prev_energy = constraint.required_energy_j;
358 }
359 }
360
361 #[test]
362 fn test_thermal_energy_calculations() {
363 let validator = UncertaintyValidator::with_temperature(300.0); let thermal_j = validator.thermal_energy();
365 let thermal_ev = thermal_j / constants::EV_TO_JOULES;
366
367 assert_relative_eq!(thermal_ev, 0.026, epsilon = 0.01);
369 }
370
371 #[test]
372 fn test_energy_time_consistency() {
373 let validator = UncertaintyValidator::new();
374
375 let time = 1e-9;
376 let required_energy = validator.calculate_required_energy(time);
377 let max_time = validator.calculate_maximum_time(required_energy);
378
379 assert_relative_eq!(time, max_time, epsilon = 1e-10);
381 }
382
383 #[test]
384 fn test_minimum_uncertainty_product() {
385 let validator = UncertaintyValidator::new();
386 let min_product = validator.minimum_uncertainty_product();
387
388 assert_relative_eq!(min_product, constants::PLANCK_HBAR / 2.0, epsilon = 1e-10);
390 }
391}