Assignment#1 (A.i Lab)
Assignment#1 (A.i Lab)
(4) ?- pass(Who).
2. For below english sentences write applicable Prolog facts, rules & goals.
(1) Maria reads logic programming book by author peter lucas.
Ans: likes(Anyone,shopping):-
Ans: ?-likes(X,shopping)
Ans: hates(kirke):-city(big,crowdy).
3. What answers do you get for below queries for given program .
Program:
vegetarian(jose).
vegetarian(james).
vegetable(carrot).
vegetable(egg_plant).
likes(jose, X) :- vegetable(X).
Queries:
?- vegetable(X).
Yes x=jose,james
?- vegetable(potato).
no
?- vegetarian(_).
no
?- likes(jose, What).
Yes , carrots,egg_plant
?- likes(Who, egg_plant).
no
?- loves(Who, egg_plant).
ANS: NO
7. In below clause, X will instantiate to what value? [X|Y]= [likes(jin, black(dog)),likes(kate, dog)
8. For given program how would prolog respond to the query if you keep entering ';' after
each solution?
Program:
p(a,b).
p(b,c).
p(X, Y):-p(Y, X).
Query:
?- p(X,Y).
Ans:
It will keep recursively run the code until it gets it final state. Like
?- can_get(town3,town1).
No
roadway(town1,town2).
roadway (town2,town3).
roadway (town3,town4).
roadway (town4,town5).
roadway (town5,town6).
can_get(X,Y):- road(X,Y).
10. Draw the complete Prolog derivation tree for the goal ? – factorial(4,24). consider the
following simple program
factorial(0,1). / *base case.
factorial(N,F):- N > 0, /*Recursive case.
N1 is N-1, factorial(N1,F1),
F is N*F1.