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
‫العائلية‬ ‫العالقات‬ ‫بوصف‬ ‫فيه‬ ‫تقومي‬
(
‫أب‬
,
‫األجداد‬ ، ‫أخت‬ ، ‫أخ‬ ، ‫أم‬
)
‫التالية‬ ‫العائلة‬ ‫لشجرة‬
:
‫العزيز‬ ‫عبد‬
‫أحمد‬
‫عبير‬
‫خالد‬
‫سالم‬
‫سمير‬ ‫عادل‬
‫محمد‬
‫سعاد‬
________ ________1.ppt
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

PDF
Logic Progamming in Perl
PDF
Prolog,Prolog Programming IN AI.pdf
PPTX
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
PDF
Regular expressions
PDF
Ai lab manual
PPT
2 Prolog L 1 V2.ppt
PPTX
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit
PDF
Turbo prolog 2.0 basics
Logic Progamming in Perl
Prolog,Prolog Programming IN AI.pdf
UOS-BSIT-3811-Artificial-Intelligence-Introduction-to-prolog-PDF.pptx
Regular expressions
Ai lab manual
2 Prolog L 1 V2.ppt
Unit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit 3 Prolog.pptxUnit
Turbo prolog 2.0 basics

Similar to ________ ________1.ppt (20)

PPT
Synaptica New Feature: Auto Match
PPTX
Poggi analytics - ebl - 1
PPT
Basics of Machine Learning
PPTX
Clean code ch03
PPTX
Introduction to Prolog
PPTX
Artificial Intelligence and Expert System
PDF
SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE
PDF
International Journal of Soft Computing, Mathematics and Control (IJSCMC)
PDF
Xml overview
PPTX
An introduction to Prolog language slide
PDF
Introduction to Prolog (PROramming in LOGic)
PPT
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
DOCX
Oo ps exam answer2
PPT
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
PDF
Introduction to prolog
PPTX
Dsm as theory building
PPTX
AI: Logic in AI
PPTX
AI: Logic in AI
PPTX
MACHINE LEARNING-LEARNING RULE
PPTX
logic for Advanced Programming Practice.pptx
Synaptica New Feature: Auto Match
Poggi analytics - ebl - 1
Basics of Machine Learning
Clean code ch03
Introduction to Prolog
Artificial Intelligence and Expert System
SL5 OBJECT: SIMPLER LEVEL 5 OBJECT EXPERT SYSTEM LANGUAGE
International Journal of Soft Computing, Mathematics and Control (IJSCMC)
Xml overview
An introduction to Prolog language slide
Introduction to Prolog (PROramming in LOGic)
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
Oo ps exam answer2
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
Introduction to prolog
Dsm as theory building
AI: Logic in AI
AI: Logic in AI
MACHINE LEARNING-LEARNING RULE
logic for Advanced Programming Practice.pptx
Ad

More from SamiAAli44 (8)

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

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Classroom Observation Tools for Teachers
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Pre independence Education in Inndia.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Cell Types and Its function , kingdom of life
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Anesthesia in Laparoscopic Surgery in India
Microbial diseases, their pathogenesis and prophylaxis
Abdominal Access Techniques with Prof. Dr. R K Mishra
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
01-Introduction-to-Information-Management.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Classroom Observation Tools for Teachers
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Pharma ospi slides which help in ospi learning
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pre independence Education in Inndia.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
102 student loan defaulters named and shamed – Is someone you know on the list?
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Cell Types and Its function , kingdom of life

________ ________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 ‫العائلية‬ ‫العالقات‬ ‫بوصف‬ ‫فيه‬ ‫تقومي‬ ( ‫أب‬ , ‫األجداد‬ ، ‫أخت‬ ، ‫أخ‬ ، ‫أم‬ ) ‫التالية‬ ‫العائلة‬ ‫لشجرة‬ : ‫العزيز‬ ‫عبد‬ ‫أحمد‬ ‫عبير‬ ‫خالد‬ ‫سالم‬ ‫سمير‬ ‫عادل‬ ‫محمد‬ ‫سعاد‬
  • 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 :