combinatorics
what
a.k.a. the derangement number
!n: How many ways to arrange the n objects, excluding any permutation where an object is in its original position.
as sum
!n=n!k=0∑nk!(−1)k=k=0∑n(n−k)!n!(−1)n−k=k=0∑nk!(−1)n−k(kn)(1)(2)(3)
where (kn) is the combination.
as recursion
!n!n=n⋅!(n−1)+(−1)n=(n−1)(!(n−2)+!(n−1))(4)(5)
(4)→(5)
!n=n⋅!(n−1)+(−1)n=n⋅((n−1)⋅!(n−2)+(−1)n−1)+(−1)n=n(n−1)⋅!(n−2)+n(−1)n−1+(−1)n−1(−1)=n(n−1)⋅!(n−2)+(n−1)(−1)n−1=(n−1)(n⋅!(n−2)+(−1)n−1)=(n−1)((n−1)⋅!(n−2)+!(n−2)+(−1)n−1)=(n−1)(!(n−1)+!(n−2))(4)(5)
(4)→(1)
!n=n⋅!(n−1)+(−1)n=n⋅(n−1)!⋅k=0∑n−1k!(−1)k+(−1)n=n!⋅k=0∑n−1k!(−1)k+(−1)nn!n!=n!⋅(k=0∑n−1k!(−1)k+n!(−1)n)=n!⋅k=0∑nk!(−1)k(4)(1)
(5)→(1)
!n=(n−1)(!(n−1)+!(n−2))=(n−1)((n−1)!⋅k=0∑n−1k!(−1)k+(n−2)!⋅k=0∑n−2k!(−1)k)=(n−1)(n−1)!⋅k=0∑n−1k!(−1)k+(n−1)(n−2)!⋅k=0∑n−2k!(−1)k=n(n−1)!⋅k=0∑n−1k!(−1)k−(n−1)!⋅k=0∑n−1k!(−1)k+(n−1)!⋅k=0∑n−2k!(−1)k=n!⋅k=0∑n−1k!(−1)k−(n−1)!⋅(k=0∑n−1k!(−1)k−k=0∑n−2k!(−1)k)=n!⋅k=0∑n−1k!(−1)k−(n−1)!⋅(n−1)!(−1)n−1=n!⋅k=0∑n−1k!(−1)k−n!⋅n!(−1)n−1=n!⋅(k=0∑n−1k!(−1)k−n!(−1)n−1)=n!⋅(k=0∑n−1k!(−1)k+n!(−1)n)=n!⋅k=0∑nk!(−1)k(5)(1)