Homework VI

 

 

1. [10 points]

Show all the Prolog responses to the following queries -- use the ';' continuation to obtain all the multiple answers.

(a) ?- 1+1=2.

(b) ?- 1+1=:=2.

(c) ?- X+1 = 2*Y+Z.

(d) ?- X=1 ; X=2.

(e) ?- [X,Y | Xs] = [a,b,c,d].

(f) ?- [X, [Y,Z], 3] = [[Z,Y], X, Z].

(g) ?- member(b, [a,,b,c]).

(h) ?- member(d, [a,b,c]).

(i) ?- member(X, [a,b,c]).

(j) ?- length(Xs,2), member(a,Xs), member(b,Xs).

 

 

Problem 2. [20 points -- 5-5-10]

For this problem you should formulate queries using pre-defined predicates, and show that the Prolog responses yield the desired result -- use the ';' continuation to obtain the multiple answers, if any, in each case.

(a)  using pre-defined predicate 'member', formulate a query that will yield each item in a numeric list greater than 100;

(b) using pre-defined predicate 'member', formulate a query that will yield each item in a numeric list greater than 50 and less than 100

(c) using pre-defined predicates 'member' and 'append', formulate a query that will yield each item that is repeated in a given list

 

 

Problem 3. [20 points]

Consider the Prolog predicate definition

alike(a,aa).   alike(aa,aaa).

alike(X,X).

alike(X,Y) :- alike(Y,X).

alike(X,Y) :- alike(X,Z), alike(Z,Y).

For the queries below, show all possible responses (i.e., repeated ;), and indicate whether these responses reflect "logical conclusions".

(a) ?- alike(a,aaa).

(b) ?- alike(aaa,aa).

(c) ?- alike(a,X).

(d) ?- alike(X,Y).

 

 

Submission instructions

Create a script file of a Prolog session encompassing all three problems, and submit the printout with your remarks about logical conclusions on problem 3 added.