Artificial Intelligence: Introduction To Prolog
Artificial Intelligence: Introduction To Prolog
INTELLIGENCE
Introduction to Prolog
Prolog
◦ PROgramming LOGic
◦ Main applications:
◦ Artificial Intelligence: expert systems, natural language
processing, …
and ,
or ;
implication :-
not not
Prolog as Logic
◦ Logic formula:
◦ Logic OR – AB : A;B.
◦ likes(george, kate).
◦ likes(george, susie).
◦ likes(george, chocolate).
◦ likes(susie, chocolate).
◦ likes(kate, sushi).
◦ likes(kate, susie).
Queries given about the
database
◦ ?- likes(george, kate).
◦ yes
◦ ?- likes(kate, susie).
◦ yes
◦ ?- likes(george, X).
◦ X = kate
◦ ;
◦ X = susie
◦ ;
◦ X = chocolate
◦ ;
◦ no
Defining Rules
◦ Only one predicate is permitted on the left hand side
◦ ?- friends(george, susie).
◦ yes
A Simple Rule
◦ English description:
◦ If X is male, F is a father of X, M is a mother of X, F is a father of Y, M is a
mother of Y then X is a brother of Y.
◦ Logic Formula:
◦ male(X) father(F,X) mother(M,X) father(F,Y) mother(M,Y) →
brother(X,Y)
◦ Prolog:
◦ Brother(X,Y) :- male(X), father(F,X), mother(M,X), father(F,Y),
mother(M,Y).
Another example
◦ Facts
◦ bigger(elephant, horse).
◦ bigger(horse, donkey).
◦ bigger(donkey, dog).
◦ bigger(donkey, monkey).
◦ Queries
◦ ?- bigger(donkey, dog).
◦ Yes
◦ ?- bigger(monkey, elephant).
◦ No
Another example
◦ Facts
◦ bigger(elephant, horse).
◦ bigger(horse, donkey).
◦ bigger(donkey, dog).
◦ bigger(donkey, monkey).
◦ Queries
◦ ?- bigger(elephant, monkey).
◦ No