Inference via Interpolation: Contrastive Representations Provably Enable Planning and Inference