We present ${\bf decalf}$, a ${\bf d}$irected, ${\bf e}$ffectful ${\bf c}$ost-${\bf a}$ware ${\bf l}$ogical ${\bf f}$ramework for studying quantitative aspects of functional programs with effects. Like ${\bf calf}$, the language is based on a formal phase distinction between the extension and the intension of a program, its pure behavior as distinct from its cost measured by an effectful step-counting primitive. The type theory ensures that the behavior is unaffected by the cost accounting. Unlike ${\bf calf}$, the present language takes account of effects, such as probabilistic choice and mutable state; this extension requires a reformulation of ${\bf calf}$'s approach to cost accounting: rather than rely on a "separable" notion of cost, here a cost bound is simply another program. To make this formal, we equip every type with an intrinsic preorder, relaxing the precise cost accounting intrinsic to a program to a looser but nevertheless informative estimate. For example, the cost bound of a probabilistic program is itself a probabilistic program that specifies the distribution of costs. This approach serves as a streamlined alternative to the standard method of isolating a recurrence that bounds the cost in a manner that readily extends to higher-order, effectful programs. The development proceeds by first introducing the ${\bf decalf}$ type system, which is based on an intrinsic ordering among terms that restricts in the extensional phase to extensional equality, but in the intensional phase reflects an approximation of the cost of a program of interest. This formulation is then applied to a number of illustrative examples, including pure and effectful sorting algorithms, simple probabilistic programs, and higher-order functions. Finally, we justify ${\bf decalf}$ via a model in the topos of augmented simplicial sets.
翻译:我们提出 ${\bf decalf}$——一种有向的、带效应的成本感知逻辑框架,用于研究带效应函数式程序的定量性质。与 ${\bf calf}$ 类似,该语言基于程序的外延与内涵之间的形式化阶段区分,即其纯行为与通过带效应步数计数原语测量的成本相区别。类型系统确保行为不受成本计算的影响。与 ${\bf calf}$ 不同,本语言考虑了效应,如概率选择和可变状态;这一扩展要求重新表述 ${\bf calf}$ 的成本计算方法:不依赖于“可分离”的成本概念,此处成本界限仅仅是另一个程序。为使这一形式化成立,我们为每个类型配备了内在预序,将程序固有的精确成本计算放松为一种松散但仍具信息量的估计。例如,概率程序的成本界限本身是一个指定成本分布的概率程序。该方法作为标准方法的简化替代方案,标准方法通过隔离成本界限的递归关系,且易于扩展到高阶带效应程序。发展过程首先引入 ${\bf decalf}$ 类型系统,该系统基于项之间的内在序关系——在外延阶段限制为外延相等,但在内涵阶段反映感兴趣程序的成本近似。随后将该形式化应用于一系列示例,包括纯与带效应的排序算法、简单概率程序以及高阶函数。最后,通过在增强单纯集拓扑斯中的模型来论证 ${\bf decalf}$ 的正确性。