TOPICS
Search

Factorial


The factorial n! is defined for a positive integer n as

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

So, for example, 4!=4·3·2·1=24. An older notation for the factorial was written FactorialOld (Mellin 1909; Lewin 1958, p. 19; Dudeney 1970; Gardner 1978; Conway and Guy 1996).

The special case 0! is defined to have value 0!=1, consistent with the combinatorial interpretation of there being exactly one way to arrange zero objects (i.e., there is a single permutation of zero elements, namely the empty set emptyset).

The factorial is implemented in the Wolfram Language as Factorial[n] or n!.

The triangular number T_n=n+(n-1)+...+2+1 can be regarded as the additive analog of the factorial n!=n·(n-1)...2·1. Another relationship between factorials and triangular numbers is given by the identity

 (2n)!=2^nproduct_(k=1)^nT_(2k-1)
(2)

(K. MacMillan, pers. comm., Jan. 21, 2008).

The factorial n! gives the number of ways in which n objects can be permuted. For example, 3!=6, since the six possible permutations of {1,2,3} are {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1}. The first few factorials for n=0, 1, 2, ... are 1, 1, 2, 6, 24, 120, ... (OEIS A000142).

The numbers of digits in (10^n)! for n=0, 1, ... are 1, 7, 158, 2568, 35660, 456574, 5565709, 65657060, ... (OEIS A061010).

Generalizations of the factorial such as the double factorial n!! and multifactorial n!...!_()_(k) can be defined. Note, however, that these are not equal to nested factorials (n!)!, ((n!)!)!, etc.

The first few values of (n!)! for n=1, 2, ... are 1, 2, 720, 620448401733239439360000, ... (Eureka 1974; OEIS A000197). The numbers of digits in (n!)! are 1, 1, 3, 24, 199, 1747, ... (OEIS A063979).

As n grows large, factorials begin acquiring tails of trailing zeros. To calculate the number Z of trailing zeros for n!, use

 Z=sum_(k=1)^(k_(max))|_n/(5^k)_|,
(3)

where

 k_(max)=|_log_5n_|
(4)

and |_x_| is the floor function (Gardner 1978, p. 63; Ogilvy and Anderson 1988, pp. 112-114). For n=1, 2, ..., the number of trailing zeros are 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, ... (OEIS A027868). This is a special application of the general result first discovered by Legendre in 1808 that the largest power of a prime p dividing n! is

 epsilon_p(n)=sum_(k=1)^(|_log_pn_|)|_n/(p^k)_|
(5)

(Landau 1974, pp. 75-76; Honsberger 1976; Hardy and Wright 1979, pp. 342; Ribenboim 1989; Ingham 1990, p. 20; Graham et al. 1994; Vardi 1991; Hardy 1999, pp. 18 and 21; Havil 2003, p. 165; Boros and Moll 2004, p. 5). This can be implemented in the Wolfram Language as

  HighestPower[p_?PrimeQ, n_] :=
    Sum[Floor[n/p^k], {k, Floor[Log[p,n]]}]

Stated another way, the exact power of a prime p which divides n! is

 (n-s_p(n))/(p-1),
(6)

where s_p(n) is the digit sum of n in base b (Boros and Moll 2004, p. 6). This can be implemented in the Wolfram Language as

  HighestPower2[p_Integer?PrimeQ, n_] :=
    (n - Total[IntegerDigits[n, p]])/(p - 1)

Therefore, as shown by Legendre,

 n!=product_(p<=n)p^(epsilon_p(n))
(7)

(Havil 2003, p. 165).

Let a(n) be the last nonzero digit in n!, then the first few values are 2, 6, 4, 2, 2, 4, 2, 8, 8, 8, 6, 8, ... (OEIS A008904). This sequence was studied by Kakutani (1967), who showed that this sequence is "5-automatic," meaning roughly that there exists a finite automaton which, when given the digits of n in base-5, will wind up in a state for which an output mapping specifies a(n). The exact distribution of digits follows from this result.

Factorial
FactorialReImAbs
Min Max
Re
Im Powered by webMathematica

By noting that

 n!=Gamma(n+1),
(8)

where Gamma(n) is the gamma function for integers n, the definition can be generalized to complex values

 z!=Gamma(z+1)=int_0^inftye^(-t)t^zdt.
(9)

This defines z! for all complex values of z, except when n is a negative integer, in which case n! is equal to complex infinity.

While Gauss (G1) introduced the notation

 Pi(s)=Gamma(s+1),
(10)

this notation was subsequently abandoned after Legendre introduced the gamma-notation (Edwards 2001, p. 8).

Using the identities for gamma functions, the values of (1/2n)! (half integral values) can be written explicitly

(-1/2)!=sqrt(pi)
(11)
(1/2)!=1/2sqrt(pi)
(12)
(n-1/2)!=(sqrt(pi))/(2^n)(2n-1)!!
(13)
(n+1/2)!=(sqrt(pi))/(2^(n+1))(2n+1)!!,
(14)

where n!! is a double factorial.

For integers s and n with s<n,

 ((s-n)!)/((2s-2n)!)=((-1)^(n-s)(2n-2s)!)/((n-s)!).
(15)

The logarithm of z! is frequently encountered

ln(z!)=1/2ln[(piz)/(sin(piz))]-gammaz-sum_(n=1)^(infty)(zeta(2n+1))/(2n+1)z^(2n+1)
(16)
=1/2ln[(piz)/(sin(piz))]-1/2ln((1+z)/(1-z))+(1-gamma)z-sum_(n=1)^(infty)[zeta(2n+1)-1](z^(2n+1))/(2n+1)
(17)
=sum_(n=1)^(infty)(z^n)/(n!)psi_(n-1)(1)
(18)
=-gammaz+sum_(n=2)^(infty)(-1)^n(z^n)/nzeta(n)
(19)
=-ln(1+z)+z(1-gamma)+sum_(n=2)^(infty)(-1)^n[zeta(n)-1](z^n)/n,
(20)

where gamma is the Euler-Mascheroni constant, zeta(z) is the Riemann zeta function, and psi_n(z) is the polygamma function.

It is also given by the limit

ln(z!)=ln[lim_(n->infty)(zn!)/((z)_(n+1))n^z]
(21)
=ln[lim_(n->infty)(n!)/((z+1)_n)n^z]
(22)
=ln[lim_(n->infty)(n!)/((z+1)(z+2)...(z+n))n^z]
(23)
=lim_(n->infty)[ln(n!)+zlnn-ln(z+1)-ln(z+2)-...-ln(z+n)],
(24)

where (z)_n is the Pochhammer symbol.

where gamma is the Euler-Mascheroni constant, zeta(z) is the Riemann zeta function, and psi_n(z) is the polygamma function. The factorial can be expanded in a series

 z!=sqrt(2pi)z^(z+1/2)e^(-z)(1+1/(12)z^(-1)+1/(288)z^(-2)-(139)/(51840)z^(-3)+...)
(25)

(OEIS A001163 and A001164). Stirling's series gives the series expansion for ln(z!),

ln(z!)=1/2ln(2pi)+(z+1/2)lnz-z+(B_2)/(2z)+...+(B_(2n))/(2n(2n-1)z^(2n-1))+...
(26)
=1/2ln(2pi)+(z+1/2)lnz-z+1/(12)z^(-1)-1/(360)z^(-3)+1/(1260)z^(-5)-...
(27)

(OEIS A046968 and A046969), where B_n is a Bernoulli number.

In general, the power-product sequences (Mudge 1997) are given by S_k^+/-(n)=(n!)^k+/-1. The first few terms of S_2^+(n) are 2, 5, 37, 577, 14401, 518401, ... (OEIS A020549), and S_2^+(n) is prime for n=1, 2, 3, 4, 5, 9, 10, 11, 13, 24, 65, 76, ... (OEIS A046029). The first few terms of S_2^-(n) are 0, 3, 35, 575, 14399, 518399, ... (OEIS A046032), but S_2^-(n) is prime for only n=2 since S_2^-(n)=(n!)^2-1=(n!+1)(n!-1) for n>2. The first few terms of S_3^-(n) are 0, 7, 215, 13823, 1727999, ... (OEIS A046033), and the first few terms of S_3^+(n) are 2, 9, 217, 13825, 1728001, ... (OEIS A019514).

The first few numbers n such that the sum of the factorials of their digits is equal to the prime counting function pi(n) are 6500, 6501, 6510, 6511, 6521, 12066, 50372, ... (OEIS A049529). This sequence is finite, with the largest term being a_(23)=11071599.

Numbers n such that

 (n-1)!+1=0 (mod n^2),
(28)

are called Wilson primes.

Brown numbers are pairs (m,n) of integers satisfying the condition of Brocard's problem, i.e., such that

 n!+1=m^2.
(29)

Only three such pairs are known: (5, 4), (11, 5), (71, 7). Erdős conjectured that these are the only three such pairs (Guy 1994, p. 193).


See also

Alladi-Grinstead Constant, Alternating Factorial, Brocard's Problem, Brown Numbers, Central Factorial, Double Factorial, Factorial Prime, Factorial Products, Factorial Sums, Factorion, Falling Factorial, Fibonorial, Gamma Function, Hyperfactorial, Legions Numbers, Leviathan Number, Multifactorial, Pochhammer Symbol, Primorial, Rising Factorial, Roman Factorial, Stirling's Series, Subfactorial, Superfactorial, Wilson Prime Explore this topic in the MathWorld classroom

Related Wolfram sites

http://functions.wolfram.com/GammaBetaErf/Factorial/

Explore with Wolfram|Alpha

References

Boros, G. and Moll, V. Irresistible Integrals: Symbolics, Analysis and Experiments in the Evaluation of Integrals. Cambridge, England: Cambridge University Press, 2004.Caldwell, C. K. "The Top Twenty: Primorial and Factorial Primes." http://www.utm.edu/research/primes/lists/top20/PrimorialFactorial.html.Conway, J. H. and Guy, R. K. "Factorial Numbers." In The Book of Numbers. New York: Springer-Verlag, pp. 65-66, 1996.Dudeney, H. E. Amusements in Mathematics. New York: Dover, p. 96, 1970.Edwards, H. M. "The Factorial Function." §in 1.3 Riemann's Zeta Function. New York: Dover, pp. 7-9, 2001.Gardner, M. "Factorial Oddities." Ch. 4 in Mathematical Magic Show: More Puzzles, Games, Diversions, Illusions and Other Mathematical Sleight-of-Mind from Scientific American. New York: Vintage, pp. 50-65, 1978.Gauss, C. F. "Disquisitiones Generales Circa Seriem Infinitam [(alphabeta)/(1·gamma)]x+[(alpha(alpha+1)beta(beta+1))/(1·2·gamma(gamma+1))]x^2 +[(alpha(alpha+1)(alpha+2)beta(beta+1)(beta+2))/(1·2·3·gamma(gamma+1)(gamma+2))]x^3+ etc. Pars Prior." Commentationes Societiones Regiae Scientiarum Gottingensis Recentiores, Vol. II. 1812. Reprinted in Gesammelte Werke, Bd. 3, pp. 123-163 and 207-229, 1866.Glynn, J. and Gray, T. The Beginner's Guide To Mathematica, Version 4. Cambridge, England: Cambridge University Press, 2000.Graham, R. L.; Knuth, D. E.; and Patashnik, O. "Factorial Factors." §4.4 in Concrete Mathematics: A Foundation for Computer Science, 2nd ed. Reading, MA: Addison-Wesley, pp. 111-115, 1994.Guy, R. K. "Equal Products of Factorials," "Alternating Sums of Factorials," and "Equations Involving Factorial n." §B23, B43, and D25 in Unsolved Problems in Number Theory, 2nd ed. New York: Springer-Verlag, pp. 80, 100, and 193-194, 1994.Hardy, G. H. Ramanujan: Twelve Lectures on Subjects Suggested by His Life and Work, 3rd ed. New York: Chelsea, 1999.Hardy, G. H. and Wright, E. M. An Introduction to the Theory of Numbers, 5th ed. Oxford, England: Clarendon Press, 1979.Havil, J. Gamma: Exploring Euler's Constant. Princeton, NJ: Princeton University Press, 2003.Hoey, D. "Re: 01 squares." math-fun@cs.arizona.edu posting, May 19, 1997.Honsberger, R. Mathematical Gems II. Washington, DC: Math. Assoc. Amer., p. 2, 1976.Ingham, A. E. The Distribution of Prime Numbers. Cambridge, England: Cambridge University Press, 1990.Jeffreys, H. and Jeffreys, B. S. Methods of Mathematical Physics, 3rd ed. Cambridge, England: Cambridge University Press, pp. 462-463, 1988.Kakutani, S. "Ergodic Theory of Shift Transformations." In Proc. 5th Berkeley Symposium on Mathematical Statistics and Probability, Vol. 2. Berkeley, CA: University of California Press, pp. 405-414, 1967.Landau, E. Handbuch der Lehre von der Verteilung der Primzahlen, 3rd ed. New York: Chelsea, 1974.Lewin, L. Dilogarithms and Associated Functions. London: Macdonald, 1958.Leyland, P. http://www.leyland.vispa.com/numth/factorization/factors/factorial+.txt.Leyland, P. http://www.leyland.vispa.com/numth/factorization/factors/factorial-.txt.Madachy, J. S. Madachy's Mathematical Recreations. New York: Dover, p. 174, 1979.Mellin, H. "Abrißeiner einheitlichen Theorie der Gamma- und der hypergeometrischen Funktionen." Math. Ann. 68, 305-337, 1909.Mudge, M. "Not Numerology but Numeralogy!" Personal Computer World, 279-280, 1997.Ogilvy, C. S. and Anderson, J. T. Excursions in Number Theory. New York: Dover, 1988.Petkovšek, M.; Wilf, H. S.; and Zeilberger, D. A=B. Wellesley, MA: A K Peters, p. 86, 1996. http://www.cis.upenn.edu/~wilf/AeqB.html.Press, W. H.; Flannery, B. P.; Teukolsky, S. A.; and Vetterling, W. T. "Gamma Function, Beta Function, Factorials, Binomial Coefficients." §6.1 in Numerical Recipes in FORTRAN: The Art of Scientific Computing, 2nd ed. Cambridge, England: Cambridge University Press, pp. 206-209, 1992.Ribenboim, P. The New Book of Prime Number Records. New York: Springer-Verlag, pp. 22-24, 1989.Sloane, N. J. A. Sequences A000142/M1675, A000197/M2187, A001163/M5400, A001164/M4878, A008904, A019514, A020549, A027868, A046029, A046032, A046033, A046968, A046969, A049529, A061010, and A063979 in "The On-Line Encyclopedia of Integer Sequences."Spanier, J. and Oldham, K. B. "The Factorial Function n! and Its Reciprocal." Ch. 2 in An Atlas of Functions. Washington, DC: Hemisphere, pp. 19-33, 1987.Trott, M. The Mathematica GuideBook for Programming. New York: Springer-Verlag, p. 81, 2004. http://www.mathematicaguidebooks.org/.Vardi, I. Computational Recreations in Mathematica. Reading, MA: Addison-Wesley, p. 67, 1991.Vout, C. and Brown, M. "Problems Drive." Eureka 37, 11, 1974.

Referenced on Wolfram|Alpha

Factorial

Cite this as:

Weisstein, Eric W. "Factorial." From MathWorld--A Wolfram Web Resource. https://mathworld.wolfram.com/Factorial.html

Subject classifications