Comb

Struct Comb 

Source
pub struct Comb<M: Module> { /* private fields */ }
Expand description

Useful struct to compute combinations

§Examples

use algonium::math::{Comb, Mod107, Mint107};
let comb: Comb<Mod107> = Comb::new(100);
assert_eq!(Mint107::from(24), comb.fact(4));
assert_eq!(Mint107::from(1), comb.fact(4) * comb.factinv(4));
assert_eq!(Mint107::from(12), comb.perm(4, 2));
assert_eq!(Mint107::from(6), comb.comb(4, 2));
assert_eq!(Mint107::from(10), comb.multi_comb(4, 2));

Implementations§

Source§

impl<M: Module> Comb<M>

Source

pub fn new(n: usize) -> Comb<M>

Create a object that provides effiecint computation of combinations for input smaller than n.

This requires O(n) time.

Source

pub fn fact(&self, n: u64) -> Mint<M>

n! = 1 * 2 * ... * n

O(1) if n is smaller than input in new method.

Source

pub fn factinv(&self, n: u64) -> Mint<M>

returns y such that n! * y == 1.

O(1) if n is smaller than input in new method.

Source

pub fn perm(&self, n: u64, r: u64) -> Mint<M>

nPr = n! / (n - r)!

O(1) if n and r are smaller than input in new method.

Source

pub fn comb(&self, n: u64, r: u64) -> Mint<M>

nCr = n! / (n - r)! / r!.

O(1) if n and r are smaller than input in new method.

Source

pub fn multi_comb(&self, n: u64, r: u64) -> Mint<M>

(n + k - 1)! / k!.

O(1) if n and r are smaller than input in new method.

Auto Trait Implementations§

§

impl<M> Freeze for Comb<M>

§

impl<M> RefUnwindSafe for Comb<M>
where M: RefUnwindSafe,

§

impl<M> Send for Comb<M>
where M: Send,

§

impl<M> Sync for Comb<M>
where M: Sync,

§

impl<M> Unpin for Comb<M>
where M: Unpin,

§

impl<M> UnwindSafe for Comb<M>
where M: UnwindSafe,

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.