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 Combinatoriek →

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 poweredSchrijf LaTeX met AI

Beste AI LaTeX Editor, Overleaf Alternatief

Octree helpt onderzoekers van 15+ universiteiten sneller onderzoeksartikelen schrijven met AI

  • Genereer mooie TikZ-diagrammen met AI
  • Upload afbeelding en converteer naadloos naar LaTeX
  • Krijg directe hulp bij het schrijven en opmaken van onderzoeksartikelen