# calculate the derivative of a function containing factorial

I got an expression for free energy F in a book as: $$F(N_1) = \frac{N_1N_2}{N}W-kT(\log N!-\log N_1!-\log N_2!),\tag1\label1$$ where $N=N_1+N_2$. As what the book later introduced, the derivative of $\eqref1$ is: $$F'(N_1)=\frac{N_1-N_2}{N}W-kT\log\frac{N_1}{N_2}.\tag2\label2$$

Can anyone tell me the steps needed to derive $\eqref2$ from $\eqref1$?

You need to use Stirling's Approximation: $$\ln n!=n\ln n-n$$
Then $$F(N_1) = \frac{N_1N_2}{N}W-kT(\log N!-\log N_1!-\log N_2!)$$ becomes $$F(N_1) = \frac{N_1N_2}{N}W-kT(N\log N-N-N_1\log N_1+N_1-N_2\log N_2+N_2)$$ $$\Rightarrow F(N_1) = \frac{N_1N_2}{N}W-kT(N\log N-N_1-N_2-N_1\log N_1+N_1-N_2\log N_2+N_2)$$ $$\Rightarrow F(N_1) = \frac{N_1N_2}{N}W-kT(N\log N-N_1\log N_1-N_2\log N_2)$$