({{, (RefLink[Subfactorial, paclet:ref/Subfactorial])[n] 
gives the number of permutations of n objects that leave no object fixed.}})

OpenersNotesSection(Spacer1)Details

Mathematical function, suitable for both symbolic and numerical manipulation.

For noninteger n, the numerical value of (RefLink[Subfactorial, paclet:ref/Subfactorial])[n] is given by (RefLink[Gamma, paclet:ref/Gamma])[n+1,-1]/(RefLink[E, paclet:ref/E]).

(RefLink[Subfactorial, paclet:ref/Subfactorial]) can be evaluated to arbitrary numerical precision.

A permutation in which no object appears in its natural place is called a derangement.

(RefLink[Subfactorial, paclet:ref/Subfactorial]) automatically threads over lists.

(RefLink[Subfactorial, paclet:ref/Subfactorial])[0] gives 1.

OpenersPrimaryExamplesSection(Spacer1)Examples  (26)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Table[Subfactorial[n],{n,10}]

OpenersExampleSection1(Spacer1)Scope  (18)

OpenersExampleSubsection0(Spacer1)Numerical Evaluation  (4)

Evaluate numerically:

Subfactorial[48]

Subfactorial[4.5]

Evaluate to high precision:

N[Subfactorial[1/3],50]

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

Subfactorial[1.100000000000000000]

Complex number input:

Subfactorial[1.6+I]

Evaluate efficiently at high precision:

Subfactorial[1/3`100]//Timing

Subfactorial[1/5`1000];//Timing

OpenersExampleSubsection1(Spacer1)Specific Values   (5)

Values of (RefLink[Subfactorial, paclet:ref/Subfactorial]) at fixed points:

Table[Subfactorial[x ],{x,1,4}]

Value at zero:

Subfactorial[0]

Evaluate symbolically:

Subfactorial[x]//FunctionExpand

Limiting values at infinity:

Limit[Subfactorial[x],x->Infinity]

Limit[Subfactorial[x]/Factorial[x],x->Infinity]

Find a value of x for which the real part of (RefLink[Subfactorial, paclet:ref/Subfactorial])[x] is equal to 5:

xval=x/.FindRoot[Re[Subfactorial[x ]]== 5,{x,4}]

Plot[Re[Subfactorial[x ]],{x,0,5},Epilog->{PointSize[Large],Red,Point[{xval,Re[Subfactorial[xval]]}]}]

OpenersExampleSubsection2(Spacer1)Visualization  (2)

Plot the absolute value of (RefLink[Subfactorial, paclet:ref/Subfactorial]):

Plot[Abs[Subfactorial[x]],{x,-1,5}]

Plot the real part of (RefLink[Subfactorial, paclet:ref/Subfactorial])[x+i y]:

ContourPlot[Re[Subfactorial[x+I y]],{x,-3,3},{y,-3,3},Contours->24]

Plot the imaginary part of (RefLink[Subfactorial, paclet:ref/Subfactorial])[x+i y]:

ContourPlot[Im[Subfactorial[x+I y]],{x,-3,3},{y,-3,3},Contours->24]

OpenersExampleSubsection3(Spacer1)Function Properties  (2)

Real domain of (RefLink[Subfactorial, paclet:ref/Subfactorial]):

FunctionDomain[Subfactorial[x],x]

Complex domain:

FunctionDomain[Subfactorial[z],z,Complexes]

(RefLink[Subfactorial, paclet:ref/Subfactorial]) automatically threads over lists:

Subfactorial[{5,10,20}]

OpenersExampleSubsection4(Spacer1)Differentiation  (2)

First derivative with respect to n:

D[Subfactorial[n],n]

Higher derivatives with respect to n:

Table[D[Subfactorial[n],{n,k}],{k,1,3}]//FullSimplify

Plot the higher derivatives with respect to n:

Plot[Evaluate[Re[%]],{n,-6,6},PlotLegends->{"First Derivative","Second Derivative","Third Derivative"}]

OpenersExampleSubsection5(Spacer1)Series Expansions  (3)

Find the Taylor expansion using (RefLink[Series, paclet:ref/Series]):

Series[Subfactorial[x],{x,0,2}]//Normal//FullSimplify

Plots of the first three approximations around x=0:

terms=Re@Normal@Table[Series[Subfactorial[x],{x,0,m}],{m,1,5,2}];
Plot[{Re[Subfactorial[x]],terms},{x,0,5},PlotRange->{-50,50},PlotLegends->"Expressions"]

Find the series expansion at (RefLink[Infinity, paclet:ref/Infinity]):

Series[Subfactorial[x],{x,Infinity,1}]//Normal//FullSimplify

Taylor expansion at a generic point:

Series[Subfactorial[x],{x,x0,2}]//Normal// FullSimplify

OpenersExampleSection2(Spacer1)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[%]

OpenersExampleSection3(Spacer1)Properties & Relations  (5)

(RefLink[Subfactorial, paclet:ref/Subfactorial])[n] is given by n! (∑_(k=0)^n)((((-1))^k)/(k!)):

n!(∑_(k=0)^n)((((-1))^k)/(k!))//FullSimplify

Recurrence relations satisfied by (RefLink[Subfactorial, paclet:ref/Subfactorial]):

Subfactorial[n]==n Subfactorial[n-1]+(((-1))^n)/.n->Range[10]

Subfactorial[n+1]==n(Subfactorial[n]+Subfactorial[n-1])/.n->Range[10]

(RefLink[Subfactorial, paclet:ref/Subfactorial]) can be represented as a (RefLink[DifferenceRoot, paclet:ref/DifferenceRoot]):

DifferenceRootReduce[Subfactorial[k],k]

(RefLink[FindSequenceFunction, paclet:ref/FindSequenceFunction]) can recognize the (RefLink[Subfactorial, paclet:ref/Subfactorial]) sequence:

Table[Subfactorial[n],{n,10}]

FindSequenceFunction[%,n]

The exponential generating function for (RefLink[Subfactorial, paclet:ref/Subfactorial]):

ExponentialGeneratingFunction[Subfactorial[n],n,x]

OpenersExampleSection4(Spacer1)Neat Examples  (1)

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

148349==Total[Subfactorial[{1,4,8,3,4,9}]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Factorial, paclet:ref/Factorial])  ▪  (RefLink[Permutations, paclet:ref/Permutations])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Combinatorial Functions, paclet:guide/CombinatorialFunctions])}, {▪(RefLinkPlain[Gamma Functions and Related Functions, paclet:guide/GammaFunctionsAndRelatedFunctions])}})}})