SlideShare a Scribd company logo
1 of 24
‫المحاضرة‬
(
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 - 1Gaston Liberman
 
Basics of Machine Learning
Basics of Machine LearningBasics of Machine Learning
Basics of Machine Learningbutest
 
Introduction to Prolog
Introduction to Prolog Introduction to Prolog
Introduction to Prolog Showkot Usman
 
Artificial Intelligence and Expert System
Artificial Intelligence and Expert System Artificial Intelligence and Expert System
Artificial Intelligence and Expert System 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
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide2021uam4641
 
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
 
Introduction to prolog
Introduction to prologIntroduction to prolog
Introduction to prologRakhi Sinha
 
Dsm as theory building
Dsm as theory buildingDsm as theory building
Dsm as theory buildingClarkTony
 
MACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEMACHINE LEARNING-LEARNING RULE
MACHINE LEARNING-LEARNING RULEDrBindhuM
 
Erlang kickstart
Erlang kickstartErlang kickstart
Erlang kickstartRyan Brown
 
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 VOTEijnlc
 
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 VOTEkevig
 

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
 
Introduction to Prolog
Introduction to Prolog Introduction to Prolog
Introduction to Prolog
 
Artificial Intelligence and Expert System
Artificial Intelligence and Expert System Artificial Intelligence and Expert System
Artificial Intelligence and Expert System
 
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
المحاضرة الاولى بور بوينت تعليم اساسي.pptxSamiAAli44
 
م.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptxم.م عقيل ثامر (4).pptx
م.م عقيل ثامر (4).pptxSamiAAli44
 
Lecture 10.pptx
Lecture 10.pptxLecture 10.pptx
Lecture 10.pptxSamiAAli44
 
م.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptxم.م عقيل ثامر (9).pptx
م.م عقيل ثامر (9).pptxSamiAAli44
 
virus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdfvirus-140717152102-phpapp02.pdf
virus-140717152102-phpapp02.pdfSamiAAli44
 
lce1 مترجمات.pptx
lce1 مترجمات.pptxlce1 مترجمات.pptx
lce1 مترجمات.pptxSamiAAli44
 
محاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptxمحاضرات في مادة طرائق التدريس التخصصية (1).pptx
محاضرات في مادة طرائق التدريس التخصصية (1).pptxSamiAAli44
 
Computer-Networks--Network.ppt
Computer-Networks--Network.pptComputer-Networks--Network.ppt
Computer-Networks--Network.pptSamiAAli44
 

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

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 

________ ________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 :