1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Contains simple functions that can be used with `apply` and `fused_flip_apply` to
//! implement basic logical operations.

/// Partial operator function corresponding to $x \land y$.
pub fn and(l: Option<bool>, r: Option<bool>) -> Option<bool> {
    match (l, r) {
        (Some(true), Some(true)) => Some(true),
        (Some(false), _) => Some(false),
        (_, Some(false)) => Some(false),
        _ => None,
    }
}

/// Partial operator function corresponding to $x \lor y$.
pub fn or(l: Option<bool>, r: Option<bool>) -> Option<bool> {
    match (l, r) {
        (Some(false), Some(false)) => Some(false),
        (Some(true), _) => Some(true),
        (_, Some(true)) => Some(true),
        _ => None,
    }
}

/// Partial operator function corresponding to $x \Leftarrow y$.
pub fn imp(l: Option<bool>, r: Option<bool>) -> Option<bool> {
    match (l, r) {
        (Some(true), Some(false)) => Some(false),
        (Some(false), _) => Some(true),
        (_, Some(true)) => Some(true),
        _ => None,
    }
}

/// Partial operator function corresponding to $x \Leftrightarrow y$.
pub fn iff(l: Option<bool>, r: Option<bool>) -> Option<bool> {
    match (l, r) {
        (Some(l), Some(r)) => Some(l == r),
        _ => None,
    }
}

/// Partial operator function corresponding to $x \not\Leftrightarrow y$.
pub fn xor(l: Option<bool>, r: Option<bool>) -> Option<bool> {
    match (l, r) {
        (Some(l), Some(r)) => Some(l ^ r),
        _ => None,
    }
}

/// Partial operator function corresponding to $x \land \neg y$.
pub fn and_not(l: Option<bool>, r: Option<bool>) -> Option<bool> {
    match (l, r) {
        (Some(false), _) => Some(false),
        (_, Some(true)) => Some(false),
        (Some(true), Some(false)) => Some(true),
        _ => None,
    }
}