use std::ops::Mul;
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
pub enum Pauli {
I,
X,
Y,
Z,
}
impl Pauli {
pub fn as_gf4(&self) -> (usize, usize) {
match self {
Self::I => (0, 0),
Self::X => (1, 0),
Self::Y => (1, 1),
Self::Z => (0, 1),
}
}
pub fn commutator_with(self, other: Self) -> i32 {
match (self, other) {
(Self::I, _) => 1,
(_, Self::I) => 1,
(a, b) => {
if a == b {
1
} else {
-1
}
}
}
}
}
impl Mul for Pauli {
type Output = Self;
fn mul(self, other: Self) -> Self::Output {
match (self, other) {
(Self::I, a) => a,
(Self::X, Self::Y) => Self::Z,
(Self::Y, Self::Z) => Self::X,
(Self::Z, Self::X) => Self::Y,
(a, b) => {
if a == b {
Pauli::I
} else {
b * a
}
}
}
}
}