Set Structures
Let \(X\) be a set. This section outlines the traits Algebraeon provides for defining elements of \(X\) and comparing elements with respect to equality or an ordering on \(X\).
Elements and Equality
Setfor an object representing a set of elements \(X\). Set the associated typeSetto a typeXto use instances ofXto represent elements of \(X\). It’s not necessary that all instances ofXrepresent valid elements of \(X\). The methodvalidate_element(a: X) -> Resultshould returnOkwhenarepresents a valid element of \(X\) andErrwhen it does not. All other operations with elements of \(X\) may exhibit undefined behaviour (ideally panic immediately - at least when building debug mode).Eq : Setfor a set with a binary predicate \(=\) called equality. \(=\) is required to be an equivalence relation, meaning \[a = a \quad \forall a \in X\] \[a = b \implies b = a \quad \forall a, b \in X\] \[a = b \quad \text{and} \quad b = c \implies a = c \quad \forall a, b \in X\] The methodequal(a: X, b: X) -> boolindicates whetheraandbare equal.
Orderings
The ordering structures make use of Rusts std::cmp::Ordering enum to relay information about how elements of a set compare with respect to an ordering.
PartialOrd : Set + Eqfor sets with a binary predicate \(\le\) satisfying the axioms for a partial order. \[a \le a \quad \forall a \in X\] \[a \le b \quad \text{and} \quad b \le a \implies a = b \quad \forall a, b \in X\] \[a \le b \quad \text{and} \quad b \le c \implies a \le c \quad \forall a, b \in X\] The methodpartial_ord(a: X, b: X) -> Option<Ordering>returns information about howaandbcompare wtih respect to \(=\) and \(\le\).Ord : Set + PartialOrdfor sets with a total ordering, so in addition to the axioms for a partial ordering, \(\le\) also satisfies \[a \le b \quad \text{or} \quad b \le a \quad \forall a, b \in X\] The methodord(a: X, b: X) -> Orderingreturns information about howaandbcompare wtih respect to \(=\) and \(\le\).