Pātuhitia tēnei: The mathematical theory of optimal processes