Generalizable Reasoning through Compositional Energy Minimization