English

A cost-aware logical framework

Programming Languages 2021-10-11 v2

Abstract

We present calf\textbf{calf}, a c\textbf{c}ost-a\textbf{a}ware l\textbf{l}ogical f\textbf{f}ramework for studying quantitative aspects of functional programs. Taking inspiration from recent work that reconstructs traditional aspects of programming languages in terms of a modal account of \emph{phase distinctions}, we argue that the cost structure of programs motivates a phase distinction between intension\textit{intension} and extension\textit{extension}. Armed with this technology, we contribute a synthetic account of cost structure as a computational effect in which cost-aware programs enjoy an internal noninterference property: input/output behavior cannot depend on cost. As a full-spectrum dependent type theory, calf\textbf{calf} presents a unified language for programming and specification of both cost and behavior that can be integrated smoothly with existing mathematical libraries available in type theoretic proof assistants. We evaluate calf\textbf{calf} as a general framework for cost analysis by implementing two fundamental techniques for algorithm analysis: the method of recurrence relations\textit{method of recurrence relations} and physicist’s method for amortized analysis\textit{physicist's method for amortized analysis}. We deploy these techniques on a variety of case studies: we prove a tight, closed bound for Euclid's algorithm, verify the amortized complexity of batched queues, and derive tight, closed bounds for the sequential and parallel\textit{parallel} complexity of merge sort, all fully mechanized in the Agda proof assistant. Lastly we substantiate the soundness of quantitative reasoning in calf\textbf{calf} by means of a model construction.

Keywords

Cite

@article{arxiv.2107.04663,
  title  = {A cost-aware logical framework},
  author = {Yue Niu and Jonathan Sterling and Harrison Grodin and Robert Harper},
  journal= {arXiv preprint arXiv:2107.04663},
  year   = {2021}
}
R2 v1 2026-06-24T04:03:25.428Z