A mathematical formulation of the random phase approximation for crystals