Write a rule that describes a child, so that child(X, Y) means
X is the child of Y. Don't allow a person to be his or her
own child.

Define an ancestor rule. An ancestor is a parent of a person, a
grandparent, a great-grandparent, etc. Naturally, this rule is
recursive (like the member predicate in the notes).

Define a "has no parents" rule. Use negation ("negation as
failure").

Make sure you actually test your queries and rules with SWI-Prolog!
And look at the video from Day 13, about the 14 minute mark, for help.

Task 2 (10 pts)

Do the following unify, and if so, what are values for the variables
that make the unification work? Note: Each pair of terms has new
variable assignments. Look at the video from Day 14 for help.

parent(tom, liz) and parent(tom, X)

parent(X, liz) and parent(liz, X)

parent(X, Y) and parent(Y, X)

head(X, [a, b, c]) and head(b, [a, b, c])

head(foo(Y), X) and head(foo(Z), [foo(w)])

foo(bar(a, b), baz(c)) and foo(bar(X), baz(Y))

Task 3 (10 pts)

Draw a resolution tree for mother(X), refering back to the database
above. Note that there is a particular order by which Prolog creates
subgoals (that is, the order that facts/rules are written in the
knowledge base). You only need to show the tree until the first time
the predicate is proved. Look at the video from Day 14 for help.

Task 4 (60 pts)

Extend the Prolog program at the bottom of this page to support the
following interactions. (The user types the stuff after the |:) Look
at the video from Day 15, starting at about the 18 minute mark, for
help. In particular, you'll need to use assertz (21:30 mark in the
video). Write this in a Prolog source file (hw6.pl maybe), and test
your code. Submit the source file so the grader can also test your
code.

?- consult('nldb.pl').
% library(error) compiled into error 0.00 sec, 18,352 bytes
% library(lists) compiled into lists 0.01 sec, 46,096 bytes
% library(readln) compiled into readln 0.01 sec, 60,696 bytes
% nldb.pl compiled 0.01 sec, 78,560 bytes
true.
?- run.
|: quit.
Ok we're done!
true.
?- run.
|: anteater is bigger than ant.
Ok, I learned that ant is smaller than anteater
|: ant is smaller than foot.
Ok, I learned that ant is smaller than foot
|: what is bigger than ant?
These are bigger:
anteater, foot.
|: what is smaller than anteater?
These are smaller:
ant.
|: what is smaller than ant?
These are smaller:
|: godzilla is bigger than anteater.
Ok, I learned that anteater is smaller than godzilla
|: what is bigger than ant?
These are bigger:
anteater, foot, godzilla.
|: what is smaller than godzilla?
These are smaller:
anteater, ant.
|: today is thursday.
Ok, I learned that today is a/an thursday
|: socrates is mortal.
Ok, I learned that socrates is a/an mortal
|: what is socrates?
socrates is a/an:
mortal.
|: what is today?
today is a/an:
thursday.
|: what is xyz?
I'm not sure! Care to tell me?
|: is xyz abc?
No
|: xyz is abc.
Ok, I learned that xyz is a/an abc
|: is xyz abc?
Yes
|: what is 15?
15
|: what is 2 + 2?
4
|: what is 2 - 3 * 5?
-13
|: what is 2 * 3 - 2?
2
|: what is 4 / 3?
1.3333333333333333
|: wow, you are very smart!
Huh?
|: quit.
Ok we're done!
true.
?-