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, one bounds the total cost encountered throughout a session. Traditionally, amortized analysis has been phrased inductively, quantifying over finite sequences of operations. Connecting to prior work on coalgebraic semantics for data structures, we develop the alternative perspective that amortized analysis is naturally viewed coalgebraically in a category of cost algebras, 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 algebraic and coalgebraic operations simultaneously 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函子(而非自函子)的余代数,我们同时支持代数与余代数运算,并利用底层范畴上的幺半结构组合势能。最后,我们在余代数的索引范畴中组合摊还论证,以基于其他数据结构实现一种摊还数据结构。