liveBook · Manning

Factorial

As explained in Statistics Every Programmer Needs

A factorial is the product of all positive integers from a given natural number down to one.

A factorial is the product of all positive integers from a natural number down to one. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120 and 3! = 6. section 2.2.3

Factorials count ordered selections without replacement: n! / (n − r)! accounts for the progressively smaller number of available choices. With five runners and three positions, the result is 60 possible rankings. section 2.2.3

Computing a permutation count in Python

Use math.factorial(n) / math.factorial(n − r) to calculate the number of ordered selections without replacement; for n = 5 and r = 3, Python returns 60. section 2.2.3

>>> import math
>>> permutations = math.factorial(n) / math.factorial(n - r)
>>> print(f'Number of permutations without replacement: '
>>>       f'{permutations}')
Number of permutations without replacement: 60

Python listing for calculating permutations without replacement with factorials. section 2.2.3

How Statistics Every Programmer Needs covers it

How deep it goes
Defines factorials, works through numerical examples, derives a permutation formula, and implements it in Python.
Examples
Uses 5!, 3!, five runners competing for three positions, and Python results for 60 permutations.
What it assumes
Assumes natural numbers and multiplication while introducing factorial notation through counting examples.
What you can do after
Apply factorials via Python's math.factorial to calculate permutation counts without replacement.
How it connects
Connects factorials to permutations, combinations, and replacement.

Also explained in

Compare how 2 books explain factorial →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.