SlideShare une entreprise Scribd logo
1  sur  73
Télécharger pour lire hors ligne
Introduction to Prolog
Different programming languages to
implement AI problem
 AIML (Artificial Intelligence Markup Language)
 IPL (Information Processing Language)
 LISP
 PROLOG (Programming in Logic)
 Planner
 Haskell
 Wolfram Language
History of prolog
 developed in 1972
 by Alain Colmerauer and P. Roussel
 at the University of Marseilles in France.
Prolog
 Prolog is programming language.
 Prolog (pro + log = programming in logic)
 Prolog = logic + programming
The Family Tree
Who is father of Roy?
Bob is male.
May is Female.
Bo is Jill’s brother.
Kath is Bo’s sister.
Bo is father of Ali.
Ron is brother of Ali.
Ali is sister of Ron.
Bo is husband of Joy.
Joy is Bo’s wife.
Ben id Jill’s husband.
Jill is Ben’s wife.
Bo is father of Roy.
Jeff is kath’s husband.
Kath is Jeff’s wife.
Tim is brother of Roy.
Beth is daughter of Jeff and Kath.
Tim is son of Jeff and Kath .
Declarative v/s Imperative
Declarative Language Imperative Language
Programmer specifies what is to be
computed
Programmer specifies how this to be
computed
A set of statements A sequence of commands
Can be divided in to Functional
Language and Logic Programming
Divided in to procedural Language and
Object Oriented Language
Logic Programming (PROLOG)
Functional Language (Haskell)
Procedural Language (C , PASCAL)
Object Oriented Language (C++, Java)
Why Prolog in Intelligent?
Because…..
It approaches the
problems in the
same way that the
human does.
Applications for prolog
• Expert Systems
• Natural Language Processing
• Robotics
• Gaming and Simulation
Facts, Objects and Predicates
Collection of knowledge - database
 The main part of prolog program consist of collection
of knowledge about specific subject.
 This collection is known as database.
 Database can be expressed in facts and rules.
Knowledge Base
Bob is male.
Bo is father of Ron.
Statements like this is known as facts.
Natural Language Translation in Prolog
Bob is male. Male(bob).
May is Female. Female(May).
Bo is Jill’s brother. Brother(Bo,Jill).
Bo is husband of Joy. Husband(Bo,Joy).
Jill is Ben’s wife. Wife(Jill,Ben).
Jeff is kath’s husband Husband(Jeff,Kath).
Beth is daughter of Jeff and Kath. Daughter(Beth,Jeff,Kath).
Expressing Facts
 English- The right speaker is dead.
Prolog- is (right_speaker, dead)
 English- Bill is an employee.
Prolog- employee(Bill)
 English- Bob is married to Marry.
Prolog- married_to(bob,mary)
 English- The speaker is defective.
Prolog- defective(speaker)
 English- Tom is student.
Prolog- student(Tom)
 English- Ganesh is son of Shiva and Parvati.
Prolog- son(Ganesh, Shiva, Parvati)
Some Facts about “Fact”
 Full stop “.” at the end of every fact.
 Functors must begin with a small letter.
 There must never be a space between the functor and the
opening bracket!
 The number of argument in a fact is called “arity”.
 Eg. Female (mary) is an instance of female/1.
 Where female is functor and 1 is arity.
 Husband(Jeff,Kath) is an instance of Husband/2.
 Daughter(Beth,Jeff,Kath) is an instance of daughter/3.
 Arity is useful to say female/1 is different than female/2.
clause
Clause
Facts Rules
clauses
 In Prolog, rules (and facts) are called clauses.
 Clause in Prolog is a unit of information in a Prolog
program ending with a full stop ("."). A clause may
be a fact, like:
likes(mary, pizza).
food(pizza).
 Notice the period at the end of clause.
 The above clauses are also known as base clause.
predicates
Facts Rules
Predicates Periods
Clause
Predicate
 Has_a(bill,computer).
 The entire expression before the period (.) is known
as predicate.
 A predicate is a function with a value of true or false.
 Predicate express a property or a relationship.
 Here “has_a” is name of predicate.
Relations
clauses
Facts Rules
Predicates Periods
Relations Arguments
Relations
 is (reight_speaker,dead)
 The Word “is” is the relation in the example.
 A relation is a name that defines the way in which a
collection of objects (or objects and variables
referring to objects) belong together.
Fact Relation
has_a(bill,computer). has_a
is_a(collie,dog). is_a
likes(sue,chocolate). likes
Argument
 Employee(bill)
 Eligible(mary)
 Marital_status(joyce,married)
 The elements within the parenthesis are arguments
of the predicate.
Arguments
clauses
Facts Rules
Predicates Periods
Relations Arguments
Object Variable
Object and variable
 Is(right_speaker,dead)
 An object is the name of an element of a certain type.
 It represents an entity or a property of an entity in
the real world.
 Here right_speaker and dead are object
 Likes(X,Y)
 Here X and Y are variable with specific data type.
Several Things about clauses
 A given relation can have any number of objects. A predicate
can have any number of arguments, including zero. The
number of argument is called the arity of the predicate.
 An object name can represent a physical entity (Bob,
automobiles) or an abstract concept (defective). It can be a
noun, adverb or adjective. Indeed, it can any sequence of
characters.
 Objects are always singular. Ex, automobiles is considered as
singular object.
 Certain names are reserved in Prolog and should not be used
for object names. Ex, abs, not, fail ,if , display
 The prolog expression does not have to contain all the words
of the English expression.
Think and give Answer…
 Likes( tom, janet)
 Likes( janet , tom)
 Both predicates are same????
First prolog program
Parts of Prolog Program
 A standard prolog program consist of 4 parts.
1. Domains
2. Predicates
3. Clauses
4. goal
Structure of Prolog Program
/* comments */
% A full line comment
domains
// ….. //
predicates
//………….//
clauses
//………….//
Goal
//……………..//
Turbo Prolog domain Type
 Char : Single character enclosed between single
quotation mars. Ex: ‘A’ , ’X’ , ’W’
 Integer: Integer from -32768 to +32768
Ex : 1, 735,1001
 Real : floating point number
Ex: 2.54, 6,78
 Symbol : character sequence of letters, numbers and
underscores with the first character as lower case
letter. Ex: status, disease
 File: symbolic file name. Ex, file.txt
Domains
 Frank is a male who is 45 years old.
person(Frank,male,45)
person(symbol , symbol , integer)
domains
Name , gender=symbol
Age=integer
domains
 The domains section is where you declare any
domains you're using that aren't Prolog's standard
domains.
 Domains enable you to give distinctive names to
different kinds of data that would otherwise look
alike.
 It is sometimes useful to declare a domain when you
want to clarify portions of the predicates section.
Declaring your own domains helps document the
predicates that you define by giving a useful name to
the argument type.
Predicates
 Frank is a male who is 45 years old.
person(Frank,male,45)
person(symbol , symbol , integer)
predicates
person(symbol , symbol , integer)
 Frank is a male who is 45 years old.
person(Frank,male,45)
person(symbol , symbol , integer)
Predicates
 If you define your own predicate in
the clauses section of a Prolog program,
you must declare it in a predicates section,
or Prolog won't know what you're talking about.
 When you declare a predicate, you
tell Prolog which domains the arguments of that
predicate belong to.
 You don't need to declare any of Prolog's built-
in predicates that you use in your program
clauses : An instance of predicate
 Frank is a male who is 45 years old.
person(Frank,male,45)
clauses
person(frank,male,45)
person(sue,female,26)
person(bob,male,39)
clauses
 The clauses section is where you put all the facts and
rules that make up your program.
 Clauses for a given predicate must be placed
together in the clauses section; a sequence of clauses
defining a predicate is called a procedure.
A simple Family Tree without Rules
Goal:
1. female(sophia)
2. Parent(charles, james)
3. Male(james)
4. Parent(george, charles)
5. Female(charles)
domains
mname , fname = symbol
Predicates
male(mname)
female(fname)
clauses
male(james).
male(charles).
male(charles).
male(james).
male(george).
female(catherine).
female(elizabeth).
female(sophia).
parent(charles, james).
parent(elizabeth, james).
parent(charles2, charles).
parent(catherine, charles).
parent(james, charles).
parent(sophia, elizabeth).
parent(george, sophia).
A simple Prolog Program
domains
disease , indication=symbol
predicates
sympton(disease,indication)
clauses
sympton(chicken_pox,high_fever).
sympton(chicken_pox, chills).
sympton(flu,chills).
sympton(cold,mild_body_ache).
sympton(cold, runny_nose).
sympton(flu,runny_nose).
sympton(flu,moderate_cough).
Goal: sympton(cold , runny_nose) True
Introduction To Term and different
data structures in Prolog
Term
 Data structures in PROLOG = Terms
 Term is a basic data structure in Prolog.
i.e., everything including program and data is
expressed in form of term.
 The generic name for all forms of Prolog data is
"term".
Prolog Data structure/Data Type
Term/data object
simple object structure
constants variables
Atoms numbers
Atom
 Atom is non-numeric literal constants.
 Atom can be constructed in three ways.
 Atoms can be strings of following characters.
1. upper-case letters (A,B,…..Z)
2. Lowe-case lettres (a,b,…..z)
3. Digits (0,1,2….9)
4. Special characters (+ , _ , * , / , < , > , = , : , . , & , _ , ~ )
Atom
1. String of letters , digits and underscore character, ‘_’
starting with a lowercase letter.
Ex, anna
nil
x25
x_25
x_25AB
x_
x_ _y
alpha_beta_procedure
miss_Jones
sarah_jones
Atom
2. Strings of special characters
Ex, <--->
======>
…
::=
When using atom of this form, some care is necessary
because some string of special characters already
have a predefined meaning; an example is ‘:-’
Atom
3. String of characters enclosed in single quotes.
This is useful if we want, for ex, to have an atom that
starts with a capital letter.
Ex, ‘Tom’
‘South_America’
‘Sarah Jones’
Confusing!!!!! How????
Atoms and arguments are different things! Atoms
may be used as arguments but not all arguments are
automatically atoms!
Number
 Number include integer numbers and real numbers.
Ex, 1
1313
0
-97
3.14
-0.0035
100.2
Variables
 Variables are string of letters, digits and underscore
characters. They are start with an upper-case letter
or and underscore character.
Ex, X
Result
Object2
Participant_list
ShoppingList
_x23
_23
Ground Term
 The variable free term is known as ground term.
 Ex,
person(peter, mueller, date(27, 11, 2007))
Prolog Program
domains
disease , indication=symbol
predicates
sympton(disease,indication)
clauses
sympton(chicken_pox,high_fever).
sympton(chicken_pox, chills).
sympton(flu,chills).
sympton(cold,mild_body_ache).
sympton(cold, runny_nose).
sympton(flu,runny_nose).
sympton(flu,moderate_couh).
Goal: sympton(Disease, runny_nose)
Disease=cold
Disease=flu
2 solutions
Anonymous Variable / Don’t care variable
 Goal: symptom(_,chills)
True
 Goal: likes(jane,_). (Jane likes everything)
 Because there is no variable, there is no binding; if prolog
program can match the relation name and the last
argument, the goal succeeds.
 Prolog doesn’t tell you which disease had the symptom
chills, as it would have if you had used ordinary variable.
 Note that in a clause, the anonymous variable stands for
all values, while in a goal it is satistied if at least one
value corresponds to it.
Think Think….
 Can we use underscore in a clause ??
 If yes, what is impact of it…
Structure
 Structure objects are objects that have several components.
 The components themselves can, in turn be structure.
 For ex, the date can be viewed as structure with three
components: day,month,year.
 Although composed of several components , structures are
treated in the program as single objects.
 In order to combine the component into single we choose a
functor.
 For Ex, date(1,may,2001)
 All the components in this example are constants (2 integer
and one atom).
 Date is functor.
Which of the following are syntactically correct
prolog object? What kind of object are they?
1. Diana
2. diana
3. ‘Diana’
4. _diana
5. ‘Diana goes south’
6. goes(diana,south)
7. 45
8. 5(X,Y)
9. +(north,west)
10. three(Black(Cats))
1. Variable
2. atom
3. atom
4. variable
5. atom
6. structure
7. number
8. incorrect
9. structure
10. structure
Compound Goal
domains
disease , indication=symbol
predicates
sympton(disease,indication)
clauses
sympton(chicken_pox,high_fever).
sympton(chicken_pox, chills).
sympton(flu,chills).
sympton(cold,mild_body_ache).
sympton(cold, runny_nose).
sympton(flu,runny_nose).
sympton(flu,moderate_couh).
Goal: symptom(Disease,runny_nose) and
symptom(Disease,mild_body_ache)
Disease=cold
1 solution
True
Prolog
work from
left to
right for
proving
compound
goal.
Backtracking : Heart of Prolog Program
domains
disease , indication=symbol
predicates
sympton(disease,indication)
clauses
sympton(chicken_pox,high_fever).
symptom(viral_syndrom,mild_body_ache)
sympton(chicken_pox, chills).
sympton(flu,chills).
sympton(cold, runny_nose).
sympton(flu,runny_nose).
sympton(flu,moderate_couh).
Symptom(viral_syndrom,runny_nose).
Goal: symptom(Disease,runny_nose) and
symptom(Disease,mild_body_ache)
Disease=cold
Disease=flu
Disease=
viral_syndrom
Backtracking
 The solution of compound goal proceeds from left to
right
 If any condition in the chain fails, prolog backtracks
to the previous condition, tries to prove it again with
another variable binding, then moves forward again
to see if the failed condition will succeed with the
new binding,
 Prolog moves relentlessly forward and backward
through the conditions, trying every variable binding
in an attempt to get the goal to succeed in many ways
as possible.
Rules in Prolog
Rules
 A rule is an expression that indicates that the truth of
a particular fact depends upon one or more other
facts.
 Ex,
A and B are sisters if
A and B are both female and
they have the same father and
they have the same mother and
A is not the same as B
 Sister(A,B):-
female(A),female(B),father(X,A),father(X,B),mother
(Y,A),mother(Y,B),not_same(A,B).
Rules
 The symbol ‘ :- ‘ is known as turnstile or break
operator.
 ‘ :- ’ is pronounced as ‘ If ’.
 Syntax:
head_of_the_rule :- body_of_the_rule
(a.k.a) (a.k.a)
conclusion antecedent
(consist of)
premises 1,premises 2, …premises n
Rules
 Each premises are connected by the word ‘and’ or
‘conjunction’ (^).
 The ‘goal’ is true if all the conditions specified for the
goal are true.
 If all the premises are true, the conclusion is true; if
any premises fails the conclusion fails.
 A rule expresses a relationship between facts. Any
given prolog program is simply a database
(collection of clauses) of facts and rules.
Conjunction and disjunction in rule
 A comma expresses an ‘and’ relationship and
semicolon expresses an ‘or’ relationship.
 Holiday in college if
there is Sunday or
there is public holiday
 Holiday(college):-day(Sunday);day(public_holiday)
OR
Holiday(college):-day(Sunday).
Holiday(college):-day(public_holiday)
Formal Reasoning
 The process of using rules and facts to solve a
problem is called formal reasoning.
Some important points about prolog execution
Rules
 In medical diagnosis system you have seen how the
variable are used.
 There are no “global” variable; that is, variables that
maintain a value throughout the entire program’s
execution.
 A variable is local to the clause of which they are part.
 Even if the same variable name is used in another clause ,
it is not the same variable.
 Ex, daughter(X):-father(Roy),mother(Sue).
daughter(X):-father(Bob),mother(Lice).
A term is said to be unify if…..
 Unification is a pattern matching process.
1. Both terms appear in predicates that have the same
number of arguments (i.e. same arity), and both
terms appear in the same position in their
predicate.
2. Both terms appear as argument of the same type - a
symbol type can only unify with a symbol and so
on.
3. All subterms unify with each other .
Rules for Unification (1)
1. A variable that is free will unify with any term that
satisfies the preceding conditions. After unification, the
variable is bound to the value of the term.
likes(ron,br0om).
likes(harry,X):-likes(ron,X).
Goal: likes(harry,broom)
Here Variable X is bounded with the value Broom.
Rules for Unification (2)
2. A constant can unify with itself or any free variable.
If the constant is unified with variable, the variable
will be bound to the value of the constant.
Ex, likes(harry,school).
Goal : likes(harry,school)
Ex, likes(harry,school).
Goal: likes(harry,X).
Rules for Unification (3)
3. A free variable will unify with any other free
variable. After unifying, the two variable will act as
one. If one of the variable becomes bound, the other
will be bound to the same value.
Ex,
likes(ron,broom).
likes(harry,X):-likes(ron,X).
Goal: likes(harry,broom).
Instantiation & Unification Exercise
Unify With Result
Likes(jem,piano) Likes(jem,X) X=piano
yes
Likes(jem,X) Likes(Y,piano) Y=jem
yes
Unifiability : Binding, substitution and unifiers
 Testing equality of terms with variables:
 Terms T1 and T2 are unifiable if there is a substitution that makes them
equal!
 A binding is an association of a variable to a term .
Two sample bindings: Name mueller and MM 11
 A substitution is a set of bindings
A sample substitution: {Name mueller, MM 11 }
 A unifier is a substitution that makes two terms equal
The above substitution is a unifier for the two person/3 terms above
The ‘not’ predicate
 To explicitly express that in the database particular
fact is not true.
 To try this use built-in ‘not’ predicate.
 The ‘not’ predicate cannot be used to express a fact
or appear in the head of a rule. It can only be used in
a premises.
 Ex, replace(right_speaker) :-
not(is(right_speaker,functional).
 In the case if is(right_speaker,functional) is in
database the rule will fail.
‘not’ predicate
 Be careful in your program design to distinguish
between the use of the not predicate and the
omission of facts from the databse.
 If a fact is not in the database, prolog considers it
false.
 However this falsity based on absence from the
database is not sufficient to prove a not premise.
 The absence of the is fact above would not prove the
not premise in the rule.
Which are the connectors available that connects
the clauses
 implication (:-)
 conjunction (,)
 disjunction (;)
Scope of variable in prolog
 The scope of a variable is the clause in which it
appears

Contenu connexe

Tendances

5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programmingKrish_ver2
 
Prolog Programming Language
Prolog Programming  LanguageProlog Programming  Language
Prolog Programming LanguageReham AlBlehid
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
Seq2Seq (encoder decoder) model
Seq2Seq (encoder decoder) modelSeq2Seq (encoder decoder) model
Seq2Seq (encoder decoder) model佳蓉 倪
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementEelco Visser
 
Backtracking Algorithm.ppt
Backtracking Algorithm.pptBacktracking Algorithm.ppt
Backtracking Algorithm.pptSalmIbrahimIlyas
 
Compter les triangles en PROLOG
Compter les triangles en PROLOGCompter les triangles en PROLOG
Compter les triangles en PROLOGJean Rohmer
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and LexemeA. S. M. Shafi
 
系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作鍾誠 陳鍾誠
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingSaranya saran
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog LanguageREHMAT ULLAH
 
Nlp toolkits and_preprocessing_techniques
Nlp toolkits and_preprocessing_techniquesNlp toolkits and_preprocessing_techniques
Nlp toolkits and_preprocessing_techniquesankit_ppt
 
Prolog (present)
Prolog (present) Prolog (present)
Prolog (present) Melody Joey
 
5. phases of nlp
5. phases of nlp5. phases of nlp
5. phases of nlpmonircse2
 

Tendances (20)

5. phase of nlp
5. phase of nlp5. phase of nlp
5. phase of nlp
 
Frames
FramesFrames
Frames
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
Prolog Programming Language
Prolog Programming  LanguageProlog Programming  Language
Prolog Programming Language
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Seq2Seq (encoder decoder) model
Seq2Seq (encoder decoder) modelSeq2Seq (encoder decoder) model
Seq2Seq (encoder decoder) model
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
 
First order logic
First order logicFirst order logic
First order logic
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Backtracking Algorithm.ppt
Backtracking Algorithm.pptBacktracking Algorithm.ppt
Backtracking Algorithm.ppt
 
Compter les triangles en PROLOG
Compter les triangles en PROLOGCompter les triangles en PROLOG
Compter les triangles en PROLOG
 
Introduction to Prolog
Introduction to PrologIntroduction to Prolog
Introduction to Prolog
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog Language
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Nlp toolkits and_preprocessing_techniques
Nlp toolkits and_preprocessing_techniquesNlp toolkits and_preprocessing_techniques
Nlp toolkits and_preprocessing_techniques
 
Prolog (present)
Prolog (present) Prolog (present)
Prolog (present)
 
5. phases of nlp
5. phases of nlp5. phases of nlp
5. phases of nlp
 

Similaire à Prolog PPT_merged.pdf

UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptxUOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptxqasim ali
 
PROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG CONTENT
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prologsaru40
 
Ilja state2014expressivity
Ilja state2014expressivityIlja state2014expressivity
Ilja state2014expressivitymaartenmarx
 
Jarrar.lecture notes.aai.2011s.ch8.fol.introduction
Jarrar.lecture notes.aai.2011s.ch8.fol.introductionJarrar.lecture notes.aai.2011s.ch8.fol.introduction
Jarrar.lecture notes.aai.2011s.ch8.fol.introductionPalGov
 
Overview prolog
Overview prologOverview prolog
Overview prologFraboni Ec
 
Adding Semantics to Ontologies
Adding Semantics to OntologiesAdding Semantics to Ontologies
Adding Semantics to OntologiesCristiano Longo
 
Overview prolog
Overview prologOverview prolog
Overview prologDavid Hoen
 

Similaire à Prolog PPT_merged.pdf (20)

UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptxUOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
 
AI Lab Manual.docx
AI Lab Manual.docxAI Lab Manual.docx
AI Lab Manual.docx
 
PROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In Prolog
 
IKL survey
IKL surveyIKL survey
IKL survey
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
Ilja state2014expressivity
Ilja state2014expressivityIlja state2014expressivity
Ilja state2014expressivity
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
 
Semantics
SemanticsSemantics
Semantics
 
Jarrar.lecture notes.aai.2011s.ch8.fol.introduction
Jarrar.lecture notes.aai.2011s.ch8.fol.introductionJarrar.lecture notes.aai.2011s.ch8.fol.introduction
Jarrar.lecture notes.aai.2011s.ch8.fol.introduction
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
prolog ppt
prolog pptprolog ppt
prolog ppt
 
Inteligencia artificial
Inteligencia artificialInteligencia artificial
Inteligencia artificial
 
Overview prolog
Overview prologOverview prolog
Overview prolog
 
Overview prolog
Overview prologOverview prolog
Overview prolog
 
Adding Semantics to Ontologies
Adding Semantics to OntologiesAdding Semantics to Ontologies
Adding Semantics to Ontologies
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
Overview prolog
Overview prologOverview prolog
Overview prolog
 
Overview prolog
Overview prologOverview prolog
Overview prolog
 
Overview prolog
Overview prologOverview prolog
Overview prolog
 

Plus de 20CE112YASHPATEL

InternetOFThings_network_communicqtionCoAP_.pptx
InternetOFThings_network_communicqtionCoAP_.pptxInternetOFThings_network_communicqtionCoAP_.pptx
InternetOFThings_network_communicqtionCoAP_.pptx20CE112YASHPATEL
 
Data_Processing_and_communication_bluetooth.pptx
Data_Processing_and_communication_bluetooth.pptxData_Processing_and_communication_bluetooth.pptx
Data_Processing_and_communication_bluetooth.pptx20CE112YASHPATEL
 
Communication Technologies in IOT.pptx
Communication Technologies in IOT.pptxCommunication Technologies in IOT.pptx
Communication Technologies in IOT.pptx20CE112YASHPATEL
 
Network_Layer_and_Internet_Protocols_IPv.pptx
Network_Layer_and_Internet_Protocols_IPv.pptxNetwork_Layer_and_Internet_Protocols_IPv.pptx
Network_Layer_and_Internet_Protocols_IPv.pptx20CE112YASHPATEL
 
Money Manager Presentation-2.pptx
Money Manager Presentation-2.pptxMoney Manager Presentation-2.pptx
Money Manager Presentation-2.pptx20CE112YASHPATEL
 

Plus de 20CE112YASHPATEL (8)

InternetOFThings_network_communicqtionCoAP_.pptx
InternetOFThings_network_communicqtionCoAP_.pptxInternetOFThings_network_communicqtionCoAP_.pptx
InternetOFThings_network_communicqtionCoAP_.pptx
 
Data_Processing_and_communication_bluetooth.pptx
Data_Processing_and_communication_bluetooth.pptxData_Processing_and_communication_bluetooth.pptx
Data_Processing_and_communication_bluetooth.pptx
 
DLP_Presentation.pptx
DLP_Presentation.pptxDLP_Presentation.pptx
DLP_Presentation.pptx
 
Communication Technologies in IOT.pptx
Communication Technologies in IOT.pptxCommunication Technologies in IOT.pptx
Communication Technologies in IOT.pptx
 
RFID.pptx
RFID.pptxRFID.pptx
RFID.pptx
 
Network_Layer_and_Internet_Protocols_IPv.pptx
Network_Layer_and_Internet_Protocols_IPv.pptxNetwork_Layer_and_Internet_Protocols_IPv.pptx
Network_Layer_and_Internet_Protocols_IPv.pptx
 
Project.pptx
Project.pptxProject.pptx
Project.pptx
 
Money Manager Presentation-2.pptx
Money Manager Presentation-2.pptxMoney Manager Presentation-2.pptx
Money Manager Presentation-2.pptx
 

Dernier

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 

Dernier (20)

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 

Prolog PPT_merged.pdf

  • 2. Different programming languages to implement AI problem  AIML (Artificial Intelligence Markup Language)  IPL (Information Processing Language)  LISP  PROLOG (Programming in Logic)  Planner  Haskell  Wolfram Language
  • 3. History of prolog  developed in 1972  by Alain Colmerauer and P. Roussel  at the University of Marseilles in France.
  • 4. Prolog  Prolog is programming language.  Prolog (pro + log = programming in logic)  Prolog = logic + programming
  • 6. Who is father of Roy? Bob is male. May is Female. Bo is Jill’s brother. Kath is Bo’s sister. Bo is father of Ali. Ron is brother of Ali. Ali is sister of Ron. Bo is husband of Joy. Joy is Bo’s wife. Ben id Jill’s husband. Jill is Ben’s wife. Bo is father of Roy. Jeff is kath’s husband. Kath is Jeff’s wife. Tim is brother of Roy. Beth is daughter of Jeff and Kath. Tim is son of Jeff and Kath .
  • 7. Declarative v/s Imperative Declarative Language Imperative Language Programmer specifies what is to be computed Programmer specifies how this to be computed A set of statements A sequence of commands Can be divided in to Functional Language and Logic Programming Divided in to procedural Language and Object Oriented Language Logic Programming (PROLOG) Functional Language (Haskell) Procedural Language (C , PASCAL) Object Oriented Language (C++, Java)
  • 8. Why Prolog in Intelligent? Because….. It approaches the problems in the same way that the human does.
  • 9. Applications for prolog • Expert Systems • Natural Language Processing • Robotics • Gaming and Simulation
  • 10. Facts, Objects and Predicates
  • 11. Collection of knowledge - database  The main part of prolog program consist of collection of knowledge about specific subject.  This collection is known as database.  Database can be expressed in facts and rules.
  • 12. Knowledge Base Bob is male. Bo is father of Ron. Statements like this is known as facts. Natural Language Translation in Prolog Bob is male. Male(bob). May is Female. Female(May). Bo is Jill’s brother. Brother(Bo,Jill). Bo is husband of Joy. Husband(Bo,Joy). Jill is Ben’s wife. Wife(Jill,Ben). Jeff is kath’s husband Husband(Jeff,Kath). Beth is daughter of Jeff and Kath. Daughter(Beth,Jeff,Kath).
  • 13. Expressing Facts  English- The right speaker is dead. Prolog- is (right_speaker, dead)  English- Bill is an employee. Prolog- employee(Bill)  English- Bob is married to Marry. Prolog- married_to(bob,mary)  English- The speaker is defective. Prolog- defective(speaker)  English- Tom is student. Prolog- student(Tom)  English- Ganesh is son of Shiva and Parvati. Prolog- son(Ganesh, Shiva, Parvati)
  • 14. Some Facts about “Fact”  Full stop “.” at the end of every fact.  Functors must begin with a small letter.  There must never be a space between the functor and the opening bracket!  The number of argument in a fact is called “arity”.  Eg. Female (mary) is an instance of female/1.  Where female is functor and 1 is arity.  Husband(Jeff,Kath) is an instance of Husband/2.  Daughter(Beth,Jeff,Kath) is an instance of daughter/3.  Arity is useful to say female/1 is different than female/2.
  • 16. clauses  In Prolog, rules (and facts) are called clauses.  Clause in Prolog is a unit of information in a Prolog program ending with a full stop ("."). A clause may be a fact, like: likes(mary, pizza). food(pizza).  Notice the period at the end of clause.  The above clauses are also known as base clause.
  • 18. Predicate  Has_a(bill,computer).  The entire expression before the period (.) is known as predicate.  A predicate is a function with a value of true or false.  Predicate express a property or a relationship.  Here “has_a” is name of predicate.
  • 20. Relations  is (reight_speaker,dead)  The Word “is” is the relation in the example.  A relation is a name that defines the way in which a collection of objects (or objects and variables referring to objects) belong together. Fact Relation has_a(bill,computer). has_a is_a(collie,dog). is_a likes(sue,chocolate). likes
  • 21. Argument  Employee(bill)  Eligible(mary)  Marital_status(joyce,married)  The elements within the parenthesis are arguments of the predicate.
  • 23. Object and variable  Is(right_speaker,dead)  An object is the name of an element of a certain type.  It represents an entity or a property of an entity in the real world.  Here right_speaker and dead are object  Likes(X,Y)  Here X and Y are variable with specific data type.
  • 24. Several Things about clauses  A given relation can have any number of objects. A predicate can have any number of arguments, including zero. The number of argument is called the arity of the predicate.  An object name can represent a physical entity (Bob, automobiles) or an abstract concept (defective). It can be a noun, adverb or adjective. Indeed, it can any sequence of characters.  Objects are always singular. Ex, automobiles is considered as singular object.  Certain names are reserved in Prolog and should not be used for object names. Ex, abs, not, fail ,if , display  The prolog expression does not have to contain all the words of the English expression.
  • 25. Think and give Answer…  Likes( tom, janet)  Likes( janet , tom)  Both predicates are same????
  • 27. Parts of Prolog Program  A standard prolog program consist of 4 parts. 1. Domains 2. Predicates 3. Clauses 4. goal
  • 28. Structure of Prolog Program /* comments */ % A full line comment domains // ….. // predicates //………….// clauses //………….// Goal //……………..//
  • 29. Turbo Prolog domain Type  Char : Single character enclosed between single quotation mars. Ex: ‘A’ , ’X’ , ’W’  Integer: Integer from -32768 to +32768 Ex : 1, 735,1001  Real : floating point number Ex: 2.54, 6,78  Symbol : character sequence of letters, numbers and underscores with the first character as lower case letter. Ex: status, disease  File: symbolic file name. Ex, file.txt
  • 30. Domains  Frank is a male who is 45 years old. person(Frank,male,45) person(symbol , symbol , integer) domains Name , gender=symbol Age=integer
  • 31. domains  The domains section is where you declare any domains you're using that aren't Prolog's standard domains.  Domains enable you to give distinctive names to different kinds of data that would otherwise look alike.  It is sometimes useful to declare a domain when you want to clarify portions of the predicates section. Declaring your own domains helps document the predicates that you define by giving a useful name to the argument type.
  • 32. Predicates  Frank is a male who is 45 years old. person(Frank,male,45) person(symbol , symbol , integer) predicates person(symbol , symbol , integer)  Frank is a male who is 45 years old. person(Frank,male,45) person(symbol , symbol , integer)
  • 33. Predicates  If you define your own predicate in the clauses section of a Prolog program, you must declare it in a predicates section, or Prolog won't know what you're talking about.  When you declare a predicate, you tell Prolog which domains the arguments of that predicate belong to.  You don't need to declare any of Prolog's built- in predicates that you use in your program
  • 34. clauses : An instance of predicate  Frank is a male who is 45 years old. person(Frank,male,45) clauses person(frank,male,45) person(sue,female,26) person(bob,male,39)
  • 35. clauses  The clauses section is where you put all the facts and rules that make up your program.  Clauses for a given predicate must be placed together in the clauses section; a sequence of clauses defining a predicate is called a procedure.
  • 36. A simple Family Tree without Rules Goal: 1. female(sophia) 2. Parent(charles, james) 3. Male(james) 4. Parent(george, charles) 5. Female(charles) domains mname , fname = symbol Predicates male(mname) female(fname) clauses male(james). male(charles). male(charles). male(james). male(george). female(catherine). female(elizabeth). female(sophia). parent(charles, james). parent(elizabeth, james). parent(charles2, charles). parent(catherine, charles). parent(james, charles). parent(sophia, elizabeth). parent(george, sophia).
  • 37. A simple Prolog Program domains disease , indication=symbol predicates sympton(disease,indication) clauses sympton(chicken_pox,high_fever). sympton(chicken_pox, chills). sympton(flu,chills). sympton(cold,mild_body_ache). sympton(cold, runny_nose). sympton(flu,runny_nose). sympton(flu,moderate_cough). Goal: sympton(cold , runny_nose) True
  • 38. Introduction To Term and different data structures in Prolog
  • 39. Term  Data structures in PROLOG = Terms  Term is a basic data structure in Prolog. i.e., everything including program and data is expressed in form of term.  The generic name for all forms of Prolog data is "term".
  • 40. Prolog Data structure/Data Type Term/data object simple object structure constants variables Atoms numbers
  • 41. Atom  Atom is non-numeric literal constants.  Atom can be constructed in three ways.  Atoms can be strings of following characters. 1. upper-case letters (A,B,…..Z) 2. Lowe-case lettres (a,b,…..z) 3. Digits (0,1,2….9) 4. Special characters (+ , _ , * , / , < , > , = , : , . , & , _ , ~ )
  • 42. Atom 1. String of letters , digits and underscore character, ‘_’ starting with a lowercase letter. Ex, anna nil x25 x_25 x_25AB x_ x_ _y alpha_beta_procedure miss_Jones sarah_jones
  • 43. Atom 2. Strings of special characters Ex, <---> ======> … ::= When using atom of this form, some care is necessary because some string of special characters already have a predefined meaning; an example is ‘:-’
  • 44. Atom 3. String of characters enclosed in single quotes. This is useful if we want, for ex, to have an atom that starts with a capital letter. Ex, ‘Tom’ ‘South_America’ ‘Sarah Jones’
  • 45. Confusing!!!!! How???? Atoms and arguments are different things! Atoms may be used as arguments but not all arguments are automatically atoms!
  • 46. Number  Number include integer numbers and real numbers. Ex, 1 1313 0 -97 3.14 -0.0035 100.2
  • 47. Variables  Variables are string of letters, digits and underscore characters. They are start with an upper-case letter or and underscore character. Ex, X Result Object2 Participant_list ShoppingList _x23 _23
  • 48. Ground Term  The variable free term is known as ground term.  Ex, person(peter, mueller, date(27, 11, 2007))
  • 49. Prolog Program domains disease , indication=symbol predicates sympton(disease,indication) clauses sympton(chicken_pox,high_fever). sympton(chicken_pox, chills). sympton(flu,chills). sympton(cold,mild_body_ache). sympton(cold, runny_nose). sympton(flu,runny_nose). sympton(flu,moderate_couh). Goal: sympton(Disease, runny_nose) Disease=cold Disease=flu 2 solutions
  • 50. Anonymous Variable / Don’t care variable  Goal: symptom(_,chills) True  Goal: likes(jane,_). (Jane likes everything)  Because there is no variable, there is no binding; if prolog program can match the relation name and the last argument, the goal succeeds.  Prolog doesn’t tell you which disease had the symptom chills, as it would have if you had used ordinary variable.  Note that in a clause, the anonymous variable stands for all values, while in a goal it is satistied if at least one value corresponds to it.
  • 51. Think Think….  Can we use underscore in a clause ??  If yes, what is impact of it…
  • 52. Structure  Structure objects are objects that have several components.  The components themselves can, in turn be structure.  For ex, the date can be viewed as structure with three components: day,month,year.  Although composed of several components , structures are treated in the program as single objects.  In order to combine the component into single we choose a functor.  For Ex, date(1,may,2001)  All the components in this example are constants (2 integer and one atom).  Date is functor.
  • 53. Which of the following are syntactically correct prolog object? What kind of object are they? 1. Diana 2. diana 3. ‘Diana’ 4. _diana 5. ‘Diana goes south’ 6. goes(diana,south) 7. 45 8. 5(X,Y) 9. +(north,west) 10. three(Black(Cats)) 1. Variable 2. atom 3. atom 4. variable 5. atom 6. structure 7. number 8. incorrect 9. structure 10. structure
  • 54. Compound Goal domains disease , indication=symbol predicates sympton(disease,indication) clauses sympton(chicken_pox,high_fever). sympton(chicken_pox, chills). sympton(flu,chills). sympton(cold,mild_body_ache). sympton(cold, runny_nose). sympton(flu,runny_nose). sympton(flu,moderate_couh). Goal: symptom(Disease,runny_nose) and symptom(Disease,mild_body_ache) Disease=cold 1 solution True Prolog work from left to right for proving compound goal.
  • 55. Backtracking : Heart of Prolog Program domains disease , indication=symbol predicates sympton(disease,indication) clauses sympton(chicken_pox,high_fever). symptom(viral_syndrom,mild_body_ache) sympton(chicken_pox, chills). sympton(flu,chills). sympton(cold, runny_nose). sympton(flu,runny_nose). sympton(flu,moderate_couh). Symptom(viral_syndrom,runny_nose). Goal: symptom(Disease,runny_nose) and symptom(Disease,mild_body_ache) Disease=cold Disease=flu Disease= viral_syndrom
  • 56. Backtracking  The solution of compound goal proceeds from left to right  If any condition in the chain fails, prolog backtracks to the previous condition, tries to prove it again with another variable binding, then moves forward again to see if the failed condition will succeed with the new binding,  Prolog moves relentlessly forward and backward through the conditions, trying every variable binding in an attempt to get the goal to succeed in many ways as possible.
  • 58. Rules  A rule is an expression that indicates that the truth of a particular fact depends upon one or more other facts.  Ex, A and B are sisters if A and B are both female and they have the same father and they have the same mother and A is not the same as B  Sister(A,B):- female(A),female(B),father(X,A),father(X,B),mother (Y,A),mother(Y,B),not_same(A,B).
  • 59. Rules  The symbol ‘ :- ‘ is known as turnstile or break operator.  ‘ :- ’ is pronounced as ‘ If ’.  Syntax: head_of_the_rule :- body_of_the_rule (a.k.a) (a.k.a) conclusion antecedent (consist of) premises 1,premises 2, …premises n
  • 60. Rules  Each premises are connected by the word ‘and’ or ‘conjunction’ (^).  The ‘goal’ is true if all the conditions specified for the goal are true.  If all the premises are true, the conclusion is true; if any premises fails the conclusion fails.  A rule expresses a relationship between facts. Any given prolog program is simply a database (collection of clauses) of facts and rules.
  • 61. Conjunction and disjunction in rule  A comma expresses an ‘and’ relationship and semicolon expresses an ‘or’ relationship.  Holiday in college if there is Sunday or there is public holiday  Holiday(college):-day(Sunday);day(public_holiday) OR Holiday(college):-day(Sunday). Holiday(college):-day(public_holiday)
  • 62. Formal Reasoning  The process of using rules and facts to solve a problem is called formal reasoning.
  • 63. Some important points about prolog execution Rules  In medical diagnosis system you have seen how the variable are used.  There are no “global” variable; that is, variables that maintain a value throughout the entire program’s execution.  A variable is local to the clause of which they are part.  Even if the same variable name is used in another clause , it is not the same variable.  Ex, daughter(X):-father(Roy),mother(Sue). daughter(X):-father(Bob),mother(Lice).
  • 64. A term is said to be unify if…..  Unification is a pattern matching process. 1. Both terms appear in predicates that have the same number of arguments (i.e. same arity), and both terms appear in the same position in their predicate. 2. Both terms appear as argument of the same type - a symbol type can only unify with a symbol and so on. 3. All subterms unify with each other .
  • 65. Rules for Unification (1) 1. A variable that is free will unify with any term that satisfies the preceding conditions. After unification, the variable is bound to the value of the term. likes(ron,br0om). likes(harry,X):-likes(ron,X). Goal: likes(harry,broom) Here Variable X is bounded with the value Broom.
  • 66. Rules for Unification (2) 2. A constant can unify with itself or any free variable. If the constant is unified with variable, the variable will be bound to the value of the constant. Ex, likes(harry,school). Goal : likes(harry,school) Ex, likes(harry,school). Goal: likes(harry,X).
  • 67. Rules for Unification (3) 3. A free variable will unify with any other free variable. After unifying, the two variable will act as one. If one of the variable becomes bound, the other will be bound to the same value. Ex, likes(ron,broom). likes(harry,X):-likes(ron,X). Goal: likes(harry,broom).
  • 68. Instantiation & Unification Exercise Unify With Result Likes(jem,piano) Likes(jem,X) X=piano yes Likes(jem,X) Likes(Y,piano) Y=jem yes
  • 69. Unifiability : Binding, substitution and unifiers  Testing equality of terms with variables:  Terms T1 and T2 are unifiable if there is a substitution that makes them equal!  A binding is an association of a variable to a term . Two sample bindings: Name mueller and MM 11  A substitution is a set of bindings A sample substitution: {Name mueller, MM 11 }  A unifier is a substitution that makes two terms equal The above substitution is a unifier for the two person/3 terms above
  • 70. The ‘not’ predicate  To explicitly express that in the database particular fact is not true.  To try this use built-in ‘not’ predicate.  The ‘not’ predicate cannot be used to express a fact or appear in the head of a rule. It can only be used in a premises.  Ex, replace(right_speaker) :- not(is(right_speaker,functional).  In the case if is(right_speaker,functional) is in database the rule will fail.
  • 71. ‘not’ predicate  Be careful in your program design to distinguish between the use of the not predicate and the omission of facts from the databse.  If a fact is not in the database, prolog considers it false.  However this falsity based on absence from the database is not sufficient to prove a not premise.  The absence of the is fact above would not prove the not premise in the rule.
  • 72. Which are the connectors available that connects the clauses  implication (:-)  conjunction (,)  disjunction (;)
  • 73. Scope of variable in prolog  The scope of a variable is the clause in which it appears