52 349 Logic Programming

Practical 1

  1. Enter Prolog, and consult one of the files in the royalty series referred to in the introductory practical notes; in particular, consult roy_sco. By use of appropriate variables, determine the facts hinted at in the introductory sheet , namely the birth and death dates of David II, King of Scots, and the details of his reign; when was the Battle of Bannockburn? Without getting carried away, what other simple facts can you extract? It may help you to know that kings are given in the form <name> <underscore> <number> and that the file employs Roman numbers for Scottish sovereigns and Arabic numbers for English ones.

  2. Now go on and consult the file /home/s3/paul/logic/query. This gives you access to three new predicates detail/1, detail/2 and detail/3. detail/2 and detail/3 are only successful if applied to integers - the components of dates - whereas detail/1 handles both numbers and atoms. Try them, on suitable data, but be warned that detail/1 and detail/3 will only give a non-empty result for integers (years) in the approximate range 800 - 1996; the reason should, by now, be fairly obvious! What (if anything) happened in previous years on your birthday?

    If you get a disappointingly empty result, consult also the file /home/s3/paul/logic/match. Then give the goal about(Day,Month,7) to find out what happened within a week of your chosen date.

    Subsequently, perhaps next week, you should give some thought (no cheating!) to how these predicates might be working.

  3. Before you leave Prolog, you may like to consult the additional files r_trees and explain from /home/s3/paul/logic. Subsequently satisfying the goal explain will give you some clue as to what else becomes available.

  4. Now exit from Prolog and construct predicates to query a family database such as royalty, but using it first on a simple family you know about! Define child/2, son/2, daughter/2 (e.g A is the daughter of B) and so on. Extend your work to siblings, grandparents and other (fairly close) relatives; how about ancestors?

    Remember that ultimately (for Practical 2) you will need either to have written your code in terms of parent/3 or else to provide a conversion predicate which relates parent/2 (as considered in the recommended text) to parent/3.

  5. You should also try trace/0. Later in the class, experiment with the various built in goals of input and output procedures, once they have been discussed in the lectures. But work through one stage at a time, doing the basic exercises first then adding sophistication.

© Paul Goldfinch 1996 Return to 52 349 Menu