Nothing Special   »   [go: up one dir, main page]

skip to main content
10.1145/568173.568177acmconferencesArticle/Chapter ViewAbstractPublication PagespepmConference Proceedingsconference-collections
Article

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

Published: 12 September 2002 Publication History

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.

References

[1]
Mads Sig Ager, Olivier Danvy, and Henning Korsholm Rohde. On obtaining Knuth, Morris, and Pratt's string matcher by partial evaluation. Technical Report BRICS RS-02-32, Department of Computer Science, University of Aarhus, Aarhus, Denmark, July 2002.
[2]
Torben Amtoft, Charles Consel, Olivier Danvy, and Karoline Malmkjaer. The abstraction and instantiation of string-matching programs. Technical Report BRICS RS-01-12, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Denmark, April 2001. To appear in Neil Jones's Festschrift.
[3]
Guntis J. Barzdins and Mikhail A. Bulyonkov. Mixed computation and translation: Linearisation and decomposition of compilers. Preprint 791, Computing Centre of Siberian Division of USSR Academy of Sciences, Novosibirsk, Siberia, 1988.
[4]
Anders Bondorf. Similix 5.1 manual. Technical report, DIKU, Computer Science Department, University of Copenhagen, Copenhagen, Denmark, May 1993. Included in the Similix 5.1 distribution.
[5]
Anders Bondorf and Olivier Danvy. Automatic autoprojection of recursive equations with global variables and abstract data types. Science of Computer Programming, 16:151--195, 1991.
[6]
Christian Charras and Thierry Lecroq. Exact string matching algorithms. http://www-igm.univ-mlv.fr/~lecroq/string/, 1997.
[7]
Sandrine Chirokoff, Charles Consel, and Renaud Marlet. Combining program and data specialization. Higher-Order and Symbolic Computation, 12(4):309--335, 1999.
[8]
Charles Consel and Olivier Danvy. Partial evaluation of pattern matching in strings. Information Processing Letters, 30(2):79--86, January 1989.
[9]
Olivier Danvy and Ulrik P. Schultz. Lambda-dropping: Transforming recursive equations into programs with block structure. Theoretical Computer Science, 248(1-2):243--287, 2000.
[10]
Yoshihiko Futamura, Zenjiro Konishi, and Robert Glück. Program transformation system based on generalized partial computation. New Generation Computing, 20(1):75--99, 2002.
[11]
Yoshihiko Futamura and Kenroku Nogi. Generalized partial computation. In Dines Bjorner, Andrei P. Ershov, and Neil D. Jones, editors, Partial Evaluation and Mixed Computation, pages 133--151. North-Holland, 1988.
[12]
Yoshihiko Futamura, Kenroku Nogi, and Akihiko Takano. Essence of generalized partial computation. Theoretical Computer Science, 90(1):61--79, 1991.
[13]
Robert Glück and Andrei Klimov. Occam's razor in metacomputation: the notion of a perfect process tree. In Patrick Cousot, Moreno Falaschi, Gilberto Filé, and Antoine Rauzy, editors, Proceedings of the Third International Workshop on Static Analysis WSA'93, number 724 in Lecture Notes in Computer Science, pages 112--123, Padova, Italy, September 1993. Springer-Verlag.
[14]
Bernd Grobauer and Julia L. Lawall. Partial evaluation of pattern matching in strings, revisited. Nordic Journal of Computing, 8(4):437--462, 2002.
[15]
Thomas Johnsson. Lambda lifting: Transforming programs to recursive equations. In Jean-Pierre Jouannaud, editor, Functional Programming Languages and Computer Architecture, number 201 in Lecture Notes in Computer Science, pages 190--203, Nancy, France, September 1985. Springer-Verlag.
[16]
Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. Partial Evaluation and Automatic Program Generation. Prentice-Hall International, London, UK, 1993. Available online at http://www.dina.kvl.dk/~sestoft/pebook/.
[17]
Richard Kelsey, William Clinger, and Jonathan Rees, editors. Revised 5 report on the algorithmic language Scheme. Higher-Order and Symbolic Computation, 11(1):7--105, 1998.
[18]
Todd B. Knoblock and Erik Ruf. Data specialization. In Proceedings of the ACM SIGPLAN'96 Conference on Programming Languages Design and Implementation, SIGPLAN Notices, Vol. 31, No 5, pages 215--225. ACM Press, June 1996.
[19]
Donald E. Knuth, James H. Morris, and Vaughan R. Pratt. Fast pattern matching in strings. SIAM Journal on Computing, 6(2):323--350, 1977.
[20]
Karoline Malmkjaer. Program and data specialization: Principles, applications, and self-application. Master's thesis, DIKU, Computer Science Department, University of Copenhagen, August 1989.
[21]
Karoline Malmkjaer. Abstract Interpretation of Partial-Evaluation Algorithms. PhD thesis, Department of Computing and Information Sciences, Kansas State University, Manhattan, Kansas, March 1993.
[22]
Torben Æ. Mogensen. Glossary for partial evaluation and related topics. Higher-Order and Symbolic Computation, 13(4):355--368, 2000.
[23]
Simon Peyton Jones and André Santos. A transformation-based optimiser for Haskell. Science of Computer Programming, 32(1-3):3--47, 1998.
[24]
Christian Queinnec and Jean-Marie Geffroy. Partial evaluation applied to pattern matching with intelligent backtrack. In Proceedings of the Second International Workshop on Static Analysis WSA'92, volume 81-82 of Bigre Journal, pages 109--117, Bordeaux, France, September 1992. IRISA, Rennes, France.
[25]
Donald A. Smith. Partial evaluation of pattern matching in constraint logic programming languages. In Paul Hudak and Neil D. Jones, editors, Proceedings of the ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation, SIGPLAN Notices, Vol. 26, No 9, pages 62--71, New Haven, Connecticut, June 1991. ACM Press.
[26]
Morten Heine Sorensen, Robert Glück, and Neil D. Jones. A positive supercompiler. Journal of Functional Programming, 6(6):811--838, 1996.

Cited By

View all

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image ACM Conferences
ASIA-PEPM '02: Proceedings of the ASIAN symposium on Partial evaluation and semantics-based program manipulation
September 2002
152 pages
ISBN:1581134584
DOI:10.1145/568173
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 12 September 2002

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Knuth-Morris-Pratt string matching
  2. data specialization
  3. program specialization
  4. trace semantics

Qualifiers

  • Article

Conference

ASIA-PEPM02
Sponsor:

Acceptance Rates

ASIA-PEPM '02 Paper Acceptance Rate 11 of 21 submissions, 52%;
Overall Acceptance Rate 11 of 21 submissions, 52%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)9
  • Downloads (Last 6 weeks)0
Reflects downloads up to 12 Nov 2024

Other Metrics

Citations

Cited By

View all
  • (2023)String Matching Algorithm Using Multi-Characters Inverted ListsWSEAS TRANSACTIONS ON COMPUTERS10.37394/23205.2023.22.1822(151-158)Online publication date: 3-Oct-2023
  • (2019)Cost-Augmented Partial Evaluation of Functional Logic ProgramsHigher-Order and Symbolic Computation10.1023/B:LISP.0000029447.02190.4217:1-2(7-46)Online publication date: 1-Jun-2019
  • (2013)BibliographyProgram Specialization10.1002/9781118576984.biblio(487-522)Online publication date: 5-Feb-2013
  • (2010)Inverted Lists String Matching AlgorithmsInternational Journal of Computer Theory and Engineering10.7763/IJCTE.2010.V2.166(352-357)Online publication date: 2010
  • (2009)Inverted lists string pattern matching2009 2nd IEEE International Conference on Computer Science and Information Technology10.1109/ICCSIT.2009.5234774(623-627)Online publication date: Aug-2009
  • (2006)Fast partial evaluation of pattern matching in stringsACM Transactions on Programming Languages and Systems (TOPLAS)10.1145/1146809.114681228:4(696-714)Online publication date: 1-Jul-2006
  • (2004)The Translation Power of the Futamura ProjectionsPerspectives of System Informatics10.1007/978-3-540-39866-0_16(133-147)Online publication date: 2004
  • (2003)Fast partial evaluation of pattern matching in stringsACM SIGPLAN Notices10.1145/966049.77739038:10(3-9)Online publication date: 7-Jun-2003
  • (2003)Fast partial evaluation of pattern matching in stringsProceedings of the 2003 ACM SIGPLAN workshop on Partial evaluation and semantics-based program manipulation10.1145/777388.777390(3-9)Online publication date: 7-Jun-2003
  • (2002)Automatic generation of efficient string matching algorithms by generalized partial computationProceedings of the ASIAN symposium on Partial evaluation and semantics-based program manipulation10.1145/568173.568174(1-8)Online publication date: 12-Sep-2002

View Options

Get Access

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media