Amortized analysis is a cost analysis technique for data structures in which cost is studied in aggregate, rather than considering the maximum cost of a single operation. Traditionally, amortized analysis has been phrased inductively, in terms of finite sequences of operations. Connecting to prior work on coalgebraic semantics for data structures, we develop the perspective that amortized analysis is naturally viewed coalgebraically in the category of algebras for a cost monad, where a morphism of coalgebras serves as a first-class generalization of potential function suitable for integrating cost and behavior. Using this simple definition, we consider amortization of other sample effects, non-commutative printing and randomization. To support imprecise amortized upper bounds, we adapt our discussion to the bicategorical setting, where a potential function is a colax morphism of coalgebras. We support parallel data structure usage patterns by using coalgebras for an endoprofunctor instead of an endofunctor, combining potential using a monoidal structure on the underlying category. Finally, we compose amortization arguments in the indexed category of coalgebras to implement one amortized data structure in terms of others.
翻译:摊销分析是一种针对数据结构成本分析的技术,其核心在于从整体角度研究成本,而非关注单个操作的最大开销。传统上,摊销分析以归纳方式表述,基于有限的操作序列。结合先前关于数据结构余代数语义的研究,我们提出一种观点:摊销分析可自然地置于成本单子代数范畴的余代数框架下进行审视,其中余代数态射可作为势函数的一类推广,适用于整合成本与行为。基于此简洁定义,我们探讨了其他示例效应(非交换打印与随机化)的摊销问题。为支持不精确的摊销上界,我们将讨论适配到双范畴框架,此时势函数表现为余代数的余松弛态射。通过采用自反pro函子(而非自反函子)的余代数,并利用底层范畴上的幺半结构组合势能,我们支持并行数据结构使用模式。最后,我们在余代数的索引范畴中组合摊销论证,以基于其他数据结构实现一种摊销化数据结构。