# Why are the two expressions of entropy for a degenerate two-state system contradictory?

Suppose we have a 2-state system with the states $$E_1$$ with degeneracy $$g_1$$ and $$E_2$$ with degeneracy $$g_2$$. The probability of the system existing in $$E_i$$ is given by $$p_i=\frac{g_{i}\exp{(-E_{i}/kT)}}{Q},$$ where $$Q$$ is the canonical partition function. We can try to find the entropy in the following ways

1. We use the well known result that $$S=-k\langle\ln{(p_i)}\rangle$$, where $$\langle\cdot\rangle$$ denotes the expectation value. This quickly yields $$S=-k[p_1\ln{(p_1)}+p_2\ln{(p_2)}].$$ As we see, the factor of $$g_i$$ occurs nowhere in this expression explicitly.

2. We start from the well known result $$S=\frac{E}{T}+k\ln{Q}$$; in this we substitute $$Q$$ from $$p_i=\frac{g_{i}\exp{(-E_{i}/kT)}}{Q}$$ and $$E$$ as $$\beta(p_1E_1+p_2E_2)$$, which is the ensemble average of the energy. This results in $$S=-k\left[p_1\ln\left(\frac{p_1}{g_1}\right)+p_2\ln\left(\frac{p_2}{g_2}\right)\right].$$ The expressions agree when $$g_i=1$$, but I am unable to understand why this difference occurs. Clearly I have made some incorrect assumptions somewhere. Any help is appreciated.

The first expression for $$S$$ is incorrect. From the point of view of statistical mechanics, the $$i$$-th degenerate state actually represents $$g_i$$ different states with the same energy. Therefore, the correct set of probabilities here is $$p_i' = p_1/g_1\quad\mbox{for}\quad i = 1,\ldots,g_1,$$ $$p_i' = p_2/g_2\quad\mbox{for}\quad i = g_1+1,\ldots,g_1+g_2.$$ These probabilities give your second expression for $$S$$: $$S = -k\sum_i p_i'\log(p_i') = -k(g_1\ p_1/g_1\log(p_1/g_1) + g_2\ p_2/g_2\log(p_2/g_2)) % = -k(p_1\log(p_1/g_1) + p_2\log(p_2/g_2))$$
You should consider that you have $$g_1$$ microstates of energy $$E_1$$ and $$g_2$$ with energy $$E_2$$. The probability for the system to be in one of the $$g_1$$ states of energy $$E_1$$ is $$p_1={1\over Q}e^{-\beta E_1}$$ where the partition function is $$Q=g_1e^{-\beta E_1}+g_2e^{-\beta E_2}$$ Therefore, the entropy reads \eqalign{ S&=-k_B\big[g_1p_1\ln p_1+g_2p_2\ln p_2\big] \cr &=-k_B\Big[g_1{e^{-\beta E_1}\over Q}\Big(-\beta E_1-\ln Q\Big) +g_2{e^{-\beta E_2}\over Q}\Big(-\beta E_2-\ln Q\Big)\Big]\cr &={1\over T}\underbrace{\Big[g_1E_1{e^{-\beta E_1}\over Q} +g_2E_2{e^{-\beta E_2}\over Q}\Big]}_{=\langle E\rangle} +{k_B\over Q}\underbrace{\Big[g_1e^{-\beta E_1} +g_2e^{-\beta E_2}\Big]}_{=Q}\ln Q\cr } Finally, we get as expected $$F=-k_BT\ln Q=\langle E\rangle-TS$$