In
mathematics
Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
, 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
with the next smaller factorial:
For example,
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 multiplication, multiplying no factors. It is by convention equal to the multiplicative identity (assuming there is an identity for the multiplication operat ...
.
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
Jain literature () 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 canonical ''Jain Agamas'', which are wri ...
, and by Jewish mystics in the Talmudic book ''
Sefer Yetzirah
''Sefer Yetzirah'' ( ''Sēp̄er Yəṣīrā'', ''Book of Formation'', or ''Book of Creation'') is a work of Jewish mysticism. Early commentaries, such as the ''Kuzari'', treated it as a treatise on mathematical and linguistic theory, as opposed t ...
''. 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 as an end to obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many ...
, 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 cal ...
s – the
permutation
In mathematics, a permutation of a set can mean one of two different things:
* an arrangement of its members in a sequence or linear order, or
* the act or process of changing the linear order of an ordered set.
An example of the first mean ...
s – of
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 ( ...
, 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 ''a_n'' represents the coefficient of the ''n''th term and ''c'' is a co ...
for the
exponential function and other functions, and they also have applications in
algebra
Algebra is a branch of mathematics that deals with abstract systems, known as algebraic structures, and the manipulation of expressions within those systems. It is a generalization of arithmetic that introduces variables and algebraic ope ...
,
number theory
Number theory is a branch of pure mathematics devoted primarily to the study of the integers and arithmetic functions. Number theorists study prime numbers as well as the properties of mathematical objects constructed from integers (for example ...
,
probability theory
Probability theory or probability calculus 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 expre ...
, and
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied 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 asymptotic 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 ...
provides an accurate approximation to the factorial of large numbers, showing that it grows more quickly than
exponential growth
Exponential growth occurs when a quantity grows as an exponential function of time. The quantity grows at a rate directly proportional to its present size. For example, when it is 3 times as big as it is now, it will be growing 3 times as fast ...
.
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, a ...
describes the exponents of the prime numbers in a
prime factorization
In mathematics, integer factorization is the decomposition of a positive integer into a product of integers. Every positive integer greater than 1 is either the product of two or more integer factors greater than 1, in which case it is a comp ...
of the factorials, and can be used to count the trailing zeros of the factorials.
Daniel Bernoulli
Daniel Bernoulli ( ; ; – 27 March 1782) was a Swiss people, Swiss-France, French mathematician and physicist and was one of the many prominent mathematicians in the Bernoulli family from Basel. He is particularly remembered for his applicati ...
and
Leonhard Euler
Leonhard Euler ( ; ; ; 15 April 170718 September 1783) was a Swiss polymath who was active as a mathematician, physicist, astronomer, logician, geographer, and engineer. He founded the studies of graph theory and topology and made influential ...
interpolate
In the mathematical field of numerical analysis, interpolation is a type of estimation, a method of constructing (finding) new data points based on the range of a discrete set of known data points.
In engineering and science, one often has a ...
d 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 for ...
s, except at the negative integers, the (offset)
gamma function
In mathematics, the gamma function (represented by Γ, capital Greek alphabet, Greek letter gamma) is the most common extension of the factorial function to complex numbers. Derived by Daniel Bernoulli, the gamma function \Gamma(z) is defined ...
.
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 of a number , denoted by , is the product of all the positive integers up to that have the same Parity (mathematics), parity (odd or even) as . That is,
n!! = \prod_^ (n-2k) = n (n-2) (n-4) \cdots.
Restated ...
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) .
\end ...
s,
primorial
In mathematics, and more particularly in number theory, primorial, denoted by "", is a function from natural numbers to natural numbers similar to the factorial function, but rather than successively multiplying positive integers, the function ...
s, and
subfactorials. Implementations of the factorial function are commonly used as an example of different
computer programming
Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by-step specifications of proc ...
styles, and are included in
scientific calculator
A scientific calculator is an Electronics, electronic calculator, either desktop or handheld, designed to perform calculations using basic (addition, subtraction, multiplication, Division (mathematics), division) and advanced (Trigonometric fun ...
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 multiplication, multiply two numbers. Depending on the size of the numbers, different algorithms are more efficient than others. Numerous algorithms are known and there has been much resea ...
s 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
Jain literature () 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 canonical ''Jain Agamas'', which are wri ...
, 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 ('; 1114–1185), also known as Bhāskarāchārya (), was an Indian people, Indian polymath, Indian mathematicians, mathematician, astronomer and engineer. From verses in his main work, Siddhānta Śiromaṇi, it can be inferre ...
mentioned factorials in his work Līlāvatī
''Līlāvatī'' is a treatise by Indian mathematician Bhāskara II 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 Hindu deities, principal deities of Hinduism. He is the supreme being within Vaishnavism, one of the major traditions within contemporary Hinduism, and the god of preservation ( ...
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 on both ends).
Conchs ...
, discus, mace, and lotus flower
''Nelumbo nucifera'', also known as the pink lotus, sacred lotus, Indian lotus, or simply lotus, is one of two extant taxon, extant species of aquatic plant in the Family (biology), family Nelumbonaceae. It is sometimes colloquially called a ...
) 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
''Sefer Yetzirah'' ( ''Sēp̄er Yəṣīrā'', ''Book of Formation'', or ''Book of Creation'') is a work of Jewish mysticism. Early commentaries, such as the ''Kuzari'', treated it as a treatise on mathematical and linguistic theory, as opposed t ...
'', 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 (, ), known variously by scholars as the Ktav Ashuri, Jewish script, square script and block script, is a unicase, unicameral abjad script used in the writing of the Hebrew language and other Jewish languages, most notably ...
. 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ī (; 718 – 786 CE), known as al-Farāhīdī, or al-Khalīl, was an Arab philologist, lexicographer and leading grammarian of Basra in ...
.[ Arab mathematician ]Ibn al-Haytham
Ḥasan Ibn al-Haytham (Latinization of names, Latinized as Alhazen; ; full name ; ) was a medieval Mathematics in medieval Islam, mathematician, Astronomy in the medieval Islamic world, astronomer, and Physics in the medieval Islamic world, p ...
(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 ...
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
Ancient Greek mathematics refers to the history of mathematical ideas and texts in Ancient Greece during Classical antiquity, classical and late antiquity, mostly from the 5th century BC to the 6th century AD. Greek mathematicians lived in cities ...
included some combinatorics, and Plato
Plato ( ; Greek language, Greek: , ; born BC, died 348/347 BC) was an ancient Greek philosopher of the Classical Greece, Classical period who is considered a foundational thinker in Western philosophy and an innovator of the writte ...
famously used 5,040 (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
Change ringing is the art of ringing a set of tuning (music), tuned bell (instrument), 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 ...
, 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
Luca Bartolomeo de Pacioli, O.F.M. (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 account ...
calculated factorials up to 11!, in connection with a problem of dining table arrangements. Christopher Clavius
Christopher Clavius, (25 March 1538 – 6 February 1612) was a Jesuit German mathematician, head of mathematicians at the , and astronomer who was a member of the Vatican commission that accepted the proposed calendar invented by Aloysius ...
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 ''a_n'' represents the coefficient of the ''n''th term and ''c'' is a co ...
for the exponential function, with the reciprocals of factorials for its coefficients, was first formulated in 1676 by Isaac Newton
Sir Isaac Newton () was an English polymath active as a mathematician, physicist, astronomer, alchemist, theologian, and author. Newton was a key figure in the Scientific Revolution and the Age of Enlightenment, Enlightenment that followed ...
in a letter to Gottfried Wilhelm Leibniz
Gottfried Wilhelm Leibniz (or Leibnitz; – 14 November 1716) was a German polymath active as a mathematician, philosopher, scientist and diplomat who is credited, alongside Sir Isaac Newton, with the creation of calculus in addition to ...
. Other important works of early European mathematics on factorials include extensive coverage in a 1685 treatise by John Wallis
John Wallis (; ; ) was an English clergyman and mathematician, who is given partial credit for the development of infinitesimal calculus.
Between 1643 and 1689 Wallis served as chief cryptographer for Parliament and, later, the royal court. ...
, a study of their approximate values for large values of 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
In mathematics, Stirling's approximation (or Stirling's formula) is an asymptotic 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 ...
, and work at the same time by Daniel Bernoulli
Daniel Bernoulli ( ; ; – 27 March 1782) was a Swiss people, Swiss-France, French mathematician and physicist and was one of the many prominent mathematicians in the Bernoulli family from Basel. He is particularly remembered for his applicati ...
and Leonhard Euler
Leonhard Euler ( ; ; ; 15 April 170718 September 1783) was a Swiss polymath who was active as a mathematician, physicist, astronomer, logician, geographer, and engineer. He founded the studies of graph theory and topology and made influential ...
formulating the continuous extension of the factorial function to the gamma function
In mathematics, the gamma function (represented by Γ, capital Greek alphabet, Greek letter gamma) is the most common extension of the factorial function to complex numbers. Derived by Daniel Bernoulli, the gamma function \Gamma(z) is defined ...
. Adrien-Marie Legendre
Adrien-Marie Legendre (; ; 18 September 1752 – 9 January 1833) was a French people, French mathematician who made numerous contributions to mathematics. Well-known and important concepts such as the Legendre polynomials and Legendre transforma ...
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, a ...
, describing the exponents in the factorization
In mathematics, factorization (or factorisation, see American and British English spelling differences#-ise, -ize (-isation, -ization), English spelling differences) or factoring consists of writing a number or another mathematical object as a p ...
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, 1 ...
s, in an 1808 text on number theory
Number theory is a branch of pure mathematics devoted primarily to the study of the integers and arithmetic functions. Number theorists study prime numbers as well as the properties of mathematical objects constructed from integers (for example ...
.
The notation 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 (mathematics), series and the Calculus, derivatives ...
, 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 from any succeeding term to its preceding term remains constant throughout the sequence. The constant difference is called common difference of that ...
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 is defined by the product of all positive integers not greater than [
This may be written more concisely in product notation as][
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
For example,
Factorial of zero
The factorial or in symbols, There are several motivations for this definition:
* For the definition of 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 multiplication, multiplying no factors. It is by convention equal to the multiplicative identity (assuming there is an identity for the multiplication operat ...
, 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 as an end to obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many ...
valid for all valid choices of their parameters. For instance, the number of ways to choose all elements from a set of is 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
Recursion occurs when the definition of a concept or process depends on a simpler or previous version of itself. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in m ...
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 allows for the compact expression of many formulae, such as the exponential function, 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 ''a_n'' represents the coefficient of the ''n''th term and ''c'' is a co ...
:
* This choice matches the gamma function
In mathematics, the gamma function (represented by Γ, capital Greek alphabet, Greek letter gamma) is the most common extension of the factorial function to complex numbers. Derived by Daniel Bernoulli, the gamma function \Gamma(z) is defined ...
and the gamma function must have this value to be a continuous function
In mathematics, a continuous function is a function such that a small variation of the argument induces a small variation of the value of the function. This implies there are no abrupt changes in value, known as '' discontinuities''. More preci ...
.
Applications
The earliest uses of the factorial function involve counting permutations
In mathematics, a permutation of a Set (mathematics), set can mean one of two different things:
* an arrangement of its members in a sequence or linear order, or
* the act or process of changing the linear order of an ordered set.
An example ...
: there are different ways of arranging 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 as an end to obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many ...
, 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 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 ...
s (subsets of from a set with and can be computed from factorials using the formula 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 items is the nearest integer
In algebra
Algebra is a branch of mathematics that deals with abstract systems, known as algebraic structures, and the manipulation of expressions within those systems. It is a generalization of arithmetic that introduces variables and algebraic ope ...
, 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, the power expands into a polynomial with terms of the form , where the exponents and a ...
, 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 polynomi ...
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
Order, ORDER or Orders may refer to:
* A socio-political or established or existing order, e.g. World order, Ancien Regime, Pax Britannica
* Categorization, the process in which ideas and objects are recognized, differentiated, and understood
* H ...
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 grou ...
s. In calculus
Calculus 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 generalizations of arithmetic operations.
Originally called infinitesimal calculus or "the ...
, 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 ( ...
, 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 ''a_n'' represents the coefficient of the ''n''th term and ''c'' is a co ...
, most notably in the series for the exponential function,[
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
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 u ...
), where they cancel factors of coming from the This usage of factorials in power series connects back to analytic combinatorics
Analytic combinatorics uses techniques from complex analysis to solve problems in enumerative combinatorics, specifically to find asymptotic estimates for the coefficients of generating functions.
History
One of the earliest uses of analyti ...
through the exponential generating function, which for a combinatorial class with elements of is defined as the power series
In number theory
Number theory is a branch of pure mathematics devoted primarily to the study of the integers and arithmetic functions. Number theorists study prime numbers as well as the properties of mathematical objects constructed from integers (for example ...
, 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 (mathematics), multiple'' of m. An integer n is divis ...
of 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, a ...
. 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
, leading to a proof of Euclid's theorem
Euclid's theorem is a fundamental statement in number theory that asserts that there are Infinite set, infinitely many prime number, prime numbers. It was first proven by Euclid in his work ''Euclid's Elements, Elements''. There are several proof ...
that the number of primes is infinite. When is itself prime it is called a factorial prime
A factorial prime is a prime number that is one less or one more than a factorial (all factorials greater than 1 are even).
The first 10 factorial primes (for ''n'' = 1, 2, 3, 4, 6, 7, 11, 12, 14) are :
: 2 (0! + 1 or 1! + 1) ...
; relatedly, Brocard's problem
Brocard's problem is a problem in mathematics that seeks integer values of n such that n!+1 is a perfect square, where n! is the factorial. Only three values of n are known — 4, 5, 7 — and it is not known whether there are any more.
...
, also posed by Srinivasa Ramanujan
Srinivasa Ramanujan Aiyangar
(22 December 188726 April 1920) was an Indian mathematician. Often regarded as one of the greatest mathematicians of all time, though he had almost no formal training in pure mathematics, he made substantial con ...
, concerns the existence of square number
In mathematics, a square number or perfect square is an integer that is the square (algebra), square of an integer; in other words, it is the multiplication, product of some integer with itself. For example, 9 is a square number, since it equals ...
s of the form In contrast, the numbers 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)-st and the ''n''-th prime numbers, i.e.,
:g_n = p_ - p_n. ...
s. 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 ( ; 26March 191320September 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 discrete mathematics, g ...
, was based on the divisibility properties of factorials. The factorial number system
In combinatorics, the factorial number system (also known as 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 ...
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 or probability calculus 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 expre ...
, 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 if these events occur with a known const ...
and in the probabilities of random permutations. In computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, 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 Iteration#Computing, systematically checking all possible candida ...
es over permutations, factorials arise in the lower bound of 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 oc ...
a set of items,[ and in the analysis of chained ]hash table
In computer science, a hash table is a data structure that implements an associative array, also called a dictionary or simply map; an associative array is an abstract data type that maps Unique key, keys to Value (computer science), values. ...
s, 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 (: quanta) is the minimum amount of any physical entity (physical property) involved in an interaction. The fundamental notion that a property can be "quantized" is referred to as "the hypothesis of quantization". This me ...
and statistical physics
In physics, statistical mechanics is a mathematical framework that applies statistical methods and probability theory to large assemblies of microscopic entities. Sometimes called statistical physics or statistical thermodynamics, its applicati ...
, 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. Sometimes called statistical physics or statistical thermodynamics, its applicati ...
, calculations of entropy
Entropy is a scientific concept, most commonly associated with states of disorder, randomness, or uncertainty. The term and the concept are used in diverse fields, from classical thermodynamics, where it was first recognized, to the micros ...
such as Boltzmann's entropy formula
In statistical mechanics, Boltzmann's entropy formula (also known as the Boltzmann–Planck equation, not to be confused with the more general Boltzmann equation, which is a partial differential equation) is a probability equation relating the en ...
or the Sackur–Tetrode equation must correct the count of microstates
A microstate or ministate is a sovereign state having a very small population or land area, usually both. However, the meanings of "state" and "very small" are not well-defined in international law. Some recent attempts to define microstates ...
by dividing by the factorials of the numbers of each type of indistinguishable particle to avoid the Gibbs paradox
In statistical mechanics, a semi-classical derivation of entropy that does not take into account the Identical particles, indistinguishability of particles yields an expression for entropy which is not extensive variable, extensive (is not proport ...
. 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 occurs when a quantity grows as an exponential function of time. The quantity grows at a rate directly proportional to its present size. For example, when it is 3 times as big as it is now, it will be growing 3 times as fast ...
, 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 a logarithm, base of the e (mathematical constant), mathematical constant , which is an Irrational number, irrational and Transcendental number, transcendental number approxima ...
of the factorial, which turns its product formula into a sum, and then estimating the sum by an integral:
Exponentiating the result (and ignoring the negligible term) approximates 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 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 asymptotic 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 ...
:
Here, the symbol means that, as 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 t ...
that becomes even more accurate when taken to greater numbers of terms:
An alternative version uses only odd exponents in the correction terms:[
Many other variations of these formulas have also been developed, by ]Srinivasa Ramanujan
Srinivasa Ramanujan Aiyangar
(22 December 188726 April 1920) was an Indian mathematician. Often regarded as one of the greatest mathematicians of all time, though he had almost no formal training in pure mathematics, he made substantial con ...
, Bill Gosper, and others.[
The ]binary logarithm
In mathematics, the binary logarithm () is the exponentiation, power to which the number must be exponentiation, raised to obtain the value . That is, for any real number ,
:x=\log_2 n \quad\Longleftrightarrow\quad 2^x=n.
For example, th ...
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 oc ...
ing, can be very accurately estimated using Stirling's approximation. In the formula below, the term invokes big O notation
Big ''O'' notation is a mathematical notation that describes the asymptotic analysis, limiting behavior of a function (mathematics), function when the Argument of a function, argument tends towards a particular value or infinity. Big O is a memb ...
.
Divisibility and digits
The product formula for the factorial implies that 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 divisibl ...
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
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, a ...
, which gives the exponent of each prime in the prime factorization of as
Here 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
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, 1 ...
s in different ways produces the multiplicative partitions of factorials.
The special case of Legendre's formula for gives the number of trailing zeros
A trailing zero is any 0 digit that comes after the last nonzero digit in a number string in positional notation. For digits ''before'' the decimal point, the trailing zeros between the decimal point and the last nonzero digit are necessary for con ...
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 from , and dividing the result by four. Legendre's formula implies that the exponent of the prime 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 ...
, states that is divisible by if and only if 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 is given by the smallest for which 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 is itself any product of factorials, then 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), also known as greatest common factor (GCF), of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For two integers , , the greatest co ...
of the values of a primitive polynomial of degree 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 small variation of the argument induces a small variation of the value of the function. This implies there are no abrupt changes in value, known as '' discontinuities''. More preci ...
.[ The most widely used of these][ uses the ]gamma function
In mathematics, the gamma function (represented by Γ, capital Greek alphabet, Greek letter gamma) is the most common extension of the factorial function to complex numbers. Derived by Daniel Bernoulli, the gamma function \Gamma(z) is defined ...
, which can be defined for positive real numbers as the integral
In mathematics, an integral is the continuous analog of a Summation, sum, which is used to calculate area, areas, volume, volumes, and their generalizations. Integration, the process of computing an integral, is one of the two fundamental oper ...
The resulting function is related to the factorial of a non-negative integer by the equation
which can be used as a definition of the factorial for non-integer arguments.
At all values for which both and 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 ...
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
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 for ...
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 (geometry), plane formed by the complex numbers, with a Cartesian coordinate system such that the horizontal -axis, called the real axis, is formed by the real numbers, and the vertical -axis, call ...
by solving for Euler's reflection formula
However, this formula cannot be used at integers because, for them, the term would produce a division by zero
In mathematics, division by zero, division (mathematics), division where the divisor (denominator) is 0, zero, is a unique and problematic special case. Using fraction notation, the general example can be written as \tfrac a0, where a is the di ...
. 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 ne ...
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 de ...
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
In mathematics, Hadamard's gamma function, named after Jacques Hadamard, is an extension of the factorial function, different from the classical gamma function (it is an instance of a pseudogamma function). This function, with its argument shift ...
, 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 ...
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(z) = \frac\ln\Gamma(z) = \frac.
It is the first of the polygamma functions. This function is Monotonic function, strictly increasing a ...
is the logarithmic derivative
In mathematics, specifically in calculus and complex analysis, the logarithmic derivative of a function is defined by the formula
\frac
where is the derivative of . Intuitively, this is the infinitesimal relative change in ; that is, the in ...
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, \dot ...
s, offset by the Euler–Mascheroni constant
Euler's constant (sometimes called the Euler–Mascheroni constant) is a mathematical constant, usually denoted by the lowercase Greek letter gamma (), defined as the limiting difference between the harmonic series and the natural logarith ...
.
Computation
The factorial function is a common feature in scientific calculator
A scientific calculator is an Electronics, electronic calculator, either desktop or handheld, designed to perform calculations using basic (addition, subtraction, multiplication, Division (mathematics), division) and advanced (Trigonometric fun ...
s. 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 can be expressed in pseudocode
In computer science, pseudocode is a description of the steps in an algorithm using a mix of conventions of programming languages (like assignment operator, conditional operator, loop) with informal, usually self-explanatory, notation of actio ...
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
Recursion occurs when the definition of a concept or process depends on a simpler or previous version of itself. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in m ...
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 to pure functions and returning the cached result when the same inputs occur ag ...
, dynamic programming, and functional programming
In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declarat ...
. 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 or RA-machine) is a model of computation that describes an abstract machine in the general class of register machines. The RA-machine is very similar to the counter machine but with the added capab ...
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 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
In computer science, a call stack is a Stack (abstract data type), stack data structure that stores information about the active subroutines and block (programming), inline blocks of a computer program. This type of stack is also known as an exe ...
. However, this model of computation is only suitable when is small enough to allow to fit into a machine word
In computing, a word is any Central processing unit, processor design's natural unit of data. A word is a fixed-sized Data (computing), datum handled as a unit by the instruction set or the hardware of the processor. The number of bits or digits ...
. 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 a maximum of 32- bit units. Compared to smaller bit widths, 32-bit computers can perform la ...
[ 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 central processing units (CPU) and arithmetic logic units (ALU) are those that are based on processor registers, a ...
integers
An integer is the number zero (0), a positive natural number (1, 2, 3, ...), or the negation of a positive natural number (−1, −2, −3, ...). The negations or additive inverses of the positive natural numbers are referred to as negative in ...
. Floating point
In computing, floating-point arithmetic (FP) is arithmetic on subsets of real numbers formed by a ''significand'' (a signed sequence of a fixed number of digits in some base) multiplied by an integer power of that base.
Numbers of this form ...
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 po ...
, because of fast growth and integer overflow
In computer programming, an integer overflow occurs when an arithmetic operation on integers 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 maximu ...
. Time of computation can be analyzed as a function of the number of digits or bits in the result.[ By Stirling's formula, has 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 multiplication, multiply two numbers. Depending on the size of the numbers, different algorithms are more efficient than others. Numerous algorithms are known and there has been much resea ...
s taking time 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 by multiplying the numbers from 1 in sequence is inefficient, because it involves multiplications, a constant fraction of which take time 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 dir ...
that multiplies a sequence of numbers by splitting it into two subsequences of 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
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
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 number, composite (i.e., not prime) the multiples of each prime, starting with ...
, 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 is an -bit number, by the prime number theorem
In mathematics, the prime number theorem (PNT) describes the asymptotic analysis, 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 p ...
, so the time for the first step is , 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 a series (mathematics), series summing the terms of an infinite geometric sequence, in which the ratio of consecutive terms is constant. For example, 1/2 + 1/4 + 1/8 + 1/16 + ⋯, the series \tfrac12 + \tfrac1 ...
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 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
In mathematics, an alternating factorial is the absolute value of the alternating sum of the first ''n'' factorials of positive integers.
This is the same as their sum, with the odd-indexed factorials multiplied by −1 if ''n'' is even, and t ...
is the absolute value of the alternating sum of the first 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
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
In mathematics, the double factorial of a number , denoted by , is the product of all the positive integers up to that have the same Parity (mathematics), parity (odd or even) as . That is,
n!! = \prod_^ (n-2k) = n (n-2) (n-4) \cdots.
Restated ...
and denoted by That is, For example, . Double factorials are used in trigonometric integrals, in expressions for the gamma function
In mathematics, the gamma function (represented by Γ, capital Greek alphabet, Greek letter gamma) is the most common extension of the factorial function to complex numbers. Derived by Daniel Bernoulli, the gamma function \Gamma(z) is defined ...
at half-integer
In mathematics, a half-integer is a number of the form
n + \tfrac,
where n is an integer. For example,
4\tfrac12,\quad 7/2,\quad -\tfrac,\quad 8.5
are all ''half-integers''. The name "half-integer" is perhaps misleading, as each integer n is its ...
s and the volumes of hyperspheres, and in counting binary trees
In computer science, a binary tree is a tree data structure in which each node has at most two children, referred to as the ''left child'' and the ''right child''. That is, it is a ''k''-ary tree with . A recursive definition using set theory ...
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 with edges and vertices , a perfect matching in is a subset of , such that every vertex in is adjacent to exact ...
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 in ...
s sum the numbers from and factorials take their product, the exponential factorial exponentiates. The exponential factorial is defined recursively For example, the exponential factorial of 4 is These numbers grow much more quickly than regular factorials.
;Falling factorial
:The notations or are sometimes used to represent the product of the greatest 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) .
\end ...
or backward factorial, and the notation is a Pochhammer symbol. Falling factorials count the number of different sequences of distinct items that can be drawn from a universe of items. They occur as coefficients in the higher derivative
In mathematics, the derivative is a fundamental tool that quantifies the sensitivity to change of a function's output with respect to its input. The derivative of a function of a single variable at a chosen input value, when it exists, is t ...
s of polynomials, and in the factorial moments of random variable
A random variable (also called random quantity, aleatory variable, or stochastic variable) is a Mathematics, mathematical formalization of a quantity or object which depends on randomness, random events. The term 'random variable' in its mathema ...
s.
;Hyperfactorials
:The hyperfactorial of is the product . 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 zero of a function, roots without computing them. More precisely, it is a polynomial function of the coef ...
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 a ...
. 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, e.g., including only woody plants with secondary growth, only ...
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
In mathematics, and more particularly in number theory, primorial, denoted by "", is a function from natural numbers to natural numbers similar to the factorial function, but rather than successively multiplying positive integers, the function ...
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 prime
A factorial prime is a prime number that is one less or one more than a factorial (all factorials greater than 1 are even).
The first 10 factorial primes (for ''n'' = 1, 2, 3, 4, 6, 7, 11, 12, 14) are :
: 2 (0! + 1 or 1! + 1) ...
s 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 ...
s
;Subfactorial
:The subfactorial yields the number of derangements of a set of objects. It is sometimes denoted , and equals the closest integer
;Superfactorial
:The superfactorial of is the product of the first factorials. The superfactorials are continuously interpolated by the Barnes G-function
In mathematics, the Barnes G-function ''G''(''z'') is a function (mathematics), 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, an ...
.
References
External links
*
*
*
{{Authority control
Combinatorics
Gamma and related functions
Factorial and binomial topics
Unary operations