{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Statement\n\nLet $n$ be a natural number, and let $D_n$ be the number of [[derangements|0TH61JR04G]] of an $n$-element set.\nThen\n$$D_n = n! \\sum_{k=0}^{n} \\frac{(-1)^k}{k!} = \\sum_{k=0}^{n} (-1)^k \\frac{n!}{k!}.$$\n\n## Remarks\n\nFor $n = 4$: $24 - 24 + 12 - 4 + 1 = 9$.\nThe proof applies the [[inclusion–exclusion principle|0FF7726C7P]] to the sets $A_i$ of permutations that fix $i$.\nThe sum is a partial sum of the series of $e^{-1}$. Thus $D_n / n! \\to 1/e$, and for $n \\ge 1$, $D_n$ is the integer nearest to $n!/e$.\n\n## Explanations\n\n### L1 human\n\nStart with all $n!$ permutations. Remove those that fix some point, add back those that fix two points, and so on.\nThe result is the alternating sum in the formula.\n",
  "commit": "f591989ed15704e9d8755a7a5a6426d73de7a3ae",
  "front": {
    "kind": "statement",
    "msc": [
      "05A05"
    ],
    "name": "Formula for the number of derangements",
    "role": "theorem",
    "sources": [
      {
        "locator": "Derivation by inclusion–exclusion principle",
        "url": "https://en.wikipedia.org/wiki/Derangement"
      }
    ],
    "tag": "03RSJXF728",
    "uses": [
      "0WFCGVMRRC",
      "0TH61JR04G",
      "03WY4HHMT1"
    ]
  },
  "kind": "statement",
  "link": "https://math2.tamnd.com/node/03RSJXF728/",
  "links": [
    {
      "field": "uses",
      "target": "0WFCGVMRRC"
    },
    {
      "field": "uses",
      "target": "0TH61JR04G"
    },
    {
      "field": "uses",
      "target": "03WY4HHMT1"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/03RSJXF728.md",
  "msc": [
    "05A05"
  ],
  "name": "Formula for the number of derangements",
  "prov": null,
  "role": "theorem",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/03R/03RSJXF728.md",
  "status": null,
  "tag": "03RSJXF728",
  "uri": "m2://03RSJXF728",
  "url": "https://math2.tamnd.com/wiki/formula-for-the-number-of-derangements/",
  "writing": {
    "tag": "03RSJXF728",
    "kind": "statement",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      }
    ]
  }
}
