Story of Your Lazy Function's Life: A Bidirectional Demand Semantics for Mechanized Cost Analysis of Lazy Programs
Li-yao Xia, Laura Israel, Maite Kramarz, Nicholas Coltharp, Koen, Claessen, Stephanie Weirich, Yao Li

TL;DR
This paper introduces a bidirectional demand semantics for analyzing the computation cost of lazy programs, enabling extrinsic reasoning without complex logics, and demonstrates its effectiveness through case studies and formal proofs.
Contribution
It presents a novel demand semantics approach that simplifies cost analysis of lazy programs and introduces the reverse physicist's method for modular reasoning.
Findings
Successfully applied to insertion sort, selection sort, and queues
Formally proved amortization and persistence properties
Avoids reliance on specialized program logics
Abstract
Lazy evaluation is a powerful tool that enables better compositionality and potentially better performance in functional programming, but it is challenging to analyze its computation cost. Existing works either require manually annotating sharing, or rely on separation logic to reason about heaps of mutable cells. In this paper, we propose a bidirectional demand semantics that allows for extrinsic reasoning about the computation cost of lazy programs without relying on special program logics. To show the effectiveness of our approach, we apply the demand semantics to a variety of case studies including insertion sort, selection sort, Okasaki's banker's queue, and the implicit queue. We formally prove that the banker's queue and the implicit queue are both amortized and persistent using the Rocq Prover (formerly known as Coq). We also propose the reverse physicist's method, a novel…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
