Foundations of demographic theory