Вы находитесь на странице: 1из 11

Tema SE

Capitolul 1

1.1 Which of the following sequences of characters are atoms, which are variables, and
which are neither?

1. vINCENT -> atom


2. Footmassage -> variabila
3. variable23 -> atom
4. Variable2000 ->variabila
5. big_kahuna_burger ->atom
6. ’big kahuna burger’ ->atom
7. big kahuna burger -> niciunul
8. ’Jules’ ->atom
9. _Jules ->variabila
10. ’_Jules’ ->atom

1.2 Which of the following sequences of characters are atoms, which are variables, which are
complex terms, and which are not terms at all? Give the functor and arity of each complex
term.

1. loves(Vincent,mia) ->termen complex, functor:loves, aritate:2


2. ’loves(Vincent,mia)’ ->atom
3. Butch(boxer) ->nu este un termen
4. boxer(Butch) ->termen complex,functor:boxer, aritate:1
5. and(big(burger),kahuna(burger)) ->termen complex, functor:and, aritate :2
6. and(big(X),kahuna(X)) –> nu este un termen
7. _and(big(X),kahuna(X)) -> nu este un termen
8. (Butch kills Vincent) -> nu este un termen
9. kills(Butch Vincent) -> nu este un termen
10. kills(Butch,Vincent -> nu este un termen

1.3 How many facts, rules, clauses, and predicates are there in the following knowledge base?
What are the heads of the rules, and what are the goals they contain?

woman(vincent).
woman(mia).
man(jules).
person(X):- man(X); woman(X).
loves(X,Y):- father(X,Y).
father(Y,Z):- man(Y), son(Z,Y).

father(Y,Z):- man(Y), daughter(Z,Y).


facts: 3
rules:4
clauses:7
predicates:7

Head Goals

person(X) man(X); woman(X).


loves(X,Y) father(X,Y).
father(Y,Z) man(Y), son(Z,Y).
father(Y,Z) man(Y), daughter(Z,Y).

1.4 Represent the following in Prolog:

1. Butch is a killer.
killer(butch).
2. Mia and Marsellus are married.
married(mia,marsellus)
3. Zed is dead.
dead(zed).
4. Marsellus kills everyone who gives Mia a footmassage.
kills(marsellus,X):-givesfootmassage(X,mia)

5. Mia loves everyone who is a good dancer.


loves(mia,X):-gooddancer(X)

6. Jules eats anything that is nutritious or tasty.


eats(jules):-nutritious(X).
eats(jules):-tasty(X).

1.5 Suppose we are working with the following knowledge base:


wizard(ron).
hasWand(harry).
quidditchPlayer(harry).
wizard(X):- hasBroom(X), hasWand(X).
hasBroom(X):- quidditchPlayer(X).
1.true

2. Undefined procedure

3.false

4.undefined procedure
5.true

6.ron,harry

7.undefined procedure

Capitolul 2
2.3 Here is a tiny lexicon (that is, information about individual words) and a mini grammar
consisting of one syntactic rule (which defines a sentence to be an entity consisting of five
words in the following order: a determiner, a noun, a verb, a determiner, a noun).
word(determiner,a).
word(determiner,every).
word(noun,criminal).

word(noun,'big kahuna burger').


word(verb,eats).
word(verb,likes).

sentence(Word1,Word2,Word3,Word4,Word5):-
word(determiner,Word1),
word(noun,Word2),
word(verb,Word3),
word(determiner,Word4),
word(noun,Word5).

Sentence(A,B,C,D,E)->genereaza toate posibilitatile


A=a,
B=criminal,
C=eats,
D=a,
E=criminal;

2.4 Here are six Italian words:

astante , astoria , baratto , cobalto , pistola , statale .

They are to be arranged, crossword puzzle fashion, in the following grid:


word(astante, a,s,t,a,n,t,e).
word(astoria, a,s,t,o,r,i,a).
word(baratto, b,a,r,a,t,t,o).
word(cobalto, c,o,b,a,l,t,o).
word(pistola, p,i,s,t,o,l,a).
word(statale, s,t,a,t,a,l,e).

crossword(V1,V2,V3,H1,H2,H3) :-

crossword(V1,V2,V3,H1,H2,H3) :-
word(H1,_,H12V12,_,H14V22,_,H16V32,_),
word(H2,_,H22V14,_,H24V24,_,H26V34,_),
word(H3,_,H32V16,_,H34V26,_,H36V36,_),

word(V1,_,H12V12,_,H22V14,_,H32V16,_),
word(V2,_,H14V22,_,H24V24,_,H34V26,_),
word(V3,_,H16V32,_,H26V34,_,H36V36,_).

Capitolul 3
3.1 In the text, we discussed the predicate
descend(X,Y) :- child(X,Y).
descend(X,Y) :- child(X,Z),
descend(Z,Y).

Suppose we reformulated this predicate as follows:

descend(X,Y) :- child(X,Y).
descend(X,Y) :- descend(X,Z),
descend(Z,Y).

3.2 Do you know these wooden Russian dolls (Matryoshka dolls) where the smaller ones are
contained in bigger ones? Here is a schematic picture:
First, write a knowledge base using the predicate directlyIn/2 which encodes which doll is
directly contained in which other doll. Then, define a recursive predicate in/2 , that tells us
which doll is (directly or indirectly) contained in which other dolls. For example, the query
in(katarina,natasha) should evaluate to true, while in(olga, katarina) should fail.

directlyIn(katarina, olga).
directlyIn(olga, natasha).
directlyIn(natasha, irina).
in(X,Y) :- directlyIn(X,Y).
in(X,Y) :-
directlyIn(X,Z),
in(Z,Y).
3.3 We have the following knowledge base:

directTrain(saarbruecken,dudweiler).
directTrain(forbach,saarbruecken).
directTrain(freyming,forbach).
directTrain(stAvold,freyming).
directTrain(fahlquemont,stAvold).
directTrain(metz,fahlquemont).
directTrain(nancy,metz).

That is, this knowledge base holds facts about towns it is possible to travel between by taking
a direct train. But of course, we can travel further by chaining together direct train journeys.
Write a recursive predicate travelFromTo/2 that tells us when we can travel by train between
two towns. For example, when given the query it should reply yes.
travelFromTo(nancy,saarbruecken).
R: travelBetween(X,Y) :- directTrain(X,Y).
travelBetween(X,Y) :-
directTrain(X,Z),
travelBetween(Z,Y).
3.4 Define a predicate greater_than/2 that takes two numerals in the notation that we
introduced in the text (that is, 0, succ(0), succ(succ(0)), and so on) as arguments and decides
whether the first one is greater than the second one. For example:
?- greater_than(succ(succ(succ(0))),succ(0)).
yes
?- greater_than(succ(succ(0)),succ(succ(succ(0)))).
No

2. Program Prolog pentru determinarea celui mai mic multiplu comun a doua numere :

R:
% cmmdc(+X, +Y, -D) (calculeaza cmmdc intre X si Y)
cmmdc(X, 0, X).
cmmdc(X, Y, D) :- Z is X mod Y, cmmdc(Y, Z, D), !.
%cmmmc(+X, +Y, -D) (calculeaza cmmmc intre X si Y)
cmmmc(X, Y, D) :- cmmdc(X, Y, Z), D is (X * Y) / Z.

3. Exercitiile din prezentarea: “P2 Unificare Prolog” .

1. Exprimati in Prolog urmatoarele fapte:


a) susan are un cal;
R:are(susan,cal)
b) rex mănâncă carne;
R:mananca(rex,carne)
c) aurul este pretios;
R:pretios(aurul)
d) maşina este un mercedes albastru cu capacitatea de cinci călători;
R:masina(Mercedes,albastru,5)

2. Traduceti în limbaj natural următoarea întrebare Prolog si precizati răspunsul posibil:


părinte(vali, X),
părinte(X, Y),
părinte(Y, roco).

R: Al cui parinte este Vali, cine este parintele X pentru Y, Cine este parintele lui Roco?

3. Doi copii pot juca un meci într-un turneu de tenis dacă au aceeaşi vârstă. Fie următorii
copii şi vârstele lor:
copil(peter, 9).
copil(paul, 10).
copil(chris, 9).
copil(susan, 9).

Definiti un predicat din care rezulta toate perechile de copii care pot juca un meci într-un
turneu de tenis.

R: Joaca(Jucator1,Jucator2):- copil(Jucator1,Varsta),copil(Jucator2,Varsta, Jucator1\=Jucator2

4. Scrieti un program care să îi găseasca Anei un partener la bal. Ea doreşte sa mearga cu un


bărbat care este nefumător sau vegetarian. Pentru aceasta dispunem de o bază de date cu
informatii despre câtiva bărbatii:
barbat(gelu).
barbat(bogdan).
barbat(toma).
fumator(toma).
fumator(dan).
vegetarian(gelu).

R: Ana_se_intalneste(X):- barbat(X),vegetarian(X), not(fumator(x).

5. Se dau următoarele enunturi:


1) Oricine poate citi este literat.
2) Delfinii nu sunt literati.
3) Anumiti delfini sunt inteligenti.
Să se demonstreze în Prolog că: “Există fiinte inteligente care nu pot citi”.

Вам также может понравиться