#![doc(include = "../../doc/references.md")]
pub use crate::helpers::*;
pub use crate::numeric::*;
pub use super::relation::*;
pub trait Equivalence: Sized {}
pub trait EquivalenceLaws: Equivalence {
fn symmetry(f: &Rel<Self>, x: &Self, y: &Self) -> bool {
imply(f(x, y), f(y, x))
}
fn reflexivity(f: &Rel<Self>, x: &Self) -> bool {
f(x, x)
}
fn transitivity(f: &Rel<Self>, x: &Self, y: &Self, z: &Self) -> bool {
imply(f(x, y) && f(y, z), f(x, z))
}
}
impl<E: Equivalence> EquivalenceLaws for E {}
pub trait NumEquivalenceLaws: NumEq + Equivalence {
fn num_symmetry(f: &NumRel<Self>, x: &Self, y: &Self, eps: &Self::Eps) -> bool {
imply(f(x, y, eps), f(y, x, eps))
}
fn num_reflexivity(f: &NumRel<Self>, x: &Self, eps: &Self::Eps) -> bool {
f(x, x, eps)
}
fn num_transitivity(f: &NumRel<Self>, x: &Self, y: &Self, z: &Self, eps: &Self::Eps) -> bool {
imply(f(x, y, eps) && f(y, z, eps), f(x, z, eps))
}
}
impl<E: NumEq + Equivalence> NumEquivalenceLaws for E {}
impl Equivalence for f32 {}
impl Equivalence for f64 {}
#[cfg(test)]
mod tests;