Reference. The Compositional Essence of Effectful Cost Analyses: Categorical Foundations and Fibered Logical Relations

Cite

Cite as @amorim_effcost (helia, typst) · \cite{amorim_effcost} (LaTeX)
BibTeX
bibtex · 6 lines
@unpublished{amorim_effcost,
 title = {The Compositional Essence of Effectful Cost Analyses: Categorical Foundations and Fibered Logical Relations},
 author = {Amorim, Pedro H. Azevedo de},
 note = {Preprint},
 url = {https://pedrohaa.github.io/papers/effcost.pdf}
}
hayagriva YAML (typst)
yaml · 6 lines
amorim_effcost:
  type: manuscript
  title: 'The Compositional Essence of Effectful Cost Analyses: Categorical Foundations and Fibered Logical Relations'
  author: Amorim, Pedro H. Azevedo de
  url: https://pedrohaa.github.io/papers/effcost.pdf
  note: Preprint
Cites 73 works (8 here)
With notes (8)

Denotational Foundations for Expected Cost Analysis amorim_2025_oopsla

Reasoning about the cost of executing programs is one of the fundamental questions in computer science. In the context of programming with probabilities, however, the notion of cost stops being deterministic, since it depends on the probabilistic samples made throughout the execution of the program. This interaction is further complicated by the non-trivial interaction between cost, recursion and evaluation strategy.

In this work we introduce cert: a Call-By-Push-Value (CBPV) metalanguage for reasoning about probabilistic cost. We equip cert with an operational cost semantics and define two denotational semantics — a cost semantics and an expected-cost semantics. We prove operational soundness and adequacy for the denotational cost semantics and a cost adequacy theorem for the expected-cost semantics.

We formally relate both denotational semantics by stating and proving a novel effect simulation property for CBPV. We also prove a canonicity property of the expected-cost semantics as the minimal semantics for expected cost and probability by building on recent advances on monadic probabilistic semantics.

Finally, we illustrate the expressivity of cert and the expected-cost semantics by presenting case-studies ranging from randomized algorithms to stochastic processes and show how our semantics capture their intended expected cost.

PDF · DOI · pldb

Logical relations for call-by-push-value models, via internal fibrations in a 2-category amorim_kura_saville_2025

We give a denotational account of logical relations for call-by-push-value (CBPV) in the fibrational style of Hermida, Jacobs, Katsumata and others. Fibrations – which axiomatise the usual notion of sets-with-relations – provide a clean framework for constructing new, logical relations-style, models. Such models can then be used to study properties such as effect simulation.

Extending this picture to CBPV is challenging: the models incorporate both adjunctions and enrichment, making the appropriate notion of fibration unclear. We handle this using 2-category theory. We identify an appropriate 2-category, and define CBPV fibrations to be fibrations internal to this 2-category which strictly preserve the CBPV semantics.

Next, we develop the theory so it parallels the classical setting. We give versions of the codomain and subobject fibrations, and show that new models can be constructed from old ones by pullback. The resulting framework enables the construction of new, logical relations-style, models for CBPV.

Finally, we demonstrate the utility of our approach with particular examples. These include a generalisation of Katsumata’s ⊤⊤-lifting to CBPV models, an effect simulation result, and a relative full completeness result for CBPV without sum types.

Web · arXiv

Tachis: Higher-Order Separation Logic with Credits for Expected Costs haselwarter-2024-tachis

We present Tachis, a higher-order separation logic to reason about the expected cost of probabilistic programs. Inspired by the uses of time credits for reasoning about the running time of deterministic programs, we introduce a novel notion of probabilistic cost credit. Probabilistic cost credits are a separation logic resource that can be used to pay for the cost of operations in programs, and that can be distributed across all possible branches of sampling instructions according to their weight, thus enabling us to reason about expected cost. The representation of cost credits as separation logic resources gives Tachis a great deal of flexibility and expressivity. In particular, it permits reasoning about amortized expected cost by storing excess credits as potential into data structures to pay for future operations. Tachis further supports a range of cost models, including running time and entropy usage. We showcase the versatility of this approach by applying our techniques to prove upper bounds on the expected cost of a variety of probabilistic algorithms and data structures, including randomized quicksort, hash tables, and meldable heaps. All of our results have been mechanized using Coq, Iris, and the Coquelicot real analysis library.
DOI · arXiv · pldb

Error Credits: Resourceful Reasoning about Error Bounds for Higher-Order Probabilistic Programs aguirre-2024-error

Probabilistic programs often trade accuracy for efficiency, and thus may, with a small probability, return an incorrect result. It is important to obtain precise bounds for the probability of these errors, but existing verification approaches have limitations that lead to error probability bounds that are excessively coarse, or only apply to first-order programs. In this paper we present Eris, a higher-order separation logic for proving error probability bounds for probabilistic programs written in an expressive higher-order language. Our key novelty is the introduction of error credits , a separation logic resource that tracks an upper bound on the probability that a program returns an erroneous result. By representing error bounds as a resource, we recover the benefits of separation logic, including compositionality, modularity, and dependency between errors and program terms, allowing for more precise specifications. Moreover, we enable novel reasoning principles such as expectation-preserving error composition, amortized error reasoning, and error induction. We illustrate the advantages of our approach by proving amortized error bounds on a range of examples, including collision probabilities in hash functions, which allow us to write more modular specifications for data structures that use them as clients. We also use our logic to prove correctness and almost-sure termination of rejection sampling algorithms. All of our results have been mechanized in the Coq proof assistant using the Iris separation logic framework and the Coquelicot real analysis library.
DOI · arXiv · pldb

Fully abstract models for effectful λ-calculi via category-theoretic logical relations kammar-2022-fully

We present a construction which, under suitable assumptions, takes a model of Moggi’s computational λ-calculus with sum types, effect operations and primitives, and yields a model that is adequate and fully abstract. The construction, which uses the theory of fibrations, categorical glueing, ⊤⊤-lifting, and ⊤⊤-closure, takes inspiration from O’Hearn & Riecke’s fully abstract model for PCF. Our construction can be applied in the category of sets and functions, as well as the category of diffeological spaces and smooth maps and the category of quasi-Borel spaces, which have been studied as semantics for differentiable and probabilistic programming.
PDF · DOI · pldb

A cost-aware logical framework niu-2022-a

We present calf, a cost-aware logical framework 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 phase distinctions, we argue that the cost structure of programs motivates a phase distinction between intension and 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 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 as a general framework for cost analysis by implementing two fundamental techniques for algorithm analysis: the method of recurrence relations and 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 complexity of merge sort, all fully mechanized in the Agda proof assistant. Lastly we substantiate the soundness of quantitative reasoning in calf by means of a model construction.
PDF · DOI · arXiv · pldb

Logical Relations as Types: Proof-Relevant Parametricity for Program Modules sterling_harper_2021

The theory of program modules is of interest to language designers not only for its practical importance to programming, but also because it lies at the nexus of three fundamental concerns in language design: the phase distinction, computational effects, and type abstraction. We contribute a fresh “synthetic” take on program modules that treats modules as the fundamental constructs, in which the usual suspects of prior module calculi (kinds, constructors, dynamic programs) are rendered as derived notions in terms of a modal type-theoretic account of the phase distinction. We simplify the account of type abstraction (embodied in the generativity of module functors) through a lax modality that encapsulates computational effects, placing projectibility of module expressions on a type-theoretic basis.

Our main result is a (significant) proof-relevant and phase-sensitive generalization of the Reynolds abstraction theorem for a calculus of program modules, based on a new kind of logical relation called a parametricity structure. Parametricity structures generalize the proof-irrelevant relations of classical parametricity to proof-relevant families, where there may be non-trivial evidence witnessing the relatedness of two programs—simplifying the metatheory of strong sums over the collection of types, for although there can be no “relation classifying relations,” one easily accommodates a “family classifying small families.”

Using the insight that logical relations/parametricity is itself a form of phase distinction between the syntactic and the semantic, we contribute a new synthetic approach to phase separated parametricity based on the slogan logical relations as types, by iterating our modal account of the phase distinction. We axiomatize a dependent type theory of parametricity structures using two pairs of complementary modalities (syntactic, semantic) and (static, dynamic), substantiated using the topos theoretic Artin gluing construction. Then, to construct a simulation between two implementations of an abstract type, one simply programs a third implementation whose type component carries the representation invariant.

DOI · arXiv

A domain theory for statistical probabilistic programming vakar-2019-a

We give an adequate denotational semantics for languages with recursive higher-order types, continuous probability distributions, and soft constraints. These are expressive languages for building Bayesian models of the kinds used in computational statistics and machine learning. Among them are untyped languages, similar to Church and WebPPL, because our semantics allows recursive mixed-variance datatypes. Our semantics justifies important program equivalences including commutativity. Our new semantic model is based on ‘quasi-Borel predomains’. These are a mixture of chain-complete partial orders (cpos) and quasi-Borel spaces. Quasi-Borel spaces are a recent model of probability theory that focuses on sets of admissible random elements. Probability is traditionally treated in cpo models using probabilistic powerdomains, but these are not known to be commutative on any class of cpos with higher order functions. By contrast, quasi-Borel predomains do support both a commutative probabilistic powerdomain and higher-order functions. As we show, quasi-Borel predomains form both a model of Fiore’s axiomatic domain theory and a model of Kock’s synthetic measure theory.
PDF · DOI · pldb
External (65)
  • Composing Codensity Bisimulations (2024)
  • Effectful semantics in bicategories: strong, commutative, and concurrent pseudomonads (2024)
  • A Modal Type Theory of Expected Cost in Higher-Order Probabilistic Programs (2024)
  • Concurrent monads for shared state (2024)
  • An Order Theory Framework of Recurrence Equations for Static Cost Analysis–Dynamic Inference of Non-Linear Inequality Invariants (2024)
  • Automatic Differentiation via Effects and Handlers (2024)
  • A calculus for amortized expected runtimes (2023)
  • Central submonads and notions of computation: Soundness, completeness and internal languages (2023)
  • Decalf: A Directed, Effectful Cost-Aware Logical Framework (2023)
  • Automatic Amortized Resource Analysis with Regular Recursive Types (2023)
  • ωpap spaces: Reasoning denotationally about higher-order, recursive probabilistic and differentiable programs (2023)
  • Higher-Order Weakest Precondition Transformers via a CPS Transformation (2023)
  • ADEV: Sound automatic differentiation of expected values of probabilistic programs (2023)
  • Automated Tail Bound Analysis for Probabilistic Recurrence Relations (2023)
  • Quantum expectation transformers for cost analysis (2022)
  • Weighted programming: a programming paradigm for specifying mathematical models (2022)
  • Automated expected amortised cost analysis of probabilistic data structures (2022)
  • On continuation-passing transformations and expected cost analysis (2021)
  • A unifying type-theory for higher-order (amortized) cost analysis (2021)
  • A modular cost analysis for probabilistic programs (2020)
  • Foundations of probabilistic programming (2020)
  • Combining probabilistic and non-deterministic choice via weak distributive laws (2020)
  • Exponential automatic amortized resource analysis (2020)
  • Raising expectations: automating expected cost analysis with types (2020)
  • Type-based complexity analysis of probabilistic functional programs (2019)
  • Recurrence extraction for functional programs through call-by-push-value (2019)
  • Codensity Games for Bisimilarity (2019)
  • Tail probabilities for randomized program runtimes via martingales for higher moments (2019)
  • Time credits and time receipts in Iris (2019)
  • Relational cost analysis for functional-imperative programs (2019)
  • Factorisation systems for logical relations and monadic lifting in type-and-effect system semantics (2018)
  • Concurrent Kleene algebra: Free model and completeness (2018)
  • Codensity lifting of monads and its dual (2018)
  • Bounded expectations: resource analysis for probabilistic programs (2018)
  • A semantic account of metric preservation (2017)
  • Relational cost analysis (2017)
  • Towards automatic resource bound analysis for OCaml (2017)
  • A weakest pre-expectation semantics for mixed-sign expectations (2017)
  • Arrays and references in resource aware ML (2017)
  • Algorithmic analysis of qualitative and quantitative termination problems for affine probabilistic programs (2016)
  • Practical Foundations for Programming Languages (2016)
  • Weakest precondition reasoning for expected run–times of probabilistic programs (2016)
  • Denotational cost semantics for functional languages with inductive types (2015)
  • Automatic static cost analysis for parallel programs (2015)
  • Fibred 2-categories and bicategories (2014)
  • Upper-expectation bisimilarity and Łukasiewicz μ-calculus (2014)
  • A static cost analysis for a higher-order language (2013)
  • Relating computational effects by ⊤⊤-lifting (2013)
  • Weighted Relational Models of Typed Lambda-Calculi (2013)
  • Tensors, Monads and Actions (2013)
  • Fibrations of bicategories (2011)
  • Concurrent Kleene algebra and its foundations (2011)
  • Logical relations for monadic types (2008)
  • Distributing probability over non-determinism (2006)
  • A semantic formulation of ⊤⊤-lifting and logical predicates for computational metalanguage (2005)
  • Continuous Lattices and Domains (2003)
  • Sketches of an Elephant: A Topos Theory Compendium, Volume 1 (2002)
  • Call-by-push-value (2001)
  • Lax logical relations (2000)
  • Handbook of categorical algebra: volume 2, Categories and Structures (1994)
  • Fibrations, Logical Predicates and Indeterminates (1993)
  • Notes on sconing and relators (1992)
  • Computational lambda-calculus and monads (1989)
  • A Hoare-like proof system for analysing the computation time of programs (1987)
  • A Note on the Height of Binary Search Trees (1986)
amorim_effcost reference entries/refs/amorim_effcost/amorim_effcost.hel