Subfactorial[n]
gives the number of permutations of n objects that leave no object fixed.
Subfactorial
Subfactorial[n]
gives the number of permutations of n objects that leave no object fixed.
Details
- 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. The subfactorial counts the number of derangements.
- Subfactorial automatically threads over lists. »
- Subfactorial[0] gives 1.
- Subfactorial can be used with CenteredInterval objects. »
Examples
open all close allBasic Examples (5)
Subfactorial[6]Plot the values on a log scale over a subset of the reals:
DiscretePlot[Subfactorial[k], {k, 12}, ScalingFunctions -> "Log"]Plot over a subset of the complexes:
ComplexPlot3D[Subfactorial[z ^ 2], {z, -2 - 2I, 2 + 2I}, PlotLegends -> Automatic]Series expansion at the origin:
Series[Subfactorial[ x], {x, 0, 2}]//Normal//FullSimplifySeries expansion at Infinity:
Series[Subfactorial[ x], {x, ∞, 2}]//Normal//FullSimplifyScope (28)
Numerical Evaluation (7)
Subfactorial[48]Subfactorial[4.5]N[Subfactorial[1 / 3], 50]The precision of the output tracks the precision of the input:
Subfactorial[1.100000000000000000]Subfactorial[1.6 + I]Evaluate efficiently at high precision:
Subfactorial[1 / 3`100]//TimingSubfactorial[1 / 5`1000];//TimingSubfactorial automatically threads over lists:
Subfactorial[{5, 10, 20}]Compute the elementwise values of an array using automatic threading:
Subfactorial[{{2, 0}, {0, 2}}]Or compute the matrix Subfactorial function using MatrixFunction:
MatrixFunction[Subfactorial[#]&, {{2, 0}, {0, 2}}]Subfactorial can be used with CenteredInterval objects:
Subfactorial[CenteredInterval[1 / 2, 1 / 100]]Specific Values (5)
Values of Subfactorial at fixed points:
Table[Subfactorial[x ], {x, 1, 4}]Subfactorial[0]Subfactorial[x]//FunctionExpandLimit[Subfactorial[x], x -> Infinity]Limit[Subfactorial[x] / Factorial[x], x -> Infinity]Find a value of
for which the real part of Subfactorial[x] is equal to 5:
xval = x /. FindRoot[Re[Subfactorial[x ]] == 5, {x, 4}]Plot[Re[Subfactorial[x ]], {x, 0, 5}, Epilog -> Style[Point[{xval, Re[Subfactorial[xval]]}], PointSize[Large], Red]]Visualization (2)
Plot the absolute value of Subfactorial:
Plot[Abs[Subfactorial[x]], {x, -1, 5}]Plot the real part of Subfactorial[z]:
ComplexContourPlot[Re[Subfactorial[z]], {z, -3 - I, 3 + 3I}, Contours -> 20]Plot the imaginary part of Subfactorial[z]:
ComplexContourPlot[Im[Subfactorial[z]], {z, -3 - I, 3 + 3I}, Contours -> 20]Function Properties (6)
Real domain of Subfactorial:
FunctionDomain[Subfactorial[x], x]FunctionDomain[Subfactorial[z], z, Complexes]Subfactorial is not an analytic function on
:
FunctionAnalytic[Subfactorial[x], x]In fact, it is singular and discontinuous everywhere on the reals:
FunctionSingularities[Subfactorial[x], x]FunctionDiscontinuities[Subfactorial[x], x]The reason is that it is only real valued at isolated points:
ReImPlot[Subfactorial[x], {x, -5, 5}]However, it is analytic in the complex plane:
FunctionAnalytic[Subfactorial[x], x, ℂ]The imaginary part of Subfactorial is not injective:
FunctionInjective[Im[Subfactorial[x]], x]Plot[{Im[Subfactorial[x]], .3}, {x, -5, 5}]The imaginary part of Subfactorial is not surjective:
FunctionSurjective[Im[Subfactorial[x]], x]Plot[{Im[Subfactorial[x]], -2}, {x, -5, 5}]The real part of Subfactorial is neither non-negative nor non-positive:
FunctionSign[Re[Subfactorial[x]], x]The real part of Subfactorial is neither convex nor concave:
FunctionConvexity[Re[Subfactorial[x]], x]FunctionConvexity[Re[Subfactorial[x]], x]Differentiation (2)
First derivative with respect to
:
D[Subfactorial[n], n]Higher derivatives with respect to
:
Table[D[Subfactorial[n], {n, k}], {k, 1, 3}]//FullSimplifyPlot the higher derivatives with respect to
:
Plot[Evaluate[Re[%]], {n, -6, 6}, PlotLegends -> {"First Derivative", "Second Derivative", "Third Derivative"}]Series Expansions (3)
Find the Taylor expansion using Series:
Series[Subfactorial[x], {x, 0, 2}]//Normal//FullSimplifyPlots of the first three approximations around
:
terms = Re@Normal@Table[Series[Subfactorial[x], {x, 0, m}], {m, 1, 3}];
Plot[{Re[Subfactorial[x]], terms}, {x, 0, 5}, PlotRange -> {-50, 50}]Find the series expansion at Infinity:
Series[Subfactorial[x], {x, Infinity, 1}]//Normal//FullSimplifyTaylor expansion at a generic point:
Series[Subfactorial[x], {x, x0, 2}]//Normal// FullSimplifyRecurrence Identities and Simplifications (3)
Subfactorial[n] == n Subfactorial[n - 1] + (-1)^n//FullSimplifySubfactorial[n + 1] == n (Subfactorial[n] + Subfactorial[n - 1])//FullSimplifyOn the positive integers, Subfactorial[n]==Round[n!/E]:
Table[Subfactorial[n] == Round[(n!/E)], {n, 10}]Applications (1)
There are 9 derangements of a set of 4 objects:
Subfactorial[4]Here are all permutations of the set {1,2,3,4}:
Permutations[Range[4]]Delete all permutations where an object is fixed:
DeleteCases[Permutations[Range[4]], {1, __} | {_, 2, __} | {__, 3, _} | {__, 4}]Check that there are only 9 derangements:
Length[%]Properties & Relations (5)
Subfactorial[n] is given by
:
n!Underoverscript[∑, k = 0, n]((-1)^k/k!)//FullSimplifyRecurrence relations satisfied by Subfactorial:
Subfactorial[n] == n Subfactorial[n - 1] + (-1)^n//FullSimplifySubfactorial[n + 1] == n (Subfactorial[n] + Subfactorial[n - 1])//FullSimplifySubfactorial can be represented as a DifferenceRoot:
DifferenceRootReduce[Subfactorial[k], k]FindSequenceFunction can recognize the Subfactorial sequence:
Table[Subfactorial[n], {n, 10}]FindSequenceFunction[%, n]The exponential generating function for Subfactorial:
ExponentialGeneratingFunction[Subfactorial[n], n, x]See Also
Related Guides
Related Links
History
Text
Wolfram Research (2007), Subfactorial, Wolfram Language function, https://reference.wolfram.com/language/ref/Subfactorial.html.
CMS
Wolfram Language. 2007. "Subfactorial." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Subfactorial.html.
APA
Wolfram Language. (2007). Subfactorial. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Subfactorial.html
BibTeX
@misc{reference.wolfram_2026_subfactorial, author="Wolfram Research", title="{Subfactorial}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/Subfactorial.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_subfactorial, organization={Wolfram Research}, title={Subfactorial}, year={2007}, url={https://reference.wolfram.com/language/ref/Subfactorial.html}, note=[Accessed: 13-June-2026]}