Minimisation of Gibbs/Helmholtz free energy and Clausius theorem I am trying to understand why (under the relevant given conditions) the free energy (either Gibbs or Helmholtz) is minimised. The derivation I have seen in several places goes like this. Set $\delta W = - PdV$
$$dE = \delta Q + \delta W = \delta Q - PdV$$
$$dE + PdV - TdS = \delta Q - TdS \leq 0$$
by Clausius' theorem. Therefore at constant T and P, $E + PV - TS$ is minimised. What bothers me about this argument is the following. Standard thermodynamics textbooks will tell you that
$$dE = TdS - PdV$$
is true in general even for irreversible processes (this makes sense to me). Therefore we have
$$dE = TdS - PdV = \delta Q + \delta W$$
$$(\delta Q - TdS) + (\delta W + PdV) = 0$$
If $\delta Q - TdS \leq 0$ then $\delta W + PdV \geq 0$ and in fact whenever $\delta Q \neq TdS$ you must have $\delta W \neq - PdV$. Thus the above derivation seems to contain a contradiction in that it simultaneously assumes $\delta Q > TdS$ but yet $\delta W = - PdV$. Is my objection correct? If so is there another way to derive the minimisation of these potentials?
 A: The source of the apparent paradox is the equation
$$
\text{d}E = T\text{d}S - P\text{d}V.
$$
This equation only applies for a pure substance at phase equilibrium. For the general case of a multi-component mixture or a pure substance not at phase equilibrium, the equation is instead
$$
\text{d}E = T\text{d}S - P\text{d}V + \sum_i \mu_i \text{d} m_i
$$
where $\mu_i$ is the chemical potential (per mass) of species $i$ and $m_i$ is the mass of species $i$. If you go through the math you will find that the sum term is zero when reversible chemical reactions (including the null reaction) occur and negative when irreversible ones occur. This is the sink term which prevents the derivation from being self-contradictory.
The derivation does not work for a pure substance at phase equilibrium because if such a substance has a well-defined $T$ and $P$ (as is stated in the derivation) then we know its state exactly. We no longer have a set of quasi-equilibrium states (here meaning "states where thermodynamics applies") from which we can pick the single true equilibrium state via a minimization principle; we have exactly one quasi-equilibrium state which is also the true equilibrium state. 
As an example to illustrate the above, imagine a system consisting of twice as many atoms of hydrogen as oxygen, held in a container which maintains constant $T$ and $P$. 


*

*In general, there are infinite possible chemical compositions satisfying these constraints, and all of these are quasi-equilibrium states, but there is only one true equilibrium state (chemical equilibrium). The quasi-equilibrium states decay into the equilibrium state via irreversible chemical reactions, and the derivation tells us that we can identify the equilibrium state as that of minimum $G$. 

*In the special case where all of the hydrogen and oxygen atoms are combined into water molecules, there is instead one possible chemical composition, and one can use steam tables to look up any property of interest as a function of $T$ and $P$. There is only one state satisfying the constraints, so the system can only undergo one "process": the null process beginning with water at the defined $T$ and $P$ and ending at the same state (which is reversible). This is perfectly consistent with what the math shows: the 'sum over chemical potentials' term is $0$, so (by the logic in your question) all possible processes are reversible. 
