HOME

TheInfoList



OR:

In mathematics, the factorial of a non-negative denoted is the
product Product may refer to: Business * Product (business), an item that serves as a solution to a specific consumer problem. * Product (project management), a deliverable or set of deliverables that contribute to a business solution Mathematics * Produ ...
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 In mathematics, an empty product, or nullary product or vacuous product, is the result of multiplying no factors. It is by convention equal to the multiplicative identity (assuming there is an identity for the multiplication operation in question ...
. Factorials have been discovered in several ancient cultures, notably in Indian mathematics in the canonical works of
Jain literature Jain literature (Sanskrit: जैन साहित्य) refers to the literature of the Jain religion. It is a vast and ancient literary tradition, which was initially transmitted orally. The oldest surviving material is contained in the c ...
, and by Jewish mystics in the Talmudic book '' Sefer Yetzirah''. The factorial operation is encountered in many areas of mathematics, notably in combinatorics, where its most basic use counts the possible distinct sequences – the permutations – of n distinct objects: there In
mathematical analysis Analysis is the branch of mathematics dealing with continuous functions, limit (mathematics), limits, and related theories, such as Derivative, differentiation, Integral, integration, measure (mathematics), measure, infinite sequences, series (m ...
, factorials are used in power series for the exponential function and other functions, and they also have applications in algebra, number theory, probability theory, and computer science. Much of the mathematics of the factorial function was developed beginning in the late 18th and early 19th centuries.
Stirling's approximation In mathematics, Stirling's approximation (or Stirling's formula) is an approximation for factorials. It is a good approximation, leading to accurate results even for small values of n. It is named after James Stirling, though a related but less p ...
provides an accurate approximation to the factorial of large numbers, showing that it grows more quickly than exponential growth.
Legendre's formula In mathematics, Legendre's formula gives an expression for the exponent of the largest power of a prime ''p'' that divides the factorial ''n''!. It is named after Adrien-Marie Legendre. It is also sometimes known as de Polignac's formula, aft ...
describes the exponents of the prime numbers in a prime factorization of the factorials, and can be used to count the trailing zeros of the factorials. Daniel Bernoulli and Leonhard Euler interpolated the factorial function to a continuous function of complex numbers, except at the negative integers, the (offset) gamma function. Many other notable functions and number sequences are closely related to the factorials, including the binomial coefficients, double factorials, falling factorials, primorials, and
subfactorial In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position. In other words, a derangement is a permutation that has no fixed points. The number of derangements of ...
s. Implementations of the factorial function are commonly used as an example of different computer programming styles, and are included in
scientific calculator A scientific calculator is an electronic calculator, either desktop or handheld, designed to perform mathematical operations. They have completely replaced slide rules and are used in both educational and professional settings. In some are ...
s 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 algorithm A multiplication algorithm is an algorithm (or method) to multiply two numbers. Depending on the size of the numbers, different algorithms are more efficient than others. Efficient multiplication algorithms have existed since the advent of the d ...
s for numbers with the same number of digits.


History

The concept of factorials has arisen independently in many cultures: *In Indian mathematics, one of the earliest known descriptions of factorials comes from the Anuyogadvāra-sūtra, one of the canonical works of
Jain literature Jain literature (Sanskrit: जैन साहित्य) refers to the literature of the Jain religion. It is a vast and ancient literary tradition, which was initially transmitted orally. The oldest surviving material is contained in the c ...
, 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 Jinabhadra or Vachanacharya Jinabhadragani Kshamashramana was Jain ascetic author of Prakrit and Sanskrit texts. Life Jinabhadra (520-623 AD) was a Svetambara Jain monk during sixth-seventh century CE. Not much is known about his life but it s ...
.. Revised by K. S. Shukla from a paper in ''
Indian Journal of History of Science The Indian National Science Academy (INSA) is a national academy in New Delhi for Indian scientists in all branches of science and technology. In August 2019, Dr. Chandrima Shaha was appointed as the president of Indian National Science Acade ...
'' 27 (3): 231–249, 1992, . See p. 363.
Hindu scholars have been using factorial formulas since at least 1150, when Bhāskara II mentioned factorials in his work Līlāvatī, in connection with a problem of how many ways Vishnu could hold his four characteristic objects (a
conch shell Conch () is a common name of a number of different medium-to-large-sized sea snails. Conch shells typically have a high spire and a noticeable siphonal canal (in other words, the shell comes to a noticeable point at both ends). In North Ame ...
, discus, mace, and lotus flower) 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. Factorials were also studied for similar reasons by 8th-century Arab grammarian
Al-Khalil ibn Ahmad al-Farahidi Abu ‘Abd ar-Raḥmān al-Khalīl ibn Aḥmad ibn ‘Amr ibn Tammām al-Farāhīdī al-Azdī al-Yaḥmadī ( ar, أبو عبدالرحمن الخليل بن أحمد الفراهيدي; 718 – 786 CE), known as Al-Farāhīdī, or Al-Khalīl, ...
. Arab mathematician Ibn al-Haytham (also known as Alhazen, c. 965 – c. 1040) was the first to formulate Wilson's theorem connecting the factorials with the prime numbers. *In Europe, although Greek mathematics included some combinatorics, and Plato 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 Fabian Stedman (1640–1713) was an English author and a leading figure in the early history of campanology, particularly in the field of method ringing. He had a key role in publishing two books ''Tintinnalogia'' (1668 with Richard Duckworth) an ...
described the application of factorials to change ringing, 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 calculated factorials up to 11!, in connection with a problem of dining table arrangements.
Christopher Clavius Christopher Clavius, SJ (25 March 1538 – 6 February 1612) was a Jesuit German mathematician, head of mathematicians at the Collegio Romano, and astronomer who was a member of the Vatican commission that accepted the proposed calendar inve ...
discussed factorials in a 1603 commentary on the work of
Johannes de Sacrobosco Johannes de Sacrobosco, also written Ioannes de Sacro Bosco, later called John of Holywood or John of Holybush ( 1195 – 1256), was a scholar, monk, and astronomer who taught at the University of Paris. He wrote a short introduction to the Hi ...
, and in the 1640s, French polymath Marin Mersenne published large (but not entirely correct) tables of factorials, up to 64!, based on the work of Clavius. The power series for the exponential function, with the reciprocals of factorials for its coefficients, was first formulated in 1676 by Isaac Newton in a letter to Gottfried Wilhelm Leibniz. Other important works of early European mathematics on factorials include extensive coverage in a 1685 treatise by John Wallis, a study of their approximate values for large values of n by Abraham de Moivre in 1721, a 1729 letter from James Stirling to de Moivre stating what became known as
Stirling's approximation In mathematics, Stirling's approximation (or Stirling's formula) is an approximation for factorials. It is a good approximation, leading to accurate results even for small values of n. It is named after James Stirling, though a related but less p ...
, and work at the same time by Daniel Bernoulli and Leonhard Euler formulating the continuous extension of the factorial function to the gamma function.
Adrien-Marie Legendre Adrien-Marie Legendre (; ; 18 September 1752 – 9 January 1833) was a French mathematician who made numerous contributions to mathematics. Well-known and important concepts such as the Legendre polynomials and Legendre transformation are name ...
included
Legendre's formula In mathematics, Legendre's formula gives an expression for the exponent of the largest power of a prime ''p'' that divides the factorial ''n''!. It is named after Adrien-Marie Legendre. It is also sometimes known as de Polignac's formula, aft ...
, describing the exponents in the
factorization In mathematics, factorization (or factorisation, see English spelling differences) or factoring consists of writing a number or another mathematical object as a product of several ''factors'', usually smaller or simpler objects of the same kind ...
of factorials into
prime power In mathematics, a prime power is a positive integer which is a positive integer power of a single prime number. For example: , and are prime powers, while , and are not. The sequence of prime powers begins: 2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17 ...
s, in an 1808 text on number theory. 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 Louis François Antoine Arbogast (4 October 1759 – 8 April 1803) was a French mathematician. He was born at Mutzig in Alsace and died at Strasbourg, where he was professor. He wrote on series and the derivatives known by his name: he was the ...
, in the first work on
Faà di Bruno's formula Faà di Bruno's formula is an identity in mathematics generalizing the chain rule to higher derivatives. It is named after , although he was not the first to state or prove the formula. In 1800, more than 50 years before Faà di Bruno, the French ...
, but referring to a more general concept of products of
arithmetic progression An arithmetic progression or arithmetic sequence () is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15, . . . is an arithmetic progression with a common differ ...
s. 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 In mathematics, a recurrence relation is an equation according to which the nth term of a sequence of numbers is equal to some combination of the previous terms. Often, only k previous terms of the sequence appear in the equation, for a parameter ...
, 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 In mathematics, an empty product, or nullary product or vacuous product, is the result of multiplying no factors. It is by convention equal to the multiplicative identity (assuming there is an identity for the multiplication operation in question ...
, 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 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 identity that would only be valid * With the recurrence relation for the factorial remains valid Therefore, with this convention, a
recursive 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 mathematics ...
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, as a power series: * This choice matches the gamma function and the gamma function must have this value to be a continuous function.


Applications

The earliest uses of the factorial function involve counting permutations: there are n! different ways of arranging n distinct objects into a sequence. Factorials appear more broadly in many formulas in combinatorics, to account for different orderings of objects. For instance the binomial coefficients \tbinom count the
combination In mathematics, a combination is a selection of items from a set that has distinct members, such that the order of selection does not matter (unlike permutations). For example, given three fruits, say an apple, an orange and a pear, there are th ...
s (subsets of from a set with and can be computed from factorials using the formula \binom=\frac. The
Stirling numbers of the first kind In mathematics, especially in combinatorics, Stirling numbers of the first kind arise in the study of permutations. In particular, the Stirling numbers of the first kind count permutations according to their number of cycles (counting fixed poin ...
sum to the factorials, and count the permutations grouped into subsets with the same numbers of cycles. Another combinatorial application is in counting
derangement In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position. In other words, a derangement is a permutation that has no fixed points. The number of derangements of ...
s, permutations that do not leave any element in its original position; the number of derangements of n items is the nearest integer In algebra, the factorials arise through the
binomial theorem In elementary algebra, the binomial theorem (or binomial expansion) describes the algebraic expansion of powers of a binomial. According to the theorem, it is possible to expand the polynomial into a sum involving terms of the form , where the ...
, 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 In mathematics, Newton's identities, also known as the Girard–Newton formulae, give relations between two types of symmetric polynomials, namely between power sums and elementary symmetric polynomials. Evaluated at the roots of a monic polynom ...
for
symmetric polynomial In mathematics, a symmetric polynomial is a polynomial in variables, such that if any of the variables are interchanged, one obtains the same polynomial. Formally, is a ''symmetric polynomial'' if for any permutation of the subscripts one has ...
s. Their use in counting permutations can also be restated algebraically: the factorials are the orders of finite
symmetric group In abstract algebra, the symmetric group defined over any set is the group whose elements are all the bijections from the set to itself, and whose group operation is the composition of functions. In particular, the finite symmetric group ...
s. In calculus, factorials occur in
Faà di Bruno's formula Faà di Bruno's formula is an identity in mathematics generalizing the chain rule to higher derivatives. It is named after , although he was not the first to state or prove the formula. In 1800, more than 50 years before Faà di Bruno, the French ...
for chaining higher derivatives. In
mathematical analysis Analysis is the branch of mathematics dealing with continuous functions, limit (mathematics), limits, and related theories, such as Derivative, differentiation, Integral, integration, measure (mathematics), measure, infinite sequences, series (m ...
, factorials frequently appear in the denominators of power series, most notably in the series for the exponential function, e^x=1+\frac+\frac+\frac+\cdots=\sum_^\frac, and in the coefficients of other Taylor series (in particular those of the
trigonometric Trigonometry () is a branch of mathematics that studies relationships between side lengths and angles of triangles. The field emerged in the Hellenistic world during the 3rd century BC from applications of geometry to astronomical studies. ...
and
hyperbolic functions In mathematics, hyperbolic functions are analogues of the ordinary trigonometric functions, but defined using the hyperbola rather than the circle. Just as the points form a circle with a unit radius, the points form the right half of the un ...
), where they cancel factors of n! coming from the This usage of factorials in power series connects back to
analytic combinatorics In combinatorics, the symbolic method is a technique for counting combinatorial objects. It uses the internal structure of the objects to derive formulas for their generating functions. The method is mostly associated with Philippe Flajolet an ...
through the
exponential generating function In mathematics, a generating function is a way of encoding an infinite sequence of numbers () by treating them as the coefficients of a formal power series. This series is called the generating function of the sequence. Unlike an ordinary series ...
, which for a
combinatorial class In mathematics, a combinatorial class is a countable set of mathematical objects, together with a size function mapping each object to a non-negative integer, such that there are finitely many objects of each size. Counting sequences and isomorphis ...
with n_i elements of is defined as the power series \sum_^ \frac. In number theory, the most salient property of factorials is the
divisibility In mathematics, a divisor of an integer n, also called a factor of n, is an integer m that may be multiplied by some integer to produce n. In this case, one also says that n is a multiple of m. An integer n is divisible or evenly divisible by ...
of n! by all positive integers up described more precisely for prime factors by
Legendre's formula In mathematics, Legendre's formula gives an expression for the exponent of the largest power of a prime ''p'' that divides the factorial ''n''!. It is named after Adrien-Marie Legendre. It is also sometimes known as de Polignac's formula, aft ...
. It follows that arbitrarily large prime numbers can be found as the prime factors of the numbers n!\pm 1, leading to a proof of
Euclid's theorem Euclid's theorem is a fundamental statement in number theory that asserts that there are infinitely many prime numbers. It was first proved by Euclid in his work ''Elements''. There are several proofs of the theorem. Euclid's proof Euclid offered ...
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, concerns the existence of square numbers 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 gap A prime gap is the difference between two successive prime numbers. The ''n''-th prime gap, denoted ''g'n'' or ''g''(''p'n'') is the difference between the (''n'' + 1)-th and the ''n''-th prime numbers, i.e. :g_n = p_ - p_n.\ W ...
s. An elementary
proof of Bertrand's postulate In mathematics, Bertrand's postulate (actually a theorem) states that for each n \ge 2 there is a prime p such that n. It was first
Paul Erdős, was based on the divisibility properties of factorials. The
factorial number system In combinatorics, the factorial number system, also called factoradic, is a mixed radix numeral system adapted to numbering permutations. It is also called factorial base, although factorials do not function as base, but as place value of digi ...
is a
mixed radix Mixed radix numeral systems are non-standard positional numeral systems in which the numerical base varies from position to position. Such numerical representation applies when a quantity is expressed using a sequence of units that are each a m ...
notation for numbers in which the place values of each digit are factorials. Factorials are used extensively in probability theory, for instance in the
Poisson distribution In probability theory and statistics, the Poisson distribution is a discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time or space if these events occur with a known co ...
and in the probabilities of
random permutation A random permutation is a random ordering of a set of objects, that is, a permutation-valued random variable. The use of random permutations is often fundamental to fields that use randomized algorithms such as coding theory, cryptography, and sim ...
s. In computer science, beyond appearing in the analysis of brute-force searches over permutations, factorials arise in the lower bound of \log_2 n!=n\log_2n-O(n) on the number of comparisons needed to comparison sort a set of n items, and in the analysis of chained
hash table In computing, a hash table, also known as hash map, is a data structure that implements an associative array or dictionary. It is an abstract data type that maps keys to values. A hash table uses a hash function to compute an ''index'', ...
s, where the distribution of keys per cell can be accurately approximated by a Poisson distribution. Moreover, factorials naturally appear in formulae from quantum and
statistical physics Statistical physics is a branch of physics that evolved from a foundation of statistical mechanics, which uses methods of probability theory and statistics, and particularly the mathematical tools for dealing with large populations and approxim ...
, where one often considers all the possible permutations of a set of particles. In statistical mechanics, calculations of entropy such as
Boltzmann's entropy formula In statistical mechanics, Boltzmann's equation (also known as the Boltzmann–Planck equation) is a probability equation relating the entropy S, also written as S_\mathrm, of an ideal gas to the multiplicity (commonly denoted as \Omega or W), the ...
or the
Sackur–Tetrode equation The Sackur–Tetrode equation is an expression for the entropy of a monatomic ideal gas. It is named for Hugo Martin Tetrode (1895–1931) and Otto Sackur (1880–1914), who developed it independently as a solution of Boltzmann's gas statistics an ...
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, but grows more slowly than a
double exponential function A double exponential function is a constant raised to the power of an exponential function. The general formula is f(x) = a^=a^ (where ''a''>1 and ''b''>1), which grows much more quickly than an exponential function. For example, if ''a'' = ''b ...
. Its growth rate is similar but slower by an exponential factor. One way of approaching this result is by taking the natural logarithm 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 In calculus, the trapezoidal rule (also known as the trapezoid rule or trapezium rule; see Trapezoid for more information on terminology) is a technique for approximating the definite integral. \int_a^b f(x) \, dx. The trapezoidal rule works by ...
, 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 In mathematics, Stirling's approximation (or Stirling's formula) is an approximation for factorials. It is a good approximation, leading to accurate results even for small values of n. It is named after James Stirling, though a related but less p ...
: 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. Stirling's formula provides the first term in an
asymptotic series In mathematics, an asymptotic expansion, asymptotic series or Poincaré expansion (after Henri Poincaré) is a formal series of functions which has the property that truncating the series after a finite number of terms provides an approximation to ...
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,
Bill Gosper Ralph William Gosper Jr. (born April 26, 1943), known as Bill Gosper, is an American mathematician and programmer. Along with Richard Greenblatt, he may be considered to have founded the hacker community, and he holds a place of pride in the ...
, and others. The binary logarithm of the factorial, used to analyze comparison sorting, can be very accurately estimated using Stirling's approximation. In the formula below, the O(1) term invokes big O notation. \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 In mathematics, a divisor of an integer n, also called a factor of n, is an integer m that may be multiplied by some integer to produce n. In this case, one also says that n is a multiple of m. An integer n is divisible or evenly divisible by ...
by all prime numbers that are at and by no larger prime numbers. More precise information about its divisibility is given by
Legendre's formula In mathematics, Legendre's formula gives an expression for the exponent of the largest power of a prime ''p'' that divides the factorial ''n''!. It is named after Adrien-Marie Legendre. It is also sometimes known as de Polignac's formula, aft ...
, 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 coefficients produces
Kummer's theorem In mathematics, Kummer's theorem is a formula for the exponent of the highest power of a prime number ''p'' that divides a given binomial coefficient. In other words, it gives the ''p''-adic valuation of a binomial coefficient. The theorem is nam ...
, 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 power In mathematics, a prime power is a positive integer which is a positive integer power of a single prime number. For example: , and are prime powers, while , and are not. The sequence of prime powers begins: 2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17 ...
s 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 Benford's law, also known as the Newcomb–Benford law, the law of anomalous numbers, or the first-digit law, is an observation that in many real-life sets of numerical data, the leading digit is likely to be small.Arno Berger and Theodore ...
. 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, states that (n-1)!+1 is divisible by n if and only if n is a prime number. For any given the
Kempner function Kempner may refer to: People * Alan H. Kempner (1897–1985), American stockbroker and rare books collector, son-in-law of Carl Loeb who founded Loeb, Rhoades & Co. * Alicia Kempner, American bridge player * Aubrey J. Kempner (1880–1973), British ...
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 In number theory, natural density (also referred to as asymptotic density or arithmetic density) is one method to measure how "large" a subset of the set of natural numbers is. It relies chiefly on the probability of encountering members of the desi ...
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 In mathematics, the greatest common divisor (GCD) of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For two integers ''x'', ''y'', the greatest common divisor of ''x'' and ''y'' is ...
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. The most widely used of these uses the gamma function, which can be defined for positive real numbers as the integral \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 In mathematics, a functional equation is, in the broadest meaning, an equation in which one or several functions appear as unknowns. So, differential equations and integral equations are functional equations. However, a more restricted meaning ...
\Gamma(n)=(n-1)\Gamma(n-1), generalizing the
recurrence relation In mathematics, a recurrence relation is an equation according to which the nth term of a sequence of numbers is equal to some combination of the previous terms. Often, only k previous terms of the sequence appear in the equation, for a parameter ...
for the factorials. The same integral converges more generally for any complex number z whose real part is positive. It can be extended to the non-integer points in the rest of the complex plane by solving for Euler's reflection formula \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 In mathematics, division by zero is division where the divisor (denominator) is zero. Such a division can be formally expressed as \tfrac, where is the dividend (numerator). In ordinary arithmetic, the expression has no meaning, as there is ...
. The result of this extension process is an analytic function, the analytic continuation 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 In mathematical analysis, the Bohr–Mollerup theorem is a theorem proved by the Danish mathematicians Harald Bohr and Johannes Mollerup. The theorem characterizes the gamma function, defined for by :\Gamma(x)=\int_0^\infty t^ e^\,dt as the '' ...
, 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 __NOTOC__ Helmut Wielandt (19 December 1910 – 14 February 2001) was a German mathematician who worked on permutation groups. He was born in Niedereggenen, Lörrach, Germany. He gave a plenary lecture ''Entwicklungslinien in der Strukturtheorie d ...
states that the complex gamma function and its scalar multiples are the only holomorphic functions 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 In mathematics, Hadamard's gamma function, named after Jacques Hadamard, is an extension of the factorial function, different from the classical gamma function. This function, with its argument shifted down by 1, interpolates the factorial and e ...
, which is an
entire function In complex analysis, an entire function, also called an integral function, is a complex-valued function that is holomorphic on the whole complex plane. Typical examples of entire functions are polynomials and the exponential function, and any fin ...
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 In mathematics, the digamma function is defined as the logarithmic derivative of the gamma function: :\psi(x)=\frac\ln\big(\Gamma(x)\big)=\frac\sim\ln-\frac. It is the first of the polygamma functions. It is strictly increasing and strict ...
is the
logarithmic derivative In mathematics, specifically in calculus and complex analysis, the logarithmic derivative of a function ''f'' is defined by the formula \frac where f' is the derivative of ''f''. Intuitively, this is the infinitesimal relative change in ''f'' ...
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 numbers, offset by the
Euler–Mascheroni constant Euler's constant (sometimes also called the Euler–Mascheroni constant) is a mathematical constant usually denoted by the lowercase Greek letter gamma (). It is defined as the limiting difference between the harmonic series and the natural l ...
.


Computation

The factorial function is a common feature in
scientific calculator A scientific calculator is an electronic calculator, either desktop or handheld, designed to perform mathematical operations. They have completely replaced slide rules and are used in both educational and professional settings. In some are ...
s. It is also included in scientific programming libraries such as the
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
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 using
iteration Iteration is the repetition of a process in order to generate a (possibly unbounded) sequence of outcomes. Each repetition of the process is a single iteration, and the outcome of each iteration is then the starting point of the next iteration. ...
as define factorial(''n''): ''f'' := 1 for ''i'' := 1, 2, 3, ..., ''n'': ''f'' := ''f'' × ''i'' return ''f'' or using recursion 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, dynamic programming, and functional programming. The computational complexity of these algorithms may be analyzed using the unit-cost random-access machine 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 In computer science, a tail call is a subroutine call performed as the final action of a procedure. If the target of a tail is the same subroutine, the subroutine is said to be tail recursive, which is a special case of direct recursion. Tail recur ...
, the recursive version takes linear space to store its call stack. 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 and 64-bit
integers An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign ( −1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
. Floating point 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 In computer science, arbitrary-precision arithmetic, also called bignum arithmetic, multiple-precision arithmetic, or sometimes infinite-precision arithmetic, indicates that calculations are performed on numbers whose digits of precision are li ...
, because of fast growth and
integer overflow In computer programming, an integer overflow occurs when an arithmetic operation attempts to create a numeric value that is outside of the range that can be represented with a given number of digits – either higher than the maximum or lower ...
. 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 can produce a product in time and faster
multiplication algorithm A multiplication algorithm is an algorithm (or method) to multiply two numbers. Depending on the size of the numbers, different algorithms are more efficient than others. Efficient multiplication algorithms have existed since the advent of the d ...
s 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 In computer science, divide and conquer is an algorithm design paradigm. A divide-and-conquer algorithm recursively breaks down a problem into two or more sub-problems of the same or related type, until these become simple enough to be solved dire ...
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 Exponentiation is a mathematical operation, written as , involving two numbers, the '' base'' and the ''exponent'' or ''power'' , and pronounced as " (raised) to the (power of) ". When is a positive integer, exponentiation corresponds to re ...
is faster than expanding an exponent into a product. An algorithm for this by
Arnold Schönhage Arnold Schönhage (born 1 December 1934 in Lockhausen, now Bad Salzuflen) is a German mathematician and computer scientist. Schönhage was professor at the Rheinische Friedrich-Wilhelms-Universität, Bonn, and also in Tübingen and Konstanz. ...
begins by finding the list of the primes up for instance using the sieve of Eratosthenes, 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, 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 In mathematics, a geometric series is the sum of an infinite number of terms that have a constant ratio between successive terms. For example, the series :\frac \,+\, \frac \,+\, \frac \,+\, \frac \,+\, \cdots is geometric, because each suc ...
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 In mathematics, an alternating series is an infinite series of the form \sum_^\infty (-1)^n a_n or \sum_^\infty (-1)^ a_n with for all . The signs of the general terms alternate between positive and negative. Like any series, an alternatin ...
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 factorial In mathematics, Bhargava's factorial function, or simply Bhargava factorial, is a certain generalization of the factorial function developed by the Fields Medal winning mathematician Manjul Bhargava as part of his thesis in Harvard University in ...
s are a family of integer sequences defined by
Manjul Bhargava Manjul Bhargava (born 8 August 1974) is a Canadian-American mathematician. He is the Brandon Fradd, Class of 1983, Professor of Mathematics at Princeton University, the Stieltjes Professor of Number Theory at Leiden University, and also holds A ...
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 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 at half-integers and the volumes of hyperspheres, and in counting binary trees and perfect matchings. ;Exponential factorial :Just as triangular numbers 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 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 derivative In mathematics, the derivative of a function of a real variable measures the sensitivity to change of the function value (output value) with respect to a change in its argument (input value). Derivatives are a fundamental tool of calculus. F ...
s of polynomials, and in the
factorial moment In probability theory, the factorial moment is a mathematical quantity defined as the expected value, expectation or average of the falling factorial of a random variable. Factorial moments are useful for studying non-negative integer-valued random ...
s of random variables. ;Hyperfactorials :The
hyperfactorial In mathematics, and more specifically number theory, the hyperfactorial of a positive integer n is the product of the numbers of the form x^x from 1^1 to n^n. Definition The hyperfactorial of a positive integer n is the product of the numbers ...
of n is the product 1^1\cdot 2^2\cdots n^n. These numbers form the discriminants of Hermite polynomials. They can be continuously interpolated by the
K-function In mathematics, the -function, typically denoted ''K''(''z''), is a generalization of the hyperfactorial to complex numbers, similar to the generalization of the factorial to the gamma function. Definition Formally, the -function is define ...
, and obey analogues to Stirling's formula and Wilson's theorem. ;Jordan–Pólya numbers :The
Jordan–Pólya number In mathematics, the Jordan–Pólya numbers are the numbers that can be obtained by multiplying together one or more factorials, not required to be distinct from each other. For instance, 480 is a Jordan–Pólya number because Every tree has a nu ...
s are the products of factorials, allowing repetitions. Every tree has a symmetry group 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 numbers less than or equal this construction gives them some similar divisibility properties to factorials, but unlike factorials they are
squarefree In mathematics, a square-free integer (or squarefree integer) is an integer which is divisible by no square number other than 1. That is, its prime factorization has exactly one factor for each prime that appears in it. For example, is square-fr ...
. As with the factorial primes researchers have studied
primorial prime In mathematics, a primorial prime is a prime number of the form ''pn''# ± 1, where ''pn''# is the primorial of ''pn'' (i.e. the product of the first ''n'' primes). Primality tests show that : ''pn''# − 1 is prime for ''n ...
s ;Subfactorial :The
subfactorial In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position. In other words, a derangement is a permutation that has no fixed points. The number of derangements of ...
yields the number of
derangement In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position. In other words, a derangement is a permutation that has no fixed points. The number of derangements of ...
s 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 In mathematics, the Barnes G-function ''G''(''z'') is a function that is an extension of superfactorials to the complex numbers. It is related to the gamma function, the K-function and the Glaisher–Kinkelin constant, and was named after mathe ...
.


References


External links

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