Liquid Amortization: Proving Amortized Complexity with LiquidHaskell (Functional Pearl)

Jan van Brügge
{"title":"Liquid Amortization: Proving Amortized Complexity with LiquidHaskell (Functional Pearl)","authors":"Jan van Brügge","doi":"arxiv-2407.13671","DOIUrl":null,"url":null,"abstract":"Formal reasoning about the time complexity of algorithms and data structures\nis usually done in interactive theorem provers like Isabelle/HOL. This includes\nreasoning about amortized time complexity which looks at the worst case\nperformance over a series of operations. However, most programs are not written\nwithin a theorem prover and thus use the data structures of the production\nlanguage. To verify the correctness it is necessary to translate the data\nstructures from the production language into the language of the prover. Such a\ntranslation step could introduce errors, for example due to a mismatch in\nfeatures between the two languages. We show how to prove amortized complexity\nof data structures directly in Haskell using LiquidHaskell. Besides skipping\nthe translation step, our approach can also provide a didactic advantage.\nLearners do not have to learn an additional language for proofs and can focus\non the new concepts only. For this paper, we do not assume prior knowledge of\namortized complexity as we explain the concepts and apply them in our first\ncase study, a simple stack with multipop. Moving to more complicated (and\nuseful) data structures, we show that the same technique works for binomial\nheaps which can be used to implement a priority queue. We also prove amortized\ncomplexity bounds for Claessen's version of the finger tree, a sequence-like\ndata structure with constant-time cons/uncons on either end. Finally we discuss\nthe current limitations of LiquidHaskell that made certain versions of the data\nstructures not feasible.","PeriodicalId":501024,"journal":{"name":"arXiv - CS - Computational Complexity","volume":"95 1","pages":""},"PeriodicalIF":0.0000,"publicationDate":"2024-07-18","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"arXiv - CS - Computational Complexity","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/arxiv-2407.13671","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 0

Abstract

Formal reasoning about the time complexity of algorithms and data structures is usually done in interactive theorem provers like Isabelle/HOL. This includes reasoning about amortized time complexity which looks at the worst case performance over a series of operations. However, most programs are not written within a theorem prover and thus use the data structures of the production language. To verify the correctness it is necessary to translate the data structures from the production language into the language of the prover. Such a translation step could introduce errors, for example due to a mismatch in features between the two languages. We show how to prove amortized complexity of data structures directly in Haskell using LiquidHaskell. Besides skipping the translation step, our approach can also provide a didactic advantage. Learners do not have to learn an additional language for proofs and can focus on the new concepts only. For this paper, we do not assume prior knowledge of amortized complexity as we explain the concepts and apply them in our first case study, a simple stack with multipop. Moving to more complicated (and useful) data structures, we show that the same technique works for binomial heaps which can be used to implement a priority queue. We also prove amortized complexity bounds for Claessen's version of the finger tree, a sequence-like data structure with constant-time cons/uncons on either end. Finally we discuss the current limitations of LiquidHaskell that made certain versions of the data structures not feasible.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
液体摊销:用 LiquidHaskell 证明摊销复杂性(功能珍珠)
关于算法和数据结构时间复杂性的正式推理通常在 Isabelle/HOL 等交互式定理证明器中完成。这包括对摊销时间复杂度的推理,摊销时间复杂度考察的是一系列操作中最差情况下的性能。然而,大多数程序并不是在定理证明器中编写的,因此使用的是生产语言的数据结构。为了验证正确性,有必要将生产语言的数据结构翻译成定理证明器的语言。这样的翻译步骤可能会引入错误,例如由于两种语言之间的特征不匹配造成的错误。我们展示了如何使用 LiquidHaskell 直接在 Haskell 中证明数据结构的摊销复杂性。除了跳过翻译步骤,我们的方法还具有教学优势:学习者不必为证明而学习额外的语言,可以只关注新概念。在本文中,我们并不假定学习者事先了解摊余复杂度的知识,因为我们会解释这些概念,并将其应用于第一个案例研究--一个简单的多幂堆栈。在转向更复杂(更有用)的数据结构时,我们证明了同样的技术适用于二叉堆,而二叉堆可用于实现优先级队列。我们还证明了克莱森版本的手指树的摊销复杂度边界,这是一种序列数据结构,其两端具有恒定时间的同意/不同意。最后,我们讨论了 LiquidHaskell 目前的局限性,这些局限性使得某些版本的数据结构不可行。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
New Direct Sum Tests Complexity and algorithms for Swap median and relation to other consensus problems Journalists, Emotions, and the Introduction of Generative AI Chatbots: A Large-Scale Analysis of Tweets Before and After the Launch of ChatGPT Almost-catalytic Computation Fast Simulation of Cellular Automata by Self-Composition
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1