Consider the following reaction:
$$\ce{A(s) + B(s) <=> AB(s)}.$$
I know there might be kinetic limitations but I am only interested in thermodynamic relations.
In general, the Gibbs free energy of reaction reads:
$$\Delta G = \Delta G^⦵ + RT\ln{\prod a_i^{\nu_i}}$$
and for the given reaction:
$\Delta G = \Delta G^⦵ + RT\ln{\frac{a_\ce{AB}}{a_\ce{A}\cdot a_\ce{B}}} \label{eqn:1}\tag{1}$
Since all components are pure solid substances, all activities equal 1 and therefore, $\Delta G = \Delta G^⦵$.
If $A$ and $B$ are elements, I found the following formula:
$$\Delta G_\mathrm{f}^⦵ = N\cdot RT\ln{\left(a_\ce{A}^{x_\ce{A}}a_\ce{B}^{x_\ce{B}}\right)} \label{eqn:2}\tag{2}$$
where $N$ is the total number of atoms and $x_\ce{A}$ and $x_\ce{B}$ are the mole fractions. To me, this latter formula implies, that the activities of $\ce{A}$ and $\ce{B}$ inside the product $\ce{AB}$ are of interest.
I have two questions:
What is the origin of the second formula $\eqref{eqn:2}$? In almost every source, the first type of Gibbs energy is used and I was not able to find any derivation. Also I think in principle, equation $\eqref{eqn:1}$ and $\eqref{eqn:2}$ should produce the same, but it looks very different!?
How does it come, that in one case the activity of the whole product $\ce{AB}$ is important and in another the single activities of the components of the product?
--------------------Update--------------------
Based on comments I'll try to reformulate my problem to make it more clear.
As I have learned, there should be no difference between the reaction product AB and the mixture of A and B with the corresponding stoichiometry (1:1). Is this valid in general or just for reactions like this (cf. my water-example in the comments)?
The transformation of equation (2) (in NightWriter's answer) shows, that it is an identity of the Gibbs free energy of mixing but in terms of moles of compound AB rather than in terms of moles of mixture.
If equation (1) describes the reaction (i.e. formation) of AB and equation (2) the mixing of A and B, and there is no difference between a product of reaction and the corresponding mixture of the two components to form that product, there must be some mathematical relation between equation (1) and equation (2). Furthermore, I am not certain, whether the standard-state symbol in equation (2) is correct or not.
After I read the answer and the comments again, I concluded the following: equation (1) describes the formation of AB and equation (2) the mixture of A and B at arbitrary compositions. So, if I set $x_A = x_B =0.5$, it should be possible to replace $\Delta G^⦵$ in equation (1) by $\Delta G_f^⦵ = N\cdot RT\ln{a_A^{0.5}a_B^{0.5}}$. $N$ must be chosen properly, since the two expressions are related to different things (mixture and compound). Is this correct?