In the diagram, the system is the gas in the piston. We use a Carnot heat engine/pump to add heat to the system at a local, varying temperature . During the process work is done on the system. (Both and could be positive or negative.) The cold reservoir of the Carnot engine is at .
The Kelvin-Planck statement of the second law says that at the end of a complete cycle of the system, we cannot have extracted net work (or else we would have turned heat from the cold reservoir into work). Looking at the figure to see how the signs of the various works are defined, that means . By conservation of energy, and because the system and engine have returned to their initial states, any net work put in must end up as heat added to the reservoir: (less than zero because is defined as heat extracted).
Looking now at the Carnot engine, we see that
if at some point in the cycle we add heat
at temperature , heat
is extracted from the
reservoir, and
Clearly if the system is taken through a reversible cycle, it can be run in reverse
and all quantities will simply change signs. But if was less than zero originally, it will be
greater for the reversed cycle, implying a net extraction of work and violating the Kelvin-Planck statement.
Thus for a reversible system, must be exactly zero, and