Derangement in LaTeX (D_n)

DnD_n
LaTeX command
D_n
Package
No package needed: built into LaTeX
Mode
Math mode only

Where it is used

Derangement number D_n: permutations of n elements in which no element stays in its original position.

D_n counts permutations without fixed points and starts 1, 0, 1, 2, 9, 44, 265. Inclusion-exclusion gives D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}, so D_n is the nearest integer to n!/e and the probability of a random derangement tends to 1/e. Recurrences include D_n = (n-1)(D_{n-1} + D_{n-2}). The classic story is the hat-check problem. The same number is also written !n, the subfactorial; D_n is easier to read in running text. Note D_n also names the dihedral group in algebra, so clarify if both appear.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

Dn=n!∑k=0n(−1)kk!D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}
\documentclass{article}
\begin{document}
Derangement: $D_n$

\[ D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!} \]
\end{document}

Related symbols

All 組み合わせ論 →

Frequently asked questions

How do I write Derangement in LaTeX?
Type D_n in math mode, for example $D_n = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}$. It works in plain LaTeX without loading any package.
Which package do I need for D_n?
None. D_n is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
Can I use D_n in text mode, or only in math mode?
Only in math mode. Outside $...$ LaTeX stops with "Missing $ inserted", so write $D_n$ in running text.
Math poweredAIでLaTeXを書く

最高のAI LaTeXエディタ、Overleaf代替

Octreeは15以上の大学の研究者がAIを使って論文をより速く書くのを支援

  • AIで美しいTikZダイアグラムを生成
  • 画像をアップロードしてシームレスにLaTeXに変換
  • 論文の執筆とフォーマットに即座にサポートを取得