PROLOG, ujian lagi dua hari
1. Translate the following sentences into a PROLOG program
Everyone who teaches a computing unit is smart.
John teaches the unit MA1
John’s wife teaches the unit SA1
MA1 is a mathematics unit
SA1 is a computing unit
a. from the above PROLOG program, identify the facts, rules, terms, and atomic formulas. Also list variables, constant, functions, and predicates.
b. Load the program to a PROLOG system and enter a query to ask if anyone is smart. What is the logical meaning of the answer
Solution
smart(X) :- teaches(X,Y),computing(Y).
teaches(john,ma1).
teaches(wife(john),sa1).
mathematics(ma1).
computing(sa1).
Facts :
teaches(john,ma1).
teaches(wife(john),sa1).
mathematics(ma1).
computing(sa1).
Rule
smart(X) :- teaches(X,Y),computing(Y).
Atomic Formulas
smart(X), teaches(X,Y), computing(Y).
Term
Variabels : X, Y
Constants : john, ma1, sa1
Function : wife(john) function symbol : wife
Predicates : smart, teaches, computing
To ask if there is anyone smart ?
?- smart(X)
X = wife(john).
no
2. Consider the following English version
Every mother likes her child if her child is good
Every mother is woman
Ann is woman
Ann’s husband is good.
a. Translate the above sentences into two different PROLOG programs : one contains function symbols and the other does not.
b. Load the program to a PROLOG system and enter a query to ask if there is any woman who likes someone’s husband. What is the logical meaning of the answer
Program 1
likes(mother(X),X) :- good(X).
woman(mother(X)).
woman(ann).
good(husband(ann)).
Program 2
likes(X,Y) :- mother(X,Y), good(Y).
woman(Y) :- mother(X,Y).
woman(ann).
good(X) :- husband(X,ann)
the program 1 is more expensive, because its functions allow reference to a large number of entities such as Ann’s husband, Ann’s mother, and Ann’s mother-in-law, whereas in program 2, the only entity that can be displayed is ann .
Is there any woman who likes someone’s husband ?
?- woman(X), likes(X,husband(Y)).
X = mother(husband(ann)).
Y = ann
?- woman(X), husband(Y,Z), likes(X,Y).
no
because the system is unable to find anyone’s husband
to do this we must introduce new constant, say ann_husband, & ann_mother_in_law
husband(ann_husband,ann).
mother(ann_mother_in_law,ann_husband)
?- woman(X), husband(Y,Z), likes(X,Y).
X = ann_mother_in_law
Y = ann_husband
Z = ann
4. The unification process of PROLOG assumes every function is one-to-one, that is f(x) = f(y) only if x = y. Consider the following pairs of expressions and determine if they are unifiable. If so, Find appropriate variable substitution !
a. loves(X,husband(Y)); loves(mother(Z),Z);
b. loves(X,husband(X)); loves(mother(Z),Z);
c. mother(john); mother(sue);
d. min(log(X),Y); min(U,exp(V)).
e. X + 1; Y + 2;
Solution
a. ?- loves(X,husband(Y))=loves(mother(Z),Z).
X = mother(husband(H13))
Y = H13
Z = husband(H13)
yes
b. no, because husband(mother(Z)) in not unifiable with Z
c. no, because john is not unifiable with sue
d. yes, U = log(X). Y = exp(V).
e. no, because 1 is not unifiable with 2
Filed by moroncoder at January 7th, 2007 under Uncategorized
ape to yan……
masih jaman logmat…
hahahaha
RuDy 'OpOr' xxx — January 7, 2007 @ 7:48 pm