Factorial as a sum. Insight appreciated I recently posted an answer to a question about ways to express the factorial function as a sum. I posted the following formula, which I discovered several years ago and I haven't seen anywhere else:
$n!=\displaystyle\sum_{k=1}^n \binom{n}{k} (-1)^{n+k} k^n$
I never took the time to find a proof, and I couldn't come up with any obvious explanation, but it certainly works. It would be interesting if anyone with decent math skills (that is, better than me) could shed some light on it (provide a proof, or a clue on why it works).
I also made a brief attempt to generalize it into a series for non-integer $n$ (analogously to Newton's generalization of the Binomial Theorem) hoping to end up with the gamma function, but that seemed either impossible or above my skills.
 A: The left hand side is counting the set $S([n])$ of all surjective (hence bijective) maps $[n]\to[n]$, where $[n]$ is your favourite $n$-element set. The right hand side, maybe better rewritten as $\sum_{k=0}^n(-1)^{n-k}\binom nkk^n$, is doing the same by the inclusion-exclusion principle. Let $[n]^{[n]}$ be the set of all maps $[n]\to[n]$, and for each $i\in[n]$ let $A_i$ be its subset of such maps for which $i$ is not in the image, and for $I\subseteq[n]$ put $A_I=\bigcap_{i\in I}A_i$ (with by convention $A_\emptyset=[n]^{[n]}$). The principle of inclusion-exclusion says that $S([n])$, which is the complement in$~[n]^{[n]}$ of $\bigcup_{i\in[n]}A_i$, has as number of elements $\sum_{I\subseteq[n]}(-1)^{|I|}|A_I|$. Now $A_I$ is the set of all maps $[n]\to([n]\setminus I)$ so $|A_I|=(n-|I|)^n$, and our formula gives
$$
  n! = \sum_{I\subseteq[n]}(-1)^{|I|}(n-|I|)^n
     = \sum_{i=0}^n(-1)^i\binom ni(n-i)^n 
     = \sum_{k=0}^n(-1)^{n-k}\binom nkk^n.
$$
If $n>0$ the term for $k=0$ can be dropped, since $0^n=0$ in that case, but $0^0=1$, so the term should be kept when $n=0$. In that case it is indeed the only term that contributes to $0!=1$, and it would be good to keep it in the general case (where it does no harm), so that the formula is valid in all meaningful cases.
A: $$n!=f(n)=\sum_{k=1}^n \binom{n}{k} (-1)^{n+k} k^n,\quad n\in\mathbb N$$
A better way to include $0$:
$$n!=f_2(n)=\sum_{k=0}^n(-1)^k\binom nkk^n=\sum_{k=0}^n(-1)^k\binom nk(n-k)^n$$
Given $n$ boxes and $n$ balls, how much different ways there're to put the $n$ balls into the $n$ boxes and none of the first $n$ boxes is empty?
Using Inclusion-Exclusion Principle, the result is the leftside of the equation. And it is obvious the result is $n!$ too.
A: As @ADG notes in his answer,
$$
\sum_{k=1}^{n}\binom{n}{k}(−1)^{n+k}k^n
= \sum_{k=0}^{n}\binom{n}{k}(−1)^{n+k}k^n
= \sum_{k=0}^{n}\binom{n}{k}(−1)^{k}(n-k)^n,
$$
since $\binom{n}{n-k}=\binom{n}{k}$.
Now, the formular is a special case of
$$
\sum_{k=0}^{n}(-1)^k\binom{n}{k}P(n-k) = n! a_n,
$$
where $P$ is a polynomial of degree $\leq n$, and $a_n$ is the coefficient of $X^n$ (see equation 10 on the Wikipedia page about the binomal coefficent: https://en.wikipedia.org/w/index.php?title=Binomial_coefficient&oldid=687765044#math_10).
Your formular follows by putting $P(X)=X^n$.
I hope this adds some insight.
