HOME

TheInfoList



OR:

In
mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
, the factorial of a non-negative denoted is the product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial: \begin n! &= n \times (n-1) \times (n-2) \times (n-3) \times \cdots \times 3 \times 2 \times 1 \\ &= n\times(n-1)!\\ \end For example, 5! = 5\times 4! = 5 \times 4 \times 3 \times 2 \times 1 = 120. The value of 0! is 1, according to the convention for an empty product. Factorials have been discovered in several ancient cultures, notably in
Indian mathematics Indian mathematics emerged in the Indian subcontinent from 1200 BCE until the end of the 18th century. In the classical period of Indian mathematics (400 CE to 1200 CE), important contributions were made by scholars like Aryabhata, Brahmagupta ...
in the canonical works of Jain literature, and by Jewish mystics in the Talmudic book '' Sefer Yetzirah''. The factorial operation is encountered in many areas of mathematics, notably in
combinatorics Combinatorics is an area of mathematics primarily concerned with counting, both as a means and an end in obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many a ...
, where its most basic use counts the possible distinct
sequence In mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order matters. Like a set, it contains members (also called ''elements'', or ''terms''). The number of elements (possibly infinite) is called ...
s – the
permutation In mathematics, a permutation of a set is, loosely speaking, an arrangement of its members into a sequence or linear order, or if the set is already ordered, a rearrangement of its elements. The word "permutation" also refers to the act or pro ...
s – of n distinct objects: there In
mathematical analysis Analysis is the branch of mathematics dealing with continuous functions, limits, and related theories, such as differentiation, integration, measure, infinite sequences, series, and analytic functions. These theories are usually studied ...
, factorials are used in
power series In mathematics, a power series (in one variable) is an infinite series of the form \sum_^\infty a_n \left(x - c\right)^n = a_0 + a_1 (x - c) + a_2 (x - c)^2 + \dots where ''an'' represents the coefficient of the ''n''th term and ''c'' is a con ...
for the
exponential function The exponential function is a mathematical function denoted by f(x)=\exp(x) or e^x (where the argument is written as an exponent). Unless otherwise specified, the term generally refers to the positive-valued function of a real variable, ...
and other functions, and they also have applications in
algebra Algebra () is one of the broad areas of mathematics. Roughly speaking, algebra is the study of mathematical symbols and the rules for manipulating these symbols in formulas; it is a unifying thread of almost all of mathematics. Elementary ...
,
number theory Number theory (or arithmetic or higher arithmetic in older usage) is a branch of pure mathematics devoted primarily to the study of the integers and integer-valued functions. German mathematician Carl Friedrich Gauss (1777–1855) said, "Ma ...
,
probability theory Probability theory is the branch of mathematics concerned with probability. Although there are several different probability interpretations, probability theory treats the concept in a rigorous mathematical manner by expressing it through a set ...
, and
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
. Much of the mathematics of the factorial function was developed beginning in the late 18th and early 19th centuries. Stirling's approximation provides an accurate approximation to the factorial of large numbers, showing that it grows more quickly than
exponential growth Exponential growth is a process that increases quantity over time. It occurs when the instantaneous rate of change (that is, the derivative) of a quantity with respect to time is proportional to the quantity itself. Described as a function, a ...
. Legendre's formula describes the exponents of the prime numbers in a
prime factorization In number theory, integer factorization is the decomposition of a composite number into a product of smaller integers. If these factors are further restricted to prime numbers, the process is called prime factorization. When the numbers are s ...
of the factorials, and can be used to count the trailing zeros of the factorials. Daniel Bernoulli and
Leonhard Euler Leonhard Euler ( , ; 15 April 170718 September 1783) was a Swiss mathematician, physicist, astronomer, geographer, logician and engineer who founded the studies of graph theory and topology and made pioneering and influential discoveries ...
interpolated the factorial function to a continuous function of
complex number In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the fo ...
s, except at the negative integers, the (offset)
gamma function In mathematics, the gamma function (represented by , the capital letter gamma from the Greek alphabet) is one commonly used extension of the factorial function to complex numbers. The gamma function is defined for all complex numbers excep ...
. Many other notable functions and number sequences are closely related to the factorials, including the
binomial coefficient In mathematics, the binomial coefficients are the positive integers that occur as coefficients in the binomial theorem. Commonly, a binomial coefficient is indexed by a pair of integers and is written \tbinom. It is the coefficient of the t ...
s,
double factorial In mathematics, the double factorial or semifactorial of a number , denoted by , is the product of all the integers from 1 up to that have the same parity (odd or even) as . That is, :n!! = \prod_^ (n-2k) = n (n-2) (n-4) \cdots. For even , the ...
s,
falling factorial In mathematics, the falling factorial (sometimes called the descending factorial, falling sequential product, or lower factorial) is defined as the polynomial :\begin (x)_n = x^\underline &= \overbrace^ \\ &= \prod_^n(x-k+1) = \prod_^(x-k) \,. \e ...
s, primorials, and subfactorials. Implementations of the factorial function are commonly used as an example of different
computer programming Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as anal ...
styles, and are included in scientific calculators and scientific computing software libraries. Although directly computing large factorials using the product formula or recurrence is not efficient, faster algorithms are known, matching to within a constant factor the time for fast multiplication algorithms for numbers with the same number of digits.


History

The concept of factorials has arisen independently in many cultures: *In
Indian mathematics Indian mathematics emerged in the Indian subcontinent from 1200 BCE until the end of the 18th century. In the classical period of Indian mathematics (400 CE to 1200 CE), important contributions were made by scholars like Aryabhata, Brahmagupta ...
, one of the earliest known descriptions of factorials comes from the Anuyogadvāra-sūtra, one of the canonical works of Jain literature, which has been assigned dates varying from 300 BCE to 400 CE. It separates out the sorted and reversed order of a set of items from the other ("mixed") orders, evaluating the number of mixed orders by subtracting two from the usual product formula for the factorial. The product rule for permutations was also described by 6th-century CE Jain monk Jinabhadra.. Revised by K. S. Shukla from a paper in '' Indian Journal of History of Science'' 27 (3): 231–249, 1992, . See p. 363. Hindu scholars have been using factorial formulas since at least 1150, when
Bhāskara II Bhāskara II (c. 1114–1185), also known as Bhāskarāchārya ("Bhāskara, the teacher"), and as Bhāskara II to avoid confusion with Bhāskara I, was an Indian mathematician and astronomer. From verses, in his main work, Siddhānta Shiroma ...
mentioned factorials in his work
Līlāvatī ''Līlāvatī'' is Indian mathematician Bhāskara II's treatise on mathematics, written in 1150 AD. It is the first volume of his main work, the ''Siddhānta Shiromani'', alongside the '' Bijaganita'', the ''Grahaganita'' and the ''Golādhyāya' ...
, in connection with a problem of how many ways
Vishnu Vishnu ( ; , ), also known as Narayana and Hari, is one of the principal deities of Hinduism. He is the supreme being within Vaishnavism, one of the major traditions within contemporary Hinduism. Vishnu is known as "The Preserver" withi ...
could hold his four characteristic objects (a conch shell, discus, mace, and
lotus flower ''Nelumbo nucifera'', also known as sacred lotus, Laxmi lotus, Indian lotus, or simply lotus, is one of two extant species of aquatic plant in the family Nelumbonaceae. It is sometimes colloquially called a water lily, though this more often re ...
) in his four hands, and a similar problem for a ten-handed god. *In the mathematics of the Middle East, the Hebrew mystic book of creation '' Sefer Yetzirah'', from the Talmudic period (200 to 500 CE), lists factorials up to 7! as part of an investigation into the number of words that can be formed from the
Hebrew alphabet The Hebrew alphabet ( he, אָלֶף־בֵּית עִבְרִי, ), known variously by scholars as the Ktav Ashuri, Jewish script, square script and block script, is an abjad script used in the writing of the Hebrew language and other Jewi ...
. Factorials were also studied for similar reasons by 8th-century Arab grammarian Al-Khalil ibn Ahmad al-Farahidi. Arab mathematician
Ibn al-Haytham Ḥasan Ibn al-Haytham, Latinized as Alhazen (; full name ; ), was a medieval mathematician, astronomer, and physicist of the Islamic Golden Age from present-day Iraq.For the description of his main fields, see e.g. ("He is one of the pr ...
(also known as Alhazen, c. 965 – c. 1040) was the first to formulate
Wilson's theorem In algebra and number theory, Wilson's theorem states that a natural number ''n'' > 1 is a prime number if and only if the product of all the positive integers less than ''n'' is one less than a multiple of ''n''. That is (using the notations of m ...
connecting the factorials with the
prime number A prime number (or a prime) is a natural number greater than 1 that is not a Product (mathematics), product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime ...
s. *In Europe, although
Greek mathematics Greek mathematics refers to mathematics texts and ideas stemming from the Archaic through the Hellenistic and Roman periods, mostly extant from the 7th century BC to the 4th century AD, around the shores of the Eastern Mediterranean. Greek mathe ...
included some combinatorics, and
Plato Plato ( ; grc-gre, Πλάτων ; 428/427 or 424/423 – 348/347 BC) was a Greek philosopher born in Athens during the Classical period in Ancient Greece. He founded the Platonist school of thought and the Academy, the first institution ...
famously used 5040 (a factorial) as the population of an ideal community, in part because of its divisibility properties, there is no direct evidence of ancient Greek study of factorials. Instead, the first work on factorials in Europe was by Jewish scholars such as Shabbethai Donnolo, explicating the Sefer Yetzirah passage. In 1677, British author Fabian Stedman described the application of factorials to
change ringing Change ringing is the art of ringing a set of tuned bells in a tightly controlled manner to produce precise variations in their successive striking sequences, known as "changes". This can be by method ringing in which the ringers commit to memor ...
, a musical art involving the ringing of several tuned bells. From the late 15th century onward, factorials became the subject of study by western mathematicians. In a 1494 treatise, Italian mathematician
Luca Pacioli Fra Luca Bartolomeo de Pacioli (sometimes ''Paccioli'' or ''Paciolo''; 1447 – 19 June 1517) was an Italian mathematician, Franciscan friar, collaborator with Leonardo da Vinci, and an early contributor to the field now known as accounting ...
calculated factorials up to 11!, in connection with a problem of dining table arrangements. Christopher Clavius discussed factorials in a 1603 commentary on the work of Johannes de Sacrobosco, and in the 1640s, French polymath
Marin Mersenne Marin Mersenne, OM (also known as Marinus Mersennus or ''le Père'' Mersenne; ; 8 September 1588 – 1 September 1648) was a French polymath whose works touched a wide variety of fields. He is perhaps best known today among mathematicians for ...
published large (but not entirely correct) tables of factorials, up to 64!, based on the work of Clavius. The
power series In mathematics, a power series (in one variable) is an infinite series of the form \sum_^\infty a_n \left(x - c\right)^n = a_0 + a_1 (x - c) + a_2 (x - c)^2 + \dots where ''an'' represents the coefficient of the ''n''th term and ''c'' is a con ...
for the
exponential function The exponential function is a mathematical function denoted by f(x)=\exp(x) or e^x (where the argument is written as an exponent). Unless otherwise specified, the term generally refers to the positive-valued function of a real variable, ...
, with the reciprocals of factorials for its coefficients, was first formulated in 1676 by
Isaac Newton Sir Isaac Newton (25 December 1642 – 20 March 1726/27) was an English mathematician, physicist, astronomer, alchemist, Theology, theologian, and author (described in his time as a "natural philosophy, natural philosopher"), widely ...
in a letter to
Gottfried Wilhelm Leibniz Gottfried Wilhelm (von) Leibniz . ( – 14 November 1716) was a German polymath active as a mathematician, philosopher, scientist and diplomat. He is one of the most prominent figures in both the history of philosophy and the history of ...
. Other important works of early European mathematics on factorials include extensive coverage in a 1685 treatise by
John Wallis John Wallis (; la, Wallisius; ) was an English clergyman and mathematician who is given partial credit for the development of infinitesimal calculus. Between 1643 and 1689 he served as chief cryptographer for Parliament and, later, the royal ...
, a study of their approximate values for large values of n by
Abraham de Moivre Abraham de Moivre FRS (; 26 May 166727 November 1754) was a French mathematician known for de Moivre's formula, a formula that links complex numbers and trigonometry, and for his work on the normal distribution and probability theory. He move ...
in 1721, a 1729 letter from James Stirling to de Moivre stating what became known as Stirling's approximation, and work at the same time by Daniel Bernoulli and
Leonhard Euler Leonhard Euler ( , ; 15 April 170718 September 1783) was a Swiss mathematician, physicist, astronomer, geographer, logician and engineer who founded the studies of graph theory and topology and made pioneering and influential discoveries ...
formulating the continuous extension of the factorial function to the
gamma function In mathematics, the gamma function (represented by , the capital letter gamma from the Greek alphabet) is one commonly used extension of the factorial function to complex numbers. The gamma function is defined for all complex numbers excep ...
. Adrien-Marie Legendre included Legendre's formula, describing the exponents in the factorization of factorials into prime powers, in an 1808 text on
number theory Number theory (or arithmetic or higher arithmetic in older usage) is a branch of pure mathematics devoted primarily to the study of the integers and integer-valued functions. German mathematician Carl Friedrich Gauss (1777–1855) said, "Ma ...
. The notation n! for factorials was introduced by the French mathematician Christian Kramp in 1808. Many other notations have also been used. Another later notation, in which the argument of the factorial was half-enclosed by the left and bottom sides of a box, was popular for some time in Britain and America but fell out of use, perhaps because it is difficult to typeset. The word "factorial" (originally French: ''factorielle'') was first used in 1800 by Louis François Antoine Arbogast, in the first work on Faà di Bruno's formula, but referring to a more general concept of products of arithmetic progressions. The "factors" that this name refers to are the terms of the product formula for the factorial.


Definition

The factorial function of a positive integer n is defined by the product of all positive integers not greater than n n! = 1 \cdot 2 \cdot 3 \cdots (n-2) \cdot (n-1) \cdot n. This may be written more concisely in product notation as n! = \prod_^n i. If this product formula is changed to keep all but the last term, it would define a product of the same form, for a smaller factorial. This leads to a recurrence relation, according to which each value of the factorial function can be obtained by multiplying the previous value n! = n\cdot (n-1)!. For example,


Factorial of zero

The factorial or in symbols, There are several motivations for this definition: * For the definition of n! as a product involves the product of no numbers at all, and so is an example of the broader convention that the empty product, a product of no factors, is equal to the multiplicative identity. * There is exactly one permutation of zero objects: with nothing to permute, the only rearrangement is to do nothing. * This convention makes many identities in
combinatorics Combinatorics is an area of mathematics primarily concerned with counting, both as a means and an end in obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many a ...
valid for all valid choices of their parameters. For instance, the number of ways to choose all n elements from a set of n is \tbinom = \tfrac = 1, a
binomial coefficient In mathematics, the binomial coefficients are the positive integers that occur as coefficients in the binomial theorem. Commonly, a binomial coefficient is indexed by a pair of integers and is written \tbinom. It is the coefficient of the t ...
identity that would only be valid * With the recurrence relation for the factorial remains valid Therefore, with this convention, a recursive computation of the factorial needs to have only the value for zero as a base case, simplifying the computation and avoiding the need for additional special cases. * Setting 0!=1 allows for the compact expression of many formulae, such as the
exponential function The exponential function is a mathematical function denoted by f(x)=\exp(x) or e^x (where the argument is written as an exponent). Unless otherwise specified, the term generally refers to the positive-valued function of a real variable, ...
, as a
power series In mathematics, a power series (in one variable) is an infinite series of the form \sum_^\infty a_n \left(x - c\right)^n = a_0 + a_1 (x - c) + a_2 (x - c)^2 + \dots where ''an'' represents the coefficient of the ''n''th term and ''c'' is a con ...
: * This choice matches the
gamma function In mathematics, the gamma function (represented by , the capital letter gamma from the Greek alphabet) is one commonly used extension of the factorial function to complex numbers. The gamma function is defined for all complex numbers excep ...
and the gamma function must have this value to be a
continuous function In mathematics, a continuous function is a function such that a continuous variation (that is a change without jump) of the argument induces a continuous variation of the value of the function. This means that there are no abrupt changes in val ...
.


Applications

The earliest uses of the factorial function involve counting
permutations In mathematics, a permutation of a set is, loosely speaking, an arrangement of its members into a sequence or linear order, or if the set is already ordered, a rearrangement of its elements. The word "permutation" also refers to the act or p ...
: there are n! different ways of arranging n distinct objects into a sequence. Factorials appear more broadly in many formulas in
combinatorics Combinatorics is an area of mathematics primarily concerned with counting, both as a means and an end in obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many a ...
, to account for different orderings of objects. For instance the
binomial coefficient In mathematics, the binomial coefficients are the positive integers that occur as coefficients in the binomial theorem. Commonly, a binomial coefficient is indexed by a pair of integers and is written \tbinom. It is the coefficient of the t ...
s \tbinom count the combinations (subsets of from a set with and can be computed from factorials using the formula \binom=\frac. The Stirling numbers of the first kind sum to the factorials, and count the permutations grouped into subsets with the same numbers of cycles. Another combinatorial application is in counting derangements, permutations that do not leave any element in its original position; the number of derangements of n items is the nearest integer In
algebra Algebra () is one of the broad areas of mathematics. Roughly speaking, algebra is the study of mathematical symbols and the rules for manipulating these symbols in formulas; it is a unifying thread of almost all of mathematics. Elementary ...
, the factorials arise through the binomial theorem, which uses binomial coefficients to expand powers of sums. They also occur in the coefficients used to relate certain families of polynomials to each other, for instance in Newton's identities for symmetric polynomials. Their use in counting permutations can also be restated algebraically: the factorials are the
orders Order, ORDER or Orders may refer to: * Categorization, the process in which ideas and objects are recognized, differentiated, and understood * Heterarchy, a system of organization wherein the elements have the potential to be ranked a number of ...
of finite symmetric groups. In
calculus Calculus, originally called infinitesimal calculus or "the calculus of infinitesimals", is the mathematics, mathematical study of continuous change, in the same way that geometry is the study of shape, and algebra is the study of generalizati ...
, factorials occur in Faà di Bruno's formula for chaining higher derivatives. In
mathematical analysis Analysis is the branch of mathematics dealing with continuous functions, limits, and related theories, such as differentiation, integration, measure, infinite sequences, series, and analytic functions. These theories are usually studied ...
, factorials frequently appear in the denominators of
power series In mathematics, a power series (in one variable) is an infinite series of the form \sum_^\infty a_n \left(x - c\right)^n = a_0 + a_1 (x - c) + a_2 (x - c)^2 + \dots where ''an'' represents the coefficient of the ''n''th term and ''c'' is a con ...
, most notably in the series for the
exponential function The exponential function is a mathematical function denoted by f(x)=\exp(x) or e^x (where the argument is written as an exponent). Unless otherwise specified, the term generally refers to the positive-valued function of a real variable, ...
, e^x=1+\frac+\frac+\frac+\cdots=\sum_^\frac, and in the coefficients of other
Taylor series In mathematics, the Taylor series or Taylor expansion of a function is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For most common functions, the function and the sum of its Taylor ser ...
(in particular those of the trigonometric and hyperbolic functions), where they cancel factors of n! coming from the This usage of factorials in power series connects back to analytic combinatorics through the exponential generating function, which for a combinatorial class with n_i elements of is defined as the power series \sum_^ \frac. In
number theory Number theory (or arithmetic or higher arithmetic in older usage) is a branch of pure mathematics devoted primarily to the study of the integers and integer-valued functions. German mathematician Carl Friedrich Gauss (1777–1855) said, "Ma ...
, the most salient property of factorials is the divisibility of n! by all positive integers up described more precisely for prime factors by Legendre's formula. It follows that arbitrarily large
prime number A prime number (or a prime) is a natural number greater than 1 that is not a Product (mathematics), product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime ...
s can be found as the prime factors of the numbers n!\pm 1, leading to a proof of Euclid's theorem that the number of primes is infinite. When n!\pm 1 is itself prime it is called a factorial prime; relatedly, Brocard's problem, also posed by
Srinivasa Ramanujan Srinivasa Ramanujan (; born Srinivasa Ramanujan Aiyangar, ; 22 December 188726 April 1920) was an Indian mathematician. Though he had almost no formal training in pure mathematics, he made substantial contributions to mathematical analysis, ...
, concerns the existence of
square number In mathematics, a square number or perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 9 is a square number, since it equals and can be written as . The u ...
s of the form In contrast, the numbers n!+2,n!+3,\dots n!+n must all be composite, proving the existence of arbitrarily large prime gaps. An elementary proof of Bertrand's postulate on the existence of a prime in any interval of the one of the first results of
Paul Erdős Paul Erdős ( hu, Erdős Pál ; 26 March 1913 – 20 September 1996) was a Hungarian mathematician. He was one of the most prolific mathematicians and producers of mathematical conjectures of the 20th century. pursued and proposed problems in ...
, was based on the divisibility properties of factorials. The factorial number system is a mixed radix notation for numbers in which the place values of each digit are factorials. Factorials are used extensively in
probability theory Probability theory is the branch of mathematics concerned with probability. Although there are several different probability interpretations, probability theory treats the concept in a rigorous mathematical manner by expressing it through a set ...
, for instance in the Poisson distribution and in the probabilities of random permutations. In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, beyond appearing in the analysis of
brute-force search In computer science, brute-force search or exhaustive search, also known as generate and test, is a very general problem-solving technique and algorithmic paradigm that consists of systematically enumerating all possible candidates for the soluti ...
es over permutations, factorials arise in the
lower bound In mathematics, particularly in order theory, an upper bound or majorant of a subset of some preordered set is an element of that is greater than or equal to every element of . Dually, a lower bound or minorant of is defined to be an elemen ...
of \log_2 n!=n\log_2n-O(n) on the number of comparisons needed to
comparison sort A comparison sort is a type of sorting algorithm that only reads the list elements through a single abstract comparison operation (often a "less than or equal to" operator or a three-way comparison) that determines which of two elements should o ...
a set of n items, and in the analysis of chained hash tables, where the distribution of keys per cell can be accurately approximated by a Poisson distribution. Moreover, factorials naturally appear in formulae from
quantum In physics, a quantum (plural quanta) is the minimum amount of any physical entity ( physical property) involved in an interaction. The fundamental notion that a physical property can be "quantized" is referred to as "the hypothesis of quantizat ...
and statistical physics, where one often considers all the possible permutations of a set of particles. In
statistical mechanics In physics, statistical mechanics is a mathematical framework that applies statistical methods and probability theory to large assemblies of microscopic entities. It does not assume or postulate any natural laws, but explains the macroscopic b ...
, calculations of
entropy Entropy is a scientific concept, as well as a measurable physical property, that is most commonly associated with a state of disorder, randomness, or uncertainty. The term and the concept are used in diverse fields, from classical thermodyna ...
such as Boltzmann's entropy formula or the Sackur–Tetrode equation must correct the count of microstates by dividing by the factorials of the numbers of each type of indistinguishable particle to avoid the Gibbs paradox. Quantum physics provides the underlying reason for why these corrections are necessary.


Properties


Growth and approximation

As a function the factorial has faster than
exponential growth Exponential growth is a process that increases quantity over time. It occurs when the instantaneous rate of change (that is, the derivative) of a quantity with respect to time is proportional to the quantity itself. Described as a function, a ...
, but grows more slowly than a double exponential function. Its growth rate is similar but slower by an exponential factor. One way of approaching this result is by taking the
natural logarithm The natural logarithm of a number is its logarithm to the base of the mathematical constant , which is an irrational and transcendental number approximately equal to . The natural logarithm of is generally written as , , or sometimes, if ...
of the factorial, which turns its product formula into a sum, and then estimating the sum by an integral: \ln n! = \sum_^n \ln x \approx \int_1^n\ln x\, dx=n\ln n-n+1. Exponentiating the result (and ignoring the negligible +1 term) approximates n! as More carefully bounding the sum both above and below by an integral, using the trapezoid rule, shows that this estimate needs a correction factor proportional The constant of proportionality for this correction can be found from the Wallis product, which expresses \pi as a limiting ratio of factorials and powers of two. The result of these corrections is Stirling's approximation: n!\sim\sqrt\left(\frac\right)^n\,. Here, the \sim symbol means that, as n goes to infinity, the ratio between the left and right sides approaches one in the
limit Limit or Limits may refer to: Arts and media * ''Limit'' (manga), a manga by Keiko Suenobu * ''Limit'' (film), a South Korean film * Limit (music), a way to characterize harmony * "Limit" (song), a 2016 single by Luna Sea * "Limits", a 2019 ...
. Stirling's formula provides the first term in an asymptotic series that becomes even more accurate when taken to greater numbers of terms: n! \sim \sqrt\left(\frac\right)^n \left(1 +\frac+\frac - \frac -\frac+ \cdots \right). An alternative version uses only odd exponents in the correction terms: n! \sim \sqrt\left(\frac\right)^n \exp\left(\frac - \frac + \frac -\frac+ \cdots \right). Many other variations of these formulas have also been developed, by
Srinivasa Ramanujan Srinivasa Ramanujan (; born Srinivasa Ramanujan Aiyangar, ; 22 December 188726 April 1920) was an Indian mathematician. Though he had almost no formal training in pure mathematics, he made substantial contributions to mathematical analysis, ...
, Bill Gosper, and others. The
binary logarithm In mathematics, the binary logarithm () is the power to which the number must be raised to obtain the value . That is, for any real number , :x=\log_2 n \quad\Longleftrightarrow\quad 2^x=n. For example, the binary logarithm of is , the ...
of the factorial, used to analyze
comparison sort A comparison sort is a type of sorting algorithm that only reads the list elements through a single abstract comparison operation (often a "less than or equal to" operator or a three-way comparison) that determines which of two elements should o ...
ing, can be very accurately estimated using Stirling's approximation. In the formula below, the O(1) term invokes
big O notation Big ''O'' notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. Big O is a member of a family of notations invented by Paul Bachmann, Edmund L ...
. \log_2 n! = n\log_2 n-(\log_2 e)n + \frac12\log_2 n + O(1).


Divisibility and digits

The product formula for the factorial implies that n! is divisible by all
prime number A prime number (or a prime) is a natural number greater than 1 that is not a Product (mathematics), product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime ...
s that are at and by no larger prime numbers. More precise information about its divisibility is given by Legendre's formula, which gives the exponent of each prime p in the prime factorization of n! as \sum_^\infty \left \lfloor \frac n \right \rfloor=\frac. Here s_p(n) denotes the sum of the digits and the exponent given by this formula can also be interpreted in advanced mathematics as the -adic valuation of the factorial. Applying Legendre's formula to the product formula for
binomial coefficient In mathematics, the binomial coefficients are the positive integers that occur as coefficients in the binomial theorem. Commonly, a binomial coefficient is indexed by a pair of integers and is written \tbinom. It is the coefficient of the t ...
s produces Kummer's theorem, a similar result on the exponent of each prime in the factorization of a binomial coefficient. Grouping the prime factors of the factorial into prime powers in different ways produces the multiplicative partitions of factorials. The special case of Legendre's formula for p=5 gives the number of trailing zeros in the decimal representation of the factorials. According to this formula, the number of zeros can be obtained by subtracting the base-5 digits of n from n, and dividing the result by four. Legendre's formula implies that the exponent of the prime p=2 is always larger than the exponent for so each factor of five can be paired with a factor of two to produce one of these trailing zeros. The leading digits of the factorials are distributed according to Benford's law. Every sequence of digits, in any base, is the sequence of initial digits of some factorial number in that base. Another result on divisibility of factorials,
Wilson's theorem In algebra and number theory, Wilson's theorem states that a natural number ''n'' > 1 is a prime number if and only if the product of all the positive integers less than ''n'' is one less than a multiple of ''n''. That is (using the notations of m ...
, states that (n-1)!+1 is divisible by n if and only if n is a
prime number A prime number (or a prime) is a natural number greater than 1 that is not a Product (mathematics), product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime ...
. For any given the Kempner function of x is given by the smallest n for which x divides For almost all numbers (all but a subset of exceptions with asymptotic density zero), it coincides with the largest prime factor The product of two factorials, always evenly divides There are infinitely many factorials that equal the product of other factorials: if n is itself any product of factorials, then n! equals that same product multiplied by one more factorial, The only known examples of factorials that are products of other factorials but are not of this "trivial" form are and It would follow from the conjecture that there are only finitely many nontrivial examples. The greatest common divisor of the values of a primitive polynomial of degree d over the integers evenly divides


Continuous interpolation and non-integer generalization

There are infinitely many ways to extend the factorials to a
continuous function In mathematics, a continuous function is a function such that a continuous variation (that is a change without jump) of the argument induces a continuous variation of the value of the function. This means that there are no abrupt changes in val ...
. The most widely used of these uses the
gamma function In mathematics, the gamma function (represented by , the capital letter gamma from the Greek alphabet) is one commonly used extension of the factorial function to complex numbers. The gamma function is defined for all complex numbers excep ...
, which can be defined for positive real numbers as the
integral In mathematics, an integral assigns numbers to functions in a way that describes displacement, area, volume, and other concepts that arise by combining infinitesimal data. The process of finding integrals is called integration. Along with ...
\Gamma(z) = \int_0^\infty x^ e^\,dx. The resulting function is related to the factorial of a non-negative integer n by the equation n!=\Gamma(n+1), which can be used as a definition of the factorial for non-integer arguments. At all values x for which both \Gamma(x) and \Gamma(x-1) are defined, the gamma function obeys the functional equation \Gamma(n)=(n-1)\Gamma(n-1), generalizing the recurrence relation for the factorials. The same integral converges more generally for any
complex number In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the fo ...
z whose real part is positive. It can be extended to the non-integer points in the rest of the
complex plane In mathematics, the complex plane is the plane formed by the complex numbers, with a Cartesian coordinate system such that the -axis, called the real axis, is formed by the real numbers, and the -axis, called the imaginary axis, is formed by the ...
by solving for Euler's
reflection formula In mathematics, a reflection formula or reflection relation for a function ''f'' is a relationship between ''f''(''a'' − ''x'') and ''f''(''x''). It is a special case of a functional equation, and it is very common in the literature ...
\Gamma(z)\Gamma(1-z)=\frac. However, this formula cannot be used at integers because, for them, the \sin\pi z term would produce a division by zero. The result of this extension process is an
analytic function In mathematics, an analytic function is a function that is locally given by a convergent power series. There exist both real analytic functions and complex analytic functions. Functions of each type are infinitely differentiable, but complex ...
, the
analytic continuation In complex analysis, a branch of mathematics, analytic continuation is a technique to extend the domain of definition of a given analytic function. Analytic continuation often succeeds in defining further values of a function, for example in a ...
of the integral formula for the gamma function. It has a nonzero value at all complex numbers, except for the non-positive integers where it has simple poles. Correspondingly, this provides a definition for the factorial at all complex numbers other than the negative integers. One property of the gamma function, distinguishing it from other continuous interpolations of the factorials, is given by the Bohr–Mollerup theorem, which states that the gamma function (offset by one) is the only log-convex function on the positive real numbers that interpolates the factorials and obeys the same functional equation. A related uniqueness theorem of Helmut Wielandt states that the complex gamma function and its scalar multiples are the only
holomorphic function In mathematics, a holomorphic function is a complex-valued function of one or more complex variables that is complex differentiable in a neighbourhood of each point in a domain in complex coordinate space . The existence of a complex deriv ...
s on the positive complex half-plane that obey the functional equation and remain bounded for complex numbers with real part between 1 and 2. Other complex functions that interpolate the factorial values include Hadamard's gamma function, which is an entire function over all the complex numbers, including the non-positive integers. In the -adic numbers, it is not possible to continuously interpolate the factorial function directly, because the factorials of large integers (a dense subset of the -adics) converge to zero according to Legendre's formula, forcing any continuous function that is close to their values to be zero everywhere. Instead, the -adic gamma function provides a continuous interpolation of a modified form of the factorial, omitting the factors in the factorial that are divisible by . The digamma function is the logarithmic derivative of the gamma function. Just as the gamma function provides a continuous interpolation of the factorials, offset by one, the digamma function provides a continuous interpolation of the
harmonic number In mathematics, the -th harmonic number is the sum of the reciprocals of the first natural numbers: H_n= 1+\frac+\frac+\cdots+\frac =\sum_^n \frac. Starting from , the sequence of harmonic numbers begins: 1, \frac, \frac, \frac, \frac, \do ...
s, offset by the Euler–Mascheroni constant.


Computation

The factorial function is a common feature in scientific calculators. It is also included in scientific programming libraries such as the Python mathematical functions module and the Boost C++ library. If efficiency is not a concern, computing factorials is trivial: just successively multiply a variable initialized by the integers up The simplicity of this computation makes it a common example in the use of different computer programming styles and methods. The computation of n! can be expressed in
pseudocode In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine re ...
using iteration as define factorial(''n''): ''f'' := 1 for ''i'' := 1, 2, 3, ..., ''n'': ''f'' := ''f'' × ''i'' return ''f'' or using
recursion Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematic ...
based on its recurrence relation as define factorial(''n''): if ''n'' = 0 return 1 return ''n'' × factorial(''n'' − 1) Other methods suitable for its computation include
memoization In computing, memoization or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again. Memoization ...
,
dynamic programming Dynamic programming is both a mathematical optimization method and a computer programming method. The method was developed by Richard Bellman in the 1950s and has found applications in numerous fields, from aerospace engineering to economics. ...
, and
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions tha ...
. The
computational complexity In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to computation time (generally measured by the number of needed elementary operations) ...
of these algorithms may be analyzed using the unit-cost
random-access machine In computer science, random-access machine (RAM) is an abstract machine in the general class of register machines. The RAM is very similar to the counter machine but with the added capability of 'indirect addressing' of its registers. Like the c ...
model of computation, in which each arithmetic operation takes constant time and each number uses a constant amount of storage space. In this model, these methods can compute n! in time and the iterative version uses space Unless optimized for tail recursion, the recursive version takes linear space to store its
call stack In computer science, a call stack is a stack data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, program stack, control stack, run-time stack, or mac ...
. However, this model of computation is only suitable when n is small enough to allow n! to fit into a machine word. The values 12! and 20! are the largest factorials that can be stored in, respectively, the
32-bit In computer architecture, 32-bit computing refers to computer systems with a processor, memory, and other major system components that operate on data in 32- bit units. Compared to smaller bit widths, 32-bit computers can perform large calculati ...
and
64-bit In computer architecture, 64-bit integers, memory addresses, or other data units are those that are 64 bits wide. Also, 64-bit CPUs and ALUs are those that are based on processor registers, address buses, or data buses of that size. A ...
integers.
Floating point In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can ...
can represent larger factorials, but approximately rather than exactly, and will still overflow for factorials larger than The exact computation of larger factorials involves arbitrary-precision arithmetic, because of fast growth and integer overflow. Time of computation can be analyzed as a function of the number of digits or bits in the result. By Stirling's formula, n! has b = O(n\log n) bits. The
Schönhage–Strassen algorithm The Schönhage–Strassen algorithm is an asymptotically fast multiplication algorithm for large integers. It was developed by Arnold Schönhage and Volker Strassen in 1971.A. Schönhage and V. Strassen,Schnelle Multiplikation großer Zahlen, ...
can produce a product in time and faster multiplication algorithms taking time O(b\log b) are known. However, computing the factorial involves repeated products, rather than a single multiplication, so these time bounds do not apply directly. In this setting, computing n! by multiplying the numbers from 1 in sequence is inefficient, because it involves n multiplications, a constant fraction of which take time O(n\log^2 n) each, giving total time A better approach is to perform the multiplications as a divide-and-conquer algorithm that multiplies a sequence of i numbers by splitting it into two subsequences of i/2 numbers, multiplies each subsequence, and combines the results with one last multiplication. This approach to the factorial takes total time one logarithm comes from the number of bits in the factorial, a second comes from the multiplication algorithm, and a third comes from the divide and conquer. Even better efficiency is obtained by computing from its prime factorization, based on the principle that exponentiation by squaring is faster than expanding an exponent into a product. An algorithm for this by Arnold Schönhage begins by finding the list of the primes up for instance using the
sieve of Eratosthenes In mathematics, the sieve of Eratosthenes is an ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite (i.e., not prime) the multiples of each prime, starting with the first prime n ...
, and uses Legendre's formula to compute the exponent for each prime. Then it computes the product of the prime powers with these exponents, using a recursive algorithm, as follows: * Use divide and conquer to compute the product of the primes whose exponents are odd * Divide all of the exponents by two (rounding down to an integer), recursively compute the product of the prime powers with these smaller exponents, and square the result * Multiply together the results of the two previous steps The product of all primes up to n is an O(n)-bit number, by the
prime number theorem In mathematics, the prime number theorem (PNT) describes the asymptotic distribution of the prime numbers among the positive integers. It formalizes the intuitive idea that primes become less common as they become larger by precisely quantifying t ...
, so the time for the first step is O(n\log^2 n), with one logarithm coming from the divide and conquer and another coming from the multiplication algorithm. In the recursive calls to the algorithm, the prime number theorem can again be invoked to prove that the numbers of bits in the corresponding products decrease by a constant factor at each level of recursion, so the total time for these steps at all levels of recursion adds in a geometric series The time for the squaring in the second step and the multiplication in the third step are again because each is a single multiplication of a number with O(n\log n) bits. Again, at each level of recursion the numbers involved have a constant fraction as many bits (because otherwise repeatedly squaring them would produce too large a final result) so again the amounts of time for these steps in the recursive calls add in a geometric series Consequentially, the whole algorithm takes proportional to a single multiplication with the same number of bits in its result.


Related sequences and functions

Several other integer sequences are similar to or related to the factorials: ;Alternating factorial :The alternating factorial is the absolute value of the alternating sum of the first n factorials, These have mainly been studied in connection with their primality; only finitely many of them can be prime, but a complete list of primes of this form is not known. ;Bhargava factorial :The Bhargava factorials are a family of integer sequences defined by Manjul Bhargava with similar number-theoretic properties to the factorials, including the factorials themselves as a special case. ;Double factorial :The product of all the odd integers up to some odd positive is called the
double factorial In mathematics, the double factorial or semifactorial of a number , denoted by , is the product of all the integers from 1 up to that have the same parity (odd or even) as . That is, :n!! = \prod_^ (n-2k) = n (n-2) (n-4) \cdots. For even , the ...
and denoted by That is, (2k-1)!! = \prod_^k (2i-1) = \frac. For example, . Double factorials are used in trigonometric integrals, in expressions for the
gamma function In mathematics, the gamma function (represented by , the capital letter gamma from the Greek alphabet) is one commonly used extension of the factorial function to complex numbers. The gamma function is defined for all complex numbers excep ...
at
half-integer In mathematics, a half-integer is a number of the form :n + \tfrac, where n is an whole number. For example, :, , , 8.5 are all ''half-integers''. The name "half-integer" is perhaps misleading, as the set may be misunderstood to include numbers ...
s and the volumes of hyperspheres, and in counting
binary trees In computer science, a binary tree is a k-ary k = 2 tree data structure in which each node has at most two children, which are referred to as the ' and the '. A recursive definition using just set theory notions is that a (non-empty) binary t ...
and
perfect matching In graph theory, a perfect matching in a graph is a matching that covers every vertex of the graph. More formally, given a graph , a perfect matching in is a subset of edge set , such that every vertex in the vertex set is adjacent to exactl ...
s. ;Exponential factorial :Just as
triangular number A triangular number or triangle number counts objects arranged in an equilateral triangle. Triangular numbers are a type of figurate number, other examples being square numbers and cube numbers. The th triangular number is the number of dots i ...
s sum the numbers from 1 and factorials take their product, the exponential factorial exponentiates. The exponential factorial is defined recursively For example, the exponential factorial of 4 is 4^=262144. These numbers grow much more quickly than regular factorials. ;Falling factorial :The notations (x)_ or x^ are sometimes used to represent the product of the n integers counting up to and equal to This is also known as a
falling factorial In mathematics, the falling factorial (sometimes called the descending factorial, falling sequential product, or lower factorial) is defined as the polynomial :\begin (x)_n = x^\underline &= \overbrace^ \\ &= \prod_^n(x-k+1) = \prod_^(x-k) \,. \e ...
or backward factorial, and the (x)_ notation is a Pochhammer symbol. Falling factorials count the number of different sequences of n distinct items that can be drawn from a universe of x items. They occur as coefficients in the higher derivatives of polynomials, and in the factorial moments of
random variable A random variable (also called random quantity, aleatory variable, or stochastic variable) is a mathematical formalization of a quantity or object which depends on random events. It is a mapping or a function from possible outcomes (e.g., the po ...
s. ;Hyperfactorials :The hyperfactorial of n is the product 1^1\cdot 2^2\cdots n^n. These numbers form the
discriminant In mathematics, the discriminant of a polynomial is a quantity that depends on the coefficients and allows deducing some properties of the roots without computing them. More precisely, it is a polynomial function of the coefficients of the orig ...
s of
Hermite polynomials In mathematics, the Hermite polynomials are a classical orthogonal polynomial sequence. The polynomials arise in: * signal processing as Hermitian wavelets for wavelet transform analysis * probability, such as the Edgeworth series, as well ...
. They can be continuously interpolated by the K-function, and obey analogues to Stirling's formula and Wilson's theorem. ;Jordan–Pólya numbers :The Jordan–Pólya numbers are the products of factorials, allowing repetitions. Every
tree In botany, a tree is a perennial plant with an elongated stem, or trunk, usually supporting branches and leaves. In some usages, the definition of a tree may be narrower, including only woody plants with secondary growth, plants that are ...
has a
symmetry group In group theory, the symmetry group of a geometric object is the group of all transformations under which the object is invariant, endowed with the group operation of composition. Such a transformation is an invertible mapping of the amb ...
whose number of symmetries is a Jordan–Pólya number, and every Jordan–Pólya number counts the symmetries of some tree. ;Primorial :The primorial n\# is the product of
prime number A prime number (or a prime) is a natural number greater than 1 that is not a Product (mathematics), product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime ...
s less than or equal this construction gives them some similar divisibility properties to factorials, but unlike factorials they are squarefree. As with the factorial primes researchers have studied primorial primes ;Subfactorial :The subfactorial yields the number of derangements of a set of n objects. It is sometimes denoted !n, and equals the closest integer ;Superfactorial :The superfactorial of n is the product of the first n factorials. The superfactorials are continuously interpolated by the Barnes G-function.


References


External links

* * * {{Authority control Combinatorics Gamma and related functions Factorial and binomial topics Unary operations