use std::hash::Hash;
use crate::{CustomSet, SetOperations};
pub struct SetLaws;
impl SetLaws {
pub fn identity_union<T: Eq + Hash + Clone>(a: &CustomSet<T>) -> bool {
let empty = CustomSet::<T>::empty();
SetOperations::union(a, &empty).equals(a)
}
pub fn identity_intersection<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
universal: &CustomSet<T>,
) -> bool {
SetOperations::intersection(a, universal).equals(a)
}
pub fn null_intersection<T: Eq + Hash + Clone>(a: &CustomSet<T>) -> bool {
let empty = CustomSet::<T>::empty();
SetOperations::intersection(a, &empty).is_empty()
}
pub fn null_union<T: Eq + Hash + Clone>(a: &CustomSet<T>, universal: &CustomSet<T>) -> bool {
SetOperations::union(a, universal).equals(universal)
}
pub fn complement_union<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
universal: &CustomSet<T>,
) -> bool {
let complement = SetOperations::complement(a, universal);
SetOperations::union(a, &complement).equals(universal)
}
pub fn complement_intersection<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
universal: &CustomSet<T>,
) -> bool {
let complement = SetOperations::complement(a, universal);
SetOperations::intersection(a, &complement).is_empty()
}
pub fn idempotent_union<T: Eq + Hash + Clone>(a: &CustomSet<T>) -> bool {
SetOperations::union(a, a).equals(a)
}
pub fn idempotent_intersection<T: Eq + Hash + Clone>(a: &CustomSet<T>) -> bool {
SetOperations::intersection(a, a).equals(a)
}
pub fn involution<T: Eq + Hash + Clone>(a: &CustomSet<T>, universal: &CustomSet<T>) -> bool {
let complement1 = SetOperations::complement(a, universal);
let complement2 = SetOperations::complement(&complement1, universal);
complement2.equals(a)
}
pub fn absorption_union<T: Eq + Hash + Clone>(a: &CustomSet<T>, b: &CustomSet<T>) -> bool {
let intersection = SetOperations::intersection(a, b);
SetOperations::union(a, &intersection).equals(a)
}
pub fn absorption_intersection<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
b: &CustomSet<T>,
) -> bool {
let union = SetOperations::union(a, b);
SetOperations::intersection(a, &union).equals(a)
}
pub fn commutative_union<T: Eq + Hash + Clone>(a: &CustomSet<T>, b: &CustomSet<T>) -> bool {
SetOperations::union(a, b).equals(&SetOperations::union(b, a))
}
pub fn commutative_intersection<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
b: &CustomSet<T>,
) -> bool {
SetOperations::intersection(a, b).equals(&SetOperations::intersection(b, a))
}
pub fn associative_union<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
b: &CustomSet<T>,
c: &CustomSet<T>,
) -> bool {
let left = SetOperations::union(a, &SetOperations::union(b, c));
let right = SetOperations::union(&SetOperations::union(a, b), c);
left.equals(&right)
}
pub fn associative_intersection<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
b: &CustomSet<T>,
c: &CustomSet<T>,
) -> bool {
let left = SetOperations::intersection(a, &SetOperations::intersection(b, c));
let right = SetOperations::intersection(&SetOperations::intersection(a, b), c);
left.equals(&right)
}
pub fn distributive_union<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
b: &CustomSet<T>,
c: &CustomSet<T>,
) -> bool {
let left = SetOperations::union(a, &SetOperations::intersection(b, c));
let right =
SetOperations::intersection(&SetOperations::union(a, b), &SetOperations::union(a, c));
left.equals(&right)
}
pub fn distributive_intersection<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
b: &CustomSet<T>,
c: &CustomSet<T>,
) -> bool {
let left = SetOperations::intersection(a, &SetOperations::union(b, c));
let right = SetOperations::union(
&SetOperations::intersection(a, b),
&SetOperations::intersection(a, c),
);
left.equals(&right)
}
pub fn de_morgan_union<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
b: &CustomSet<T>,
universal: &CustomSet<T>,
) -> bool {
let union = SetOperations::union(a, b);
let complement_union = SetOperations::complement(&union, universal);
let complement_a = SetOperations::complement(a, universal);
let complement_b = SetOperations::complement(b, universal);
let intersection_complements = SetOperations::intersection(&complement_a, &complement_b);
complement_union.equals(&intersection_complements)
}
pub fn de_morgan_intersection<T: Eq + Hash + Clone>(
a: &CustomSet<T>,
b: &CustomSet<T>,
universal: &CustomSet<T>,
) -> bool {
let intersection = SetOperations::intersection(a, b);
let complement_intersection = SetOperations::complement(&intersection, universal);
let complement_a = SetOperations::complement(a, universal);
let complement_b = SetOperations::complement(b, universal);
let union_complements = SetOperations::union(&complement_a, &complement_b);
complement_intersection.equals(&union_complements)
}
pub fn law_zero<T: Eq + Hash + Clone>(universal: &CustomSet<T>) -> bool {
let empty = CustomSet::<T>::empty();
SetOperations::complement(&empty, universal).equals(universal)
}
pub fn law_one<T: Eq + Hash + Clone>(universal: &CustomSet<T>) -> bool {
SetOperations::complement(universal, universal).is_empty()
}
}