{
  "id": "factorial",
  "title": "Factorial",
  "lang": "en",
  "source_lang": "en",
  "summary": "The factorial of a nonnegative integer is the product of all positive integers up to it, with zero factorial defined as one.",
  "category": "mathematics",
  "subcategory": "discrete-logic",
  "type": "concept",
  "aliases": [
    "Factorial function"
  ],
  "generated_at": "2026-10-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/factorial/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/factorial/",
      "json": "https://aiwiki.page/zh/factorial.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The factorial is a function that assigns to each nonnegative integer \\(n\\) the product of all positive integers from \\(1\\) through \\(n\\). Written \\(n!\\) and read “\\(n\\) factorial,” it includes the convention \\(0!=1\\). Factorials are fundamental in combinatorics, particularly for counting arrangements of distinct objects, and also appear in mathematical analysis and scientific computation. (reference.wolfram.com)"
    },
    {
      "heading": "Definition and elementary properties",
      "text": "For a positive integer \\(n\\),\n\n\\[n!=\\prod_{k=1}^{n}k=1\\cdot2\\cdot3\\cdots n.\\]\n\nFor example, \\(4!=24\\) and \\(5!=120\\). Beginning with \\(n=0\\), the first values are\n\n\\[1,\\ 1,\\ 2,\\ 6,\\ 24,\\ 120,\\ 720,\\ 5040.\\]\n\nThe exclamation mark denotes this multiplication operation, not punctuation or exponentiation. (reference.wolfram.com)\n\nAn equivalent recurrence relation is\n\n\\[0!=1,\\qquad n!=n(n-1)!\\quad(n\\geq1).\\]\n\nThe zero case agrees with the convention that an empty product equals the multiplicative identity, \\(1\\). It also has a counting interpretation: there is exactly one ordering of a collection containing no objects—the empty ordering. Consequently, formulas involving factorials remain valid at boundary cases such as selecting no objects. (reference.wolfram.com)\n\nSuccessive factorials satisfy \\((n+1)!/n!=n+1\\). This allows common factors to be canceled without evaluating either factorial fully. For example, \\(8!/6!=8\\cdot7=56\\). These identities follow directly from the product definition. (reference.wolfram.com)"
    },
    {
      "heading": "Counting arrangements and selections",
      "text": "A permutation is an ordering of distinct objects. There are \\(n!\\) permutations of \\(n\\) objects: the first position has \\(n\\) possible occupants, the second has \\(n-1\\), and successive positions have progressively fewer choices. Multiplication gives \\(n(n-1)\\cdots1\\). Three distinct objects therefore have six possible orderings. (math.dartmouth.edu)\n\nIf only \\(k\\) objects are selected and their order matters, the number of arrangements without repetition is\n\n\\[P(n,k)=\\frac{n!}{(n-k)!},\\qquad 0\\leq k\\leq n.\\]\n\nIf order does not matter, each selected subset has been counted \\(k!\\) times. Dividing by this number gives the binomial coefficient,\n\n\\[\\binom nk=\\frac{n!}{k!(n-k)!}.\\]\n\nThus five distinct objects yield twenty ordered selections of two objects, but only ten unordered selections. (math.dartmouth.edu)\n\nWhen objects include indistinguishable copies, the count changes. If \\(n_i\\) objects belong to category \\(i\\), with \\(n_1+\\cdots+n_r=n\\), their distinct orderings number\n\n\\[\\frac{n!}{n_1!\\cdots n_r!}.\\]\n\nThis multinomial coefficient removes the overcounting caused by exchanges among identical copies. For instance, the letters A, A, and B have three distinct orderings rather than six. (reference.wolfram.com)"
    },
    {
      "heading": "Factorials in mathematical analysis",
      "text": "Factorials appear naturally in Taylor series. For an analytic function expanded around \\(a\\),\n\n\\[f(x)=\\sum_{n=0}^{\\infty} \\frac{f^{(n)}(a)}{n!}(x-a)^n\\]\n\nwithin its region of convergence. The denominator compensates for the factor \\(n!\\) produced by taking the \\(n\\)th derivative of \\((x-a)^n\\). The resulting coefficients encode the function’s successive derivatives at the expansion point. (dlmf.nist.gov)\n\nA prominent example is the exponential function:\n\n\\[e^x=\\sum_{n=0}^{\\infty}\\frac{x^n}{n!}.\\]\n\nThis power series converges for every real or complex \\(x\\). Setting \\(x=1\\) expresses \\(e\\) as the sum of reciprocal factorials. Factorials therefore connect finite counting problems with infinite expansions of continuous functions. (dlmf.nist.gov)"
    },
    {
      "heading": "Growth and approximation",
      "text": "Factorials increase rapidly. Their size for large \\(n\\) is described by Stirling’s approximation:\n\n\\[n!\\sim\\sqrt{2\\pi n}\\left(\\frac ne\\right)^n.\\]\n\nThe symbol \\(\\sim\\) means that the ratio of the two expressions approaches \\(1\\) as \\(n\\) tends to infinity; it does not indicate exact equality at finite \\(n\\). (dlmf.nist.gov)\n\nA refined asymptotic expansion begins\n\n\\[n!=\\sqrt{2\\pi n}\\left(\\frac ne\\right)^n \\left(1+\\frac{1}{12n}+O(n^{-2})\\right).\\]\n\nHere big-O notation describes the order of the remaining correction. Taking logarithms gives\n\n\\[\\log(n!)= n\\log n-n+\\tfrac12\\log(2\\pi n)+O(n^{-1}).\\]\n\nThese formulas imply that factorial growth eventually exceeds \\(c^n\\) for every fixed positive constant \\(c\\). The logarithmic form describes magnitude without requiring the enormous integer itself. (dlmf.nist.gov)"
    },
    {
      "heading": "Extension through the gamma function",
      "text": "The gamma function extends factorial values beyond integers. For a complex number \\(z\\) with positive real part, it is defined by the integral\n\n\\[\\Gamma(z)=\\int_0^\\infty t^{z-1}e^{-t}\\,dt.\\]\n\nFor every nonnegative integer \\(n\\),\n\n\\[\\Gamma(n+1)=n!.\\]\n\nAccordingly, the conventional extension is \\(z!=\\Gamma(z+1)\\). This is an extension of the product definition, not a product containing a noninteger number of factors. (dlmf.nist.gov)\n\nThrough analytic continuation, this extension is defined throughout the complex plane except at negative integers, where it has poles. It assigns finite values to many noninteger arguments; for example,\n\n\\[\\left(\\tfrac12\\right)!=\\Gamma\\left(\\tfrac32\\right)=\\frac{\\sqrt{\\pi}}2.\\]\n\nThe original factorial on nonnegative integers and its gamma-based extension should therefore be distinguished by their domains. (dlmf.nist.gov)"
    },
    {
      "heading": "Computation",
      "text": "The recurrence provides a direct algorithm: start with \\(1\\) and multiply successively by \\(2,3,\\ldots,n\\). This is a mathematical consequence of the definition and can be expressed using iteration or recursion. Exact factorials and approximate gamma values are distinct computational operations; Python’s mathematical library, for example, provides separate functions for them. (reference.wolfram.com)\n\nFor logarithmic calculations, \\(\\log(n!)=\\log\\Gamma(n+1)\\). A log-gamma routine can evaluate this quantity without first forming \\(n!\\). Such a result describes the factorial’s logarithm rather than its exact integer value, an important distinction when choosing a numerical representation. (dlmf.nist.gov)"
    }
  ],
  "links": [
    "mathematical-function",
    "integer",
    "combinatorics",
    "recurrence-relation",
    "permutation",
    "subset",
    "binomial-coefficient",
    "multinomial-coefficient",
    "taylor-series",
    "analytic-function",
    "derivative",
    "exponential-function",
    "power-series",
    "stirlings-approximation",
    "asymptotic-expansion",
    "big-o-notation",
    "logarithm",
    "gamma-function",
    "complex-number",
    "integral",
    "analytic-continuation",
    "algorithm",
    "recursion"
  ],
  "sources": [
    {
      "title": "reference.wolfram.com/language/ref/Factorial.html",
      "url": "https://reference.wolfram.com/language/ref/Factorial.html?q=Factorial"
    },
    {
      "title": "math.dartmouth.edu/~prob/prob/extra/amsbook.mac.pdf",
      "url": "https://math.dartmouth.edu/~prob/prob/extra/amsbook.mac.pdf"
    },
    {
      "title": "dlmf.nist.gov/1.10",
      "url": "https://dlmf.nist.gov/1.10"
    },
    {
      "title": "dlmf.nist.gov/5.11",
      "url": "https://dlmf.nist.gov/5.11"
    },
    {
      "title": "dlmf.nist.gov/5.2",
      "url": "https://dlmf.nist.gov/5.2"
    },
    {
      "title": "dlmf.nist.gov/5.4",
      "url": "https://dlmf.nist.gov/5.4"
    }
  ],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}