Yet another follow up to this question,
I am struggling to understand the example provided in Chet Miller's answer:
An example of this is expansion of an ideal gas in contact with an ideal constant temperature reservoir at the initial temperature of the gas. The maximum work and decrease in F for a reversible path are $$W=-\Delta F=nRT\ln{(V_2/V_1)}$$The work for an irreversible path, say where we drop the pressure from the initial value $nRT/V_1$ to the final pressure $nRT/V_2$ and hold it at this final value for the entire expansion, the work is $$W=nRT\left[1-\frac{V_1}{V_2}\right]$$Mathematically, this is less than for the reversible path.
For a non-ideal gas, the internal energy can change even if the temperature is constant. It can also change at constant temperature if there is a phase change or a chemical reaction.
This example discusses the expansion of ideal gas (inside a balloon) in the environment of constant temperature $T$. The system (gas) is assumed to be in thermal equilibrium with the environment.
In particular, I have doubts about how the free energy of the gas changes in the reversible expansion and the irreversible expansion. The differential for the system's Helmholtz energy $F$ in terms of the total entropy of the universe $S_{univ}=S+S_{env}$ is
$$dF=-TdS_{univ}$$
This means if $S_{univ}$ does not change, then $F$ does not change as well. If we apply the thermodynamic identity for $F$ to this equation:
$$dF=-SdT-PdV+\sum_i\mu_i dN_i=-TdS_{univ}$$
We see that $S_{univ}$ and $F$ are constant when the system is in thermal equilibrium $dT=0$, mechanical equilibrium $dV=0$ and chemical equilibrium $dN_i=0$.
If the gas expansion is irreversible, there is nonzero entropy change $\Delta S_{univ}>0$ which makes nonzero Helmholtz energy decrease $\Delta F<0$. I have no problems understanding why the system does work on the environment in this case.
However, in the reversible gas expansion, the total entropy of the universe does not change $\Delta S_{univ}=0$, so this implies that the gas's Helmholtz energy does not change $\Delta F=0$, am I right? If so, why the gas is able to do nonzero expansion work on the environment as in the example?