*** 1 Consider the following general logic program: founding(X) :- on(Y,X), on_ground(X). on_ground(X) :- \+ off_ground(X). off_ground(X) :- on(X,Y). above(X,Y) :- on(X,Y). above(X,Y) :- on(X,Z),above(Z,Y). on(c,b). on(b,a). Construct the SLDNF-forest of the general goal ?- founding(X). Test the goal on your Prolog system. *** 2 Consider the following general logic program: go_well_together(X, Y) :- \+ incompatible(X, Y). incompatible(X, Y) :- \+ likes(X, Y). incompatible(X, Y) :- \+ likes(Y, X). likes(X, Y) :- harmless(Y). likes(X, Y) :- eats(X, Y). harmless(rabbit). eats(python, rabbit). Construct the SLDNF-forest of ?- go_well_together(rabbit,rabbit). Test the goal on your Prolog system. Test now the following goals: ?- go_well_together(Y,rabbit). ?- go_well_together(python,rabbit). Justify the answers. *** 3 You are given the following clauses. father(john,jim). father(john,carla). mother(liz,carla). mother(dilly,jim). mother(carla,peter). person(X) :- mother(X,_). person(X) :- mother(_,X). person(X) :- father(X,_). person(X) :- father(_,X). Define a predicate orphan/1 that captures the persons who have no mother and father. Test it on the above program. *** 4 Define a predicate len/2 that takes a list and gives the number of arguments in the list. For example, ?- len([a,b],X). should return X=2. Test it now with the input and output reversed, e.g., ?- len(L,3). *** 5 Define a predicate lenp/2 that takes a list and gives the number of arguments in the list expressed a la Peano, i.e., zero is the constant 0, and the successor of a number X is s(X) For example, ?- lenp([a,b],X). should return X=s(s(0)). Test it now with the input and output reversed, e.g., ?- lenp(L,s(s(s(0)))). *** 6 Define a predicate add/3 that takes two numbers expressed a la Peano and returns their sum expressed a la Peano. For example, ?- add(s(0),s(0),X). should return X=s(s(0)). *** 7 Define a predicate stars/1 that takes a number N and prints the '*' character N times. To print a '*' use the call write('*'). Hint: construct a list of length N, test membership of a generic element in the list, force backtracking using the fail/0 predicate (a predefined predicate that simply fails) and print a '*' each time you backtrack. *** 8 Define a predicate table/1 that takes a list of numbers and prints all possible products between all possible pairs of numbers taken from the list. For example, ?- table([1,2,3]). should print 1*1=1 1*2=2 1*3=3 2*1=2 2*2=4 2*3=6 3*1=3 3*2=6 3*3=9 Hint: force backtracking with fail/0 as before