pub struct ModNum<N> { /* private fields */ }
Expand description
Represents an integer a (mod m)
Implementations§
Source§impl<N: NumType + Signed> ModNum<N>
impl<N: NumType + Signed> ModNum<N>
Sourcepub fn chinese_remainder(&self, other: ModNum<N>) -> ModNum<N>
pub fn chinese_remainder(&self, other: ModNum<N>) -> ModNum<N>
Solves a pair of modular equations using the Chinese Remainder Theorem.
This is my translation into Rust of Brent Yorgey’s Haskell implementation.
self
represents the modular equation x = a (mod m)other
represents the modular equation x = b (mod n)- It returns a
ModNum
corresponding to the equation x = c (mod mn) where c is congruent both to a (mod m) and b (mod n)
Sourcepub fn chinese_remainder_system<I: Iterator<Item = ModNum<N>>>(
modnums: I,
) -> Option<ModNum<N>>
pub fn chinese_remainder_system<I: Iterator<Item = ModNum<N>>>( modnums: I, ) -> Option<ModNum<N>>
Solves a system of modular equations using ModMum::chinese_remainder()
.
Each equation in the system is an element of the modnums iterator parameter.
- Returns None if the iterator is empty.
- Returns Some(element) if the iterator has only one element.
- Returns Some(solution) if the iterator has two or more elements, where the solution is found by repeatedly calling ModNum::chinese_remainder().
Trait Implementations§
Source§impl<N: NumType> AddAssign<N> for ModNum<N>
impl<N: NumType> AddAssign<N> for ModNum<N>
Source§fn add_assign(&mut self, rhs: N)
fn add_assign(&mut self, rhs: N)
Performs the
+=
operation. Read moreSource§impl<N: NumType> AddAssign for ModNum<N>
impl<N: NumType> AddAssign for ModNum<N>
Source§fn add_assign(&mut self, rhs: ModNum<N>)
fn add_assign(&mut self, rhs: ModNum<N>)
Performs the
+=
operation. Read moreSource§impl<N: NumType + Signed> DivAssign<N> for ModNum<N>
impl<N: NumType + Signed> DivAssign<N> for ModNum<N>
Source§fn div_assign(&mut self, rhs: N)
fn div_assign(&mut self, rhs: N)
Performs the
/=
operation. Read moreSource§impl<N: NumType + Signed> DivAssign for ModNum<N>
impl<N: NumType + Signed> DivAssign for ModNum<N>
Source§fn div_assign(&mut self, rhs: ModNum<N>)
fn div_assign(&mut self, rhs: ModNum<N>)
Performs the
/=
operation. Read moreSource§impl<N: NumType> MNum for ModNum<N>
impl<N: NumType> MNum for ModNum<N>
Source§impl<N: NumType> MulAssign<N> for ModNum<N>
impl<N: NumType> MulAssign<N> for ModNum<N>
Source§fn mul_assign(&mut self, rhs: N)
fn mul_assign(&mut self, rhs: N)
Performs the
*=
operation. Read moreSource§impl<N: NumType> MulAssign for ModNum<N>
impl<N: NumType> MulAssign for ModNum<N>
Source§fn mul_assign(&mut self, rhs: ModNum<N>)
fn mul_assign(&mut self, rhs: ModNum<N>)
Performs the
*=
operation. Read moreSource§impl<N: Ord> Ord for ModNum<N>
impl<N: Ord> Ord for ModNum<N>
Source§impl<N: NumType> PartialEq<N> for ModNum<N>
Returns true if other is congruent to self.a() (mod self.m())
impl<N: NumType> PartialEq<N> for ModNum<N>
Returns true if other is congruent to self.a() (mod self.m())
Source§impl<N: NumType> PartialOrd<N> for ModNum<N>
impl<N: NumType> PartialOrd<N> for ModNum<N>
Source§impl<N: PartialOrd> PartialOrd for ModNum<N>
impl<N: PartialOrd> PartialOrd for ModNum<N>
Source§impl<N: NumType> SaturatingAdd for ModNum<N>
impl<N: NumType> SaturatingAdd for ModNum<N>
Source§fn saturating_add(&self, v: &Self) -> Self
fn saturating_add(&self, v: &Self) -> Self
Saturating addition. Computes
self + other
, saturating at the relevant high or low boundary of
the type.Source§impl<N: NumType> SaturatingSub for ModNum<N>
impl<N: NumType> SaturatingSub for ModNum<N>
Source§fn saturating_sub(&self, v: &Self) -> Self
fn saturating_sub(&self, v: &Self) -> Self
Saturating subtraction. Computes
self - other
, saturating at the relevant high or low boundary of
the type.Source§impl<N: NumType> SubAssign<N> for ModNum<N>
impl<N: NumType> SubAssign<N> for ModNum<N>
Source§fn sub_assign(&mut self, rhs: N)
fn sub_assign(&mut self, rhs: N)
Performs the
-=
operation. Read moreSource§impl<N: NumType> SubAssign for ModNum<N>
impl<N: NumType> SubAssign for ModNum<N>
Source§fn sub_assign(&mut self, rhs: ModNum<N>)
fn sub_assign(&mut self, rhs: ModNum<N>)
Performs the
-=
operation. Read moreimpl<N: Copy> Copy for ModNum<N>
impl<N: Eq> Eq for ModNum<N>
impl<N> StructuralPartialEq for ModNum<N>
Auto Trait Implementations§
impl<N> Freeze for ModNum<N>where
N: Freeze,
impl<N> RefUnwindSafe for ModNum<N>where
N: RefUnwindSafe,
impl<N> Send for ModNum<N>where
N: Send,
impl<N> Sync for ModNum<N>where
N: Sync,
impl<N> Unpin for ModNum<N>where
N: Unpin,
impl<N> UnwindSafe for ModNum<N>where
N: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more