CSCI 301 Program 1, Spring 2018
You are going to be using Prolog to encode the Simpsons family tree.
The relationships that you will be encoding can be found: simpsons_graph.pdf.
You can find a sample Prolog file here to get you started.
I also want you to encode the relationships for father and mother as described in class.
- A father of a child is both a parent of that child and is a male.
- A mother of a child is both a parent of that child and a female.
Prolog should now be available on all of the G1 lab machines. In order to invoke Prolog go to Start>Swi-Prolog and click the red owl. This will bring up the Prolog interpreter. To load the sample file first download it to your account. You can view the file in the built in editor by going to File> Edit. You can consult the file by going to File>Consult. Once you consult the file you can issue queries about the relationships encoded (not many) with a Query: male(homer_simpson).
In Prolog there are two types of queries:
In the event of a query with one or more variables, multiple possible answers may exist. If you hit enter (or return) you tell the system that you are satisfied with the first answer. If you hit the ; (semi-colon) you are asking the system for any additional values for the query (try both with your own code to verify that it is working correctly).
- Queries involving literal values. E.g.,
father(homer_simpson, bart_simpson). asks whether Homer Simpson is the father of Bart Simpson.
- Queries involving variables. E.g.,
father(homer_simpson, X). asks the system to fill in the blank for all values of X that match the predicate statement.
A query can have any number of variables or literals as long as it matches the a rule or fact definition. E.g.,
father(X, Y). asks for all father/child combinations in the knowledge base.
If you attempt to find multiple solutions to a query, eventually the system will return with "no" (a value of false) letting you know that there are no more results in the knowledge base.
- All programs should begin with a file comment that describes your program's name, author, date, statement of purpose, dependencies, and any other info that the user will need to compile/import/run your program.
- Identifier names should be meaningful (and pronounceable). Let them describe the purpose of the variable, function, etc.
- Use whitespace consistently.
When you get started on this program, start by focusing on the immediate family outlined in class.
%Comments start like this
Remember to end every statement with a period (".").
Remember that, variables in Prolog start with capitol letters. Everything else is lower case.
Remember that facts and rules that start with the same identifier must be together (all male(). facts, for instance).
Thorough testing of the program is the student's responsibility. I should be able to run queries like the following:
%Should be true
%Should infer all children correctly.
%Should infer all father, child relationships.
What you should turn in:
By email you should turn in a program lastname_firstname.pl (where lastname is your last name and firstname is your first name) with the following predicates fully specified:
Remember, all work should be your own.
- Facts for male.
- Facts for female.
- Facts for parent.
- A rule for being married (lets make the simplifying assumption that having a child with someone makes you married).
- A rule for father
- A rule for mother
- A rule for son.
- A rule for daughter.
- A rule for a sibling.
- A rule for a brother.
- A rule for a sister.
- A rule for an aunt.
- A rule for an uncle
- Your program should load correctly, and should not crash when I run queries.