First, I should mention that the question was already asked here: Why is active mass of a pure solid or liquid always taken as unity? However, the treatment there is qualitative and I do not really understand the reasoning for the disclusion of solids and liquids from the reaction qoutient that is presented there. I have attempted to derive this fact mathematically and failed, which why I ask this question again.
Let us look at an example reaction which involves solids and gases. The treatment for other reactions or reactions with liquids shouldn't differ significantly. A very simple reaction for this matter will be the combustion of graphite
$$\ce{C(s) + O2(g) -> CO2(g)}$$
Reaction quotients are derived from the equation for change in Gibbs free energy at nonstandard pressures, so let's find that. Suppose the reaction is carried out in nonstandard pressure, and $\Delta G^o_r$ is known. Let's (I) compress the system isothermally to standard pressure, (II) carry out the reaction and then (III) return it isothermally to the original pressure.
I. $\Delta G$ for the oxygen here is the well known $RT\ln (1/(P/P_o))$. For the carbon: In any isothermal process $dG=VdP$, let's assume for our ideal solid that the volume is constant (I have also tried this in a model where the volume changes with pressure with bulk moduli, the result does not differ significantly), so $\Delta G=V(P-P_o)$.
II. Here simply $\Delta G=\Delta G^o_r$.
III. Here it's just gas compressing so again $\Delta G=RT\ln (P/P_o)$
Adding the contributions from all three stages we have $$ \Delta G=RT\ln (1/(P/P_o))+V(P-P_o)+\Delta G^o_r+RT\ln (P/P_o)=\Delta G^o_r+V(P-P_o) $$
This result is different from what a model of an activity of unity for the carbon would predict. What went wrong? And why are activities of solids and liquids taken to be unity? Any help will be appreciated.