Consider a massless, frictionless piston fit into an airtight container containing an ideal gas. And let us say that the gas undergoes quasi-static isothermal expansion by lowering the pressure applied by the piston slowly.
The piston moves a distance, say $dr$ in an instant in which the force applied on it by the gas is $F$. So, the work done on it by the gas should be $\delta W=Fdr$.
Now, my textbook states that work done on the gas by the piston should be equal to the negative of the work done on the piston by the gas, saying that it is a consequence of Newton's third law of motion.
The problem is, according to Newton's third law of motion, the mutual forces of interaction between the gas particles and the piston should be equal and opposite to one another. But for the corresponding work done to be negative of one another, each gas particle must be displaced in the opposite direction with same displacement $dr$, which is not necessarily true. So, how come does this hold true?
EDIT: Can anyone prove it mathematically that work done on the gas by the piston should be equal to the negative of the work done on the piston by the gas?