[][src]Struct acm::ArithmeticCongruenceMonoid

pub struct ArithmeticCongruenceMonoid { /* fields omitted */ }

Arithmetic congruence monoid implementation.

Methods

impl ArithmeticCongruenceMonoid[src]

pub fn new(a: u32, b: u32) -> Result<ArithmeticCongruenceMonoid, ACMError>[src]

Attempts to construct a new ACM with components a and b, requiring that a % b == a.pow(2) % 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());

pub fn a(&self) -> u32[src]

Returns the a component of the ACM.

pub fn b(&self) -> u32[src]

Returns the b component of the ACM.

pub fn element(&self, n: u32) -> u32[src]

Returns the nearst ACM element equal to or below n.

Examples

let acm = acm::ArithmeticCongruenceMonoid::new(1, 4).unwrap();
assert_eq!(acm.element(5), 5);
assert_eq!(acm.element(6), 5);

pub fn elements(&self, n: u32, s: u32) -> Vec<u32>[src]

Generate n ACM elements starting at nearest element below or equal to s.

Examples

let acm = acm::ArithmeticCongruenceMonoid::new(1, 4).unwrap();
assert_eq!(acm.elements(5, 1), [1, 5, 9, 13, 17]);

pub fn contains(&self, n: u32) -> bool[src]

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));

pub fn divisors(&self, n: u32) -> Vec<u32>[src]

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]);

pub fn factorize(&mut self, n: u32) -> &Vec<Vec<u32>>[src]

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 factorize requires that the ACM binding be declared mutable.

Examples

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

pub fn atomic(&mut self, n: u32) -> bool[src]

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 factorize, 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));

pub fn atoms(&mut self, n: u32, s: u32) -> Vec<u32>[src]

Returns a vector of the first n atoms of the ACM. Because of underlying usage of atomic, using atoms requires that the ACM binding be declared mutable.

Examples

let mut acm = acm::ArithmeticCongruenceMonoid::new(3, 6).unwrap();
assert_eq!(acm.atoms(5, acm.a()), [3, 15, 21, 33, 39]);

pub fn atom_density(&mut self, n: u32, s: u32) -> Vec<u32>[src]

Returns a vector of the density (distance between) the first n atoms of the ACM. Because of underlying usage of atoms, using atom_density requires that the ACM binding be declared mutable.

Examples

let mut acm = acm::ArithmeticCongruenceMonoid::new(1, 4).unwrap();
assert_eq!(acm.atom_density(10, acm.a()), [4, 4, 4, 4, 8, 4, 4, 4, 8]);

Trait Implementations

impl Debug for ArithmeticCongruenceMonoid[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]