Expand description
§relmath
relmath is the G1 library crate inside the relmath-rs repository.
It provides exact finite unary and binary relations with deterministic
BTreeSet-backed iteration order.
§Current G1 Surface
The current public API covers:
UnaryRelation<T>for finite unary relations (sets)BinaryRelation<A, B>for finite binary relations- union, intersection, and difference
- domain, range, converse, and composition
- domain/range restriction plus image/preimage with unary relations
- identity on a carrier
- transitive and reflexive-transitive closure on homogeneous relations
- relation property checks for reflexivity, irreflexivity, symmetry, antisymmetry, transitivity, equivalence, and partial order
Composition uses relational order:
r.compose(&s)meansr ; s- the result contains
(a, c)when somebsatisfies(a, b) in rand(b, c) in s
§Current Limits
This crate currently implements the exact G1 core only:
- no n-ary relations
- no weighted or temporal relations
- no solver-backed or symbolic evaluation
The repository ships three focused examples under examples/:
familyfor ancestry and reachabilityaccess_controlfor role-permission propagationworkflowfor state reachability
§Example
use relmath::{BinaryRelation, UnaryRelation};
let parent = BinaryRelation::from_pairs([
("Ada", "Bob"),
("Bob", "Cara"),
]);
let people = UnaryRelation::from_values(["Ada", "Bob", "Cara", "Finn"]);
let grandparent = parent.compose(&parent);
let ancestor_or_self = parent.reflexive_transitive_closure(&people);
assert_eq!(grandparent.to_vec(), vec![("Ada", "Cara")]);
assert!(ancestor_or_self.contains(&"Ada", &"Cara"));
assert!(ancestor_or_self.contains(&"Finn", &"Finn"));§Status
This crate is the exact unary/binary relation core for the first public G1 release candidate.
Re-exports§
pub use crate::core::BinaryRelation;pub use crate::core::UnaryRelation;pub use crate::traits::FiniteRelation;