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>
impl<M: Module> Comb<M>
Sourcepub fn new(n: usize) -> Comb<M>
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.
Sourcepub fn fact(&self, n: u64) -> Mint<M>
pub fn fact(&self, n: u64) -> Mint<M>
n! = 1 * 2 * ... * n
O(1) if n is smaller than input in new method.
Sourcepub fn factinv(&self, n: u64) -> Mint<M>
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.
Sourcepub fn perm(&self, n: u64, r: u64) -> Mint<M>
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.
Sourcepub fn comb(&self, n: u64, r: u64) -> Mint<M>
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.
Sourcepub fn multi_comb(&self, n: u64, r: u64) -> Mint<M>
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> 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