Skip to content

Commit

Permalink
feat: IntegralDomain impl
Browse files Browse the repository at this point in the history
  • Loading branch information
geet-eth committed Aug 1, 2024
1 parent a0c3e18 commit 354e91f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ pub trait CommutativeRing: Ring + CommutativeMultiplication {}
/// ∀ a, b ∈ D, if a · b = 0, then a = 0 or b = 0
/// 3. The zero element is distinct from the unity:
/// 0 ≠ 1
pub trait IntegralDomain: CommutativeRing {}
pub trait IntegralDomain: CommutativeRing {

/// Represents a Unique Factorization Domain (UFD), an integral domain where every non-zero
/// Represents a Unique Factorization Domain (UFD), an integral domain where every non-zero
/// non-unit element has a unique factorization into irreducible elements.
///
/// # Mathematical Definition
Expand All @@ -366,6 +366,24 @@ pub trait IntegralDomain: CommutativeRing {}
/// 2. If a = p₁ · ... · pₙ = q₁ · ... · qₘ are two factorizations of a into irreducible elements,
/// then n = m and there exists a bijection σ: {1, ..., n} → {1, ..., n} such that pᵢ is
/// associated to qₛᵢ for all i.
fn is_zero_divisor(&self) -> bool{
self.is_zero()
}

fn divides(&self, other: &Self) -> bool{
if self.is_zero(){
other.is_zero()
} else {
let mut c = Self::zero();
while c * *self != *other {
c = c + Self::one();
if c.is_zero(){
return false;
}
} true
}
}
}
pub trait UniqueFactorizationDomain: IntegralDomain {}

/// Represents a Principal Ideal Domain (PID), an integral domain where every ideal is principal.
Expand Down Expand Up @@ -584,8 +602,8 @@ impl<T: AdditiveAbelianGroup + MultiplicativeMonoid + Distributive> Ring for T {
// CommutativeRing
impl<T: Ring + CommutativeMultiplication> CommutativeRing for T {}

// IntegralDomain
// Note: This is a simplified implementation. In practice, you'd need to check for zero divisors.
// IntegralDomain
//added implementation which checks for zero diversers

impl<T: CommutativeRing> IntegralDomain for T {}

Expand Down

2 comments on commit 354e91f

@geet-eth
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly unsure what the plans for implementing is supposed to be so just sticking with this.
also UFD would be an extension of IntegralDomain afaik it would be better to define it separately

@geet-eth
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly unsure what the plans for implementing is supposed to be so just sticking with this. also UFD would be an extension of IntegralDomain afaik it would be better to define it separately

ahh just realized i was stupid and reading comments wrong ree

Please sign in to comment.