Story of Your Lazy Function's Life: A Bidirectional Demand Semantics for Mechanized Cost Analysis of Lazy Programs

被引:0
|
作者
Xia, Li-yao [1 ]
Israel, Laura [1 ]
Kramarz, Maite [2 ]
Coltharp, Nicholas [1 ,2 ]
Claessen, Koen [3 ]
Weirich, Stephanie [4 ]
Li, Yao [1 ]
机构
[1] Portland State Univ, Portland, OR 97207 USA
[2] Univ Toronto, Toronto, ON, Canada
[3] Chalmers Univ, Gothenburg, Sweden
[4] Univ Penn, Philadelphia, PA USA
基金
美国国家科学基金会;
关键词
formal verification; computation cost; lazy evaluation; amortized analysis;
D O I
10.1145/3674626
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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 variant of the classical physicist's method, which enables mechanized, modular and compositional reasoning about amortization and persistence with the demand semantics.
引用
收藏
页数:34
相关论文
共 3 条