Prolog Assignment for csci271 1) Setting up Prolog USC has a Prolog system installed on the UNIX servers, but by default it isn't incorporated into your environment. In order to be able to use Prolog, add the following three lines to .login in your home directory: if (-f /usr/usc/qprolog/default/setup.csh) then source /usr/usc/qprolog/default/setup.csh endif To do that, just log in and use your preferred text editor to open the file called .login, then type or copy-and-paste the above lines at the bottom of the file. Then log out and log back in. You should now be able to start the Prolog system. To execute the Prolog interpreter, type 'prolog' at the command prompt. You'll see something like: * Could not write users file * Permission error: cannot write file '/usr/usc/qprolog/3.3/license3.3/users.qof' * O/S error : Read-only file system Quintus Prolog Release 3.3 (Sun 4, SunOS 5.5.1) Originally developed by Quintus Corporation, USA. Copyright (C) 1996, AI International Ltd. All rights reserved. Castle Chambers, High Street, Berkhamsted, Herts, UK. +44 (0)1442 873873 Email: support@aiil.co.uk WWW: http://www.aiil.co.uk Licensed to University of Southern California, Information Services Division | ?- If you do see a chunk of text like the above, the Prolog system is ready for you to use. Don't worry about those errors. After you've created a Prolog knowledge base, you can load it by starting up Prolog and then typing: consult('example.pro'). where example.pro is the name of the file containing your knowledge base. You'll then be able to query it and test that it is valid. To get out of Prolog, type 'halt.' (without the quotes) and hit enter. 2) Prolog example - the below text is a simple but complete example prolog knowledge base. Lines beginning with % are comments. % This is how to define an implication. In english, this means "If X % likes Y and X is hungry, X eats Y. eats(X, Y) :- likes(X, Y), hungry(X). % And here we're telling Prolog some facts. Alice likes % hamburgers, Bob is hungry, et cetera. likes(alice, hamburger). likes(alice, salad). likes(bob, steak). likes(bob, nachos). hungry(bob). % To load this knowledge base into prolog, type % consult('example.pro'). % Once the knowledge base is loaded, you can ask it an whether % bob likes salad by typing % likes(bob, salad). % at the query prompt. You can ask what bob east by typing % eats(bob, X). Here are some Prolog operators: OR ; AND , NOT EQUAL \== You can do output by using the write and nl statements. For example: writeXY(X, Y) :- write('X is '), write(X), write(' and Y is '), write(Y), nl. If you define a predicate multiple times, for example: eats(X, Y) :- likes(X, Y), hungry(X). eats(X, Y) :- edible(Y), starving(X). then the bodies are ORed together. For example, the above is equivalent to: eats(X, Y) :- (likes(X, Y), hungry(X)); (edible(Y), starving(X)). Multiple definitions are the preferred way of representing OR in Prolog. 3) The Assignment - All the text below should be cut and pasted into a file called hw2prolog.pro. Follow the directions and include any queries you have designed. We will give you directions later for submitting the file to us. % Fill in the bodies of the following eleven predicates so that they % correctly encode the relationships between the people described in % the fact section. % Show that using your rules, you can infer that salvador, % sally and francis are beth's cousins, and that beth and bob are % one-another's brother and sister. Create some queries that test % every predicate. % Challenge: create a relative(X, Y) predicate which is able to % correctly determine whether two people are related, and do it in % such a way that you can use the predicate to query the database for % all of a person's relatives (the query must terminate, rather than % return an infiite sequence of answers). mother(X, Y) :- father(X, Y) :- child(X, Y) :- daughter(X, Y) :- son(X, Y) :- sibling(X, Y) :- sister(X, Y) :- brother(X, Y) :- uncle(X, Y) :- aunt(X, Y) :- cousin(X, Y) :- % Fact section. Do not modify, add, or delete facts. Your assignment % is to complete the predicates so that they work with these facts. female(mary). female(jane). female(joan). female(beth). female(sally). female(francis). male(mark). male(mel). male(john). male(bob). male(salvador). parent(mary, jane). parent(mary, john). parent(mary, joan). parent(mark, jane). parent(mark, john). parent(mel, joan). parent(jane, beth). parent(jane, bob). parent(john, salvador). parent(john, sally). parent(joan, francis).