Get the latest tech news
Verified dynamic programming with Σ-types in Lean
1. IntroductionIf you’ve taken an algorithms class, you have likely seen dynamic programming, specifically a technique called memoization. Memoization works to optimize recursive algorithms by caching the solutions to subproblems in a table, and when a subproblem is encountered, it queries the table instead of recomputing the solution. This gives us an exponential performance boost.
It then calls the helper on the empty map and returns the n th value(Exercise : Rewrite this using a state monad to simulate mutating the hashmap instead of passing around a new one with each insertion) We implemented a naive memoized version using a HashMap, and discussed why proving its correctness directly is tough due to the difficulty of reasoning about data structure invariants. Each of the following DP problems can be solved using the same framework introduced in this post: define a recurrence relation as a specification, write a memoized implementation that returns values paired with correctness proofs via subtypes, and prove the top-level function computes the intended result.
Or read this on Hacker News