Prolog Tutorial

De Augusto Baffa Wiki
Ir para navegação Ir para pesquisar
Esta página é uma versão traduzida da página Prolog Tutorial. Sua tradução está 100% completa.
Outros idiomas:
English • ‎português do Brasil

This material was originally published by professor Dr. John R. Fisher, Ph.D., professor emeritus at California State Polytechnic University, Pomona, with its authorization granted on October 14, 2020. All content is being reviewed by Dr. Augusto Baffa, D.Sc., lecturer at Departamento de Informática at Pontifical Catholic University of Rio de Janeiro (PUC-Rio) which should also add new examples with connectors for Python programs.

See the table of contents for details.


Introduction

Prolog is a logical and a declarative programming language. The name itself, Prolog, is short for PROgramming in LOGic. Prolog's heritage includes the research on theorem provers and other automated deduction systems developed in the 1960s and 1970s. The inference mechanism of Prolog is based upon Robinson's resolution principle (1965)[1] together with mechanisms for extracting answers proposed by Green (1968)[2]. These ideas came together forcefully with the advent of linear resolution procedures. Explicit goal-directed linear resolution procedures, such as those of Kowalski e Kuehner (1971)[3] and Kowalski (1974)[4], gave impetus to the development of a general purpose logic programming system. The "first" Prolog was "Marseille Prolog" based on work by Colmerauer (1970). The first detailed description of the Prolog language was the manual for the Marseille Prolog interpreter (Roussel, 1975). The other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing.


Prolog is the major example of a fourth generation programming language supporting the declarative programming paradigm. The Japanese Fifth-Generation Computer Project, announced in 1981, adopted Prolog as a development language, and thereby focused considerable attention on the language and its capabilities. The programs in this tutorial are written in "standard" (University of) Edinburgh Prolog, as specified in the classic Prolog textbook by authors Clocksin e Mellish (1981, 1992)[5]. The other major kind of Prolog is the PrologII family of Prologs which are the descendants of Marseille Prolog. The reference to Giannesini, et.al. (1986)[6] uses a version of PrologII. There are differences between these two varieties of Prolog; part of the difference is syntax, and part is semantics. However, students who learn either kind of Prolog can easily adapt to the other kind.


This tutorial is intended to be used to help learn the essential, basic concepts of Prolog. The sample programs have been especially chosen to help promote the use of Prolog programming in an artificial intelligence course. Lisp and Prolog are the most frequently used symbolic programming languages for artificial intelligence. They are widely regarded as excellent languages for "exploratory" and "prototype programming".

Chapters

For a complete view of all content, see the table of contents.

  • Chapter 1 explains the Prolog programming environment for the beginner.
  • Chapter 2 explains Prolog syntax and many essentials of Prolog programming through the use of carefully chosen sample programs. The sample programs are arranged to guide the student through the development of Prolog programs that are constructed in a top-down, declarative fashion. Care has been taken to cover Prolog programming techniques that are very useful in an artificial intelligence course. In fact, this primer can serve as a convenient, small, concise Prolog introduction for such a course. Semantic issues have been addressed by introducing early the concept of a program clause tree that is used to define in an abstract way what are supposed to be the consequences of a Prolog program specification. The author believes this to be a viable way to promote the basic semantic issues of software verification for Prolog programming. The last section of this chapter introduces an example that shows that Prolog can be effectively used to give careful, precise specifications of systems, contrary to its usual reputation as being hard to document because it is easy to use as an exploratory programming tool.
  • Chapter 3 explains the operation of the underlying inference engine of Prolog. Chapter 3 should be first read after the student has studied two or three of the sample programs in Chapter 2. The last section in this chapter introduces Prolog meta-interpreters.
  • Chapter 4 gives an outlined view of the major built-in predicates of Prolog, many of which are exemplified in Chapter 2.
  • Chapter 5 gives an outline for developing A* search programs in prolog. Section 5.3 has an αβ search program for the game of tic tac toe.
  • Chapter 6 presents a unique and extensive presentation of a logic meta-interpreter for normal logical rulebases. {Note 9/4/2006: I have edited this chapter heavily, and the section links are all new.}
  • Chapter 7 gives an introduction to Prolog's built-in grammar parser generator, and a brief overview of how Prolog can be used to parse English (natural language) sentences. Also, there is a section covering the construction of simple idiomatic natural language interfaces to programs.
  • Chapter 8 shows how to implement varios prolog prototypes. A new section (§8.4) develops an interactive connection between prolog (inference engine) and Java (GUI) to play tic tac toe. The simple connection model is quite widely adaptable and applicable.


Final Author's Notes

Earlier versions of portions of this tutorial date back to 1988. The introductory material was originally used to help explain a Prolog interpreter developed by the author (no longer available) for use in his courses. The author believes that the introductory material, gathered together in the form given here might be very useful for the student who wants a quick, but well-tailored, introduction to Prolog

For fuller treatments of Prolog the student is advised to see the textbooks by Clocksin e Mellish (1981,1992)[5], by O'Keefe (1990)[7], by Clocksin (1997[8], 2003[9]), or by Sterling e Shapiro (1986)[10].

For excellent historical notes regarding Prolog and natural language processing using Prolog the text by Pereira e Shieber (1987)[11] is recommended.


Professor J.R. Fisher

Pomona, California

1988-2019


References

  • A Prolog Compendium (pdf) by Marc Bezem:This is an excellent conceptual overview of the Prolog suitable for the logical programming component of a Principles of Programming Languages course.

  1. Appel, K.R., and Haken, W., Every planar map is four colorable, Bull. Am. Math. Soc., vol. 82, pp. 711-712, 1976.
  2. Apt, K., and Etalle, S., On the Unification Free Prolog Programs, Computer Science/Department of Software Technology, Report CS-R9331, May 1993.
  3. Baader, and F., Snyder, W., Unification Theory, Chapter 8 of Handbook of Automated Reasoning, edited by Alan Robinson and Andrei Voronkov, Elsevier Science Publishers , 2001.
  4. Bratko, I., Prolog Programming for Artificial Intelligence, Addison-Wesley International Computer Science Series, 1986.
  5. Campbell, J.A., ed., Implementations of Prolog, Wiley, 1984.
  6. Chang, C., and Lee, R. C., Symbolic Logic and Mechanical Theorem Proving, Academic Press, 1973.
  7. Clocksin, W.F., and Mellish, C.S., Programming in Prolog, Springer-Verlag, 1981, 1992.
  8. Clocksin, W.F., Cause and Effect: Prolog programming for the working programmer, Springer-Verlag, 1997.
  9. Clocksin, W.F., Programming in Prolog: using the ISO standard , Springer-Verlag, 2003.
  10. Covington, M. A.,Nute, D., and Vellino, A. Prolog Programming in Depth, Scott, Foresman and Company, Glenview, IL, London, 1988.
  11. DeGroot, D., and Lindstrom, G., Logic Programming, Relations, and Equations, Prentice- Hall, 1986.
  12. Fisher, J.R., Semantic trees for disjunctive logic programs, Intelligent Systems, Proc. Third Golden West International Conference, ed. E.A. Yfantis, pp.291-305, Klewer Academic Publishers, 1995.
  13. Fisher, J.R., Logic program based action specifications, Proc. 1995 Symposium on Applied Computing (SAC'95), Nashville, Tenn., pp.248-52.
  14. Fisher, J.R., and Tran, L., A Visual Logic, Proc. 1996 Symposium on Applied Computing (SAC'96), Philadelphia, Pa., pp.17-21.
  15. Gazdar, G., and Mellish, C., Natural Language Processing in Prolog, Addison-Wesley, 1989.
  16. Giannesini, F, Kanoui, H, Pasero, R., and van Caneghem, M, Prolog, Addison-Wesley International Computer Science Series, 1986.
  17. Green, C., Theorem-proving by resolution as a basis for question-answering systems, in B. Meltzer and D. Michie, eds., Machine Intelligence 4, 183-205, Edinburgh University press, 1968.
  18. Kowalski, R.A., Logic for problem solving, DCL Memo 75, Department of Artificial Intelligence, University of Edinburgh, Scotland, 1974.
  19. Kowalski, R.A., Logic for Problem Solving, North Holland, 1979.
  20. Kowalski, R.A., and Kuehner, D., Linear Resolution with selection function, Artificial Intelligence, (2) 227-60, 1971.
  21. Lloyd, J.W., Foundations of Logic Programming, Springer-Verlag, 1984, 2nd ed. 1987.
  22. Nilsson, N., Principles of Artificial Intelligence, Tioga, 1980.
  23. O'Keefe, Richard A.,The Craft of Prolog, MIT Press, 1990.
  24. Pereira, Fernando C.N., and Shieber, Stuart M., Prolog and Natural-Language Analysis, CSLI, 1987.
  25. Robinson, J.A., A machine-oriented logic based on the resolution principle, Journal A.C.M., (12) 23-44, 1965.
  26. Rowe, W.C., AI Through Prolog, Prentice Hall, 1988.
  27. Shoham, Y., Artificial Intelligence Techniques in Prolog, Morgan Kaufmann Publishers, 1994.
  28. Sterling, Leon, and Shapiro, Ehud, The Art of Prolog, MIT Press, 1986.
  29. Van Le, T., Prolog Programming, Wiley, 1993.
  30. Winston, Patrick Henry, Artificial Intelligence, 2nd. ed., Addison-Wesley, 1984.
  31. Winston, P.H., and Horn, P., Lisp, Addison-Wesley, 1985.


See also


References

  1. Robinson, J.A., A machine-oriented logic based on the resolution principle, Journal A.C.M., (12) 23-44, 1965
  2. Green, C., Theorem-proving by resolution as a basis for question-answering systems, in B. Meltzer and D. Michie, eds., Machine Intelligence 4, 183-205, Edinburgh University press, 1968
  3. Kowalski, R.A., and Kuehner, D., Linear Resolution with selection function, Artificial Intelligence, (2) 227-60, 1971
  4. Kowalski, R.A., Logic for problem solving, DCL Memo 75, Department of Artificial Intelligence, University of Edinburgh, Scotland, 1974.
  5. 5,0 5,1 Clocksin, W.F., and Mellish, C.S., Programming in Prolog, Springer-Verlag, 1981, 1992.
  6. Giannesini, F, Kanoui, H, Pasero, R., and van Caneghem, M, Prolog, Addison-Wesley International Computer Science Series, 1986.
  7. O'Keefe, Richard A.,The Craft of Prolog, MIT Press, 1990.
  8. Clocksin, W.F., Cause and Effect: Prolog programming for the working programmer, Springer-Verlag, 1997
  9. Clocksin, W.F., Programming in Prolog: using the ISO standard , Springer-Verlag, 2003.
  10. Sterling, Leon, and Shapiro, Ehud, The Art of Prolog, MIT Press, 1986.
  11. Pereira, Fernando C.N., and Shieber, Stuart M., Prolog and Natural-Language Analysis, CSLI, 1987.