0% found this document useful (0 votes)
1K views4 pages

Assignment#1 (A.i Lab)

This document contains a student's answers to an assignment involving Prolog concepts. The student provides English translations of Prolog rules and facts, writes Prolog representations of English statements, determines the answers to queries against example programs, and analyzes terms and queries for unification. The student also draws a derivation tree for a factorial query and writes a recursive program to check if travel is possible between towns connected by a one-way road.

Uploaded by

Usaid Siddique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views4 pages

Assignment#1 (A.i Lab)

This document contains a student's answers to an assignment involving Prolog concepts. The student provides English translations of Prolog rules and facts, writes Prolog representations of English statements, determines the answers to queries against example programs, and analyzes terms and queries for unification. The student also draws a derivation tree for a factorial query and writes a recursive program to check if travel is possible between towns connected by a one-way road.

Uploaded by

Usaid Siddique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT#1

NAME: ASHAJ BIN ARSHAD (10097)


1. For below facts, rules, and goals write English Meanings.
(1) color(carrots, orange).

Ans: carrots color is orange.

(2) likes(Person, carrots):-vegetarian(Person).

Ans: person likes carrots if person is vegetarian.

(3) pass(Student) :- study_hard(Student).

Ans: Student pass if student study hard

(4) ?- pass(Who).

Ans: who will pass?

(5) ?- teaches(professor, Course).

Ans: Which course professor teaches?

(6) enemies(X, Y) :- hates(X, Y), fights(X, Y).

Ans: If X & Y are enemies then X hates Y and X fights Y.

2. For below english sentences write applicable Prolog facts, rules & goals.
(1) Maria reads logic programming book by author peter lucas.

Ans: reads(Maria,logicprogrammingbook):- author(peter_lucas).

(2) Anyone likes shopping if she is a girl.

Ans: likes(Anyone,shopping):-

(3) Who likes shopping?

Ans: ?-likes(X,shopping)

(4) kirke hates any city if it is big and crowdy

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).

loves(Who, egg_plant) :- vegetarian(Who).

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).

Yes jose, james

4. likes(jax, X). and likes(X, jin). - Do these terms unify? Why?

ANS: NO

5. food(X, Y, Z). and food(M, M, M). - Do these terms unify? Why?

ANS: Yes it will unify.

6. [H|T]=[a,b,c,[d,a],[1,2],list]. - Do these terms unify? Why?

ANS: Yes it will unify.

7. In below clause, X will instantiate to what value? [X|Y]= [likes(jin, black(dog)),likes(kate, dog)

Ans: X= likes(jin, black(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

First p(X,Y) then its return p(Y,X)

And last it will give p(X,Y) then program will stop.

9. town1----->-----town2---->----town3---->----town4--->----town5---->---town6 A one way


road links 6 towns. Write a program that can work out if you can travel on that road. For
example. Here are two sample program behaviors .
?- can_get(town2,town5).

Yes a(X):- b(X,Y), a(X).

?- 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).

can_get(X,Y):- road(X,Z), can_get(Z,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.

You might also like