0% found this document useful (0 votes)
14 views5 pages

ARTIL LAB1 All Slides Info

The document explains the fundamentals of Logical Programming using PROLOG, a declarative programming language associated with AI and computational linguistics. It outlines how facts and rules are defined, how queries are processed through an inference engine, and the main applications of PROLOG in AI, databases, and mathematics. Additionally, it provides insights into logical operators, arithmetic operations, and tips for using PROLOG effectively.

Uploaded by

mr.sajjadov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

ARTIL LAB1 All Slides Info

The document explains the fundamentals of Logical Programming using PROLOG, a declarative programming language associated with AI and computational linguistics. It outlines how facts and rules are defined, how queries are processed through an inference engine, and the main applications of PROLOG in AI, databases, and mathematics. Additionally, it provides insights into logical operators, arithmetic operations, and tips for using PROLOG effectively.

Uploaded by

mr.sajjadov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ARIT LAB1 telegram channel : https://t.

me/+DAsruO893Sg0OWZk

Red=example

Q- How does the Logical programming works ?

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 .

LOGical PROgramming(PROLOG) : it’s a logical programming language associated with Ai


and computational linguistics .

- 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 .

-variables :upper case ,underscore .

-constant :lower case , single quotes .

_ahmad , ‘Henry’ , Skain , verit .

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 .

Logical operators in PROLOG :


Arithmetic expression Terms Identical
Equality : Likes(henry,prolog)==likes(lili,prolog).
10+3=:=5*4-7 False ;because the var henry and lili are
Is 13 equal to 13 ? true different
Inequlity : Likes(henry)/==likes(lili) . true
24=/=17+4 Or
Is 24 not equal to 21 ? true Likes(lili).not likes(lili).false

Unification ( matching each element )


5+A=5+3
A=3
So we match 5 with 5 , + with + , A (which equals 3) with 3 . thus the result is true

?-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 .

Arithmetic operation in PROLOG


/ is a real division // integer division mod modulus
** power sqrt square root maximum max
Less than or equal to =< greater than or equal to >=

- ?- 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 .

Tips on using PROLOG :


- To add a comment /* and */
- To stop execution : abort.
- To exit : halt.
- The typing format is free , you can write as many clauses as you want
ending it with dot .
- Prolog will give you the first solution of a query , you can obtain
additional responses by typing ;
- The operator “is” assigns the value
(x is 5 ) means assigning ( x=5 is unification that return true or false ) .
- Type the query “pwd.” To see active directory .
- Up and down arrows to scroll recent commands
- The negation \+ is used as a prefix operator without parenthesis
Married(x):-\+single(x). x is not single if x is married .
- nl for new line
Practice : convert a database into knowledge base in PROLOG
DB information :

Facts Rules : Questions

- Henry is a teacher -person 1 is a parent of person 2 if -who is jaber’s father ?


Person 1 is the father of person 2 or
-Nora is a teacher Person 1 is the mother of person 2 . -is Nora the mother of Jaber ?

-Saleh is the father of -person 1 is a grandparent of person -does Hamza have


Jaber 2 if person 3 is the parent of person grandchild ?
2 and person 1 is the parent of
-Nora is the mother of person 3 .
Jaber

-Hamza is the father of


saleh

KB of facts (Lets convert it to prolog ) :

You might also like