freeCodeCamp/guide/english/mathematics/factorials/index.md

2.2 KiB

title
Factorials

Factorials

Definition of Factorial

The factorial is to multiply it by every intiger lower then it ending at one. If the initial number is negative the result is infinity.

A factorial of n , a non-negative integer, is defined as:

n! = 1 * 2 * ... * (n - 1) * n

A special case arises when n = 0 . Namely, 0! = 1 .

Convenience of Factorials

The definition above provides you with convenience in certain computations. For example, factorials inside fractions can often be simplified as follows:

Example 1: 7! / 5! = (1 * 2 * 3 * 4 * 5 * 6 * 7) / (1 * 2 * 3 * 4 * 5) = 6 * 7 = 42

Example 2: (n + 1)! / n! = (1 * 2 * ... * n * (n + 1)) / (1 * 2 * ... * n) = n + 1

Alternative Definition

Alternatively, factorials can be defined as follows:

0! = 1

n! = n * (n - 1)! if n > 0

This recursive definition means the exact same as the traditional definition. Applying this to the second example above, we get:

(n + 1)! / n! = (n + 1) * n! / n! = n + 1

Aside: Extension to Non-Integers

Note that factorial as defined above applies only to non-negative integers. Actually, there is a generalization of factorials that extends to non-integers as well, which is the Gamma function. In particular, for any natural number n , you have n! = Gamma(n + 1) = n * Gamma(n) .

For more, see Extension of factorial to non-integer values of argument.

One tricky example that many may not know if 0! = 1. For futher proof see the link under More Information.

More Information:

Factorials