Module 15 Project
In this PA, you will practice writing Prolog by encoding various family relationships using Prolog predicates.
Project starter files:
There are three Prolog files:
facts.pl- This file contains a list of facts describing a sample family tree. You should NOT change this file in any way.
test.pl-This file contains a bunch of test predicates. You should NOT change the existing test clauses in any way, but you should feel free to add new clauses (separated by commas). You should not submit this file.
p5.pl- This is the file you should edit. Currently it provides only some rule stubs so that the test file does not crash.
You can test your code by loading the Prolog files into
swipl (e.g., using
[facts]. to load
facts.pl) and running queries or test
predicates directly. You can also use the provided
test.sh shell script, which
swipl and runs each test predicate separately, automating the process
of parsing the output and counting failed tests for you.
You must write the following predicates:
parent(X,Y)- A parent is either one of a person’s biological parents.
parent(X,Y)is read “X has parent Y.”
step_parent(X,Y)- A step parent is a non-biological parent; i.e., a spouse of a biological parent.
step_parent(X,Y)is read “X has step-parent Y.”
sibling(X,Y)- Siblings are distinct people who share a biological parent.
sibling(X,Y)is symmetric. (Hint: at the end of your rule, include
X\==Y, which succeeds only if X and Y are not instantiated to the same atom.)
aunt_uncle(X,Y)- An aunt or uncle is a sibling of a parent, or the spouse of a sibling of a parent.
aunt_uncle(X,Y)is read “X has aunt or uncle Y.”
grandparent(X,Y)- A grandparent is a biological parent of a biological parent.
grandparent(X,Y)is read “X has grandparent Y.”
ancestor(X,Y)- The ancestor predicate is the transitive closure of the biological parent relation. In other words, a person’s ancestors are their parents, their parents’ parents, their parents’ parents’ parents, etc.
ancestor(X,Y)is read “X has ancestor Y.”
relative(X,Y)- A (blood) relative of a person is anyone else that is either an ancestor of that person, has a common ancestor with that person, or is a descendant of that person; nobody is a relative of themselves.
relative(X,Y)is read “X has relative Y.”
in_law(X,Y)- An in-law of a person is any (blood) relative of that person’s spouse that is not also that person’s relative.
in_law(X,Y)is read “X has in-law Y.”
Hint: Run the individual tests as you write your predicates. Later predicates
will be easier to write if you use earlier ones; it will be much easier to debug
your code as you go along than waiting until the end. If a test fails, try each
of its parts until you isolate the problem. If you are having trouble, you might
find it helpful to draw the family tree given in
You should not hard-code any of these predicates (e.g., by enumerating all correct conclusions as new facts). In other words, your implementations should continue to work if a different family tree is provided.
Your program must contain implementations as described above. You must name your
Prolog script file
p5.pl. You must put your name in a comment at the top of
the file. As usual, decompose your rules if necessary to make them more
readable, use good names, indent properly, and so on. You will partly be graded
on the readability of your code but mostly on whether it works.
p5.pl to the appropriate assignment on Canvas by the deadline.
This PA was originally designed by Dr. Chris Fox; much of the wording on this page was originally his.