H+Declarative+Language+Questions

1. Here is a simple Prolog program made up of 4 facts:

likes(mary,food). likes(mary,wine). likes(john,wine). likes(john,mary).

The first line can be read as: mary likes food

What do you think the answer to the following queries will be (yes or no)? (a) ?- likes(mary,food).

(b) ?- likes(john,wine).

(c) ?- likes(john,food).

2. Here is a more complex Prolog program which contains the facts and rules for a family tree

male(james1). male(charles1). male(charles2). male(james2). male(george1).

female(catherine). female(elizabeth). female(sophia).

parentof(james1,charles1). parentof(james1,elizabeth). parentof(charles1,charles2). parentof(charles1,catherine). parentof(charles1,james2). parentof(elizabeth,sophia). parentof(sophia,george1).

motherof(X,Y):- parent(X,Y),female(X)

The final line of this code is a rule and can be read as: X is the mother of Y if X is the parent of Y and X is female

What would be the result of the following queries: (a) ?- parentof(charles1,james1). (yes or no)

(b) ?- parentof(catherine,sophia). (yes or no)

(c) ?- parentof(charles1,X). (Note that X is a variable which will display all of the possible matches)

(d) ?- parentof(Y,george1). (Note that Y is also being used as a variable)

(e) ?- motherof(charles1,catherine). (yes or no)

(f) ?- motherof(elizabeth,sophia). (yes or no)

(g) Using the rule motherof as a guide, can you write a rule for fatherof?

(h) Can you write a rule for siblingof?