Digital Garden
Maths
Common Functions
Factorial

Factorial

The factorial is a function that is defined only for non-negative integers nn. The factorial of a number is written as n!n!, and is the product of all positive integers less than or equal to nn. Important to note is that 0!=10! = 1 and 1!=11! = 1. For n>1n > 1, the factorial is defined as:

n!=nβ‹…(nβˆ’1)β‹…(nβˆ’2)β‹…...β‹…2β‹…1n! = n \cdot (n-1) \cdot (n-2)\cdot ... \cdot 2 \cdot 1

or alternatively,

n!=∏x=1nxn! = \prod_{x=1}^{n}{x}
Example
nnn!n!
0011
1111
222β‹…1=22 \cdot 1 = 2
333β‹…2β‹…1=63 \cdot 2 \cdot 1 = 6
444β‹…3β‹…2β‹…1=244 \cdot 3 \cdot 2 \cdot 1 = 24
555β‹…4β‹…3β‹…2β‹…1=1205 \cdot 4 \cdot 3 \cdot 2 \cdot 1 = 120
nnnβ‹…(nβˆ’1)β‹…(nβˆ’2)β‹…...β‹…2β‹…1n \cdot (n-1) \cdot (n-2)\cdot ... \cdot 2 \cdot 1
Why is $0! = 1$?

There are many reasons why 0!0! must be 11, most of them being related to combinatorics and counting problems. However, there is an intuitive explanation that can be given. Notice above that n!=nβ‹…(nβˆ’1)!n! = n \cdot (n-1)!. This means that the factorial of a number is the product of that number and the factorial of the number that is one less than it.

For the above to hold true for 1!1! we need to have 0!=10! = 1 because if 0!=00!=0, then 1!1! would be:

1!=1β‹…(1βˆ’1)!=1β‹…0!=1β‹…0=01! = 1 \cdot (1-1)! = 1 \cdot 0! = 1 \cdot 0 = 0

and all other factorials would also be 00 as well. Therefore, 0!0! must be 11.

Sterlings Approximation

n!β‰ˆ2Ο€n(ne)nn! \approx \sqrt{2\pi n} \left(\frac{n}{e}\right)^n