Abstract
We show how to obtain all of Knuth, Morris, and Pratt's linear-time string matcher by specializing a quadratic-time string matcher with respect to a pattern string. Although it has been known for fifteen years how to obtain this linear matcher by partial evaluation of a quadratic one, how to obtain it in linear time has remained an open problem.Obtaining a linear matcher by the partial evaluation of a quadratic one is achieved by performing its backtracking at specialization time and memoizing its results. We show (1) how to rewrite the source matcher such that its static intermediate computations can be shared at specialization time and (2) how to extend the memoization capabilities of a partial evaluator to static functions. Such an extended partial evaluator, if its memoization is implemented efficiently, specializes the rewritten source matcher in linear time. Finally, we show that the method also applies to a variant of Boyer and Moore's string matcher.
- Ager, M. S., Danvy, O., and Rohde, H. K. 2002. On obtaining Knuth, Morris, and Pratt's string matcher by partial evaluation. In Proceedings of the ACM SIGPLAN Asian Symposium on Partial Evaluation and Semantics-Based Program Manipulation (W. N. Chin Ed.), 32--46. Extended version available as Tech. rep. BRICS-RS-02-32.]] Google Scholar
Digital Library
- Aho, A. V., Hopcroft, J. E., and Ullman, J. D. 1974. The Design and Analysis of Computer Algorithms. Addison Wesley, Reading, Mass.]] Google Scholar
Digital Library
- Alpuente, M., Falaschi, M., Juliàn, P., and Vidal, G. 1997. Specialization of inductively sequential functional logic programs. In Proceedings of the ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation, C. Consel, ed. 151--162.]] Google Scholar
Digital Library
- Amtoft, T. 1993. Sharing of computations. Ph.D. thesis, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Denmark. Tech. rep. PB-453.]]Google Scholar
- Amtoft, T., Consel, C., Danvy, O., and Malmkjær, K. 2002. The abstraction and instantiation of string-matching programs. In The Essence of Computation: Complexity, Analysis, Transformation. Essays Dedicated to Neil D. Jones, T. æ. Mogensen et al., eds. LNCS vol. 2566, Springer 332--357.]] Google Scholar
Digital Library
- Bellman, R. 1957. Dynamic Programming. Princeton University Press, Princeton, N. J.]] Google Scholar
Digital Library
- Bird, R. S. 1977. Improving programs by the introduction of recursion. Commun. ACM 20, 11 (Nov.), 856--863.]] Google Scholar
Digital Library
- Bondorf, A. and Danvy, O. 1991. Automatic autoprojection of recursive equations with global variables and abstract data types. Sci. Compu. Program. 16, 151--195.]] Google Scholar
Digital Library
- Boyer, R. S. and Moore, J. S. 1977. A fast string searching algorithm. Commun. ACM 20, 10, 762--772.]] Google Scholar
Digital Library
- Bulyonkov, M. A. 1984. Polyvariant mixed computation for analyzer programs. Acta Informatica 21, 473--484.]]Google Scholar
Digital Library
- Charras, C. and Lecroq, T. 1997. Exact string matching algorithms. http://www-igm.univ-mlv.fr/~lecroq/string/.]] Google Scholar
Digital Library
- Chen, W. and Warren, D. S. 1996. Tabled evaluation with delaying for general logic programs. J. ACM 43, 1 (Jan.), 20--74.]] Google Scholar
Digital Library
- Chin, W.-N., ed. 2002. ACM SIGPLAN Asian Symposium on Partial Evaluation and Semantics-Based Program Manipulation.]]Google Scholar
- Colussi, L. 1991. Correctness and efficiency of pattern matching algorithms. Inf. Comput. 95, 225--251.]] Google Scholar
Digital Library
- Consel, C. and Danvy, O. 1989. Partial evaluation of pattern matching in strings. Inf. Process. Lett. 30, 2 (Jan.), 79--86.]] Google Scholar
Digital Library
- Consel, C. and Danvy, O. 1993. Tutorial notes on partial evaluation. In Proceedings of the 20th Annual ACM Symposium on Principles of Programming Languages, S. L. Graham, ed. 493--501.]] Google Scholar
Digital Library
- Dijkstra, E. W. 1976. A Discipline of Programming. Prentice-Hall, Upper Saddle River, N.J.]] Google Scholar
Digital Library
- Futamura, Y., Konishi, Z., and Glück, R. 2002a. Automatic generation of efficient string matching algorithms by generalized partial computation. In Proceedings of the ACM SIGPLAN Asian Symposium on Partial Evaluation and Semantics-Based Program Manipulation (W. N. Chin Ed.) 1--8.]] Google Scholar
Digital Library
- Futamura, Y., Konishi, Z., and Glück, R. 2002b. Program transformation system based on generalized partial computation. New Gen. Comput. 20, 1, 75--99.]] Google Scholar
Digital Library
- Futamura, Y. and Nogi, K. 1988. Generalized partial computation. In Partial Evaluation and Mixed Computation, D. Bjørner et al. eds. North-Holland, Amsterdam, the Netherlands, 133--151.]]Google Scholar
- Glück, R. and Jørgensen, J. 1994. Generating optimizing specializers. In Proceedings of the 5th IEEE International Conference on Computer Languages, H. Bal, ed. 183--194.]]Google Scholar
- Glück, R. and Klimov, A. 1993. Occam's razor in metacomputation: The notion of a perfect process tree. In Proceedings of the 3th International Workshop on Static Analysis WSA'93, P. Cousot et al., eds. LNCS vol. 724 Springer, Berlin, 112--123.]] Google Scholar
Digital Library
- Grobauer, B. and Lawall, J. L. 2002. Partial evaluation of pattern matching in strings, revisited. Nordic J. Comput. 8, 4, 437--462.]] Google Scholar
Digital Library
- Hernández, M. and Rosenblueth, D. A. 2003. Disjunctive partial deduction of a right-to-left string-matching algorithm. Inf. Process. Lett. 87, 235--241.]] Google Scholar
Digital Library
- Hernández, M. and Rosenblueth, D. A. 2001. Development reuse and the logic program derivation of two string-matching algorithms. In Proceedings of the 3rd International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (PPDP'01), H. Søndergaard, ed. 38--48.]] Google Scholar
Digital Library
- Holst, C. K. and Gomard, C. K. 1991. Partial evaluation is fuller laziness. In Proceedings of the ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation. SIGPLAN Notices (N. Jones and P. Hudak Eds.), vol. 26, 9, 223--233.]] Google Scholar
Digital Library
- Hudak, P. and Jones, N. D., eds. 1991. ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation. SIGPLAN Notices, vol. 26, no 9.]]Google Scholar
- Jones, N. D., Gomard, C. K., and Sestoft, P. 1993. Partial Evaluation and Automatic Program Generation. Prentice-Hall, UK. http://www.dina.kvl.dk/sestoft/pebook/.]] Google Scholar
Digital Library
- Kaneko, K. and Takeichi, M. 1993. Derivation of a Knuth-Morris-Pratt algorithm by fully lazy partial computation. Adv. Softw. Sci. Technol. 5, 11--24.]]Google Scholar
Cross Ref
- Kelsey, R., Clinger, W., and Rees, J. 1998. Revised5 report on the algorithmic language scheme. Higher-Order Symbol. Comput. 11, 1, 7--105.]] Google Scholar
Digital Library
- Knuth, D. E., Morris, J. H., and Pratt, V. R. 1977. Fast pattern matching in strings. SIAM J. Comput. 6, 2, 323--350.]]Google Scholar
Digital Library
- Lafave, L. and Gallagher, J. P. 1997. Constraint-Based partial evaluation of rewriting-based functional logic programs. In Proceeding of the 7th International Workshop on Program Synthesis and Transformation, N. E. Fuchs, ed. LNCS vol. 1463. Springer, Berlin, 168--188.]]Google Scholar
- Mogensen, T. A. 1989. Binding time aspects of partial evaluation. Ph.D. thesis, DIKU, Computer Science Department, University of Copenhagen, Copenhagen, Denmark.]]Google Scholar
- Mogensen, T. A. 2000. Glossary for partial evaluation and related topics. Higher-Order Symbol. Comput. 13, 4, 355--368.]] Google Scholar
Digital Library
- Queinnec, C. and Geffroy, J.-M. 1992. Partial evaluation applied to pattern matching with intelligent backtrack. In Proceedings of the 2nd International Workshop on Static Analysis WSA'92. Bigre J. vol. 81-82, 109--117.]]Google Scholar
- Sagonas, K., Swift, T., and Warren, D. S. 1994. XSB as an efficient deductive database engine. In Proceedings of the ACM SIGMOD International Conference on the Management of Data. 442--453.]] Google Scholar
Digital Library
- Secher, J. P. 2002. Driving-Based program transformation in theory and practice. Ph.D. thesis, DIKU, Computer Science Department, University of Copenhagen, Copenhagen, Denmark. DIKU Rapport D-486.]]Google Scholar
- Smith, D. A. 1991. Partial evaluation of pattern matching in constraint logic programming languages. In Proceedings of the ACM SIGPLAN Asian Symposium on Partial Evaluation and Semantics-Based Program Manipulation (N. Jones and P. Hudak Eds.) 62--71.]] Google Scholar
Digital Library
- Sørensen, M. H. 1994. Turchin's supercompiler revisited. An operational theory of positive information propagation. M.S. thesis, DIKU, Computer Science Department, University of Copenhagen Copenhogen, Denmark. DIKU Rapport 94/17.]]Google Scholar
- Sørensen, M. H., Glück, R., and Jones, N. D. 1996. A positive supercompiler. J. Functional Program. 6, 6, 811--838.]]Google Scholar
Cross Ref
- Takeichi, M. and Akama, Y. 1990. Deriving a functional Knuth-Morris-Pratt algorithm. J. Inf. Process. 13, 4, 522--528.]] Google Scholar
Digital Library
Index Terms
Fast partial evaluation of pattern matching in strings
Recommendations
Fast partial evaluation of pattern matching in strings
Proceedings of the ACM SIGPLAN symposium on principles and practice of parallel programming (PPoPP 2003) and workshop on partial evaluation and semantics-based program manipulation (PEPM 2003)We show how to obtain all of Knuth, Morris, and Pratt's linear-time string matcher by partial evaluation of a quadratic-time string matcher with respect to a pattern string. Although it has been known for 15 years how to obtain this linear matcher by ...
Fast partial evaluation of pattern matching in strings
PEPM '03: Proceedings of the 2003 ACM SIGPLAN workshop on Partial evaluation and semantics-based program manipulationWe show how to obtain all of Knuth, Morris, and Pratt's linear-time string matcher by partial evaluation of a quadratic-time string matcher with respect to a pattern string. Although it has been known for 15 years how to obtain this linear matcher by ...
Partial evaluation of pattern matching in strings, revisited
Specialization of a string matcher is a canonical example of partial evaluation. A naive implementation of a string matcher repeatedly matches a pattern against every substring of the data string; this operation should intuitively benefit from ...






Comments