On obtaining Knuth, Morris, and Pratt's string matcher by partial evaluation

M. Ager, O. Danvy, H. Rohde
{"title":"On obtaining Knuth, Morris, and Pratt's string matcher by partial evaluation","authors":"M. Ager, O. Danvy, H. Rohde","doi":"10.1145/568173.568177","DOIUrl":null,"url":null,"abstract":"We present the first formal proof that partial evaluation of a quadratic string matcher can yield the precise behaviour of Knuth, Morris, and Pratt's linear string matcher.Obtaining a KMP-like string matcher is a canonical example of partial evaluation: starting from the naive, quadratic program checking whether a pattern occurs in a text, one ensures that backtracking can be performed at partial-evaluation time (a binding-time shift that yields a staged string matcher); specializing the resulting staged program yields residual programs that do not back up on the text, a la KMP. We are not aware, however, of any formal proof that partial evaluation of a staged string matcher precisely yields the KMP string matcher, or in fact any other specific string matcher.In this article, we present a staged string matcher and we formally prove that it performs the same sequence of comparisons between pattern and text as the KMP string matcher. To this end, we operationally specify each of the programming languages in which the matchers are written, and we formalize each sequence of comparisons with a trace semantics. We also state the (mild) conditions under which specializing the staged string matcher with respect to a pattern string provably yields a specialized string matcher whose size is proportional to the length of this pattern string and whose time complexity is proportional to the length of the text string. Finally, we show how tabulating one of the functions in this staged string matcher gives rise to the 'next' table of the original KMP algorithm.The method scales for obtaining other linear string matchers, be they known or new.","PeriodicalId":187828,"journal":{"name":"ASIA-PEPM '02","volume":"80 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2002-07-05","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"22","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"ASIA-PEPM '02","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/568173.568177","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 22

Abstract

We present the first formal proof that partial evaluation of a quadratic string matcher can yield the precise behaviour of Knuth, Morris, and Pratt's linear string matcher.Obtaining a KMP-like string matcher is a canonical example of partial evaluation: starting from the naive, quadratic program checking whether a pattern occurs in a text, one ensures that backtracking can be performed at partial-evaluation time (a binding-time shift that yields a staged string matcher); specializing the resulting staged program yields residual programs that do not back up on the text, a la KMP. We are not aware, however, of any formal proof that partial evaluation of a staged string matcher precisely yields the KMP string matcher, or in fact any other specific string matcher.In this article, we present a staged string matcher and we formally prove that it performs the same sequence of comparisons between pattern and text as the KMP string matcher. To this end, we operationally specify each of the programming languages in which the matchers are written, and we formalize each sequence of comparisons with a trace semantics. We also state the (mild) conditions under which specializing the staged string matcher with respect to a pattern string provably yields a specialized string matcher whose size is proportional to the length of this pattern string and whose time complexity is proportional to the length of the text string. Finally, we show how tabulating one of the functions in this staged string matcher gives rise to the 'next' table of the original KMP algorithm.The method scales for obtaining other linear string matchers, be they known or new.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
用部分求值法求出Knuth, Morris,和Pratt的字符串匹配器
我们提出了第一个正式证明,二次型字符串匹配器的部分求值可以产生Knuth, Morris和Pratt的线性字符串匹配器的精确行为。获得一个类似于kmp的字符串匹配器是部分求值的一个典型例子:从简单的二次型程序开始检查一个模式是否出现在文本中,确保回溯可以在部分求值时执行(一个产生分段字符串匹配器的绑定时间偏移);专门化所产生的阶段程序会产生不备份文本的剩余程序,就像KMP一样。然而,我们不知道有任何正式的证据表明,对分段字符串匹配器的部分求值精确地产生KMP字符串匹配器,或者实际上产生任何其他特定的字符串匹配器。在本文中,我们提出了一个分阶段的字符串匹配器,并正式证明了它在模式和文本之间执行与KMP字符串匹配器相同的比较序列。为此,我们在操作上指定编写匹配器的每种编程语言,并使用跟踪语义形式化每个比较序列。我们还陈述了(温和的)条件,在这些条件下,针对模式字符串专门化阶段字符串匹配器可证明产生专门化字符串匹配器,其大小与该模式字符串的长度成正比,其时间复杂度与文本字符串的长度成正比。最后,我们将展示如何将这个分段字符串匹配器中的一个函数制表为原始KMP算法的“下一个”表。该方法适用于获得其他线性字符串匹配器,无论是已知的还是新的。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
Automatic generation of efficient string matching algorithms by generalized partial computation Using indexed data structures for program specialization Jones optimality, binding-time improvements, and the strength of program specializers Compiling real time functional reactive programming Defying the speed of light:: a spatially-aware compiler for wire-exposed architectures
×
引用
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