The Mathematical Theory of Optimal Processes