Examples#

This gallery walks through every public feature of mathematicskit.combinatorics: permutation/combination counting and generation, Pascal’s triangle, integer partitions, the inclusion-exclusion principle, and Stirling/ Catalan/Bell numbers.

See also the narrative tutorial:

Each script in this gallery is self-contained and can be run directly with python examples/combinatorics/<section>/<script>.py.

Sections#

  • counting – permutation/combination counting and sequence generation, and multinomial coefficients.

  • pascals_triangle – the binomial-coefficient recurrence.

  • partitions – the partition function, enumeration, and Young diagrams.

  • inclusion_exclusion – the inclusion-exclusion principle and derangements.

  • special_numbers – Stirling numbers, Catalan numbers, and Bell numbers.

Counting#

Permutation/combination counting and generation, and multinomial coefficients.

Counting poker hands

Counting poker hands

Gersonides’ counting formulas

Gersonides' counting formulas

Combinatorial designs#

Latin squares and orthogonal pairs.

Euler’s officers: orthogonal Latin squares

Euler's officers: orthogonal Latin squares

Extremal combinatorics#

Ramsey’s theorem and the Erdős-Szekeres theorem: order that must appear in any large enough structure.

Ramsey’s theorem: R(3,3) = 6

Ramsey's theorem: R(3,3) = 6

The Erdős-Szekeres theorem: monotone subsequences

The Erdős-Szekeres theorem: monotone subsequences

Inclusion-exclusion#

The inclusion-exclusion principle and derangements.

The hat-check problem: derangements via inclusion-exclusion

The hat-check problem: derangements via inclusion-exclusion

Matchings#

Hall’s marriage theorem and bipartite matchings.

Hall’s marriage theorem

Hall's marriage theorem

Necklaces#

Pólya enumeration: counting colorings up to symmetry.

Pólya’s enumeration theorem: necklaces and bracelets

Pólya's enumeration theorem: necklaces and bracelets

Integer partitions#

The partition function, enumeration, and Young diagrams.

Integer partitions, the partition function, and Young diagrams

Integer partitions, the partition function, and Young diagrams

Pascal’s triangle#

The binomial-coefficient recurrence, built by hand.

Pascal’s triangle vs. scipy-computed binomial coefficients

Pascal's triangle vs. scipy-computed binomial coefficients

Integer sequences#

Fibonacci numbers, Bernoulli numbers and sums of powers, and Gray codes.

Fibonacci’s rabbits and domino tilings

Fibonacci's rabbits and domino tilings

Jacob Bernoulli’s numbers and sums of powers

Jacob Bernoulli's numbers and sums of powers

Gray codes: counting one bit at a time

Gray codes: counting one bit at a time

Special numbers#

Stirling numbers, Bell numbers, and Catalan numbers.

Stirling’s numbers: cycles, set partitions, and Bell numbers

Stirling's numbers: cycles, set partitions, and Bell numbers

Catalan numbers: Euler’s polygon triangulations and Catalan’s brackets

Catalan numbers: Euler's polygon triangulations and Catalan's brackets

Labeled trees#

Cayley’s formula and Prüfer codes.

Cayley’s formula via Prüfer codes

Cayley's formula via Prüfer codes

Gallery generated by Sphinx-Gallery