1See RamseyCassKoopmans for the discounted Hamiltonian optimality conditions and HamiltonianVSDiscrete for the intuition of the logic behind the Hamiltonian.