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 Prolog. 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 whether % bob likes salad by typing at the query prompt. likes(bob, salad). % Prolog will respond with yes or no. % You can ask what bob eats by typing eats(bob, X). %The system will respond with X = steak %If you now type a semi-colon, you get the next binding. In this case: X = nachos %If you type a period, the search ends. %If prolog gets into a loop, you can type ctl-c to get out of it. Here are some Prolog operators: OR ; AND , NOT EQUAL \== %You can have complex queries using these operators. For example: eats(bob,X) , eats(alice, X). % will show all the foods that bob eats and alice eats. 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. 4) The Assignment - You are to create a prolog knowledge base called politics.pro. It is based on the diagrams in the GovtPictures.zip file stored on the class website. You are to design some "interesting" implications and some "interesting" queries. What does "interesting" mean or look like? We'll discuss it in class. Certainly you should start like this: - Get some basic government types and properties designed. - Build the simple rules that define the taxonomy. - Build the simple rules that define the domain and ranges of the properties. - Do some simple retrievals to make sure what you have works. - Add more complexity by adding some new rules that lead to inferences. For example, try to define FreeSociety(x) where x is a state.