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.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of types

types

Related news:

News photo

Brown fat “repressor” protein targets cancer-related weight loss | The discovery opens the door to developing treatments for the extreme weight loss, muscle wasting, and malnutrition seen in some types of cancer.

News photo

Types of optical systems in a lens designer's toolbox (2020)

News photo

Propositions as Types (2014) [pdf]