Files
freeCodeCamp/guide/english/mathematics/factorial-function/index.md
Alexander Molnar b7e6591a6c Added content to factorial stub (#34330)
* Added content to stub

Added definition, examples and some uses as well as computational info and interesting formulas that occur.

* Update index.md
2019-03-12 01:04:42 +05:30

3.8 KiB
Raw Blame History

title
title
Factorial Function

Factorial Function

The factorial function is a useful function in combinatorics for counting things such as permutations as well as the definition of Euler's number, the base of the natural logarithm, and appears in many other areas.

For any positive integer n we define the factorial of n, denoted n!, as the product

n! = 1 × 2 × 3 × ... × (n-2) × (n-1) × n.

For example,

  • 1! = 1,
  • 2! = 2 × 1 = 2,
  • 5! = 5 × 4 × 3 × 2 × 1 = 120.

Notice this function satisfies the recurrence n! = n × (n-1)! which is a particularly useful viewpoint to use in many areas of mathematics allowing the factorial to be generalized to non-integer values. (For example, this recurrence can be extended with (-1/2)! = sqrt(π).)

As convention, the empty product, that is, the product of nothing, is usually taken to be 1, so with this definition we have 0! = 1. This convention makes sense in all the uses below.

Uses

If you have n different objects and want to know how many ways they can be arranged in a row, there are n choices for the first object, then (after picking the first object) n-1 choices for the second object, n-2 choices for the third object, etc... and so we see there are n! ways to arrange the objects.

Another common method of counting involves combinations which are a given by a quotient of factorials. The combinations then come up in, for example, the binomial formula, the coefficients in the expansion of

(x + y)n

for any integer n.

Factorials also appear in many useful representations of functions, including approximations of derivatives in Taylor's formula, exponential and trigonometric functions.

Computation

Computing the factorial of a positive integer is incredibly straightforward, it is simply a product of all positive integers less than or equal to itself. However, this is not an efficient approach for very large numbers, and such a product will be incredibly large as well, so it is usually better to use an approximation when looking to compute very large factorials. One simple approximation is Stirling's approximation, namely,

n! ~ sqrt(2πn)[n/e]n

so, for example,

10100! ~ sqrt(2π10100)[10100/e]10100 ~ e-10100 × 1010102.

Interesting formulas

As mentioned above, the factorial can be used to defined Euler's number, namely

Σ 1/n! = e

With a slight adjustment we have the fascinating sum

Σ 1/[(n+2)n!] = 1

Lastly, the generalization of the factorial to non-integer values comes from the formula

n! = ∫0 tze-t dt

This formula is where the value for (-1/2)! above comes from, since

0 t-1/2e-t dt = sqrt(π)

The recurrence now tells us that each half integer factorial is just a multiple of sqrt(π) as, for example

(3/2)! = (3/2)(1/2)! = (3/2)(1/2)*(-1/2)! = 3sqrt(π)/4