Академический Документы
Профессиональный Документы
Культура Документы
Capitolul 1
1.1 Which of the following sequences of characters are atoms, which are variables, and
which are neither?
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.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).
Head Goals
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)
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).
sentence(Word1,Word2,Word3,Word4,Word5):-
word(determiner,Word1),
word(noun,Word2),
word(verb,Word3),
word(determiner,Word4),
word(noun,Word5).
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).
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.
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.