ArithmeticCongruenceMonoid

Struct ArithmeticCongruenceMonoid 

Source
pub struct ArithmeticCongruenceMonoid<T>
where for<'b> T: TBounds + Ops<T, T> + Ops<&'b T, T> + AssignOps<&'b T>, for<'a, 'a, 'b> &'a T: Ops<T, T> + Ops<&'b T, T>,
{ /* private fields */ }
Expand description

Arithmetic congruence monoid implementation.

Implementations§

Source§

impl<T> ArithmeticCongruenceMonoid<T>
where for<'b> T: TBounds + Ops<T, T> + Ops<&'b T, T> + AssignOps<&'b T>, for<'a, 'a, 'b> &'a T: Ops<T, T> + Ops<&'b T, T>,

Source

pub fn new(a: T, b: T) -> Result<ArithmeticCongruenceMonoid<T>, ACMError<T>>

Construct a new ACM with components $a$ and $b$ satisfying $a\equiv a^2\pmod b$.

§Examples
// A valid ACM (1 % 4 == 1 == 1*1 % 4)
assert!(acm::ArithmeticCongruenceMonoid::new(1, 4).is_ok());

// An invalid ACM (2 % 4 == 2 != 0 == 2*2 % 4)
assert!(acm::ArithmeticCongruenceMonoid::new(2, 4).is_err());
Source

pub fn a(&self) -> &T

Returns the $a$ component of the ACM.

Source

pub fn b(&self) -> &T

Returns the $b$ component of the ACM.

Source

pub fn contains(&self, x: &T) -> bool

Returns true if n is an element of the ACM.

§Examples
let acm = acm::ArithmeticCongruenceMonoid::new(1, 4).unwrap();
assert!( acm.contains(&5));
assert!(!acm.contains(&6));
Source

pub fn nearest<U: Into<T>>(&self, s: U) -> T

Returns the nearst ACM element less-than or equal to $s$. If $s < a$, returns $a$.

§Examples
let acm = acm::ArithmeticCongruenceMonoid::new(1, 4).unwrap();
assert_eq!(acm.nearest(0), 1);
assert_eq!(acm.nearest(1), 1);
assert_eq!(acm.nearest(5), 5);
assert_eq!(acm.nearest(6), 5);
Source

pub fn iter(&self) -> ACMElementIterator<T>

Returns an iterator over ACM elements.

Source

pub fn iter_from(&self, s: T) -> ACMElementIterator<T>

Source

pub fn ith<U: Into<T>>(&self, i: U) -> T

Returns the $n$th ACM element.

§Examples
let acm = acm::ArithmeticCongruenceMonoid::new(1, 4).unwrap();
assert_eq!(acm.ith(0), 1);
assert_eq!(acm.ith(1), 5);
assert_eq!(acm.ith(56), 225);
Source

pub fn index(&self, n: T) -> Option<T>

Get ACM element index of an integer.

Source

pub fn divisors(&self, n: T) -> Vec<T>

Returns the ACM element divisors of an integer n.

§Examples
let acm = acm::ArithmeticCongruenceMonoid::new(1, 4).unwrap();
assert_eq!(acm.divisors(225), [1, 9, 5, 25, 45, 225]);
Source

pub fn factor<U: Into<T>>(&mut self, n: U) -> &Vec<Vec<T>>

Returns a reference to the vector of ACM atom factorizations of an integer n. If n is not an element of the ACM then the vector will be empty. Because factorization results are stored internally to the ACM in order to reduce computational costs, using factor requires that the ACM binding be declared mutable.

§Examples
let mut acm = acm::ArithmeticCongruenceMonoid::new(3, 6).unwrap();
assert_eq!(acm.factor(1),   &[[]]);
assert_eq!(acm.factor(2),   &[[]; 0]);
assert_eq!(acm.factor(3),   &[[3]]);
assert_eq!(acm.factor(9),   &[[3, 3]]);
assert_eq!(acm.factor(225), &[[15, 15], [3, 75]]);
Source

pub fn atomic(&mut self, n: &T) -> bool

Returns true if n is atomic under the ACM (is an ACM element, and cannot be expressed as a product of smaller ACM atoms). Because of underlying usage of factor, using atomic requires that the ACM binding be declared mutable.

§Examples
let mut acm = acm::ArithmeticCongruenceMonoid::new(1, 4).unwrap();
assert!( acm.contains(&5)  &&  acm.atomic(&5));
assert!(!acm.contains(&15) && !acm.atomic(&15));
assert!( acm.contains(&25) && !acm.atomic(&25));

Trait Implementations§

Source§

impl<T> Debug for ArithmeticCongruenceMonoid<T>
where for<'b> T: TBounds + Ops<T, T> + Ops<&'b T, T> + AssignOps<&'b T> + Debug, for<'a, 'a, 'b> &'a T: Ops<T, T> + Ops<&'b T, T>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.