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

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Xia, Li-yao, Israel, Laura, Kramarz, Maite, Coltharp, Nicholas, Claessen, Koen, Weirich, Stephanie, Li, Yao
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866929431657840640
author Xia, Li-yao
Israel, Laura
Kramarz, Maite
Coltharp, Nicholas
Claessen, Koen
Weirich, Stephanie
Li, Yao
author_facet Xia, Li-yao
Israel, Laura
Kramarz, Maite
Coltharp, Nicholas
Claessen, Koen
Weirich, Stephanie
Li, Yao
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2406_14787
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Story of Your Lazy Function's Life: A Bidirectional Demand Semantics for Mechanized Cost Analysis of Lazy Programs
Xia, Li-yao
Israel, Laura
Kramarz, Maite
Coltharp, Nicholas
Claessen, Koen
Weirich, Stephanie
Li, Yao
Programming Languages
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.
title Story of Your Lazy Function's Life: A Bidirectional Demand Semantics for Mechanized Cost Analysis of Lazy Programs
topic Programming Languages
url https://arxiv.org/abs/2406.14787