polymerist.maths.combinatorics.numbers

Utilities for calculating fundamental combinatorial numbers

Attributes

choose

Functions

alt_sign(→ int)

Returns the value of -1^n (useful for alternating sums)

binomial_coeff(→ float)

Calculates a generalized binomial coefficient

multiset_coeff(→ float)

Calculates a multiset coefficient

multinomial_coeff(→ float)

Calculate the multinomial coefficient of a set of multiplicities

multinomial_coeff_native(→ float)

Calculate the multinomial coefficient of a set of multiplicities

catalan(→ float)

Calculates the n-th Catalan number

pentagonal(→ float)

Calculates the n-th pentagonal number

stirling_second(→ float)

Calculates the Stirling number of the second kind S(n, k)

stirling_first(→ float)

Calculates the Stirling number of the first kind c(n, k)

bell(→ float)

Calculates the n-th Bell number

bernoulli(→ int)

Calculates the n-th Bernoulli number

bernoulli_up_to(→ list[fractions.Fraction])

Computes a list of the first N Bernoulli numbers using the Akiyama-Tanigawa algorithm

count_labelled_graphs(→ int)

Gives number of all labelled graphs on N nodes

count_connected_labelled_graphs(→ float)

Gives array of number labelled graphs with one connected component on N nodes

Module Contents

polymerist.maths.combinatorics.numbers.alt_sign(n: int) int[source]

Returns the value of -1^n (useful for alternating sums)

polymerist.maths.combinatorics.numbers.binomial_coeff(n: complex, k: int) float[source]

Calculates a generalized binomial coefficient Counts the number of distinct ways to make and unordered selection of k elemnts from a set of n items

polymerist.maths.combinatorics.numbers.choose
polymerist.maths.combinatorics.numbers.multiset_coeff(n: int, k: int) float[source]

Calculates a multiset coefficient Counts the number of ways to form a multiset of cardinality n from a support of size k

polymerist.maths.combinatorics.numbers.multinomial_coeff(multips: Iterable[int]) float[source]

Calculate the multinomial coefficient of a set of multiplicities Counts the number of distinct permutations of a multiset with given multiplicites

polymerist.maths.combinatorics.numbers.multinomial_coeff_native(multips: Iterable[int]) float[source]

Calculate the multinomial coefficient of a set of multiplicities Counts the number of distinct permutations of a multiset with given multiplicites

Native Python implementation of multinomial_coeff() which is slightly slower but requires no imports

polymerist.maths.combinatorics.numbers.catalan(n: int) float[source]

Calculates the n-th Catalan number Counts dozens of different things, including the number of monotonic 2D random walks and the number of valid (i.e. fully closed) groupings of n pairs of parentheses

polymerist.maths.combinatorics.numbers.pentagonal(n: int) float[source]

Calculates the n-th pentagonal number Counts the number of points in n “concentric” pentagon figures which share a corner vertex

Related to the generating function for numbers of partitions

polymerist.maths.combinatorics.numbers.stirling_second(n: int, k: int) float[source]

Calculates the Stirling number of the second kind S(n, k) Counts the number of ways to partition n objects into k non-empty pairwise-disjoint subsets

Recurrence used as listed in NIST DLMF (https://dlmf.nist.gov/26.8)

polymerist.maths.combinatorics.numbers.stirling_first(n: int, k: int) float[source]

Calculates the Stirling number of the first kind c(n, k) Counts the number of ways to to decompose a permutation of n objects into k cycles

Recurrence used as listed in Abramowitz ans Stegun (https://www.convertit.com/Go/ConvertIt/Reference/AMS55.ASP?Res=150&Page=825)

polymerist.maths.combinatorics.numbers.bell(n: int) float[source]

Calculates the n-th Bell number Counts the number of ways to partition n objects into any number of non-empty pairwise-disjoint subsets

polymerist.maths.combinatorics.numbers.bernoulli(n: int) int[source]

Calculates the n-th Bernoulli number Related to the sums of powers of integers (via Faulhalber’s formula)

polymerist.maths.combinatorics.numbers.bernoulli_up_to(N: int) list[fractions.Fraction][source]

Computes a list of the first N Bernoulli numbers using the Akiyama-Tanigawa algorithm

polymerist.maths.combinatorics.numbers.count_labelled_graphs(N: int) int[source]

Gives number of all labelled graphs on N nodes

polymerist.maths.combinatorics.numbers.count_connected_labelled_graphs(n: int) float[source]

Gives array of number labelled graphs with one connected component on N nodes