How work done on a spring changes based on compression or stretching If you apply a force to a spring, causing the spring to compress by a distance 0.1 m, and the spring is at rest before and after the compression. Assuming no sources or dissipation of mechanical energy in the spring, would the total work you did on the spring be zero because the kinetic energy is zero before and after compression?
 A: It might be helpful to first get the result, then ask why it is not zero. The spring initially had no potential energy, but upon being compressed, stores a potential energy $$U=\frac{1}{2}kx^2$$ $x$ being 0.1m here. By energy conservation, this has to be supplied from outside, and is equal to the work done on the spring. So, why is the work done not zero? 
Well, a lot of equations are merely meant to describe very particular situations, rather than being fundamental laws. I believe you are implicitly using some equation that relates the work done to the change in kinetic energy. This works well when moving point masses by constant forces, but is less fundamental than the law of conservation of energy. When generalizing, it is the more fundamental laws that are more likely to continue being applicable.
A: The work-energy principle, when applied properly, says that the net work done by all forces acting on the system matches the change in the kinetic energy. That means that instead of accounting potential energy, you let that count for work. If the change in PE is $\Delta U$, then the work done by the conservative force is $-\Delta U$ (by definition). If some outside push does work $W_{\mathrm{ext}}$, the net work is $W_{\mathrm{ext}}-\Delta U$. With the change in kinetic energy equal to zero $$W_{\mathrm{ext}}-\Delta U=0$$
$$W_{\mathrm{ext}}=\Delta U$$
The external work is equal to the change in the potential energy of the system.
A: Suppose for simplicity that the spring is massless, and have a mass attached to it. There is a external force and the spring restoring force acting on the mass at each instant.
An example of starting from the equilibium position and ending with the spring compressed with displacement 0.1m, is to apply an external force programmed to decrease as the spring is being compressed.
$F_{ext} = k(0.1 - x)$
As the spring force is $F_s = kx$, the net force is: $k(0.1 - x) - kx = k(0.1 - 2x)$
The net force decreases linearly from an initial value of $k(0.1)$. When $x=0.05$m it is zero. When $x = 0.1$ it is $-k(0.1)$.
But at that instant, the external force is suddenly set to $(k 0.1)$ and stays constant. As the mass was momentarily stopped at that point, it stays at rest.
The total work of the net force is zero because there was no change of velocity between the initial and final points.
But the work of the external force is clearly not zero. $$w_{ext} = \int_0^{0.1} k(0.1 - x)dx = k(0.1^2 - \frac{0.1^2}{2}) = k\frac{0.1^2}{2}$$
