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
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
//! The verdict carrier: a bounded lattice with complement — the output type of `Collection`
//! aggregation.
/// A **verdict**: a bounded lattice with complement (a Boolean algebra for `bool`; an MV-algebra
/// for the probability carrier, where `complement(p) = 1 − p`).
///
/// The aggregation output type is a `Verdict`: `All` folds `meet`, `Any` folds `join`, and `None`
/// is `Any` post-composed with `complement`. `bottom`/`top` are the lattice bounds (`false`/`true`
/// for `bool`).
///
/// # Laws
/// - bounded-lattice: `meet`/`join` are associative, commutative, absorptive; `bottom`/`top` are
/// the identities of `join`/`meet`.
/// - complement: involution `complement(complement(x)) == x` and (for the Boolean class) De Morgan.
pub trait Verdict: Sized {
/// The lattice bottom (identity of `join`).
fn bottom() -> Self;
/// The lattice top (identity of `meet`).
fn top() -> Self;
/// Greatest lower bound (`∧` for `bool`).
fn meet(self, other: Self) -> Self;
/// Least upper bound (`∨` for `bool`).
fn join(self, other: Self) -> Self;
/// Complement (`!` for `bool`; `1 − p` for the probability MV-algebra).
fn complement(self) -> Self;
}
impl Verdict for bool {
#[inline]
fn bottom() -> Self {
false
}
#[inline]
fn top() -> Self {
true
}
#[inline]
fn meet(self, other: Self) -> Self {
self && other
}
#[inline]
fn join(self, other: Self) -> Self {
self || other
}
#[inline]
fn complement(self) -> Self {
!self
}
}