## Logic Programming Engineering

### 1References

• Sterling, L.; Shapiro, E.: The Art of Prolog, MIT Press, 1994
• O´Keefe, R.A.: The Craft of Prolog, MIT Press, 1994
• Clocksin, W.F.; Mellish, C.S.: Programming in Prolog, Springer-Verlag, 1987
• Bratko, I.: Prolog Programming for Artificial Intelligence, Addison-Wesley, 1986
• Apt, K.R.: From Logic Programming to Prolog, Prentice Hall, 1997
• Weisweber, W.: Prolog - Logische Programmierung in der Praxis, International Thomson Publishing, 1997
• Endriss, Ulle: An Introduction to Prolog Programming, 2000
• Miller, D.: lambda-Prolog: An Introduction to the Language and its Logic, 1998

### 2News

Exam: 7 February 2012, starting at 10:00am, duration 120 min, room E5 (and E6 should E5 not be sufficient).

The course terminated on 26/1/2012. No lectures/tutorials will take place before the exam.

The sessions on 3/11 and 10/11 will take place regularly, and will be held by Peter and Amin

### 4Course Info

#### Lectures and topics

13.10.11—Lecture 1Introduction to the course, and pages 1--20 of the document with 100 slides).
Practical session 1, for which you need the file family.pl (or the .doc document)

• Before the next lecture, you are encouraged to complete the activities of the practical session on your own; you might need further Prolog constructs/operators to solve your problems such as disjunction in clauses or negation as failure. We will treat this in more detail in the future, and you can already read the relevant pages in the slide presentation, pp 55-63. Try the different effects of using \==,\+, with ground and with non-ground queries. What do you observe?

20.10.11—Lecture 2(Please refer to the document with 100 slides). Prolog terms (pp 19--23); List processing, some built-in primitives, type checking, comparing terms arithmetics (pp 40--51); Disjunction, Negation (pp 56--63).
Practical session 2, for which you need the file lfamily.pl.

27.10.11—Lecture 3(Please refer to the document with 100 slides). Non-determinism and efficiency (pp 31--36. ) This practical session will focus on list processing and recursion, already presented last time: you find these in pages 40--43.
Practical session 3.

03.11.11—Lecture 4This practical session will focus on list and string processing, recursion, I/O. You may want to consult the SWI manual for built-in I/O commands (write, writeln, ln); strings are represented between double quotes. Recall the built-ins for comparing arithmetic expressions (=:=, == ,\==, is), negation as failure (\+), and the predicate 'fail'. Concatenation of atomic strings is obtained by the built-in atom_concat(_,_,_). Save your program for the exercise 4.3, you will need it for the practical session 5.
Practical session 4.

10.11.11—Lecture 5This practical session will focus on list and string processing, recursion, I/O, being a continuation of the previous one.
Practical session 5.

17.11.11—Lecture 6This practical session will focus on list processing and backtracking. You might need to use some predicates you have already implemented to solve past exercises (and you are encouraged to use your versions!). Yet, should you be running out of time, and not have yours, here are some auxiliary predicates you might need for this session. Please keep in mind that it is a good idea to store somewhere all your solutions in an incremental file, for your reference.
Practical session 6.

24.11.11—Lecture 7This practical session will focus on backtracking, and is easier than the past one. Built-ins you might need are negation as failure (\+), test for unification (=), and test among arithmetic expressions. Please keep in mind that it is a good idea to store somewhere all your solutions in an incremental file, for your reference.
Practical session 7.

1.12.11—Lecture 8This practical session will focus on backtracking, breadth-first search, use of cut, aggregation. We will introduce now the cut (!), the existence operator (^), the built-ins for aggregation (setof, bagof, findall). In addition to referring to the SWI manual, you may find here some useful documentation on aggregation and examples (so, we are definitely leaving the realm of "pure Prolog").
You will need some auxiliary predicates for running this session:
1) lfamily.pl already used for the practical sessions 1 and 2;
2) the predicate bf.pl that implements breadth-first search;
3) the solution to the exercise 7.3 (if you don't have it, here is flipcoin.pl and remember that it was using depth-first search!)
Practical session 8.

8.12.11—Lecture 9This practical session will focus on the use of cut, especially for optimisation. Continue working on the activities proposed for the session 8, if you have not completed them; then, proceed with the activities for today: you will need to work on a solution for the exercise 4.1. If you don't have it available, please try to implement it again.
Practical session 9.

15.12.11—Lecture 10This practical session will focus on the use of cut and its effects on backtracking. Moreover we will introduce some built-ins on terms (=.., atom, var, atomic, number, ground), commands for I/O (read, write), and the already used nl and fail. For all these Prolog primitives and commands, you may refer to the manual. Continue working on the activities proposed for the session 9, if you have not completed them yet; then proceed with the activities for today.
Practical session 10.

05.01.12—Lecture 11Since several students have not completed the previous assignments in past sessions, today we will not propose new activities and we will instead focus on competing the past assignments.

12.01.12—Lecture 12This practical session will focus on several built-ins for I/O, for memory management and for dynamic programming. The task is to build the code for a small game: the interface (in form of a menu) for the player needs to be developed, and we will need interaction with a database whose elements shall be read, maybe modified and stored. The database can dynamically grow.
The following built-ins (among others) might be used: you may need to read about them in the SWI-Prolog Manual:
get_single_char, put, name;
abolish
, exists_file, consult;
dynamic
, assert (and asserta and, dually, retract);
tell
, listing, told.
The activity is organised as follows:
1) Download and save the file guesword.pl, it provides an initial template you can modify and increment for the interface by implementing the tasks one at the time.
2) Some auxiliary simple databases you may use for your activity: words.pl, animals.pl, colors.pl
Practical session 11.

19.01.12—Lecture 13Today we continue working on the activities of the previous session.

26.01.12—Lecture 14Today we have completed working on the activity initiated on 12/01. The course is now over.

### 5 Material covered and to be prepared for the exam

• In principle, all what has been covered and is listed in Lectures and topics.
• Modality of exam: written examination. All written materials are allowed, no electronic devices. Id card and TUD registration card are necessary.
• Exam: 7 February 2012, starting at 10:00am, duration 120 min, room E5 (and E6 should E5 not be sufficient).

### 6Tutors and Office Hours

Tutors in the lab will be Peter Steinke and Amin Timany. The Open house slot is a good venue for discussing your questions, and hopefully I can answer them. Otherwise just drop me an email and we'll arrange for an appointment.

27.01.12Paola Bruscoliemail (replace AT by @)