The number of functions from $[5]$ to $[5]$ such that $f(f(x)) \neq x $ for $ x=1, \ldots 5$ is $44$

According to OEIS's A134362, for $[5]$ it should be $444$. A general formula for the number of functions $f:[n]\to[n]$ such that for every $x\in[n]$, $f(f(x)) \not =x$ is $$n!\sum_{k=0}^{\lfloor n/2\rfloor}(-1)^k\cdot\frac{(n-1)^{n-2k}}{2^k k!(n-2k)!}.$$

P.S. Note that such $f$ are not necessarily injective: $$[1,2,3,4,5]\stackrel{f}{\to} [2, 3, 1, 1, 1]\stackrel{f}{\to} [3, 1, 2, 2, 2]$$

A proof for this formula by Marco Riedl is alredy published at math.stackoverflow.


The condition $f(f(i)) \neq i$ will imply bijectivity. There are indeed $44$ derrangements of $[5]$, there are $24$ of the "flavour" $(abcde)$ and $20$ of the "flavour" $(ab)(cde)$. The latter "flavour" will not satisfy the condtion $f(f(i)) \neq i$. So there are $\color{blue}{24}$ functions on $[5]$ whose second iterated map also has no fixed points.

Edit : Double functions with no fixed points.

On a three element set there are $2$ functions of the form $ a \rightarrow b \rightarrow c \rightarrow a $. ($a \neq b \neq c \neq a$)

On $[4]$, there are $6$ of the form $ a \rightarrow b \rightarrow c \rightarrow d \rightarrow a$ & there are $24$ of the form $ a \rightarrow b \rightarrow c \rightarrow d \rightarrow b$. So $30$ in toto.

On $[5]$,

There are $24$ of the form $ a \rightarrow b \rightarrow c \rightarrow d \rightarrow e \rightarrow a$

There are $120$ of the form $ a \rightarrow b \rightarrow c \rightarrow d \rightarrow e \rightarrow b$

There are $120$ of the form $ a \rightarrow b \rightarrow c \rightarrow d \rightarrow e \rightarrow c$

There are $60$ of the form $ a \text{ and } b \rightarrow c \rightarrow d \rightarrow e \rightarrow c$

There are $120$ of the form $ a \rightarrow c , b \text{ and } c \rightarrow d \rightarrow e \rightarrow c$

So there are $444$ in toto.