Skip to main content

meta_language/
semantics.rs

1/// Many-valued semantic truth value.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum TruthValue {
4    True,
5    False,
6    Unknown,
7    Both,
8}
9
10impl TruthValue {
11    /// Logical conjunction.
12    #[must_use]
13    pub const fn and(self, other: Self) -> Self {
14        match (self, other) {
15            (Self::False, _) | (_, Self::False) => Self::False,
16            (Self::True, value) | (value, Self::True) => value,
17            (Self::Both, _) | (_, Self::Both) => Self::Both,
18            (Self::Unknown, Self::Unknown) => Self::Unknown,
19        }
20    }
21
22    /// Logical disjunction.
23    #[must_use]
24    pub const fn or(self, other: Self) -> Self {
25        match (self, other) {
26            (Self::True, _) | (_, Self::True) => Self::True,
27            (Self::False, value) | (value, Self::False) => value,
28            (Self::Both, _) | (_, Self::Both) => Self::Both,
29            (Self::Unknown, Self::Unknown) => Self::Unknown,
30        }
31    }
32
33    /// Logical negation.
34    #[must_use]
35    pub const fn negate(self) -> Self {
36        match self {
37            Self::True => Self::False,
38            Self::False => Self::True,
39            Self::Unknown => Self::Unknown,
40            Self::Both => Self::Both,
41        }
42    }
43}