Two exercises in prolog. 1. Solve the farmer-fox-chicken-corn puzzle. Do not use negation, do everything in positive terms. Have a "function of functions" to represent the state, for example state(farmer(w), fox(w), chicken(e), corn(e)) would be unsafe. You should expect the constants w and e to be replaced by variables in most cases in your definitions. An opposite(X, Y) predicate with a very simple two line definition will help. The one final prolong example in class on 31st March shows how to record the path. 2. Using the fact predicates below, with more of your own added, create predicates for a large number of family relationships including related(X, is-brother-of, Y), and the same for sister, mother, uncle, grandparent, cousin, descendant, blood-relation, ancestor, son, daughter, grandmother, great-aunt, related, great-grandfather, etc. add more people and more relationships so your tests can be good. Also add a predicate (of three parameters so it is compatible with the existing ones) that discovers Nth cousin M times removed relationships, using a function to squeeze all the necessary information in: related(X, is-nth-cousin-of(N), Y). where N is a number related(X, is-nth-cousin-of(N, removed-up, M), Y). where N, M are numbers and removed-up and down is a constant. This is a relationship that some people don't properly understand so I'll make it clear here in a vaguely mathematical way. Consider these definitions You are a 0-ancestor of yourself Your parents are 1-ancestors of you Your grandparents are 2-ancestors of you Your great grandparents are 3-ancestors of you, and so on. If A is an N-ancestor of X, and an M-ancestor of Y (M, N both >= 2) then Y is an (N-1)th cousin of X and X is an (M-1)th cousin of Y. This means that the plain version of cousin, someone who shares a grandparent with you, is also a first cousin, and a second cousin might share a great grandparent with you. If M and N are not equal, the "removed" notation can (but does not need to be) used. Let's take a specific A who is a 5-ancestor of X but only a 2-ancestor of Y. Then Y is a 4th cousin three times removed upwards of X: related(Y, is-nth-cousin-of(4, removed-up, 3), X). and X is a 1st cousin three times removed downwards of Y: related(X, is-nth-cousin-of(1, removed-down, 3). Y). in case it isn't obvious, the threes are there because that is the difference in generations, 5 - 2. Don't worry, this is a lot easier than it sounds. A family tree diagram is included with the assignment posting on rabbit to make these facts easier to understand. male(tim-ant). male(jim-bat). male(joe-ant). male(mike-ant). male(bill-bat). male(matt-dog). male(bob-ant). male(jim-ant). male(joe-dog). male(bob-fig). male(tim-fig). male(tom-ink). male(jim-ink). female(jill-emu). female(meg-gum). female(pam-ant). female(amy-bat). female(mab-cat). female(emma-ham). female(ann-ant). female(sal-dog). female(moll-bat). female(pat-hat). female(mary-ant). female(amy-ant). married(tim-ant, jill-emu). married(jim-bat, meg-gum). married(joe-ant, amy-bat). married(mike-ant, mab-cat). married(pam-ant, matt-dog). married(bill-bat, emma-ham). married(ann-ant, bob-fig). married(bob-ant, tim-fig). married(jim-ant, pat-hat). married(moll-bat, tom-ink). parent(joe-ant, tim-ant). parent(joe-ant, jill-emu). parent(mike-ant, tim-ant). parent(mike-ant, jill-emu). parent(pam-ant, tim-ant). parent(pam-ant, jill-emu). parent(amy-bat, jim-bat). parent(amy-bat, meg-gum). parent(bill-bat, jim-bat). parent(bill-bat, meg-gum). parent(ann-ant, joe-ant). parent(ann-ant, amy-bat). parent(bob-ant, joe-ant). parent(bob-ant, amy-bat). parent(jim-ant, joe-ant). parent(jim-ant, amy-bat). parent(joe-dog, pam-ant). parent(joe-dog, matt-dog). parent(sal-dog, pam-ant). parent(sal-dog, matt-dog). parent(moll-bat, bill-bat). parent(moll-bat, emma-ham). parent(mary-ant, jim-ant). parent(mary-ant, pat-hat). parent(amy-ant, jim-ant). parent(amy-ant, pat-hat). parent(jim-ink, moll-bat). parent(jim-ink, tom-ink).