Skip to main content

2013 | Buch

Logic Programming with Prolog

insite
SUCHEN

Über dieses Buch

Logic Programming is the name given to a distinctive style of programming, very different from that of conventional programming languages such as C++ and Java. By far the most widely used Logic Programming language is Prolog. Prolog is a good choice for developing complex applications, especially in the field of Artificial Intelligence.

Logic Programming with Prolog does not assume that the reader is an experienced programmer or has a background in Mathematics, Logic or Artificial Intelligence. It starts from scratch and aims to arrive at the point where quite powerful programs can be written in the language. It is intended both as a textbook for an introductory course and as a self-study book. On completion readers will know enough to use Prolog in their own research or practical projects.

Each chapter has self-assessment exercises so that readers may check their own progress. A glossary of the technical terms used completes the book.

This second edition has been revised to be fully compatible with SWI-Prolog, a popular multi-platform public domain implementation of the language. Additional chapters have been added covering the use of Prolog to analyse English sentences and to illustrate how Prolog can be used to implement applications of an 'Artificial Intelligence' kind.

Max Bramer is Emeritus Professor of Information Technology at the University of Portsmouth, England. He has taught Prolog to undergraduate computer science students and used Prolog in his own work for many years.

Inhaltsverzeichnis

Frontmatter
Chapter 1. Getting Started
Abstract
This chapter shows how to write simple Prolog programs, load them into the Prolog database and enter goals that can be evaluated using them. It also introduces basic terminology and the different types of data object (terms).
After reading this chapter you should be able to:
  • Write and load a simple Prolog program
  • Enter goals at the Prolog system prompt
  • Understand the basic terminology of the Prolog language
  • Distinguish between different types of term (data objects)
Max Bramer
Chapter 2. Clauses and Predicates
Abstract
This chapter introduces the two types of Prolog clause, namely facts and rules and their components. It also introduces the concept of a predicate and describes different features of variables.
After reading this chapter you should be able to:
  • Identify the components of rules and facts
  • Explain the meaning of the term predicate
  • Make correct use of variables in goals and clauses
Max Bramer
Chapter 3. Satisfying Goals
Abstract
This chapter demonstrates how Prolog uses unification to match goals with the heads of clauses and how it uses the combination of unification and backtracking to evaluate goals entered by the user and to find multiple solutions if required. The chapter ends with a warning about the use of ’user-controlled’ backtracking.
After reading this chapter you should be able to:
  • Determine whether two call terms unify and thus whether a goal can be matched with a clause in the database
  • Understand how Prolog uses unification and backtracking to evaluate a sequence of goals entered by the user
Max Bramer
Chapter 4. Operators and Arithmetic
Abstract
This chapter introduces operator notation for predicates and describes the operators provided for evaluating and comparing the values of arithmetic expressions, for testing for equality of either arithmetic expressions or terms and for testing for the negation of a goal or the disjunction of two goals.
After reading this chapter you should be able to:
  • Convert unary and binary predicates to operators
  • Evaluate arithmetic expressions and compare their values
  • Test for equality of arithmetic expressions and terms
  • Use the ’not’ and disjunction operators
Max Bramer
Chapter 5. Input and Output
Abstract
Describes the principal built-in predicates available for both term by term and character by character input and output and for reading and writing files. Also introduces the notion of the ASCII value of a character.
After reading this chapter you should be able to:
  • Use the built-in predicates that read from and write to either the user’s terminal (keyboard and screen) or a file, both term by term and character-by-character in your own programs
  • Use ASCII values to manipulate strings of characters
Max Bramer
Chapter 6. Loops
Abstract
This chapter describes how a set of goals can be evaluated repeatedly in Prolog, either a fixed number of times or until a specified condition is met, and how multiple solutions can be arrived at using the technique of ’backtracking with failure’.
After reading this chapter you should be able to:
  • Define a predicate which causes a sequence of goals to be evaluated repeatedly, either a fixed number of times or until a specified condition is satisfied
  • Define a predicate which searches a database to find all the clauses with a specified property
Max Bramer
Chapter 7. Preventing Backtracking
Abstract
This chapter describes how the ‘cut’ predicate can be used to prevent undesirable backtracking and how ‘cut’ can be used in conjunction with the ‘fail’ predicate to specify exceptions to general rules.
After reading this chapter you should be able to:
  • Use the cut predicate to prevent unwanted backtracking
  • Use ‘cut with failure’ to specify exceptions to general rules
Max Bramer
Chapter 8. Changing the Prolog Database
Abstract
This chapter describes the built-in predicates for adding clauses to or deleting clauses from the Prolog database and shows how to use them to create and maintain a database of related facts within the overall Prolog database.
After reading this chapter you should be able to:
  • Define a predicate which causes one or more clauses to be added to or deleted from the Prolog database
  • Define predicates to create and manipulate a database of related facts within the Prolog database
Max Bramer
Chapter 9. List Processing
Abstract
This chapter describes a flexible type of data object called a list. It shows how to work through a list element by element from left to right using recursion to perform the same or a similar operation on each element, how to manipulate lists using built-in predicates and how to create a list containing all the possible values that would satisfy a specified goal.
After reading this chapter you should be able to:
  • Represent data in the form of lists
  • Use built-in predicates to manipulate lists
  • Define predicates to work through a list element by element from left to right using recursion
Max Bramer
Chapter 10. String Processing
Abstract
This chapter describes the principal techniques of string processing in Prolog, based on converting from atoms to lists and vice versa. The techniques are illustrated with examples of user-defined predicates to meet common string processing requirements.
After reading this chapter you should be able to:
  • Use a built-in predicate to convert strings of characters to lists and vice versa
  • Define predicates for the most common types of string processing
Max Bramer
Chapter 11. More Advanced Features
Abstract
This chapter describes some of the more advanced features provided by Prolog: the use of operators to extend the language (e.g. to provide new arithmetic operators, improved facilities for processing strings or facilities for processing sets) and facilities for processing terms, including finding their functors and arities, extracting a specified argument of a term, converting terms to lists or evaluating terms as goals. A user-defined predicate to unify two compound terms is given.
After reading this chapter you should be able to:
  • Define operators to extend the basic Prolog language
  • Define basic operations on sets as well as numbers and strings
  • Use built-in predicates to manipulate terms
Max Bramer
Chapter 12. Using Grammar Rules to Analyse English Sentences
Abstract
This chapter describes the use of the special syntax provided in Prolog for analyzing grammar rules: the operator -->/2, the predicate phrase/2 and braces to enclose ’regular’ Prolog used in conjunction with grammar rules. A simple grammar able to deal with basic sentences is defined. Predicates are given to enable the validity of sentences presented as lists of words to be established and to extract important information such as the type of each noun_phrase from valid sentences. Finally, predicates are defined to convert sentences in standard English into the ’list of words’ form required by the grammar rules.
After reading this chapter you should be able to:
  • Understand and use the special syntax provided in Prolog for analyzing grammar rules.
  • Define a simple grammar able to deal with basic sentences of English.
  • Define predicates to enable the validity of sentences presented as lists of words to be established and to extract important information such as the type of each noun phrase from valid sentences.
  • Define predicates to convert sentences in standard English into the ’list of words’ form required by Prolog grammar rules
Max Bramer
Chapter 13. Prolog in Action
Abstract
This chapter illustrates how Prolog can be used to develop applications of an ’Artificial Intelligence’ kind. It is shown how to implement (1) an artificial language to control the movements of an imaginary robot and (2) a shell program that can be used to construct a series of similar applications, in this case multiple-choice tests or quizzes.
After reading this chapter you should be able to:
  • Implement an artificial language of your own devising, using the techniques described elsewhere in this book. This will be illustrated by a simple language to control the movements of an imaginary robot
  • Implement a shell program, which can be used to construct a series of similar applications (the example used is a series of multiple-choice tests or quizzes). There are two phases to the implementation: the setup phase, during which the ’content’ of the application is read in from a data file and converted into facts placed in the Prolog database, and the execution phase where a dialogue with the user is automatically generated
Max Bramer
Backmatter
Metadaten
Titel
Logic Programming with Prolog
verfasst von
Max Bramer
Copyright-Jahr
2013
Verlag
Springer London
Electronic ISBN
978-1-4471-5487-7
Print ISBN
978-1-4471-5486-0
DOI
https://doi.org/10.1007/978-1-4471-5487-7