relmath-rs 0.7.0

Relation-first mathematics and scientific computing in Rust.
Documentation
//! Deterministic valid-time relations with snapshot and restriction queries.

use relmath::{
    UnaryRelation,
    temporal::{Interval, ValidTimeRelation},
};

fn main() {
    let assignments = ValidTimeRelation::from_facts([
        (
            ("alice", "review"),
            Interval::new(1, 3).expect("expected valid interval"),
        ),
        (
            ("alice", "review"),
            Interval::new(3, 5).expect("expected valid interval"),
        ),
        (
            ("bob", "approve"),
            Interval::new(2, 4).expect("expected valid interval"),
        ),
    ]);

    let alice = UnaryRelation::singleton("alice");
    let fact_support = assignments.support();
    let exact_support = assignments.to_binary_relation();
    let audit_window = Interval::new(2, 4).expect("expected valid interval");
    let active_at_three = assignments.snapshot_at(&3);
    let audit_assignments = assignments.restrict_to(&audit_window);

    assert_eq!(
        assignments
            .valid_time_of(&("alice", "review"))
            .expect("expected support")
            .to_vec(),
        vec![Interval::new(1, 5).expect("expected valid interval")]
    );
    assert!(assignments.is_active_at(&("alice", "review"), &4));
    assert!(!assignments.is_active_at(&("alice", "review"), &5));
    assert_eq!(
        active_at_three.to_vec(),
        vec![("alice", "review"), ("bob", "approve")]
    );
    assert_eq!(
        fact_support.to_vec(),
        vec![("alice", "review"), ("bob", "approve")]
    );
    assert_eq!(
        audit_assignments
            .valid_time_of(&("alice", "review"))
            .expect("expected support")
            .to_vec(),
        vec![Interval::new(2, 4).expect("expected valid interval")]
    );
    assert_eq!(
        audit_assignments.to_binary_relation().to_vec(),
        vec![("alice", "review"), ("bob", "approve")]
    );
    assert_eq!(exact_support.image(&alice).to_vec(), vec!["review"]);

    println!(
        "fact support: {:?}; active at t=3: {:?}; audit restriction: {:?}",
        fact_support.to_vec(),
        active_at_three.to_vec(),
        audit_assignments
            .valid_time_of(&("alice", "review"))
            .expect("expected support")
            .to_vec()
    );
}