# On the numerical evaluation of factorials X

The last post in this sequence was about some more general way to work with the prime factorization of the factorials and about the Narayana numbers:

${\displaystyle{ N(n,k) = \frac{1}{n}{ \binom nk}{\binom n{k-1}} }}$

Which expands to

${\displaystyle{ {{n!^2}\over{\left(k-1\right)!\,k!\,n\,\left(n-k\right)!\,\left(n-k +1\right)!}} }}$

Using $(n+1)! = n(n!)$ and vice versa $(n-1)! = \frac{n!}{n}$ we can shove more things together and get

${\displaystyle{ \frac{k n!^2}{k!^2 n \left(n-k+1\right) \left(n-k\right)!^2} }}$

Get the non-factorials out of the way

${\displaystyle{ \frac{k}{n \left(n-k+1\right)}\; \frac{n!^2}{k!^2 \left(n-k\right)!^2} }}$

With $P_n$ the prime factorization of $n!$ and with their arithmetic resembling the relation of the arithmetic of numbers and the arithmetic of their logarithms (e.g.:$x\cdot y = \exp\left(\log\left(x\right)+\log\left(y\right) \right)$ ) we get (dropping the fraction with the non-factorials)

{\displaystyle{ \begin{aligned} \phantom{\Leftrightarrow\;} &2P_n - \left( 2P_k + 2P_{n-k} \right) \\ \Leftrightarrow\; &2P_n - 2P_k - 2P_{n-k} \\ \Leftrightarrow\; &2\left(P_n - P_k - P_{n-k} \right) \end{aligned} }}

We have to be carefull with the term $n \left(n-k+1\right)$ for it can overflow, so we should divide the prime factorization by and by instead of multiplying $n \left(n-k+1\right)$ out and divide by that all together.

The actual implementation is left as an exercise for the reader.
Or just wait until I do it myself in the next days 😉