A Formalism for Optimal Search with Dynamic Heuristics (Extended Version)