# 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)` means `r ; s`
- the result contains `(a, c)` when some `b` satisfies `(a, b) in r` and
`(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/`:
- `family` for ancestry and reachability
- `access_control` for role-permission propagation
- `workflow` for state reachability
## Example
```rust
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.