Download for FREE in 4 easy steps...
Users who viewed this item also viewed
About the book
The book Prolog Techniques is the first of two volumes by the author on the programming language Prolog and its applications; the second, forthcoming, textbook is entitled Applications of Prolog. In the first volume you can read about the accumulator technique, difference lists, program manipulations and exploratory code development.
Prolog is considered difficult by students. Usually, by the time they learn Prolog, which is most likely to happen in preparation for a course in Artificial Intelligence (AI) or Expert Systems, they will have studied imperative programming and/or the object oriented paradigm. Unfortunately, this prior experience is not always conducive to learning Prolog. Even though there is a good provision of traditional Prolog textbooks (for example ), students still find it hard to write solutions in Prolog to problems of any notable complexity. In my experience this holds also (and in particular) for problems for which Prolog should be the natural choice.
This book is intended to relieve the problem by providing a good collection of programming projects, case studies and exercises of various complexity. It will be useful for three kinds of students.
- Those whose prime source of information is a traditional introductory lecture course in Prolog. For these people my book will serve to show in context how the various programming techniques and language elements may be employed. The book may be used to accompany such a course as a workbook and the student should find in it a wealth of information to answer questions concerning the aspects of Prolog taught in the course.
- Those who want to refresh and extend their knowledge of Prolog, perhaps with some field of application in mind.
- Students of AI learning about search algorithms in particular. Most AI books present search algorithms by pseudocode and are not concerned with details of implementation. In my experience, however, anything seen implemented is more likely to be retained (beyond the exam).
There is a deeper reason also why such a book is felt timely. Programming is a creative activity and it is an innate human need to take pleasure (and pride) in the object of one’s creation, be it a sculpture, a painting, a piece of music, or indeed, a computer program. The opportunity is provided here for students to learn (and experience the said intellectual satisfaction) by creating their own solutions in Prolog to a host of interesting, challenging and varied programming problems. Many of the problems and the way they are approached here are believed to be novel.
Sadly, it is felt that the creative aspect of learning is not given enough room in today’s educational environment in the UK.1 It is hoped that this book will help the student to rediscover Prolog programming as a worthwhile and enjoyable activity.
The core of the material in this book grew out of laboratory classes and coursework prepared by the author for second year computer science students at Bradford University, as part of the lecture course Symbolic and Declarative Computing – Artificial Intelligence. This is a two-semester course with an introduction to Functional Programming with Haskell, Logic Programming with Prolog and the basics of AI. The choice of examples and topics for this book is of course tinged by the context in which Prolog was presented. For example, I discuss the functional programming style since it is useful in producing concise, readable and elegant implementations also in Prolog. The selection of topics for the examples was influenced in part by the AI element of the course though much new material has found its way into the book. To make set problems more easily accessible for the reader, I subdivide the overall task into managable portions indicating in each the desired outcome (if applicable, in form of a sample session in Prolog) with suggestions for how best to attack the subtasks.
The working style advocated here is best described by the following attributes:
- example based,
- exploratory and experimental,
- progressing from the specific to the more general,
- identifying patterns of computation with a view to generalization.
It will be seen from the list of contents that the material, by its very nature, is not ordered in a linear fashion but is grouped in topics deemed important for programming in Prolog.
The work comprises two parts: the present volume Prolog Techniques and the forthcoming Applications of Prolog. This first volume is in four chapters and illustrates special Prolog programming techniques. The second volume will concentrate on applications of Prolog, mainly from Artificial Intelligence.
The order in which the books may be studied is fairly free even though an example introduced somewhere may serve in a later chapter to illustrate the generalization or improvement afforded by the material just covered.
The SWI-Prolog compiler is used throughout: it has been around for quite some time; it is well documented; it is free; and, it is being maintained with new, improved versions becoming available all the time. Furthermore, there is an object oriented extension to SWI-Prolog (XPCE) for building graphical applications, useful if one wants to pursue this line further.
Solutions for a selection of exercises are discussed in the appendices. All Prolog source code produced in the course of this book project (including model solutions for all the exercises) can be downloaded from the Ventus website.
I am grateful to Dr. Coxhead of Birmingham University for discussions and extensive comments on initial versions of several of the chapters. My colleague Dr. Fretwell gave me many tips concerning LATEX, the typesetting system used to produce the books.
1 Accumulator Technique
1.1 A Simple Example
1.2 Hand Computations
1.3 Further Examples
1.6 Case Study: The Perceptron Training Algorithm
1.6.1 Classification Problem
2 Difference Lists
2.1 Implementations of List Concatenation
2.2 Implementations of List Flattening
2.2.1 Project: Lists as Trees & flatten/2
2.2.2 Flattening Lists by append/3
2.2.3 flatten/2 by the Difference List Technique
2.2.4 Comparing Different Versions
2.3 Implementations of List Reversal
2.3.1 Program Transformations
2.3.2 Difference Lists as Accumulators
2.4 Case Study: Dijkstra’s Dutch Flag Problem
2.4.1 Basic Implementation Using append/3
2.4.2 A More Concise Version
2.4.3 Using Difference Lists
2.5.1 Rotating a List
2.5.2 The Perceptron Training Algorithm Revisited
2.5.3 Planar Rotations
2.5.4 Application: The Gauss–Seidel Method
3 Program Manipulations
3.1 Simple Database Operations
3.1.1 Basic Database Manipulation
3.1.2 Changing the Database
3.1.3 File Modifications
3.1.4 Updating right_to/2 and people.pl
3.1.5 Automated Saving of Selected Predicates
3.1.6 Miniproject: Modelling a Stamp Collection
3.2 Case Study: Automated Unfolding
3.2.1 Elementary Unfolding
3.2.2 Complete One Step Unfolding
3.2.3 Rearranging Clauses
3.3 Dijkstra’s Dutch Flag Problem Revisited
3.3.1 Problem Generalization and First Solution
3.3.2 Enhanced Implementations
4 Exploratory Code Development
4.1 A Nursery Rhyme
4.1.1 First Preliminary Implementation
4.1.2 Another Preliminary Implementation
4.1.3 The Final Version
4.1.4 Other Approaches
4.2 Project: ’One Man Went to Mow ...’
4.3 Chapter Notes
A. Solutions of Selected Exercises
A.1 Chapter 1 Exercises
A.2 Chapter 2 Exercises
A.3 Chapter 3 Exercises
A.4 Chapter 4 Exercises
About the Author
The embed frame is free to use for private persons, universities and schools. It is not allowed to be used by any company for commercial purposes unless it is for media coverage. You may not modify, build upon, or block any portion or functionality of the embed frame, including but not limited to links back to the bookboon.com website.
The Embed frame may not be used as part of a commercial business offering. The embed frame is intended for private people who want to share eBooks on their website or blog, professors or teaching professionals who want to make an eBook available directly on their page, and media, journalists or bloggers who wants to discuss a given eBook
If you are in doubt about whether you can implement the embed frame, you are welcome to contact Thomas Buus Madsen on email@example.com and seek permission.