Document 10805469

advertisement
Short Quiz 5 1 ) How many programming paradigm have we covered? What are they? Imperative(Fortran), Functional(Lisp,ML), Declarative(Prolog) We often refer to Prolog as Logic Programming paradigm too. COP5025 Spring 2003 – Final Exam (Chs. 8+9+Prolog
Name:
(Please print)
Put the answers on these sheets. Use additional sheets when necessary. You
2) If we say declarative programming is a programming paradigm that points in total
for thisdexam.
A bonus
question
is included
for an additional
expresses the logic of 100
a computation without escribing its control flow, is it correct ? ( Yes/ No )This
exam is open book and open notes.
1. Prolog (15 points) Consider the following assumptions made by Sir Bedeve
Python and the Holy Grail to argue that the girl is a witch:
COP5025
Spring 2003 – Final
Exam
(Chs. 8+9+Prolog)
witch(X)
:- burns(X), woman(X).
3) Which language is declarative ? (SQL, XML Prolog, all of them ) burns(X)
:-, isMadeOfWood(X).
isMadeOfWood(X)
:floats(X).
(Please print)
Name:
floats(X)
:- sameWeight(X, Y), floats(Y).
Put the answers on these sheets. Use additional
sheets when necessary. You can collect
floats(duck).
duck).
100 points in total for this exam. A bonussameWeight(girl,
question is included
for an additional 15 points.
woman(girl).
This exam
is open book and open notes.
4) This is a more complicated example :Consider the following assumptions made Mark
the queries
that
return
a successful
answer:
1. Prolog
points)in Consider
following
assumptions
made
bythat Sir tBedever
by Sir (15
Bedever Monty Pthe
ython and the Holy Grail to argue he girl is ina Monty
witch: Python
and the Holy Grail to argue that the girl is a witch:
floats(wood)
floats(duck)
witch(X)
:- burns(X), woman(X).
burns(X)
:- isMadeOfWood(X).
floats(girl)
isMadeOfWood(X) :- floats(X).
burns(duck)
floats(X)
:- sameWeight(X, Y), floats(Y).
burns(girl)
floats(duck).
witch(duck)
sameWeight(girl, duck).
woman(girl).
witch(girl)
Markthe
thequeries
queries
thatreturn
returnaasuccessful
successfulanswer:
answer: Mark
that
2.
Propositions
(10 points) Consider the language of propositional formula
note
94
and
Section
8.5). Given
ρ = {�x,
witch(X) . Burns(Y). isMadeOfWood(Z). floats(S). TRUE�, �y, FALSE�, �z, TRUE�}
floats(wood) formulas
how you derived your answers.
X = duck; Y = girl ; the following
Z = wood; is true?
Show
S=wood; floats(duck)
X = girl. Y = duck; Z = duck; S=duck; (a) floats(girl)
M[[x ⇒ y]] ρ
Y = wood. Z= girl. S=girl. (b) burns(duck)
M[[¬z ⇒ (y ⇒ x)]] ρ
burns(girl)
witch(duck)
witch(girl)
2. Propositions (10 points) Consider the language of propositional formulas (lecture
note 94 and Section 8.5). Given ρ = {�x, TRUE�, �y, FALSE�, �z, TRUE�}, which of
the following formulas is true? Show how you derived your answers.
(a) M[[x ⇒ y]] ρ
5) What is the result of following Prolog program ? MOTHER( jane ) FATHER ( adam ) Person ( nobel ) Relation( Y ) :-­‐ person( Y ), \+MOTHER( Y ), \+ FATHER( Y) ?-­‐ Relation( Y ) Y = nobel 6) Given data structure point ( _ , _, _) , what is the result of following program? ?-­‐ cube(point(1,0,0),point(1,3,0),point(1,3,3), point(1,0,3),point(3,0,0),point(3,3,0),point(3,3,3),point3,0,3) ) = cube(point(1,0,3),point(3,0,0),point(3,3,0),point(3,3,3),point3,0,3), (point(1,0,0),point(1,3,0),point(1,3,3)) No (Notice here cube is data structure ) 7) Is [1,4, 6, 9, 15] equivalent to .(1, .(4, .(5, .(7, .(9,.(15, [])))))) ? ( Yes/ No ) 8) Show two results of queries, based on the following predicates: Tables( Y, 7 ) :-­‐ employee( Y ), !. Tables( Y, 100 ) employee( john ). ? – Tables( tom, 7 ) false. ? -­‐ Tables ( john , 100 ) true. 9 ) What is the result for the following statement ? Sum2 ( [], 0 ) Sum2 ( [_|L], X ) :-­‐ Sum2(L, Y ), X is Y + 1 ?-­‐ Sum2 (L , 7) L = [_G2061, _G2064, _G2067, _G2070, _G2073, _G2076, _G2079] ( Notice: this is the result of swi-­‐prolog ) . 10) What is the result of following Prolog program ? ?-­‐ setof( Y, member(Y, [5, 6,7,8], Y<7 ), R ) [5,6] 
Download