Skip to main content

EuclideanDomain

Trait EuclideanDomain 

Source
pub trait EuclideanDomain: CommutativeRing {
    type EuclideanValue: Ord;

    // Required methods
    fn euclidean_fn(&self) -> Self::EuclideanValue;
    fn div_euclid(&self, other: &Self) -> Self;
    fn rem_euclid(&self, other: &Self) -> Self;

    // Provided methods
    fn gcd(&self, other: &Self) -> Self
       where Self: Sized + Clone { ... }
    fn lcm(&self, other: &Self) -> Self
       where Self: Sized + Clone + Div<Output = Self> { ... }
}
Expand description

Represents a Euclidean Domain.

A Euclidean domain is an integral domain equipped with a Euclidean function that enables division with remainder. This is the foundation of the Euclidean algorithm for computing greatest common divisors.

§Mathematical Definition

A commutative ring R is a Euclidean domain if there exists a function φ: R \ {0} → ℕ (the Euclidean function) such that for any a, b ∈ R with b ≠ 0, there exist q, r ∈ R satisfying:

  1. a = b·q + r
  2. Either r = 0 or φ(r) < φ(b)

For integers, φ(n) = |n| (absolute value).

§Properties

  • Every Euclidean domain is a Principal Ideal Domain (PID).
  • Every Euclidean domain is a Unique Factorization Domain (UFD).
  • The Euclidean algorithm terminates in finite steps.

§Examples

  • Integers with φ(n) = |n|
  • Gaussian integers ℤ[i] with φ(a + bi) = a² + b²
  • Polynomial rings F[x] over a field with φ(p) = deg(p)

Required Associated Types§

Source

type EuclideanValue: Ord

The Euclidean function value type (typically a measure of “size”). For integers, this is the absolute value.

Required Methods§

Source

fn euclidean_fn(&self) -> Self::EuclideanValue

Computes the Euclidean function value.

For integers, this returns the absolute value. For polynomials, this would return the degree.

Source

fn div_euclid(&self, other: &Self) -> Self

Computes the quotient of Euclidean division.

For a.div_euclid(b), returns q such that a = b*q + r where 0 ≤ r < |b|.

Source

fn rem_euclid(&self, other: &Self) -> Self

Computes the remainder of Euclidean division.

For a.rem_euclid(b), returns r such that a = b*q + r where 0 ≤ r < |b|.

Unlike the % operator, the result is always non-negative.

Provided Methods§

Source

fn gcd(&self, other: &Self) -> Self
where Self: Sized + Clone,

Computes the greatest common divisor using the Euclidean algorithm.

§Properties
  • gcd(a, 0) = |a|
  • gcd(a, b) = gcd(b, a % b)
  • gcd(a, b) divides both a and b
  • Any common divisor of a and b also divides gcd(a, b)
Source

fn lcm(&self, other: &Self) -> Self
where Self: Sized + Clone + Div<Output = Self>,

Computes the least common multiple.

lcm(a, b) = |a * b| / gcd(a, b)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl EuclideanDomain for i8

Source§

type EuclideanValue = u8

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for i16

Source§

type EuclideanValue = u16

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for i32

Source§

type EuclideanValue = u32

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for i64

Source§

type EuclideanValue = u64

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for i128

Source§

type EuclideanValue = u128

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for isize

Source§

type EuclideanValue = usize

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for u8

Source§

type EuclideanValue = u8

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for u16

Source§

type EuclideanValue = u16

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for u32

Source§

type EuclideanValue = u32

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for u64

Source§

type EuclideanValue = u64

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for u128

Source§

type EuclideanValue = u128

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Source§

impl EuclideanDomain for usize

Source§

type EuclideanValue = usize

Source§

fn euclidean_fn(&self) -> Self::EuclideanValue

Source§

fn div_euclid(&self, other: &Self) -> Self

Source§

fn rem_euclid(&self, other: &Self) -> Self

Implementors§