SlideShare a Scribd company logo
‫المحاضرة‬
(
5
)
‫المنطقية‬ ‫البرمجة‬ ‫الى‬ ‫مقدمة‬
‫البرلوج‬ ‫لغة‬ ‫باستخدام‬
prolog programming
Prolog Fundamentals :
 Objectives :
 Introduction to Prolog . -
 Sentences (Facts & Rules). -
 - Queries .
 -variables .
 - overview .
1.Introduction to Prolog :
 Prolog stands for PROgramming in LOGic. It is a logic language that
is particularly used by programs that use non-numeric objects. For
this reason it is a frequently used language in Artificial
Intelligence where manipulation of symbols is a common task.
Prolog differs from the most common programming languages
because it is declarative language. Traditional programming
languages are said to be procedural. This means that the
programmer specify how to solve a problem. In declarative
languages the programmers only give the problem and the language
find himself how to solve the problem.
1.Introduction to Prolog cont.:
 Prolog program is not a sequence of actions , it include an
inference engine because it is a collection of facts together with
rules for drawing conclusion from those facts this is called (
pattern matching)so the programmer arrives at solutions by
logically inferring one thing from something already known .
 Prolog is based on Predicate Logic which is a formal system for
reasoning about things and the way they relate to each other .
Prolog takes advantage of this syntax to develop a programming
language based on the logic .
2.Sentences : Facts and Rules :
In predicate logic , you first eliminate all unnecessary words from your
sentences . You then transform the sentence, placing the relationship
first and grouping the objects after the relationship . The objects then
become arguments that the relationship acts upon .
A prolog programmer defines objects and relation , then defines rules abut
when these relations are true . For example, the sentence :
Ahmed likes cats
Shows a relation between the objects Ahmed and Cats , the relation is likes .
Here is a rule that defines when the sentence : Ahmed likes cats is true :
Ahmed likes cats if the cats are nice .
2.1 Facts : What Is Known
In natural language, a relation between objects is symbolized by a sentence . In
prolog , a relation is called predicate which summarized in a simple phrase – a
fact- that consists of the relation name followed by the object or objects
enclosed in parentheses . As with a sentence, the fact ends with a period (.)
For example : the following sentences are transformed into predicate logic syntax :
Predicate Logic
Natural Language
Fun(car).
A car is fun.
Red(rosr).
A rose is red.
Red(car)
A car is red
Likes(Khalid , books).
Khalid likes books.
Likes(Ahmed,car) if fun(car)
Ahmed likes a car if the car is fun .
2.2 Rules : What You Can Infer
from Given Facts :
Rules enable you to infer facts from other facts . Here are some rules
concerning (likes) relation :
Ahmed likes everything that is red .
Ali likes every things that Khalid likes .
Given this rule , you can infer from the previous facts some of the
things that Ahmed likes :
Ahmed likes rose .
Ahmed likes car .
Ali likes books .
2.2 Rules : What You Can Infer
from Given Facts cont.:
To encode this same rules into prolog , you only need to change the
syntax a little, Like this :
Likes (ali , something) :- Likes (khalid , something).
Likes(ahmed , something) :- green(something).
The ( :- ) symbol simply pronounced ( if ) , and serves to separate the
two parts of a rule : the head and the body .
You can also think of rules as meaning " To prove that Ali likes
something , prove that Khalid likes that same thing " and " To prove
that Ahmed likes something , prove that it is green " .
A rule also can ask prolog to perform actions other than proving things
proving things such as : writing something or creating a file.
3.Queries :
Once we give Prolog a set of facts, we can proceed to ask
questions concerning these facts , this is known as
querying the Prolog system .(psattern matching)
In natural language, we can ask you : Does Ahmed like car ?
In Prolog syntax, we can ask Prolog : likes(ahmed, car) . Given
this query, Prolog would answer : yes . because Prolog has a
fact that says so which is : likes(ahmed , car).
3.Queries cont.:
As a little more complicated and general question, we could ask in natural language :
What does Ahmed like?
In Prolog syntax , We ask Prolog likes(ahmed , What). It is important to notice that
the second object ( What) begins with a capital letter , while the first object (ahmed)
does not . This is because (ahmed) is a constant object known as value but What is
variable . Variables always begins with upper-case letter or on underscore .
Prolog always looks for an answer to a query by starting at the top of the facts . It
looks at each fact until it reaches the bottom , where there are no more .
Given the query about what Ahmed likes . Prolog will return :
what = car
what = rose
2 solutions . This is because Prolog knows : likes (ahmed , car). And
likes(ahmed,rose)
Putting Facts, Rules and Queries
Together :
A fast car is fun .
A big car is nice .
A little car is practical .
Ahmed likes car if the car is fun
.
When we read this facts , we can deduce that
Ahmed likes a fast car . Prolog will come to the
same conclusion . If no fact were given about fast
cars , then you would not be able to logically
deduce what kind of a car Ahmed likes . We could
guess what kind of a car might be fun but Prolog
only knows what we tell it . Prolog does not guess .
4. Variables : General
Sentences
In Prolog, variables enable us to write general facts and rules
and ask general questions .
For example : In natural language we can write general
sentence as : Ali likes the same thing as Khalid .
To represent that in Prolog , we can write :
likes ( ali , Thing) :- likes (khalid , Thing).
AS we mentioned earlier to represent variables in Prolog the
first character should be an upper-case letter . in our
example ( Thing) is the variable and it must be able to
match any thing that Khalid likes .
The objects : ali and Khalid begins with lower-case letter
because they are symbols having a constant value .
Visual Prolog can also handle text string if the text
surrounded by double quotes . So the name ali could have
been written as "Ali" , if you wanted it to begin with an
upper-case letter .
5. Overview :
1- A Prolog program is made up of tow types of phrases ( also known as clause) : facts and
rules .
Facts : are relations or properties that the programmer know to be true .
Rules : are dependent relations , they allow Prolog to infer one piece of information from
another . A rule become true if a given set of conditions is proven to be true . Each rule
depends upon proving its conditions to be true .
2- In Prolog , all rules have two parts , a head and a body separated by the special :- token .
The head is the fact that would be true if some number of conditions were true . The body
is the set of conditions that must be true so that prolog can prove that the head of the
rule is true .
3- Facts and rules are really the same , except that a fact has no explicit body. The fact
simply behaves as if it had a body that was always true .
4- Once you give Prolog a set of facts and rules, you can proceed to ask questions
concerning these . this is known as querying the prolog system .
Prolog always looks for a solution by starting at the top of the facts and/or rules , and
keeps looking until it reaches the bottom .
5- Prolog's inference engine take the condition of a rule ( the body of the rule ) and looks
through its list of known facts and rules, trying to satisfy the conditions . Once all the
conditions have been met , the dependent relation (the head of the rule ) is found to be
true . If all condition can not be matched with known facts , the rule doesn't conclude
anything .
Syntax for Predicate Calculus
Programming:
Prolog
Predicate Calculus
English
,
˄
and
;
˅
or
:-
←
only if
not
¬
not
Example:
George likes kate and George likes Susie.
likes (george,kate),likes(george,susie).
George likes kate or George likes Susie.
likes (george,kate); likes(george,susie).
George likes Susie if George does not likes kate.
likes (george, susie):- not(likes(george, kate)).
Example:
A simple description of a blue bird might be a
blue bird is a small blue colored bird and a bird
is a feathered flying vertebrate.
This may be represented as a set of logical
predicates:
hassize(bluebird, small)
hascovering(bird, feather)
hascolor(bluebird, blue)
hasproperty(bird, flies)
is a(bluebird,bird)
is a(bird, vertebrate)
Comments:
It's good programming style to include comments in your program
to explain things that might not be obvious to someone else. This
makes the program easy for you and others to understand .
Multiple line comments must begin with the character /*(slash,
asterisk) and end with the characters */ (asterisk, slash )
To set off single line comments you can use these same
characters, or you can begin the comments with a percent sign
(%)
the domains section:
The domain section serves two very useful purpose. First, you can give
meaningful names to domains even if, internally, they are the same as
domains that already exist. Second, special domain declarations are used to
declare data structures that are not defined by the standard domains.
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.
Here's an example to illustrate how declaring domains helps to document your
predicates:
Ahmad is a male who is 45 years old.
With the pre-defined domains, you come up with the following predicate
declaration :
Person(symbol, symbol, integer)
The declaration will work fine for most purpose.
The following decoration will help you understand what
the argument in the predicate declaration stand for:
DOMAINS
name , sex = symbol
age = integer
PREDICATES
person( name, sex, age)
One of the main advantages of this declarations is that visual prolog can catch the type
errors, like the following obvious mistake :
same_sex(X, Y):-
person(X, sex, _ ),
person(sex, Y,_ ).
Even though name and sex are both defined as symbol, they are not equivalent to each
other. This enables visual prolog to detect an error if you accidentally swap them. This
feature is very useful when your programs get large and complex.
You might be wondering why we don’t use special domains for all argument declarations,
since special domains communicate the meaning of the argument so much better. The
answer is that once an argument is typed to a specific domain, that domain can't be
mixed with another domain you have declared, even if the domains are the same. So,
even though name and sex are of the same domain (symbol), they can't be mixed.
However, all user-defined domains can be matched with the pre-defined domains.
The Goal Section:
The goal section is the same as the body of a rule
it's simply a list of subgoals. There are two
differences between the goal section and a rule:
The goal keyword is not followed by :-.
Visual Prolog automatically executes the goal when
the program runs.
It's as if Visual Prolog makes a call to goal and the
program runs, trying to satisfy the body of the
goal rule. If the subgoals in the goal section all
succeed, then the program terminate successfully.
If, while the program is running, a subgoal in the
goal section fails, then the program is said to have
failed.
‫تمرين‬
:
‫بلغة‬ ‫برنامج‬ ‫اكتبي‬
Prolog
‫العائلية‬ ‫العالقات‬ ‫بوصف‬ ‫فيه‬ ‫تقومي‬
(
‫أب‬
,
‫األجداد‬ ، ‫أخت‬ ، ‫أخ‬ ، ‫أم‬
)
‫التالية‬ ‫العائلة‬ ‫لشجرة‬
:
‫العزيز‬ ‫عبد‬
‫أحمد‬
‫عبير‬
‫خالد‬
‫سالم‬
‫سمير‬ ‫عادل‬
‫محمد‬
‫سعاد‬
Quires :
Run  Run As  Interpreted project (pro)
?- father(X,khaled).
X = ahmad ;
no
?-
mother(X,mhmma
d).
X = abeer ;
no
?- bother(X,abeer).
no
?-
?- brother(X,abeer).
X = khaled ;
X = salem ;
no
?- sister(X,salem).
X = abeer ;
no
?- sister(X,samir).
no
predecessor(abeer,X).
X = mhmmad ;
no
?-
predecessor(ahmad,X).
X = abeer ;
X = khaled ;
X = salem ;
X = mhmmad ;
X = adel ;
X = samir ;
X = abdlaziz ;
X = soad ;
no
?- quit.
‫مالحظة‬
:

‫لتنزيل‬
Amzi Prolog + Logic Server IDE 7.6.9
‫من‬
‫الرابط‬
http://softwaredownloadmirror.com/trial/amzi-
prolog-logic-server-ide-7.6.9/100198213/

‫برنامج‬ ‫استخدام‬ ‫لشرح‬ ‫فيديو‬ ‫مقطع‬
Amzi
http://www.amzi.com/videos/eclipse_first_use/ecli
pse_first_use.html
‫الواجب‬
:

‫بلغة‬ ‫برنامج‬ ‫اكتبي‬
Prolog
‫العائلية‬ ‫العالقات‬ ‫لوصف‬
(
‫أب‬
,
‫أم‬
‫األجداد‬ ، ‫أخت‬ ، ‫أخ‬ ،
)
‫امث‬ ‫وضع‬ ‫مع‬ ‫بك‬ ‫الخاصة‬ ‫العائلة‬ ‫لشجرة‬
‫لة‬
‫عن‬ ‫التقل‬ ‫لالستفسارات‬
5
:

More Related Content

Similar to ________ ________1.ppt

Poggi analytics - ebl - 1
Poggi   analytics - ebl - 1Poggi   analytics - ebl - 1
Poggi analytics - ebl - 1
Gaston Liberman
 
Basics of Machine Learning
Basics of Machine LearningBasics of Machine Learning
Basics of Machine Learningbutest
 
Clean code ch03
Clean code ch03Clean code ch03
Clean code ch03
Saeb Panahifar
 
Artificial Intelligence and Expert System
Artificial Intelligence and Expert System Artificial Intelligence and Expert System
Artificial Intelligence and Expert System
Showkot Usman
 
Introduction to Prolog
Introduction to Prolog Introduction to Prolog
Introduction to Prolog
Showkot Usman
 
SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE
SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE
SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE
ijscmcjournal
 
Xml overview
Xml overviewXml overview
Xml overview
Haresh Chaudhari
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
2021uam4641
 
Introduction to Prolog (PROramming in LOGic)
Introduction to Prolog (PROramming in LOGic)Introduction to Prolog (PROramming in LOGic)
Introduction to Prolog (PROramming in LOGic)
Ahmed Gad
 
Oo ps exam answer2
Oo ps exam answer2Oo ps exam answer2
Oo ps exam answer2
Kaushal Vaishnav
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
Rakhi Sinha
 
Dsm as theory building
Dsm as theory buildingDsm as theory building
Dsm as theory buildingClarkTony
 
AI: Logic in AI
AI: Logic in AIAI: Logic in AI
AI: Logic in AI
DataminingTools Inc
 
AI: Logic in AI
AI: Logic in AIAI: Logic in AI
AI: Logic in AI
Datamining Tools
 
MACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEMACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULE
DrBindhuM
 
PROLOG: Introduction To Prolog
PROLOG: Introduction To PrologPROLOG: Introduction To Prolog
PROLOG: Introduction To Prolog
DataminingTools Inc
 
Erlang kickstart
Erlang kickstartErlang kickstart
Erlang kickstart
Ryan Brown
 
AI Lab Manual.docx
AI Lab Manual.docxAI Lab Manual.docx
AI Lab Manual.docx
KPRevathiAsstprofITD
 
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTEA FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
ijnlc
 
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTEA FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
kevig
 

Similar to ________ ________1.ppt (20)

Poggi analytics - ebl - 1
Poggi   analytics - ebl - 1Poggi   analytics - ebl - 1
Poggi analytics - ebl - 1
 
Basics of Machine Learning
Basics of Machine LearningBasics of Machine Learning
Basics of Machine Learning
 
Clean code ch03
Clean code ch03Clean code ch03
Clean code ch03
 
Artificial Intelligence and Expert System
Artificial Intelligence and Expert System Artificial Intelligence and Expert System
Artificial Intelligence and Expert System
 
Introduction to Prolog
Introduction to Prolog Introduction to Prolog
Introduction to Prolog
 
SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE
SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE
SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE
 
Xml overview
Xml overviewXml overview
Xml overview
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
 
Introduction to Prolog (PROramming in LOGic)
Introduction to Prolog (PROramming in LOGic)Introduction to Prolog (PROramming in LOGic)
Introduction to Prolog (PROramming in LOGic)
 
Oo ps exam answer2
Oo ps exam answer2Oo ps exam answer2
Oo ps exam answer2
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prolog
 
Dsm as theory building
Dsm as theory buildingDsm as theory building
Dsm as theory building
 
AI: Logic in AI
AI: Logic in AIAI: Logic in AI
AI: Logic in AI
 
AI: Logic in AI
AI: Logic in AIAI: Logic in AI
AI: Logic in AI
 
MACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEMACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULE
 
PROLOG: Introduction To Prolog
PROLOG: Introduction To PrologPROLOG: Introduction To Prolog
PROLOG: Introduction To Prolog
 
Erlang kickstart
Erlang kickstartErlang kickstart
Erlang kickstart
 
AI Lab Manual.docx
AI Lab Manual.docxAI Lab Manual.docx
AI Lab Manual.docx
 
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTEA FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
 
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTEA FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
A FILM SYNOPSIS GENRE CLASSIFIER BASED ON MAJORITY VOTE
 

More from SamiAAli44

المحاضرة الاولى بور بوينت تعليم اساسي.pptx
المحاضرة  الاولى      بور بوينت تعليم اساسي.pptxالمحاضرة  الاولى      بور بوينت تعليم اساسي.pptx
المحاضرة الاولى بور بوينت تعليم اساسي.pptx
SamiAAli44
 
م.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptxم.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptx
SamiAAli44
 
Lecture 10.pptx
Lecture 10.pptxLecture 10.pptx
Lecture 10.pptx
SamiAAli44
 
م.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptxم.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptx
SamiAAli44
 
virus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdfvirus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdf
SamiAAli44
 
lce1 مترجمات.pptx
lce1 مترجمات.pptxlce1 مترجمات.pptx
lce1 مترجمات.pptx
SamiAAli44
 
محاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptxمحاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptx
SamiAAli44
 
Computer-Networks--Network.ppt
Computer-Networks--Network.pptComputer-Networks--Network.ppt
Computer-Networks--Network.ppt
SamiAAli44
 

More from SamiAAli44 (8)

المحاضرة الاولى بور بوينت تعليم اساسي.pptx
المحاضرة  الاولى      بور بوينت تعليم اساسي.pptxالمحاضرة  الاولى      بور بوينت تعليم اساسي.pptx
المحاضرة الاولى بور بوينت تعليم اساسي.pptx
 
م.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptxم.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptx
 
Lecture 10.pptx
Lecture 10.pptxLecture 10.pptx
Lecture 10.pptx
 
م.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptxم.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptx
 
virus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdfvirus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdf
 
lce1 مترجمات.pptx
lce1 مترجمات.pptxlce1 مترجمات.pptx
lce1 مترجمات.pptx
 
محاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptxمحاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptx
 
Computer-Networks--Network.ppt
Computer-Networks--Network.pptComputer-Networks--Network.ppt
Computer-Networks--Network.ppt
 

Recently uploaded

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 

Recently uploaded (20)

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 

________ ________1.ppt

  • 1. ‫المحاضرة‬ ( 5 ) ‫المنطقية‬ ‫البرمجة‬ ‫الى‬ ‫مقدمة‬ ‫البرلوج‬ ‫لغة‬ ‫باستخدام‬ prolog programming
  • 2. Prolog Fundamentals :  Objectives :  Introduction to Prolog . -  Sentences (Facts & Rules). -  - Queries .  -variables .  - overview .
  • 3. 1.Introduction to Prolog :  Prolog stands for PROgramming in LOGic. It is a logic language that is particularly used by programs that use non-numeric objects. For this reason it is a frequently used language in Artificial Intelligence where manipulation of symbols is a common task. Prolog differs from the most common programming languages because it is declarative language. Traditional programming languages are said to be procedural. This means that the programmer specify how to solve a problem. In declarative languages the programmers only give the problem and the language find himself how to solve the problem.
  • 4. 1.Introduction to Prolog cont.:  Prolog program is not a sequence of actions , it include an inference engine because it is a collection of facts together with rules for drawing conclusion from those facts this is called ( pattern matching)so the programmer arrives at solutions by logically inferring one thing from something already known .  Prolog is based on Predicate Logic which is a formal system for reasoning about things and the way they relate to each other . Prolog takes advantage of this syntax to develop a programming language based on the logic .
  • 5. 2.Sentences : Facts and Rules : In predicate logic , you first eliminate all unnecessary words from your sentences . You then transform the sentence, placing the relationship first and grouping the objects after the relationship . The objects then become arguments that the relationship acts upon . A prolog programmer defines objects and relation , then defines rules abut when these relations are true . For example, the sentence : Ahmed likes cats Shows a relation between the objects Ahmed and Cats , the relation is likes . Here is a rule that defines when the sentence : Ahmed likes cats is true : Ahmed likes cats if the cats are nice .
  • 6. 2.1 Facts : What Is Known In natural language, a relation between objects is symbolized by a sentence . In prolog , a relation is called predicate which summarized in a simple phrase – a fact- that consists of the relation name followed by the object or objects enclosed in parentheses . As with a sentence, the fact ends with a period (.) For example : the following sentences are transformed into predicate logic syntax : Predicate Logic Natural Language Fun(car). A car is fun. Red(rosr). A rose is red. Red(car) A car is red Likes(Khalid , books). Khalid likes books. Likes(Ahmed,car) if fun(car) Ahmed likes a car if the car is fun .
  • 7. 2.2 Rules : What You Can Infer from Given Facts : Rules enable you to infer facts from other facts . Here are some rules concerning (likes) relation : Ahmed likes everything that is red . Ali likes every things that Khalid likes . Given this rule , you can infer from the previous facts some of the things that Ahmed likes : Ahmed likes rose . Ahmed likes car . Ali likes books .
  • 8. 2.2 Rules : What You Can Infer from Given Facts cont.: To encode this same rules into prolog , you only need to change the syntax a little, Like this : Likes (ali , something) :- Likes (khalid , something). Likes(ahmed , something) :- green(something). The ( :- ) symbol simply pronounced ( if ) , and serves to separate the two parts of a rule : the head and the body . You can also think of rules as meaning " To prove that Ali likes something , prove that Khalid likes that same thing " and " To prove that Ahmed likes something , prove that it is green " . A rule also can ask prolog to perform actions other than proving things proving things such as : writing something or creating a file.
  • 9. 3.Queries : Once we give Prolog a set of facts, we can proceed to ask questions concerning these facts , this is known as querying the Prolog system .(psattern matching) In natural language, we can ask you : Does Ahmed like car ? In Prolog syntax, we can ask Prolog : likes(ahmed, car) . Given this query, Prolog would answer : yes . because Prolog has a fact that says so which is : likes(ahmed , car).
  • 10. 3.Queries cont.: As a little more complicated and general question, we could ask in natural language : What does Ahmed like? In Prolog syntax , We ask Prolog likes(ahmed , What). It is important to notice that the second object ( What) begins with a capital letter , while the first object (ahmed) does not . This is because (ahmed) is a constant object known as value but What is variable . Variables always begins with upper-case letter or on underscore . Prolog always looks for an answer to a query by starting at the top of the facts . It looks at each fact until it reaches the bottom , where there are no more . Given the query about what Ahmed likes . Prolog will return : what = car what = rose 2 solutions . This is because Prolog knows : likes (ahmed , car). And likes(ahmed,rose)
  • 11. Putting Facts, Rules and Queries Together : A fast car is fun . A big car is nice . A little car is practical . Ahmed likes car if the car is fun . When we read this facts , we can deduce that Ahmed likes a fast car . Prolog will come to the same conclusion . If no fact were given about fast cars , then you would not be able to logically deduce what kind of a car Ahmed likes . We could guess what kind of a car might be fun but Prolog only knows what we tell it . Prolog does not guess .
  • 12. 4. Variables : General Sentences In Prolog, variables enable us to write general facts and rules and ask general questions . For example : In natural language we can write general sentence as : Ali likes the same thing as Khalid . To represent that in Prolog , we can write : likes ( ali , Thing) :- likes (khalid , Thing). AS we mentioned earlier to represent variables in Prolog the first character should be an upper-case letter . in our example ( Thing) is the variable and it must be able to match any thing that Khalid likes . The objects : ali and Khalid begins with lower-case letter because they are symbols having a constant value . Visual Prolog can also handle text string if the text surrounded by double quotes . So the name ali could have been written as "Ali" , if you wanted it to begin with an upper-case letter .
  • 13. 5. Overview : 1- A Prolog program is made up of tow types of phrases ( also known as clause) : facts and rules . Facts : are relations or properties that the programmer know to be true . Rules : are dependent relations , they allow Prolog to infer one piece of information from another . A rule become true if a given set of conditions is proven to be true . Each rule depends upon proving its conditions to be true . 2- In Prolog , all rules have two parts , a head and a body separated by the special :- token . The head is the fact that would be true if some number of conditions were true . The body is the set of conditions that must be true so that prolog can prove that the head of the rule is true . 3- Facts and rules are really the same , except that a fact has no explicit body. The fact simply behaves as if it had a body that was always true . 4- Once you give Prolog a set of facts and rules, you can proceed to ask questions concerning these . this is known as querying the prolog system . Prolog always looks for a solution by starting at the top of the facts and/or rules , and keeps looking until it reaches the bottom . 5- Prolog's inference engine take the condition of a rule ( the body of the rule ) and looks through its list of known facts and rules, trying to satisfy the conditions . Once all the conditions have been met , the dependent relation (the head of the rule ) is found to be true . If all condition can not be matched with known facts , the rule doesn't conclude anything .
  • 14. Syntax for Predicate Calculus Programming: Prolog Predicate Calculus English , ˄ and ; ˅ or :- ← only if not ¬ not Example: George likes kate and George likes Susie. likes (george,kate),likes(george,susie). George likes kate or George likes Susie. likes (george,kate); likes(george,susie). George likes Susie if George does not likes kate. likes (george, susie):- not(likes(george, kate)).
  • 15. Example: A simple description of a blue bird might be a blue bird is a small blue colored bird and a bird is a feathered flying vertebrate. This may be represented as a set of logical predicates: hassize(bluebird, small) hascovering(bird, feather) hascolor(bluebird, blue) hasproperty(bird, flies) is a(bluebird,bird) is a(bird, vertebrate)
  • 16. Comments: It's good programming style to include comments in your program to explain things that might not be obvious to someone else. This makes the program easy for you and others to understand . Multiple line comments must begin with the character /*(slash, asterisk) and end with the characters */ (asterisk, slash ) To set off single line comments you can use these same characters, or you can begin the comments with a percent sign (%)
  • 17. the domains section: The domain section serves two very useful purpose. First, you can give meaningful names to domains even if, internally, they are the same as domains that already exist. Second, special domain declarations are used to declare data structures that are not defined by the standard domains. 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. Here's an example to illustrate how declaring domains helps to document your predicates: Ahmad is a male who is 45 years old. With the pre-defined domains, you come up with the following predicate declaration : Person(symbol, symbol, integer) The declaration will work fine for most purpose.
  • 18. The following decoration will help you understand what the argument in the predicate declaration stand for: DOMAINS name , sex = symbol age = integer PREDICATES person( name, sex, age) One of the main advantages of this declarations is that visual prolog can catch the type errors, like the following obvious mistake : same_sex(X, Y):- person(X, sex, _ ), person(sex, Y,_ ). Even though name and sex are both defined as symbol, they are not equivalent to each other. This enables visual prolog to detect an error if you accidentally swap them. This feature is very useful when your programs get large and complex. You might be wondering why we don’t use special domains for all argument declarations, since special domains communicate the meaning of the argument so much better. The answer is that once an argument is typed to a specific domain, that domain can't be mixed with another domain you have declared, even if the domains are the same. So, even though name and sex are of the same domain (symbol), they can't be mixed. However, all user-defined domains can be matched with the pre-defined domains.
  • 19. The Goal Section: The goal section is the same as the body of a rule it's simply a list of subgoals. There are two differences between the goal section and a rule: The goal keyword is not followed by :-. Visual Prolog automatically executes the goal when the program runs. It's as if Visual Prolog makes a call to goal and the program runs, trying to satisfy the body of the goal rule. If the subgoals in the goal section all succeed, then the program terminate successfully. If, while the program is running, a subgoal in the goal section fails, then the program is said to have failed.
  • 20. ‫تمرين‬ : ‫بلغة‬ ‫برنامج‬ ‫اكتبي‬ Prolog ‫العائلية‬ ‫العالقات‬ ‫بوصف‬ ‫فيه‬ ‫تقومي‬ ( ‫أب‬ , ‫األجداد‬ ، ‫أخت‬ ، ‫أخ‬ ، ‫أم‬ ) ‫التالية‬ ‫العائلة‬ ‫لشجرة‬ : ‫العزيز‬ ‫عبد‬ ‫أحمد‬ ‫عبير‬ ‫خالد‬ ‫سالم‬ ‫سمير‬ ‫عادل‬ ‫محمد‬ ‫سعاد‬
  • 21.
  • 22. Quires : Run  Run As  Interpreted project (pro) ?- father(X,khaled). X = ahmad ; no ?- mother(X,mhmma d). X = abeer ; no ?- bother(X,abeer). no ?- ?- brother(X,abeer). X = khaled ; X = salem ; no ?- sister(X,salem). X = abeer ; no ?- sister(X,samir). no predecessor(abeer,X). X = mhmmad ; no ?- predecessor(ahmad,X). X = abeer ; X = khaled ; X = salem ; X = mhmmad ; X = adel ; X = samir ; X = abdlaziz ; X = soad ; no ?- quit.
  • 23. ‫مالحظة‬ :  ‫لتنزيل‬ Amzi Prolog + Logic Server IDE 7.6.9 ‫من‬ ‫الرابط‬ http://softwaredownloadmirror.com/trial/amzi- prolog-logic-server-ide-7.6.9/100198213/  ‫برنامج‬ ‫استخدام‬ ‫لشرح‬ ‫فيديو‬ ‫مقطع‬ Amzi http://www.amzi.com/videos/eclipse_first_use/ecli pse_first_use.html
  • 24. ‫الواجب‬ :  ‫بلغة‬ ‫برنامج‬ ‫اكتبي‬ Prolog ‫العائلية‬ ‫العالقات‬ ‫لوصف‬ ( ‫أب‬ , ‫أم‬ ‫األجداد‬ ، ‫أخت‬ ، ‫أخ‬ ، ) ‫امث‬ ‫وضع‬ ‫مع‬ ‫بك‬ ‫الخاصة‬ ‫العائلة‬ ‫لشجرة‬ ‫لة‬ ‫عن‬ ‫التقل‬ ‫لالستفسارات‬ 5 :