{
  "id": "stirlings-approximation",
  "title": "Stirling's approximation",
  "lang": "en",
  "source_lang": "en",
  "summary": "Stirling's approximation describes the growth of factorials and the gamma function, with refinements that provide systematic corrections and explicit error bounds.",
  "category": "mathematics",
  "subcategory": "analysis",
  "type": "concept",
  "aliases": [
    "Stirling's formula",
    "Stirling approximation"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/stirlings-approximation/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/stirlings-approximation/",
      "json": "https://aiwiki.page/zh/stirlings-approximation.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "Stirling's approximation is an asymptotic formula for the factorial of a large positive integer:\n\n\\[n!\\sim \\sqrt{2\\pi n}\\left(\\frac{n}{e}\\right)^n.\\]\n\nHere \\(e\\) is Euler's number, and the symbol \\(\\sim\\) means that the ratio of the two sides tends to \\(1\\) as \\(n\\) tends to infinity. The formula converts a product of many integers into an expression involving powers and an exponential. It is fundamental in combinatorics, probability, mathematical analysis, and numerical computation. More precise forms supply correction terms, rigorous error bounds, and extensions to the gamma function."
    },
    {
      "heading": "Basic forms and meaning",
      "text": "For a positive integer \\(n\\),\n\n\\[n!=1\\cdot2\\cdots n.\\]\n\nStirling's approximation states that\n\n\\[\\lim_{n\\to\\infty} \\frac{n!}{\\sqrt{2\\pi n}(n/e)^n}=1.\\]\n\nThis is a statement about relative error, not absolute error. Although the relative error tends to zero, the absolute difference between \\(n!\\) and the leading approximation grows without bound.\n\nTaking the natural logarithm gives an equivalent form:\n\n\\[\\log(n!) = n\\log n-n+\\frac12\\log(2\\pi n) +O\\!\\left(\\frac1n\\right).\\]\n\nThe big-O notation specifies the order of the remaining error as \\(n\\) grows. A coarser but often useful version is\n\n\\[\\log(n!)=n\\log n-n+O(\\log n).\\]\n\nThe leading term \\(n\\log n\\) captures most of the logarithmic growth. The subtraction of \\(n\\) is essential for a multiplicatively accurate estimate, while the factor \\(\\sqrt{2\\pi n}\\) supplies the normalization needed for asymptotic equivalence.\n\nFor example,\n\n\\[10!=3{,}628{,}800,\\]\n\nwhereas\n\n\\[\\sqrt{20\\pi}\\left(\\frac{10}{e}\\right)^{10} \\approx3{,}598{,}695.62.\\]\n\nThe leading approximation is about \\(0.83\\%\\) too small. Including just one correction term reduces the relative error to about \\(0.0032\\%\\)."
    },
    {
      "heading": "Historical development",
      "text": "The formula emerged from work on factorials and probability in the early eighteenth century. Abraham de Moivre obtained an approximation of the form\n\n\\[n!\\sim C\\sqrt n\\left(\\frac ne\\right)^n,\\]\n\nwith an initially undetermined constant \\(C\\). James Stirling identified the constant as \\(\\sqrt{2\\pi}\\). Their results appeared around 1730.\n\nThe historical roles are therefore complementary: de Moivre established the principal asymptotic structure, while Stirling supplied the constant associated with the familiar formula. Later developments in summation methods and asymptotic analysis produced the systematic correction series now commonly called Stirling's series."
    },
    {
      "heading": "Correction terms and rigorous bounds",
      "text": "A refined multiplicative expansion is\n\n\\[n!\\sim \\sqrt{2\\pi n}\\left(\\frac ne\\right)^n \\left( 1+\\frac{1}{12n} +\\frac{1}{288n^2} -\\frac{139}{51840n^3} -\\frac{571}{2488320n^4} +\\cdots \\right).\\]\n\nThe corresponding logarithmic expansion has a simpler structure:\n\n\\[\\log(n!) \\sim \\left(n+\\frac12\\right)\\log n-n +\\frac12\\log(2\\pi) +\\frac{1}{12n} -\\frac{1}{360n^3} +\\frac{1}{1260n^5} -\\frac{1}{1680n^7} +\\cdots.\\]\n\nMore generally, for a fixed nonnegative integer \\(m\\),\n\n\\[\\log(n!) = \\left(n+\\frac12\\right)\\log n-n +\\frac12\\log(2\\pi) + \\sum_{k=1}^{m} \\frac{B_{2k}}{2k(2k-1)n^{2k-1}} +R_m(n),\\]\n\nwhere \\(B_{2k}\\) are Bernoulli numbers; the sum is empty when \\(m=0\\).\n\nFor positive \\(n\\), the remainder has the sign of the first omitted term and satisfies\n\n\\[0<(-1)^mR_m(n) < \\frac{|B_{2m+2}|}{(2m+2)(2m+1)n^{2m+1}}.\\]\n\nThus, truncating the logarithmic series gives both an approximation and a direct bound on its error.\n\nA particularly convenient pair of bounds, often called Robbins' bounds, holds for every integer \\(n\\geq1\\):\n\n\\[\\sqrt{2\\pi n}\\left(\\frac ne\\right)^n e^{1/(12n+1)} < n! < \\sqrt{2\\pi n}\\left(\\frac ne\\right)^n e^{1/(12n)}.\\]\n\nThese inequalities show, in particular, that the leading Stirling expression always underestimates \\(n!\\).\n\nAn asymptotic series, not a convergent series\n\nStirling's correction series generally diverges when treated as an infinite series at a fixed argument. Its meaning is asymptotic: retaining any fixed number of terms gives the stated order of accuracy as \\(n\\to\\infty\\).\n\nThis differs from a convergent Taylor series, where taking indefinitely more terms approaches the function within a suitable domain. In a divergent asymptotic expansion, terms typically decrease in size at first and then increase. Truncation near the smallest term is often effective; continuing far beyond that point can worsen the approximation."
    },
    {
      "heading": "Why the formula arises",
      "text": "Two approaches explain different features of Stirling's formula.\n\nSummation and the Euler–Maclaurin formula\n\nTaking logarithms turns the factorial product into a sum:\n\n\\[\\log(n!)=\\sum_{k=1}^{n}\\log k.\\]\n\nAn integral gives the first approximation:\n\n\\[\\int_1^n\\log x\\,dx=n\\log n-n+1.\\]\n\nThis explains the dominant terms \\(n\\log n-n\\), but not the complete normalization.\n\nThe Euler–Maclaurin formula refines the relationship between a sum and an integral by adding endpoint and derivative corrections. Applied to \\(\\log x\\), it yields the logarithmic Stirling expansion, including the term \\(\\frac12\\log n\\) and the inverse odd powers of \\(n\\).\n\nDetermining the constant term requires an additional normalization argument. One classical route uses Wallis' product for \\(\\pi\\), yielding the constant \\(\\frac12\\log(2\\pi)\\).\n\nThe gamma integral and Gaussian concentration\n\nThe gamma function gives the exact representation\n\n\\[n!=\\Gamma(n+1)=\\int_0^\\infty t^ne^{-t}\\,dt.\\]\n\nThe integrand is largest at \\(t=n\\). Write\n\n\\[t=n+\\sqrt n\\,u.\\]\n\nFor fixed \\(u\\), expansion of the exponent gives\n\n\\[n\\log t-t = n\\log n-n-\\frac{u^2}{2} +O\\!\\left(\\frac{|u|^3}{\\sqrt n}\\right).\\]\n\nSince \\(dt=\\sqrt n\\,du\\), the dominant contribution is approximately\n\n\\[n^ne^{-n}\\sqrt n \\int_{-\\infty}^{\\infty}e^{-u^2/2}\\,du.\\]\n\nThe Gaussian integral equals \\(\\sqrt{2\\pi}\\), producing\n\n\\[n!\\sim\\sqrt{2\\pi n}(n/e)^n.\\]\n\nThis is an instance of Laplace's method: an integral whose integrand is sharply concentrated near a maximum is approximated by replacing its exponent locally with a quadratic function. A rigorous proof also controls the contribution away from that maximum."
    },
    {
      "heading": "Extension to the gamma function",
      "text": "For positive real \\(x\\), Stirling's formula extends to\n\n\\[\\Gamma(x) \\sim \\sqrt{2\\pi}\\,x^{x-\\frac12}e^{-x}.\\]\n\nEquivalently,\n\n\\[\\Gamma(x+1) \\sim \\sqrt{2\\pi x}\\left(\\frac xe\\right)^x.\\]\n\nThese expressions must be distinguished carefully: \\(\\Gamma(x+1)=x\\Gamma(x)\\), so shifting the argument changes the power of \\(x\\).\n\nFor a complex variable \\(z\\), the logarithmic expansion is\n\n\\[\\log\\Gamma(z) \\sim \\left(z-\\frac12\\right)\\log z-z +\\frac12\\log(2\\pi) + \\sum_{k=1}^{\\infty} \\frac{B_{2k}}{2k(2k-1)z^{2k-1}}.\\]\n\nWith consistent branches of the logarithms, this expansion holds uniformly in closed sectors\n\n\\[|\\arg z|\\leq\\pi-\\delta, \\qquad \\delta>0,\\]\n\nas \\(|z|\\to\\infty\\).\n\nThe sector restriction excludes a neighborhood of the negative real axis, where the gamma function has poles at the nonpositive integers and logarithmic branch issues become important. Error bounds from the positive real case do not transfer unchanged to arbitrary complex arguments."
    },
    {
      "heading": "Applications",
      "text": "Counting and combinatorics\n\nMany quantities in combinatorics are factorial ratios. For a binomial coefficient, applying Stirling's formula to all three factorials gives\n\n\\[\\binom nk \\sim \\frac{1}{\\sqrt{2\\pi n p(1-p)}} \\exp\\!\\left(nH(p)\\right), \\qquad p=\\frac kn,\\]\n\nprovided \\(k\\to\\infty\\) and \\(n-k\\to\\infty\\). Here\n\n\\[H(p)=-p\\log p-(1-p)\\log(1-p)\\]\n\nis binary entropy measured using natural logarithms.\n\nWhen \\(p\\) remains bounded away from \\(0\\) and \\(1\\), the approximation is particularly straightforward. If \\(k\\) stays fixed while \\(n\\) grows, replacing \\(k!\\) by its leading Stirling approximation does not give a relative error tending to zero.\n\nA notable special case is the central binomial coefficient:\n\n\\[\\binom{2n}{n}\\sim\\frac{4^n}{\\sqrt{\\pi n}}.\\]\n\nSuch estimates describe the growth of many combinatorial sequences.\n\nProbability and statistics\n\nStirling's approximation converts discrete probabilities involving factorials into tractable expressions. For a binomial distribution with fixed success probability \\(p\\in(0,1)\\), it leads to the local Gaussian approximation\n\n\\[\\Pr(X=k) \\sim \\frac{1}{\\sqrt{2\\pi np(1-p)}} \\exp\\!\\left( -\\frac{(k-np)^2}{2np(1-p)} \\right)\\]\n\nas \\(n\\to\\infty\\), when \\(k-np=O(\\sqrt n)\\).\n\nThis connects factorial estimates with the normal distribution and the central limit theorem. The displayed approximation concerns individual probability masses in the central region; it is not automatically a relative-error approximation in far tails.\n\nThe formula also appears in calculations involving the Poisson and multinomial distributions, likelihoods, and asymptotic normalization constants.\n\nNumerical computation\n\nFactorials grow too rapidly for direct representation in many standard floating-point formats. Computing\n\n\\[\\log(n!) \\approx \\left(n+\\frac12\\right)\\log n-n +\\frac12\\log(2\\pi) +\\frac{1}{12n} -\\frac{1}{360n^3}\\]\n\navoids forming the enormous value of \\(n!\\) itself.\n\nLogarithmic calculations are especially useful for products and ratios of factorials, such as binomial probabilities and likelihood functions. However, subtracting several large, nearly equal logarithms can still cause cancellation and loss of accuracy. Reliable implementations therefore combine asymptotic formulas, argument shifting through the gamma recurrence, and methods designed for numerical stability."
    },
    {
      "heading": "Accuracy and limitations",
      "text": "The leading approximation has relative error\n\n\\[\\frac{n!}{\\sqrt{2\\pi n}(n/e)^n}-1 = \\frac{1}{12n}+O(n^{-2}).\\]\n\nConsequently, its accuracy improves at roughly the rate \\(1/n\\). Including the factor \\(1+1/(12n)\\) reduces the relative error to order \\(n^{-2}\\).\n\nSeveral distinctions are important:\n\n- Large arguments are required for asymptotic accuracy. Exact inequalities remain valid for small positive integers, but a truncated approximation may still have substantial relative error.\n- Absolute and relative errors behave differently. A small relative error in a huge factorial can correspond to a very large absolute discrepancy.\n- More terms do not always mean better accuracy. The correction series is asymptotic rather than convergent.\n- Approximating each factorial requires checking each argument. In a ratio such as \\(n!/[k!(n-k)!]\\), large \\(n\\) alone does not ensure that \\(k\\) and \\(n-k\\) are large.\n- Complex arguments require domain and branch control. The positive-real error bounds cannot be used indiscriminately throughout the complex plane."
    }
  ],
  "links": [
    "asymptotic-expansion",
    "factorial",
    "e-mathematical-constant",
    "natural-logarithm",
    "big-o-notation",
    "bernoulli-numbers",
    "infinite-series",
    "taylor-series",
    "integral",
    "gamma-function",
    "laplaces-method",
    "complex-number",
    "combinatorics",
    "binomial-coefficient",
    "information-entropy",
    "binomial-distribution",
    "normal-distribution",
    "central-limit-theorem",
    "floating-point-arithmetic",
    "numerical-stability"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}