The subfactorial function is used to calculate the number of permutations of a set of n objects in which none of the elements occur in their natural place, whereas the factorial function calculates the total number of permutations of the set. In practical terms, subfactorial is the number of ways of putting n letters into n envelopes (one in each envelope) with none in its correct envelope.
It can be calculated using the inclusion-exclusion principle.
Subfactorials can also be calculated in the following way:
where [x] denotes the nearest integer function .
The first few values of the function are:
- !1 = 0
- !2 = 1
- !3 = 2
- !4 = 9
- !5 = 44
- !6 = 265
- !7 = 1,854
- !8 = 14,833
- !9 = 133,496
- !10 = 1,334,961
- !11 = 14,684,570
- !12 = 176,214,841
- !13 = 2,290,792,932
- !14 = 32,071,101,049
The number 148,349 has the surprising and unique property that it is equal to the sum of the subfactorials of its digits:
- 148,349 = !1 + !4 + !8 + !3 + !4 + !9
Subfactorial is sometimes permitted in the Four fours mathematical game where !4 being 9 is helpful.