Trait malachite_base::num::arithmetic::traits::Subfactorial

source ·
pub trait Subfactorial {
    // Required method
    fn subfactorial(n: u64) -> Self;
}
Expand description

Computes the subfactorial of a u64. The subfactorial of a non-negative integer $n$ counts the number of derangements of $n$ elements, which are the permutations in which no element is fixed.

Required Methods§

source

fn subfactorial(n: u64) -> Self

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Subfactorial for u8

source§

fn subfactorial(n: u64) -> u8

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

source§

impl Subfactorial for u16

source§

fn subfactorial(n: u64) -> u16

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

source§

impl Subfactorial for u32

source§

fn subfactorial(n: u64) -> u32

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

source§

impl Subfactorial for u64

source§

fn subfactorial(n: u64) -> u64

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

source§

impl Subfactorial for u128

source§

fn subfactorial(n: u64) -> u128

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

source§

impl Subfactorial for usize

source§

fn subfactorial(n: u64) -> usize

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Implementors§