Theory of the alternating-gradient synchrotron