use crate::{CausalMultiVector, CausalMultiVectorError, Metric};
use deep_causality_num::{Complex, RealField, Zero};
use std::fmt::{Display, Formatter};
#[derive(Debug, Clone, PartialEq)]
pub struct HilbertState<R: RealField> {
mv: CausalMultiVector<Complex<R>>,
}
impl<R: RealField> HilbertState<R> {
pub fn new_spin10(data: Vec<Complex<R>>) -> Result<Self, CausalMultiVectorError> {
let metric = Metric::NonEuclidean(10);
let mv = CausalMultiVector::new(data, metric)?;
Ok(Self { mv })
}
pub fn new(data: Vec<Complex<R>>, metric: Metric) -> Result<Self, CausalMultiVectorError> {
let mv = CausalMultiVector::new(data, metric)?;
Ok(Self { mv })
}
pub fn new_unchecked(data: Vec<Complex<R>>, metric: Metric) -> Self {
let mv = CausalMultiVector::unchecked(data, metric);
Self { mv }
}
pub fn from_multivector(mv: CausalMultiVector<Complex<R>>) -> Self {
Self { mv }
}
pub fn into_inner(self) -> CausalMultiVector<Complex<R>> {
self.mv
}
pub fn as_inner(&self) -> &CausalMultiVector<Complex<R>> {
&self.mv
}
pub fn mv(&self) -> &CausalMultiVector<Complex<R>> {
&self.mv
}
}
impl<R: RealField> Default for HilbertState<R> {
fn default() -> Self {
let metric = Metric::Euclidean(0);
let data = vec![Complex::zero()];
let mv = CausalMultiVector::new(data.clone(), metric)
.unwrap_or(CausalMultiVector::unchecked(data, metric));
Self { mv }
}
}
impl<R: RealField> core::ops::Add for HilbertState<R> {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self {
mv: self.mv + rhs.mv,
}
}
}
impl<R: RealField> core::ops::Mul<Complex<R>> for HilbertState<R> {
type Output = Self;
fn mul(self, rhs: Complex<R>) -> Self::Output {
Self { mv: self.mv * rhs }
}
}
impl<R: RealField + core::fmt::Debug> Display for HilbertState<R> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.mv)
}
}