Professional Documents
Culture Documents
AI Prolog Reminder
AI Prolog Reminder
female(liz).
Prolog Reminder female(irene).
male(brendon).
male(emlyn).
Remember Remember
• Each statement, ending in a full stop, is • Variables start with an upper case letter or
called a clause. _. There are no global variables in Prolog,
• female, male are unary predicates. so the X and Y in rule for mother are
• parent, mother, grandparent are binary different from the X and Y in the rule for
predicates. grandparent.
• :- means IF and , means AND • All clauses are statements of what is
assumed to be true, and each clause is
• The clauses defining mother and logically independent of the others. Hence
grandparent predicates are rules, and the reordering clauses does not change the
rest are facts. meaning of the program.
1
Exercise Lists in Prolog
Write Prolog queries to solve the following • To represent a list of elements in a particular
problems, and state the solutions the Prolog order in Prolog, use a list structure, e.g.
interpreter would find: [a,b,c,d,e].
• We can represent a list using notation [H|T] to
1. Who are the males in the family? mean a head item H and a list T, the tail,
containing the rest of the elements in the list.
2. Who is Liz’s mother? • E.g. if we unify the list [a,b,c,d,e] with [H|T]
the result is H = a, T = [b,c,d,e] if we unify the
3. Who are the grandchildren of Irene?
list [a] with [H|T] the result is H = a, T = [].