Introduction to Prolog
Prolog is a logic language that is particularly suited to programs that involve symbolic or non-numeric computation. For this reason it is a frequently used language in Artificial Intelligence where manipulation of symbols and inference about them is a common task.
Prolog was invented in the early seventies at the University of Marseille. Prolog stands for PROgramming in LOGic. It is a logic language that is particularly used by programs that use non-numeric objects. For this reason it is a frequently used language in Artificial Intelligence where manipulation of symbols is a common task. Prolog differs from the most common programmings languages because it is declarativre language. Traditional programming languages are said to be procedural. This means that the programmer specify how to solve a problem. In declarative languages the programmers only give the problem and the language find himself how to solve the problem. Prolog is firmly based on logic, and Prolog programs can be understood as statements in a formal logic. i.e., a Prolog program can be thought of as a set of statements in first-order logic, and the meaning of the program is the set of true implications of those logical statements.
Q.N. Develop a knowledge base that encapsulates the following family tree diagram.
Legend:
X=Y :X is married with Y
X Y :X is parent of Y
Bernd=Maria
Micheal=Vera Silke
Karl=Monika Thomas=Berbel Lars
Clara Ute Sabine
Sven=Beate
Uwe=Tina
Huns Simone
Q. Ensure that your knowledge base correctly answers the following questions.
1. Who are Monika's brothers?
2. Who are Monika's sisters –in –law?
3. Who are Monika's grandparents?
4. Who are Monika's aunts?
5. Who are Clara's grandparents?
6. Who are Simone's grandparents?
7. Who are the parents of Lars?
8. Is Thomas parent of Ute?
9. Who is the grandmother of Ute?
10.Who is the grandmother of Hans?
Solution:
Domains
name=string
Predicates
parent(name,name)
grandparent(name,name)
married(name,name)
brother(name,name)
sister(name,name)
male(name)
female(name)
aunts(name,name)
sisterinlaw(name,name)
grandmother(name,name)
father(name)
notwife(name,name)
Clauses
married(bernd,maria).
married(michael,vera).
married(karl,monika).
married(thomas,berbel).
married(sven,beate).
married(uwe,tina).
parent(maria,michael).
parent(bernd,silke).
parent(bernd,michael).
parent(maria,silke).
parent(michael,monika).
parent(michael,thomas).
parent(michael,lars).
parent(vera,monika).
parent(vera,thomas).
parent(vera,lars).
parent(monika,clara).
parent(karl,clara).
parent(thomas,ute).
parent(thomas,sabine).
parent(berbel,ute).
parent(berbel,sabine).
parent(beate,tina).
parent(sven,tina).
parent(tina,hans).
parent(uwe,hans).
parent(tina,simone).
parent(uwe,simone).
father(bernd).
father(michael).
father(karl).
father(thomas).
father(sven).
father(uwe).
notwife(michael,silke).
notwife(karl,lars).
male(bernd).
male(michael).
male(karl).
male(thomas).
male(ute).
male(sven).
male(uwe).
male(hans).
male(simone).
female(maria).
female(vera).
female(silke).
female(monika).
female(berbel).
female(lars).
female(clara).
female(sabine).
female(beate).
female(tine).
brothers(X,Y):- parent(Z,X),parent(Z,Y),male(X),male(Z).
sis_in_law(X,Y):-brothers(Z,Y),married(Z,X).
grandparents(X,Z):-parent(X,Y),parent(Y,Z).
aunts(X,Y):-brothers(Z,X),female(X),parent(Z,Y).
grandmother(X,Z):-grandparents(X,Z),female(X).
GOAL
goal 1:-
brothers(X,monika).
output:-
X=thomas
X=lars
2 Solutions
goal 2:-
sis_in_law(X,monika).
output:-
X=berbel
1 Solution
goal 3:-
grandparents(X,monika).
output:-
X=bernd
X=maria
2 Solutions
goal 4:-
aunts(X,monika).
output:-
X=silke
1 Solution
goal 5:-
grandparents(X,clara).
output:-
X=michael
X=vera
2 Solutions
goal 6:-
grandparents(X,simone).
output:-
X=sven
X=beate
2 Solutions
goal 7:-
parent(X,lars).
output:-
X=michael
X=vera
2 Solutions
goal 8:-
parent(thomas,ute).
output:-
yes
goal 9:-
grandmother(X,ute).
output:-
X=vera
1 Solution
goal 10:-
grandmother(X,hans).
output:-
X=beate
1 Solution
No comments:
Post a Comment