ARTIL LAB1 All Slides Info
ARTIL LAB1 All Slides Info
me/+DAsruO893Sg0OWZk
Red=example
We define facts and rules (relations) and give it the program , we ask it what we want
(Queries ). Then it will answer using available facts and reasoning .
- It’s a declarative language which means : its for describing a situation and you
don’t need to write the code line by line as in procedural languages ( c++, Java..) .
- Its important in Ai and good for knowledge -rich tasks .
- In PROLOG the logic is expressed as relations (facts and rules ) .
- Basic Idea of PROLOG :
1- Ask a question in the interactive prompt .
2- Prolog logically deduces new facts about the situation described .
3- Lastly it gives a deduction back as answers .
- Main application in PROLOG :
• AI ( expert systems – NLP – machine learning )
• Database ( query languages ,data mining ) .
• Mathematics ( theorem proving , symbolic packaging )
- Component of PROLOG :
1- Knowledge base :
• Logic programming languages are one way to implement the knowledge base .
• The KB consist of :
Facts Rules (the Horn clause )
- The form : - The form :
Predicate (atom1,atom2..) Predicate (var1,var2):-predicate1(..),predicate2(..)
Predicate : is a name that we give to a relation , its usually - Logical operator :
an adj. • AND
atom : a constant value written in lower case . Using the coma to indicate AND .
dance(mariam):-happy(mariam),coding(mariam) .
-The fact Comes from the Horn Clause (which is a rule ) : this means :
H:-B1,B2…Bn this means if all the Bs are true then H(the happy(mariam)^coding(mariam) → dance(mariam)
fact ) is true .. mariam dances if she is happy AND coding .
- a fact is a rule that doesn’t have the right hand side (it’s
the H only without the condition ) . • OR
e.g : Henry is a man Using the semi colon or separate statements
dances(omar) :- happy(omar);listensToMusic(omar).
woman ( skain). Or :
male ( henry). dances(omar):-happy(omar).
dances(omar):-coding (omar).
• After encoding your KB the inference engine will attempt to answer your quires .
2- Inference engine :
• It answers your quires by building constructive proofs that is entailed by the KB .
• The KB uses : the facts ,rules and inference engine to answer quires .
• E.g : is Ahmad mortal ? Yes .
?-likes(A,omar)=likes(prolog,B).
A=prolog
B=omar
We match likes and likes , A (which equals prolog ) with prolog .. so its true .
Non- unification
5+4\=2+7
Focus ! in this example we don’t say 9=9 , remember that this is a unification , element
by element checking . so it will result false .
- ?- X is sqrt(9), Y is 2 ** 4, Z is floor(3.14).
X = 3.0 Y = 16.0 Z=3
- minimum(x,y,x) :-x<y.
This means : the min is x if the x is less than y ,lets say for instance the user
enters ?- minimum(3,8,A). we will assign A=3 and y=8 . is A<y ,3<8 ? true . so
the min is A =3 .