Abstract: Modern programming frequently requires generalised notions of program equivalence based on a metric or a similar structure. Previous work addressed this challenge by introducing the notion of a V-equation, i.e. an equation labelled by an element of a quantale V, which covers inter alia (ultra-)metric, classical, and fuzzy (in)equations. It also introduced a V-equational system for the linear variant of lambda-calculus where any given resource must be used exactly once. In this paper we drop the (often too strict) linearity constraint by adding graded modal types which allow multiple uses of a resource in a controlled manner. We show that such a control, whilst providing more expressivity to the programmer, also interacts more richly with V-equations than the linear or Cartesian cases. Our main result is the introduction of a sound and complete V-equational system for a lambda-calculus with graded modal types interpreted by what we call a Lipschitz exponential comonad. We also show how to build such comonads canonically via a universal construction, and use our results to derive graded metric equational systems (and corresponding models) for programs with timed and probabilistic behaviour.
Introduction
In classical computer science, program equivalence is typically binary: two programs are either identical or different. However, modern applications in probabilistic robotics, timed systems, and differential privacy demand a more nuanced "quantitative" equality. Researchers often need to determine if two programs are approximately the same—for instance, whether two Bayesian filters agree within a total variation error of $\epsilon$.
While quantitative reasoning has been successfully applied to linear $\lambda$-calculus (where resources are used exactly once), linearity is often too restrictive for practical programming. Standard non-linear resource reuse, however, breaks quantitative reasoning: multiple uses of a variable can cause small errors to propagate and explode, making it impossible to bound the distance between programs. This paper introduces a graded $\lambda$-calculus that allows for controlled resource reuse while maintaining rigorous bounds on program distances.
Technical Framework
The authors' approach rests on three technical pillars:
- Graded Modal Types: Instead of the "all or nothing" approach of linear logic, a semiring tracks the weight or frequency of resource usage.
- $\mathcal{V}$-Equations: Equations are labeled by elements of a quantale ($\mathcal{V}$), allowing the logic to generalize across domains like metric spaces, ultra-metrics, and fuzzy logic.
- Lipschitz Exponential Comonads: This categorical innovation generalizes the "!" (bang) operator from linear logic. Similar to Lipschitz-continuous functions, this comonad ensures that when a resource is used $n$ times, the "distance" between programs grows predictably.
The calculus is designed such that the substitution rule is derivable. This technical choice is essential for proving the completeness of the equational system, ensuring that every true statement in the model can be formally proven.
Key Results
The primary contribution is the proof of Soundness and Completeness (Theorem 3.13). The equational system perfectly matches its categorical models: any quantitative equation holding in all valid models can be derived using the provided rules, and vice versa.
The utility of this framework is demonstrated through several models:
- Timed Computation: The system can model a "wait" command and prove that
wait_1(x)andwait_2(x)are within 1 second of each other, even when embedded in complex, non-linear functions. - Probabilistic Random Walks: By applying the theory to Banach spaces, the authors bound the Total Variation distance between different random walks. Complex bounds that are difficult to calculate manually at the semantic level can be derived straightforwardly using this equational logic.
Conclusion and Future Work
This work provides a robust foundation for quantitative reasoning in non-linear settings. The "Lipschitz" constraint acts as a mathematical "speed limit," preventing error compounding. Future research directions include extending this approach to hybrid systems (combining discrete and continuous dynamics) and quantum computation. Additionally, the authors aim to further investigate the monoidal nature of the adjunctions involved in their canonical comonad construction.
Summary updated