noether 0.3.0

Abstract algebraic structures for Rust
Documentation
//! Set theory foundations.
//!
//! This module provides the foundational Set trait which forms the basis
//! of all algebraic structures in Noether.

/// Represents a mathematical set as defined in Zermelo-Fraenkel set theory with Choice (ZFC).
///
/// # Formal Notation
/// - ∅: empty set
/// - ∈: element of
/// - ⊆: subset of
/// - ∪: union
/// - ∩: intersection
/// - \: set difference
/// - Δ: symmetric difference
/// - |A|: cardinality of set A
///
/// # Axioms of ZFC
/// 1. Extensionality: ∀A∀B(∀x(x ∈ A ↔ x ∈ B) → A = B)
/// 2. Empty Set: ∃A∀x(x ∉ A)
/// 3. Pairing: ∀a∀b∃A∀x(x ∈ A ↔ x = a ∨ x = b)
/// 4. Union: ∀F∃A∀x(x ∈ A ↔ ∃B(x ∈ B ∧ B ∈ F))
/// 5. Power Set: ∀A∃P∀x(x ∈ P ↔ x ⊆ A)
/// 6. Infinity: ∃A(∅ ∈ A ∧ ∀x(x ∈ A → x ∪ {x} ∈ A))
/// 7. Separation: ∀A∃B∀x(x ∈ B ↔ x ∈ A ∧ φ(x)) for any formula φ
/// 8. Replacement: ∀A(∀x∀y∀z((x ∈ A ∧ φ(x,y) ∧ φ(x,z)) → y = z) → ∃B∀y(y ∈ B ↔ ∃x(x ∈ A ∧ φ(x,y))))
/// 9. Foundation: ∀A(A ≠ ∅ → ∃x(x ∈ A ∧ x ∩ A = ∅))
/// 10. Choice: ∀A(∅ ∉ A → ∃f:A → ∪A ∀B∈A(f(B) ∈ B))
pub trait Set: Sized + PartialEq {}

// Blanket implementation for any type that satisfies the trait bounds
impl<T: PartialEq> Set for T {}

#[cfg(test)]
mod tests {
    use super::*;

    // Define some test types to validate the Set trait implementation
    #[derive(PartialEq, Debug)]
    struct Point {
        x: i32,
        y: i32,
    }

    #[test]
    fn test_set_implementation_for_primitives() {
        // Test that primitive types implement Set
        fn assert_is_set<T: Set>(_: &T) {}

        assert_is_set(&42i32);
        assert_is_set(&"hello");
        assert_is_set(&std::f64::consts::PI);
        assert_is_set(&true);
        assert_is_set(&[1, 2, 3]);
    }

    #[test]
    fn test_set_implementation_for_custom_types() {
        // Test that custom types implement Set
        fn assert_is_set<T: Set>(_: &T) {}

        let point = Point { x: 1, y: 2 };
        assert_is_set(&point);
    }

    #[test]
    fn test_set_equality() {
        // Test that Set equality works as expected
        let a = Point { x: 1, y: 2 };
        let b = Point { x: 1, y: 2 };
        let c = Point { x: 3, y: 4 };

        assert_eq!(a, b);
        assert_ne!(a, c);
    }
}