Derive expression for internal energy of mixing and entropy of mixing using statistical thermodynamics I want to derive an expression for the internal energy of mixing, $\Delta_\mathrm{mix}U$, and entropy of mixing, $\Delta_\mathrm{mix}S$. The framework for this is the Lattice Theory of Ideal Solutions. Specifically, I am mixing $N_A$ molecules of type A with $N_B$ molecules of type B together. I am supposed to find the following two relations:

$$
\Delta_\mathrm{mix} U = 0 \\
\Delta_\mathrm{mix} S = -kM (x_A \ln x_A + x_B\ln x_B)
$$



My attempted solution

I have the canonical partition function for an ideal solution of two different components:

$$
Q = \left( q_A e^{-cw_{AA}/2kT} \right)^{N_A} \left( q_B e^{-cw_{BB}/2kT} \right)^{N_B} \frac{(M)!}{N_A!N_B!}
$$

Taking the logarithm 

$$
\ln Q = N_A\ln q_A - N_A\frac{cw_{AA}}{2kT} + N_B\ln q_B - N_B\frac{cw_{BB}}{2kT} + M \ln M - N_A\ln N_A - N_B \ln N_B
$$

where $w_{xx}$ is the pairwise interaction energy, $M=N_A+N_B$ is the total number of molecules = number of lattice sites.

Further, some thermodynamical relations for this system

$$
U = kT^2\left( \frac{\partial \ln Q}{\partial T} \right)_{N,M}
$$

$$
S = \frac{U}{T} + k\ln Q
$$

The internal energy of mixing and entropy of mixing should be

$$
\Delta_\mathrm{mix}U = \Delta U_A + \Delta U_B \\
\Delta_\mathrm{mix}S = \Delta S_A + \Delta S_B
$$

Generally we have that

$$
\Delta U = U_\mathrm{final} - U_\mathrm{initial} \\
\Delta S = S_\mathrm{final} - S_\mathrm{initial}
$$

I am a bit confused about how to compare the final and initial conditions of the system. I assume that we have initially two separated and equal volumes, one containing $N_A$ of A and one containing $N_B$ of B. Then we allow flow between the two volumes. Hence, the final volume is twice the initial volume. $N_A$ and $N_B$ are constant during the mixing. So I should have something like this

$$
\Delta U_A = U_{final} - U_{initial} = kT^2\left( \frac{\partial \ln Q}{\partial T} \right)_{N_A,M} - kT^2\left( \frac{\partial \ln Q}{\partial T} \right)_{N_A,M/2}
$$

and similarly for the other component. I just replace $M$ with $M/2$ for the expression of the initial state for both components? Most of the terms will be zero when doing the derivations, and the non-zero terms will actually just cancel. This gives that $\Delta_\mathrm{mix} U = 0$, which is the expected result for an ideal solution.

Looking at $\Delta_\mathrm{mix} S$ we have

$$
\Delta_\mathrm{mix} S = \Delta S_A + \Delta S_B = [S_{f,A} - S_{i,A}] + [S_{f,B} - S_{i,B}] \\
= \left[ \left(\frac{U_{f,A}}{T} + k\ln Q_f \right)- \left( \frac{U_{i,A}}{T} + k\ln Q_i \right) \right] + \left[ \left( \frac{U_{f,B}}{T} + k\ln Q_f \right) - \left( \frac{U_{i,B}}{T} + k\ln Q_i \right) \right] \\
=\frac{1}{T} (U_{f,A} - U_{i,A} + U_{f,B} - U_{i,B}) + 2k(\ln Q_f - \ln Q_i) \\
= \frac{\Delta_\mathrm{mix}U}{T} + 2k(\ln Q_f - \ln Q_i) \\
= 2k(\ln Q_f - \ln Q_i)
$$

where I used in the last step that $\Delta_\mathrm{mix} U=0$ for an ideal solution, as explained above. However, using this last expression to calculate the entropy of mixing, I find that (most of the terms cancel directly)

$$
\Delta_\mathrm{mix}S = kM \ln (2N_A + 2N_B)
$$

which is quite different from the correct expression. Is there something wrong with my procedure? (there likely is!)



Following the commented suggestion:

$$
S = k\ln W \Rightarrow \Delta_\mathrm{mix}S = k\ln \frac{W_\mathrm{mix}}{W_AW_B} = k\ln W_\mathrm{mix} = k\ln \frac{M!}{N_A!N_B!} \\
= kM [\ln M - x_A\ln N_A - x_B \ln N_B]
$$

which is almost correct. If I could divide all logarithmic arguments by $M$, I would get the correct answer.
In the solution there are two types of molecules $N_1$ and $N_2$. Assume that they do not interact with one another but simply occupy particular 'lattice' sites by blocking them. The total number occupied sites is $N=N_1 + N_2$. The first molecule can be placed at any of the $N$ sites, the second at $N-1$ empty sites and so on. The total number of possibilities is $N(N-1)(N-2)\cdots = (N_1 + N_2)!$ . Now, molecules of the same type are not distinguishable from one another thus this number must be divided by $N_1$ for molecules of the first type and similarly for the other type. Thus the number of distinguishable arrangements is

$$W_\mathrm{mix}= \frac{(N_1 + N_2)!}{N_1!N_2!} $$

The pure compounds have only one type of molecule thus for them $W_1=N_1!/N_1! = 1$ etc.

The entropy is defined as $S=k\ln(\Omega)$ where $\Omega$ is the number of arrangements $W_\mathrm{mix}/(W_1W_2)$ thus 
$$ \Delta S=k\ln\left(\frac{(N_1 + N_2)!}{N_1!N_2!}\right)$$

To simplify this it is convenient to use Stirling's approximation as $N$ is large:

$$\ln(N!) \approx N\ln(N)-N+1$$ and also as $N$ is large the $1$ can be ignored, giving $$\ln(N!) \approx N\ln(N)-N$$

Expanding gives 
$$ \Delta S = k[(N_1 + N_2)\ln(N_1 + N_2)-N_1\ln(N_1)-N_2\ln(N_2)]$$
expanding, multiplying by $-1$ and simplify gives

$$ \Delta S = -k\left[N_1\ln (\frac{N_1}{N_1 + N_2} )+ N_2\ln(\frac{N_1}{N_1 + N_2})\right]  $$

which can be expressed as mole fractions
$$ \Delta S= -k[N_1\ln(x_1) + N_2\ln(x_2)]$$

in molar terms, $ \Delta S= -R[n_1\ln(x_1) + n_2\ln(x_2)]$. This is the ideal solution entropy of mixing.

If the molecules do interact then this is a complicated problem in regular solutions, the free energy is 
$$\Delta G = RT[n_1\ln(x_1)+n_2\ln(x_2)] +(n_1+n_2)x_1x_2w$$

where $w \approx (2E_{12}- E_{11} - E_{22})$ and $E_{12}$ is the interaction energy between molecules of type $1$ and $2$ when they are adjacent and similarly for $E_{11}$ and $E_{22}$ all of which are negative. From a consideration of the energies involved $w$ is expected to be positive.