Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Princess Noura Bint Abdulrahman University College of Computer Science and Information Systems Computer Science Department Submission is online homework sent to the CS461: Artificial Intelligence Lab Homework #1 due date in Tuse,1April Homework #1 by a link not by email. Any email will be ignored. Q1: Consider the following Prolog program: father(ahmad,sami). father(ahmad,khalid). father(sami,dana). father(sami,mohammed). father(khalid,reem). 1. Define a Rule which holds iff brother(X,Y) and X Y are brothers. brother(X,Y):-father(Z,X),father(Z,Y),not(X=Y). 2. Define a Rule cousin(X,Y) which holds iff X and Y are cousins. cousin(X,Y) :- father(Z,X), father(W,Y), brother(Z,W). 3. Define a Rule grandson(X,Y) which holds iff X is a grandson of Y. grandson(X,Y) :- father(Z,X), father(Y,Z). 4. Define a Rule descendent(X,Y) which holds iff X is a descendent of Y. descendent(X,Y) :- father(Y,X). descendent(X,Y) :- father(Z,X), descendent(Z,Y). 1) What Prolog answers to these questions (“True”, “False”, or variables bindings – write all possible bindings ). a. ?- brother(X,Y). X = sami, Y = khalid ; X = khalid, Y = sami ; X = dana, Y = mohammed ; X = mohammed, Y = dana ; false. b. ?- cousin(dana,Y). Y = reem. c. ?- grandson(X,reem). false. d. ?- descendent(ahmad,reem). false. Princess Noura Bint Abdulrahman University College of Computer Science and Information Systems Computer Science Department CS461: Artificial Intelligence Lab Homework #1 due date in Tuse,1April Q2: Which of the following are syntactically correct Prolog objects? What kind of objects are they? (atom , number , variable , structure) a. Diana variable b. Diana atom c. 'Diana' atom d. _diana variable e. 'diana goes south' atom f. goes (diana,south) structure g. 45 number h. 5(X,Y) incorrect i. +(north, west) structure j. three(black(cats)). Structure Q3: Will the following matching operation succeed or fail? If they succeed, what are the resulting instantiation of variables? a) point( A, B) = point( 1, 2) b) =(ann,'ann') c) point( A, B) = point( X, Y, Z) d) plus( 2, 2) = 4. e) +( 2, D) = +( E, 2). f) triangle( point(-1,0), P2, P3) = triangle( P1, point(1,0), point(0,Y) ) g) parent (adam, liz) = X. h) ?- point(A,B) = point(1,2). A=1 B=2. i) =(ann,'ann'). True. j) ?- point(A,B) = point(X,Y,Z). False. k) ?- plus(2,2) = 4. False. l) ?- +(2,D) = +(E,2). D=2 E=2. m) ?- triangle(point(-1,0),P2,P3) = triangle(P1,point(1,0),point(0,Y)). P2 = point(1, 0) P3 = point(0, Y) P1 = point(-1, 0). n) ?-parent (adam, liz) = X. X = parent(adam, liz). Princess Noura Bint Abdulrahman University College of Computer Science and Information Systems Computer Science Department CS461: Artificial Intelligence Lab Homework #1 due date in Tuse,1April Q4: Consider the following program: f( 1, one). f( s(1), two). f( s(s(1)), three). f(s(s( s(s(s(X))))), N) :-f( X, N). How will Prolog answer the following questions? Whenever several answers are possible, give at least two. 1. ?- f( s(1), A). A = two. 2. ?- f( s(s(1)), two). False. 3. ?- f( s(s(s(s(s(s(1)))))), C). C=two. 4. ?- f( D, three). D = s(s(1)) ; D = s(s( s(s(s(s(s(X))))))); 5. ?- f(A,B). A = 1, B = one ; A = s(1), B = two ; 6. ?-f(s(X),1). Error. 7. ?- f(1,N). N=one.