deep_causality_physics/quantum/
gates.rs1use deep_causality_multivector::{CausalMultiVector, MultiVector};
7use deep_causality_num::Complex;
8
9pub trait QuantumGates {
11 fn gate_identity() -> Self;
12 fn gate_x() -> Self;
13 fn gate_y() -> Self;
14 fn gate_z() -> Self;
15 fn gate_hadamard() -> Self;
16 fn gate_cnot() -> Self;
20}
21
22pub trait QuantumOps {
24 fn dag(&self) -> Self;
26
27 fn bracket(&self, other: &Self) -> Complex<f64>;
29
30 fn expectation_value(&self, operator: &Self) -> Complex<f64>;
32
33 fn normalize(&self) -> Self;
35}
36
37impl QuantumOps for CausalMultiVector<Complex<f64>> {
38 fn dag(&self) -> Self {
39 let reverted = self.reversion();
41 let conjugated_data = reverted
42 .data()
43 .iter()
44 .map(|c| Complex::new(c.re, -c.im))
45 .collect::<Vec<_>>();
46 CausalMultiVector::new(conjugated_data, reverted.metric()).unwrap_or_else(|_| {
49 CausalMultiVector::new(
50 vec![Complex::new(0.0, 0.0); reverted.data().len()],
51 reverted.metric(),
52 )
53 .expect("consistent metric")
54 })
55 }
56
57 fn bracket(&self, other: &Self) -> Complex<f64> {
58 let prod = self.dag().geometric_product(other);
59 prod.get(0).cloned().unwrap_or(Complex::new(0.0, 0.0))
60 }
61
62 fn expectation_value(&self, operator: &Self) -> Complex<f64> {
63 let bra_psi = self.dag();
64 let a_psi = operator.geometric_product(self);
65 let prod = bra_psi.geometric_product(&a_psi);
66 prod.get(0).cloned().unwrap_or(Complex::new(0.0, 0.0))
67 }
68
69 fn normalize(&self) -> Self {
70 use deep_causality_multivector::MultiVectorL2Norm;
71 self.normalize_l2()
72 }
73}