gives the number of permutations of n objects that leave no object fixed.


  • Mathematical function, suitable for both symbolic and numerical manipulation.
  • For noninteger n, the numerical value of Subfactorial[n] is given by Gamma[n+1,-1]/E.
  • Subfactorial can be evaluated to arbitrary numerical precision.
  • A permutation in which no object appears in its natural place is called a derangement.
  • Subfactorial automatically threads over lists.
  • Subfactorial[0] gives 1.


open allclose all

Basic Examples  (5)

Evaluate numerically:

Plot the sequence:

Plot over a subset of the complexes:

Series expansion at the origin:

Series expansion at Infinity:

Scope  (18)

Numerical Evaluation  (4)

Evaluate numerically:

Evaluate to high precision:

The precision of the output tracks the precision of the input:

Complex number input:

Evaluate efficiently at high precision:

Specific Values  (5)

Values of Subfactorial at fixed points:

Value at zero:

Evaluate symbolically:

Limiting values at infinity:

Find a value of for which the real part of Subfactorial[x] is equal to 5:

Visualization  (2)

Plot the absolute value of Subfactorial:

Plot the real part of Subfactorial[x+ y]:

Plot the imaginary part of Subfactorial[x+ y]:

Function Properties  (2)

Real domain of Subfactorial:

Complex domain:

Subfactorial automatically threads over lists:

Differentiation  (2)

First derivative with respect to :

Higher derivatives with respect to :

Plot the higher derivatives with respect to :

Series Expansions  (3)

Find the Taylor expansion using Series:

Plots of the first three approximations around :

Find the series expansion at Infinity:

Taylor expansion at a generic point:

Applications  (1)

There are 9 derangements of a set of 4 objects:

Here are all permutations of the set {1,2,3,4}:

Delete all permutations where an object is fixed:

Check that there are only 9 derangements:

Properties & Relations  (5)

Subfactorial[n] is given by :

Recurrence relations satisfied by Subfactorial:

Subfactorial can be represented as a DifferenceRoot:

FindSequenceFunction can recognize the Subfactorial sequence:

The exponential generating function for Subfactorial:

Neat Examples  (1)

The only number equal to the sum of subfactorials of its digits:

Wolfram Research (2007), Subfactorial, Wolfram Language function,


Wolfram Research (2007), Subfactorial, Wolfram Language function,


@misc{reference.wolfram_2020_subfactorial, author="Wolfram Research", title="{Subfactorial}", year="2007", howpublished="\url{}", note=[Accessed: 10-April-2021 ]}


@online{reference.wolfram_2020_subfactorial, organization={Wolfram Research}, title={Subfactorial}, year={2007}, url={}, note=[Accessed: 10-April-2021 ]}


Wolfram Language. 2007. "Subfactorial." Wolfram Language & System Documentation Center. Wolfram Research.


Wolfram Language. (2007). Subfactorial. Wolfram Language & System Documentation Center. Retrieved from