AI and robotics from first principles: how machines learn to think and act, and what they might become