Skip to main content

Discrete Math with SageMath: Learn math with open-source software

Section 3.1 Combinatorics

Subsection 3.1.1 Factorial Function

The factorial of a non-negative integer \(n\text{,}\) denoted by \(n!\text{,}\) is the product of all positive integers less than or equal to \(n\text{.}\)
Compute the factorial of \(5\text{:}\)

Subsection 3.1.2 Combinations

The combination \((n, k)\) is an unordered selection of \(k\) objects from a set of \(n\) objects.
Calculate the number of ways to choose \(3\) elements from a set of \(5\text{:}\)
List the combinations:
The binomial() function provides an alternative method to compute the number of combinations.

Subsection 3.1.3 Permutations

A permutation \((n, k)\) is an ordered selection of \(k\) objects from a set of \(n\) objects.
To calculate the number of ways to choose \(3\) elements from a set of \(5\) when the order matters, use the Permutations() method.
List the permutations:
When \(n = k\text{,}\) we can calculate permutations of \(n\) elements.
Calculate the number of permutations of a set with \(3\) elements:
List the permutations:
The following is an example of permutations of specified elements:
Choose \(2\text{:}\)