use num::Complex;
pub type Cf64 = Complex<f64>;
pub type Matrix = [[Cf64; 2]; 2];
#[inline]
pub(crate) fn identity() -> Matrix {
[
[Cf64::new(1.0, 0.0), Cf64::new(0.0, 0.0)],
[Cf64::new(0.0, 0.0), Cf64::new(1.0, 0.0)],
]
}
#[inline]
pub(crate) fn is_identity(m: &Matrix) -> bool {
const EPS: f64 = 1e-12;
let [[a, b], [c, d]] = m;
(a.re - 1.0).abs() < EPS
&& a.im.abs() < EPS
&& b.norm() < EPS
&& c.norm() < EPS
&& (d.re - 1.0).abs() < EPS
&& d.im.abs() < EPS
}
#[inline]
pub(crate) fn mat_mul(lhs: &Matrix, rhs: &Matrix) -> Matrix {
let [[a, b], [c, d]] = lhs;
let [[e, f], [g, h]] = rhs;
[
[a * e + b * g, a * f + b * h],
[c * e + d * g, c * f + d * h],
]
}