PA - Family


Introduction

In this PA, you will practice writing Prolog by encoding various family relationships using Prolog predicates. The boilerplate file is provided below. You will need to download it and add the predicates described below.

family.pl

At the top of the file, you will see a list of facts describing a sample family tree. If you look towards the bottom of the file, you will also see a bunch of test predicates. You should NOT change either the facts or the test predicates in any way. If you load this file into gprolog as-is and run the test predicate, you will see that the tests fail. As you write your code, you can keep running main (or any of the individual test functions) for an indication of whether your code works.

Predicates

You must write the following predicates:

  • female(X) - Anyone who is not a male is a female (this makes unknown people female).
  • parent(X,Y) - A parent is either one of a person’s biological parents. parent(X,Y) is read X has parent Y.
  • father(X,Y) - A father is a male biological parent. father(X,Y) is read X has father Y.
  • mother(X,Y) - A mother is a female biological parent. mother(X,Y) is read X has mother Y.
  • step_parent(X,Y) - A step parent is a non-biological parent of a spouse of a biological parent. step_parent(X,Y) is read X has step_parent Y.
  • step_father(X,Y) - A step father is a non-biological parent who is a male spouse of a biological parent. step_father(X,Y) is read X has step_father 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.
  • sister(X,Y) - A sister is a female sibling. sister(X,Y) is read X has sister Y.
  • aunt(X,Y) - An aunt is a sister of a parent, or the female spouse of a sibling of a parent. aunt(X,Y) is read X has aunt Y.
  • grandparent(X,Y) - A grandparent is a biological parent of a biological parent. grandparent(X,Y) is read X has grandparent Y.
  • grandfather(X,Y) - A grandfather is a male grandparent. grandfather(X,Y) is read X has grandfather 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 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.

The final program must have all the test predicates uncommented, in particular the predicate test at the very end of the file.

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.

Deliverable Requirements

Submit your modified Prolog script file on Canvas by 11:59 pm on Friday, April 3, 2015. Please fill in your name at the top of the file. Do not modify the testing code.

Acknowledgement

This PA was originally designed by Dr. Chris Fox; much of the wording on this page was originally his.