A Theory for Emergence of Complex Skills in Language Models