Skip to main content

EuclideanDomain

Trait EuclideanDomain 

Source
pub trait EuclideanDomain:
    Ring
    + Div<Output = Self>
    + Rem<Output = Self> {
    // Required methods
    fn div_rem(&self, other: &Self) -> (Self, Self);
    fn abs(&self) -> Self;

    // Provided method
    fn gcd(&self, other: &Self) -> Self { ... }
}
Expand description

Euclidean domain: ring with division algorithm

A Euclidean domain is a ring where division with remainder is defined. Examples: integers Z, polynomials K[x] over field K, Gaussian integers Z[i]

Key property: For any a, b ≠ 0, exists q, r such that a = q*b + r where either r = 0 or deg(r) < deg(b)

Required Methods§

Source

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

Division with remainder: returns (quotient, remainder)

§Example
let (q, r) = a.div_rem(&b);
assert_eq!(a, &(&q * &b) + &r);
Source

fn abs(&self) -> Self

Absolute value (for content extraction and normalization)

Provided Methods§

Source

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

Greatest common divisor using Euclidean algorithm

§Example
assert_eq!(gcd(12, 18), 6);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl EuclideanDomain for Ratio<i64>

Source§

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

Source§

fn abs(&self) -> Self

Source§

impl EuclideanDomain for i64

Source§

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

Source§

fn abs(&self) -> Self

Implementors§