Prolog, Prolog Programming IN AI. Prolog is an Artificial Intelligence programming language. Prolog is a logic programming language associated with artificial intelligence and computational linguistics. Its applications include natural language understanding and expert systems. Prolog is notably a s...
Prolog, Prolog Programming IN AI. Prolog is an Artificial Intelligence programming language. Prolog is a logic programming language associated with artificial intelligence and computational linguistics. Its applications include natural language understanding and expert systems. Prolog is notably a so-called nonprocedural, or declarative, language.
Rulesareextinctionsoffacts
thatcontainconditional
clauses.Tosatisfyarule
theseconditionsshouldbe
met.
Rules
Andtorunaprolog
program,weneedsome
questions,andthose
questionscanbeanswered
bythegivenfactsandrules
Questions
Factsarestatements
thatdescribeobject
propertiesorrelations
betweenobjects.
Thefactispredicatethat
istrue,forexample,ifwe
say,“Tomisthesonof
Jack”,thenthisisafact.
Facts
Prolog language basically has three different elements −
Facts Rules Queries
Prolog Syntax
The syntax of Prolog is as follows:
relationship(object1,object2)
Prolog
»Example:
»“Arslan owns the book”
»Owns (arslan, book) relationship(object1, object2)
»The relationship has a specific order, arslan own the
book, but the book dose not owns arslan, and this
relationship and its representation above called fact.
11
English Predicate CalculusProlog
If → :-
Not ~ Not
Or V ;
and ^ ,
female,Male,X,Y,mother_of,_father,Pro34
Variableisastring.Thestringcanbeacombinationoflowercaseor
uppercaseletters.Thestringcanalsocontainunderscorecharacters
thatbeginwithanunderscoreoranupper-caseletter.Rulesfor
formingnamesandpredicatecalculusarethesame.
Usingthefollowingtruth-functionalsymbols,theProlog
expressionsarecomprised.Thesesymbolshavethesame
interpretationasinthepredicatecalculus.
Symbols
Variables
Rules extend the logic program capabilities. Rules are used
to provide the decision-making process in Prolog. Rules are
specified in the form:
head:-t1,t2,t3,…..,tk.Wherek>=1
The head is known as the clause of the head.
:-isknownastheclauseneck.It
isreadas'if'.Thebodyofthe
clauseisspecifiedbyt1,t2,t3,…,
tk.Itcontainsoneormore
components,anditcanbe
separatedusingthecommas.A
rulewillreadas'headistrueif
t1,t2,t3,….,tkarealltrue'.
Rules
In the following program, first two lines indicate the facts and last two lines indicate the rules:
dog(pulu).large(pulu).
cat(momo).large(momo).
large_animal(A):-dog(A),large(A).
large_animal(C):-cat(C),large(C).
Theaboverulesmeanthat'large_animal(A)istrueifdog(A)istrue,andlarge(A)istrue,etc.'
Thelastlinemeansthat'large_animal(C)istrueifcat(C)istrue,andlarge(C)istrue.
Facts and Rules make up
the knowledge base.
likes(tarzan, jane).
likes(jane, tarzan).
likes(terk, jane).
facts
Arguments / objects / items
.dot is necessary to end the statement
relation
friends(X,Y):-likes(X,Y), likes(Y,X).
Predicate name
head body
variables
Horn Clause
Example
elephant(george).
elephant(mary).
elephant(X) :-grey(X), mammal(X), hasTrunk(X).
Procedure for elephant
Predicate
Clauses
Rule
Facts
?-elephant(george).
yes
?-elephant(jane).
no
Queries
Replies
Queries
Rules
facts
Example 1 :Belowfoodtable shows the facts, rules, goals and their English meanings.
Queries / Goals
?-food(pizza). // Is pizza a food?
?-meal(X), lunch(X). // Which food is meal and lunch?
?-dinner(sandwich). // Is sandwich a dinner?
Facts English meanings
food(burger). // burger is a food
food(sandwich). // sandwich is a food
food(pizza). // pizza is a food
lunch(sandwich). // sandwich is a lunch
dinner(pizza). // pizza is a dinner
Rule
meal(X) :-food(X).
// Every food is a meal OR
Anything is a meal if it is a food
Queries
Rules
facts
Example 2 :Below student-professor relation table shows the facts, rules, goals and their English meanings.
.
Facts English meanings
studies(charlie, csc135). // charlie studies csc135
studies(olivia, csc135). // oliviastudies csc135
studies(jack, csc131). // jack studies csc131
studies(arthur, csc134).
likes('John', car(bmw))
// arthur studies csc134
// Read as : john likes bmwcar
gives(john, chocolate, jane). // Read as : john gives chocolate to jane
Rules
professor(X, Y) :-
teaches(X, C),studies(Y, C).
// X is a professor of Y if X teaches
C and Y studies C.
Queries / Goals
?-studies(charlie, What).
// charlie studies what? OR
What does charlie study?
?-professor(kirke, Students).
// Who are the students of
professor kirke.
Here are some simple clauses.
The following queries yield the specified answers.
How do you add the following facts?
likes(mary,food).
likes(mary,juice).
likes(john,juice).
likes(john,mary).
| ?-likes(mary,food).
yes.
| ?-likes(john,juice).
yes.
| ?-likes(john,food).
no.
John likes anything that Mary likes
John likes anyone who likes juice
John likes anyone who likes themselves
Example 3 :
Some Applications of Prolog
Prologisusedinvarious
domains.Itplaysavitalrolein
automationsystem.Following
aresomeotherimportant
fieldswherePrologisused−
Prologisusedinvarious
domains.Itplaysavitalrolein
automationsystem.Following
aresomeotherimportant
fieldswherePrologisused−
•IntelligentDatabaseRetrieval
•NaturalLanguageUnderstanding
•SpecificationLanguage
•MachineLearning
•RobotPlanning
•AutomationSystem
•Problem Solving
•Expert Systems
What is
Prolog used
for
Good at
▪Grammars and Language processing,
▪Knowledge representation and reasoning,
▪Unification,
▪Pattern matching,
▪Planning and Search.
i.e. Prolog is good at Symbolic AI.
?
23
Advantages :
1.Easy to build database. Doesn’t
need a lot of programming effort
2.Pattern matching is easy.
Search is recursion based
.3.Ithasbuiltinlisthandling.
Makesiteasiertoplaywith
anyalgorithminvolvinglists.
2.Sometimes input and output is
not easy.
Disadvantages :
1.LISP(anotherlogic
programming language)
dominatesoverprologwith
respecttoI/Ofeatures
3. Repetitive number crunching,
Representing complex data
structures,
Input/output (interfaces).