Theory of the one- and two-dimensional electron gas