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>
impl<T> ArithmeticCongruenceMonoid<T>
Sourcepub fn new(a: T, b: T) -> Result<ArithmeticCongruenceMonoid<T>, ACMError<T>>
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());Sourcepub fn contains(&self, x: &T) -> bool
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));Sourcepub fn nearest<U: Into<T>>(&self, s: U) -> T
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);Sourcepub fn iter(&self) -> ACMElementIterator<T> ⓘ
pub fn iter(&self) -> ACMElementIterator<T> ⓘ
Returns an iterator over ACM elements.
pub fn iter_from(&self, s: T) -> ACMElementIterator<T> ⓘ
Sourcepub fn ith<U: Into<T>>(&self, i: U) -> T
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);Sourcepub fn divisors(&self, n: T) -> Vec<T>
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]);Sourcepub fn factor<U: Into<T>>(&mut self, n: U) -> &Vec<Vec<T>>
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]]);Sourcepub fn atomic(&mut self, n: &T) -> bool
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));