SlideShare a Scribd company logo
1 of 27
Prepared by: Sharif Omar Salem – ssalemg@gmail.com
Formal Logic:
PROgramming in
LOGic
0
Declarative Programming Languages
• A declarative language is based on predicate logic.
• A program written in a declarative language consists only of statements
(clauses) (actually predicate wffs) that are declared as hypotheses.
• Execution of a declarative program allows the user to pose queries,
asking for information about possible conclusions that can be derived
from the hypotheses.
• After obtaining the user’s query, the language turns on its “inference
engine” and applies its rules of inference to the hypotheses to see
which conclusions fit the user’s query.
1
Prolog
• Prolog (PROgramming in LOGic) is a declarative programming language.
• Structure of programs
– Programs consist of procedures.
– Procedures consist of clauses.
– Each clause is a fact or a rule.
– Programs are executed by posing queries.
• The set of declarations that constitutes a Prolog program is also known as a
Prolog database.
• Items in a Prolog database are either facts or rules.
2
Prolog
• Example of Prolog facts
(a binary predicate called “eat(x,y)”):
– eat (bear, fish)
– eat (bear, fox)
– eat (deer, grass)
– “bear,” “fish,” “fox,” “deer,” and “grass” are constants because they
represent specific elements in the domain.
• Other facts that we could add to the Prolog database:
– animal (bear)
– animal (fish)
– animal (fox)
– animal (deer)
– plant (grass)
3
Prolog
• We can now pose some simple queries.
– is (eat (deer, grass))
• yes
– is (eat (bear, rabbit))
• no
• “is” asks if the fact exists in the database.
• Queries may include variables, for example:
– which(x: eat(bear, x))
• produces:
– fish
– Fox
4
Example
elephant(george).
elephant(mary).
elephant(X) :- grey(X), mammal(X), hasTrunk(X).
5
Procedure for elephant
Predicate
Clauses
Rule
Facts
Example
6
?- elephant(george).
yes
?- elephant(jane).
no
Queries
Replies
Prolog
7
 The second type of item in a Prolog database is a Prolog
rule.
 A rule is a description of a predicate by means of an
implication.
 Prolog rule structure can be as
 Head if G1 and G2 and G3…..and Gn.
 Head :- G1, G2, G3,……………...., Gn.
 Where head is the predicate like Prey(x)
 G1…..Gn are the body and it is the conditional rule of the
head predicate. Like { eat (y,x) and animal(x) }.
Prolog Rules
• For example, we might use a rule to define a predicate of prey:
– prey(x)  Prolog Predicate.
– prey(x) if eat(y, x) and animal(x)  If eat(y, x) and animal(x) , then
Prey(x)  Prolog Rule.
Can be written prey(x) :- eat(y, x), animal(x).
– This says that x is a prey if it is an animal that is eaten.
• If we add this rule to our database, then in response to the query:
– which(x: prey(x))
• we would get:
• fish
• fox
8
Exercise
male(bertram).
male(percival).
female(lucinda).
female(camilla).
pair(X, Y) :- male(X), female(Y).
9
?- pair(percival, Y).
?- pair(apollo, daphne).
?- pair(camilla, Y).
?- pair(X, lucinda).
?- pair(X, X).
?- pair(bertram, lucinda).
?- pair(X, daphne).
?- pair(X, Y).
Exercise
drinks(john, martini).
drinks(mary, gin).
drinks(susan, vodka).
drinks(john, gin).
drinks(fred, gin).
pair(X, Y, Z) :-
drinks(X, Z),
drinks(Y, Z).
10
?- pair(X, john, martini).
?- pair(mary, susan, gin).
?- pair(john, mary, gin).
?- pair(john, john, gin).
?- pair(X, Y, gin).
?- pair(bertram, lucinda).
?- pair(bertram, lucinda,
vodka).
?- pair(X, Y, Z).
This definition forces X and Y to be distinct:
pair(X, Y, Z) :- drinks(X, Z), drinks(Y, Z), X == Y.
Exercise
11
berkshire
wiltshire
surrey
hampshire sussex
kent
How to represent this relation?
Note that borders are symmetric (two directions).
(a) Representing a symmetric relation.
(b) Implementing a strange ticket condition.
SEE TUTORIAL 1 FOR MORE DETAILS
12
Recursion
• Prolog rules are implications.
• Their antecedents may depend on facts or other rules.
• The antecedent of a rule may also depend on that rule itself, in
which case the rule is defined in terms of itself.
• For example, we can then define a binary relation in-food-chain(x,
y), meaning “y is in x’s food chain.” This means one of two things:
1. x eats y directly.  food-chain(x,y) . No recursion.
2. x eats something that eats something that eats something .. that
eats y. x eats z and y is in z’s food chain. recursion
 food-chain(x,z) ^ food-chain(z,y)
13
Recursion
• Case (1) is simple to test from our existing facts, in-food-chain means nothing
different than eat.
• On the other hand, Case (2) without (1) sends us down an infinite path of
something eating something eating something and so on, with nothing telling us
when to stop.
• Recursive definitions always need a stopping point that consists of specific
information.
• The Prolog rule for in-food-chain incorporates (1) and (2):
– in-food-chain(x, y) if eat(x, y)
– in-food-chain(x, y) if eat(x, z) and in-food-chain(z, y)
• is a recursive rule because it defines the predicate in-food-chain in terms
of in-food-chain.
14
?- path(f, f).
?- path(a, c).
?- path(g, e).
?- path(g, X).
?- path(X, h).
path(X, Y) :- t(X, Y).
path(X, Y) :- t(X, Z), path(Z, Y).
t(g, h).
t(g, d).
t(e, d).
t(h, f).
t(e, f).
t(a, e).
t(a, b).
t(b, f).
t(b, c).
t(f, c).
Example
15
arc a
ed
g
h
f
c
b
Examples
16
Rules
Facts
Goals/Queries
Examples
17
Rules
Facts
Goals/Queries
Examples
18
Prolog Standards
19
Prolog Standards
20
Horn Clauses and Resolution
Prolog clauses as Predicate logic wffs.
• We can describe the facts in prolog by the wffs in predicate logic.
As example
 animal(fox) in Prolog could be written as A(f) in Predicate logic .
 partents(john, diana) in Prolog ………. P(j,d) in Predicate logic.
• And describe the rules as a predicate formula.
with the rule: E(y, x) Λ A(x)  Pr (x)
– Prolog treats the rule as being universally quantified and uses
universal instantiation to strip off the universal quantifiers:
– ( y)( x)[E(y, x) Λ A(x)  Pr(x)]
21
Horn Clauses and Resolution
• A Horn clause is a wff composed of predicates and the negations of
predicates joined by disjunctions, where, at most, one predicate is un-
negated.
• Example of Horn clause: [E(y, x)] V [A(x)] V Pr(x)
• This can be rewritten using DeMorgan’s law as
[E(y, x) Λ A(x)]’ V Pr(x)
• Using Implication rule the formula is equivalent to:
E(y, x) Λ A(x)  Pr(x)
• The above is a rule in the Prolog programming.
22
Horn Clauses and Resolution
• The rule of inference used by Prolog is called resolution ( proof
sequence).
• Two Horn clauses in a Prolog database are resolved into a new Horn
clause if one contains an unnegated predicate that matches a negated
predicate in the other clause.
• For example:
A(a) , [A(a)] V B(b) A(a) Λ [A(a)] V B(b) 
A(a), A(a)  B(b) B(b)
• which is just an application of modus ponens.
• Therefore, Prolog’s rule of inference includes modus ponens as a special
case.
23
Expert Systems
• Many interesting applications programs have been developed, in
Prolog and similar logic programming languages, that gather a
database of facts and rules about some domain and then use
this database to draw conclusions.
• Such programs are known as expert systems, knowledge-
based systems, or rule-based systems.
• The database in an expert system attempts to capture the
knowledge (“elicit the expertise”) of a human expert in a
particular field.
• This includes both the facts known to the expert and the expert’s
reasoning path in reaching conclusions from those facts.
24
Prepared by: Sharif Omar Salem – ssalemg@gmail.com
End Of Lecture
25
Prepared by: Sharif Omar Salem – ssalemg@gmail.com
Next Lecture:
ProLogic_Tutorial
26

More Related Content

What's hot

ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introductionwahab khan
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prologbaran19901990
 
PROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologPROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologDataminingTools Inc
 
09 logic programming
09 logic programming09 logic programming
09 logic programmingsaru40
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prologsaru40
 
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologDataminingTools Inc
 
Soirée Guava et Lombok avec Thierry Leriche
Soirée Guava et Lombok avec Thierry LericheSoirée Guava et Lombok avec Thierry Leriche
Soirée Guava et Lombok avec Thierry LericheNormandy JUG
 
201209 Lombok & Guava
201209 Lombok & Guava201209 Lombok & Guava
201209 Lombok & Guavalyonjug
 
Milou fait un régime Guava Lombok
Milou fait un régime Guava LombokMilou fait un régime Guava Lombok
Milou fait un régime Guava LombokLorraine JUG
 
Prolog programming
Prolog programmingProlog programming
Prolog programmingHarry Potter
 
PROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG CONTENT
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)Nitesh Singh
 
Jarrar: First Order Logic
Jarrar: First Order LogicJarrar: First Order Logic
Jarrar: First Order LogicMustafa Jarrar
 
Babar: Knowledge Recognition, Extraction and Representation
Babar: Knowledge Recognition, Extraction and RepresentationBabar: Knowledge Recognition, Extraction and Representation
Babar: Knowledge Recognition, Extraction and RepresentationPierre de Lacaze
 

What's hot (20)

ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
Introduction to Prolog
Introduction to PrologIntroduction to Prolog
Introduction to Prolog
 
PROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In PrologPROLOG: Cuts And Negation In Prolog
PROLOG: Cuts And Negation In Prolog
 
09 logic programming
09 logic programming09 logic programming
09 logic programming
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In Prolog
 
Prolog
PrologProlog
Prolog
 
Soirée Guava et Lombok avec Thierry Leriche
Soirée Guava et Lombok avec Thierry LericheSoirée Guava et Lombok avec Thierry Leriche
Soirée Guava et Lombok avec Thierry Leriche
 
201209 Lombok & Guava
201209 Lombok & Guava201209 Lombok & Guava
201209 Lombok & Guava
 
Milou fait un régime Guava Lombok
Milou fait un régime Guava LombokMilou fait un régime Guava Lombok
Milou fait un régime Guava Lombok
 
Prolog programming
Prolog programmingProlog programming
Prolog programming
 
Logic Programming and ILP
Logic Programming and ILPLogic Programming and ILP
Logic Programming and ILP
 
PROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In Prolog
 
Logic programming (1)
Logic programming (1)Logic programming (1)
Logic programming (1)
 
Plc part 4
Plc  part 4Plc  part 4
Plc part 4
 
Jarrar: First Order Logic
Jarrar: First Order LogicJarrar: First Order Logic
Jarrar: First Order Logic
 
Babar: Knowledge Recognition, Extraction and Representation
Babar: Knowledge Recognition, Extraction and RepresentationBabar: Knowledge Recognition, Extraction and Representation
Babar: Knowledge Recognition, Extraction and Representation
 
Classical Sets & fuzzy sets
Classical Sets & fuzzy setsClassical Sets & fuzzy sets
Classical Sets & fuzzy sets
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 

Viewers also liked

#3 formal methods – propositional logic
#3 formal methods – propositional logic#3 formal methods – propositional logic
#3 formal methods – propositional logicSharif Omar Salem
 
#7 formal methods – loop proof examples
#7 formal methods – loop proof   examples#7 formal methods – loop proof   examples
#7 formal methods – loop proof examplesSharif Omar Salem
 
#6 formal methods – loop proof using induction method
#6 formal methods – loop proof using induction method#6 formal methods – loop proof using induction method
#6 formal methods – loop proof using induction methodSharif Omar Salem
 
#2 formal methods – principles of logic
#2 formal methods – principles of logic#2 formal methods – principles of logic
#2 formal methods – principles of logicSharif Omar Salem
 
#4 formal methods – predicate logic
#4 formal methods – predicate logic#4 formal methods – predicate logic
#4 formal methods – predicate logicSharif Omar Salem
 
#1 formal methods – introduction for software engineering
#1 formal methods – introduction for software engineering#1 formal methods – introduction for software engineering
#1 formal methods – introduction for software engineeringSharif Omar Salem
 

Viewers also liked (6)

#3 formal methods – propositional logic
#3 formal methods – propositional logic#3 formal methods – propositional logic
#3 formal methods – propositional logic
 
#7 formal methods – loop proof examples
#7 formal methods – loop proof   examples#7 formal methods – loop proof   examples
#7 formal methods – loop proof examples
 
#6 formal methods – loop proof using induction method
#6 formal methods – loop proof using induction method#6 formal methods – loop proof using induction method
#6 formal methods – loop proof using induction method
 
#2 formal methods – principles of logic
#2 formal methods – principles of logic#2 formal methods – principles of logic
#2 formal methods – principles of logic
 
#4 formal methods – predicate logic
#4 formal methods – predicate logic#4 formal methods – predicate logic
#4 formal methods – predicate logic
 
#1 formal methods – introduction for software engineering
#1 formal methods – introduction for software engineering#1 formal methods – introduction for software engineering
#1 formal methods – introduction for software engineering
 

Similar to #8 formal methods – pro logic

CPSC 125 Ch 1 Sec 5
CPSC 125 Ch 1 Sec 5CPSC 125 Ch 1 Sec 5
CPSC 125 Ch 1 Sec 5David Wood
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide2021uam4641
 
Knowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and ReasoningKnowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and ReasoningSagacious IT Solution
 
Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)SHUBHAM KUMAR GUPTA
 
Tutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and SystemsTutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and SystemsAdrian Paschke
 
Knowledge engg using & in fol
Knowledge engg using & in folKnowledge engg using & in fol
Knowledge engg using & in folchandsek666
 
Application of Bayesian and Sparse Network Models for Assessing Linkage Diseq...
Application of Bayesian and Sparse Network Models for Assessing Linkage Diseq...Application of Bayesian and Sparse Network Models for Assessing Linkage Diseq...
Application of Bayesian and Sparse Network Models for Assessing Linkage Diseq...Gota Morota
 
SOFIE - A Unified Approach To Ontology-Based Information Extraction Using Rea...
SOFIE - A Unified Approach To Ontology-Based Information Extraction Using Rea...SOFIE - A Unified Approach To Ontology-Based Information Extraction Using Rea...
SOFIE - A Unified Approach To Ontology-Based Information Extraction Using Rea...Tobias Wunner
 
Prolog Programming : Basics
Prolog Programming : BasicsProlog Programming : Basics
Prolog Programming : BasicsMitul Desai
 
Lecture 2 fuzzy inference system
Lecture 2  fuzzy inference systemLecture 2  fuzzy inference system
Lecture 2 fuzzy inference systemParveenMalik18
 
L03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicL03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicManjula V
 

Similar to #8 formal methods – pro logic (20)

CPSC 125 Ch 1 Sec 5
CPSC 125 Ch 1 Sec 5CPSC 125 Ch 1 Sec 5
CPSC 125 Ch 1 Sec 5
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
Prolog2 (1)
Prolog2 (1)Prolog2 (1)
Prolog2 (1)
 
An introduction to Prolog language slide
An introduction to Prolog language slideAn introduction to Prolog language slide
An introduction to Prolog language slide
 
Knowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and ReasoningKnowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and Reasoning
 
Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)
 
02 RULES OF INFERENCES.pptx
02 RULES OF INFERENCES.pptx02 RULES OF INFERENCES.pptx
02 RULES OF INFERENCES.pptx
 
chapter9.ppt
chapter9.pptchapter9.ppt
chapter9.ppt
 
Tutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and SystemsTutorial - Introduction to Rule Technologies and Systems
Tutorial - Introduction to Rule Technologies and Systems
 
Knowledge engg using & in fol
Knowledge engg using & in folKnowledge engg using & in fol
Knowledge engg using & in fol
 
Application of Bayesian and Sparse Network Models for Assessing Linkage Diseq...
Application of Bayesian and Sparse Network Models for Assessing Linkage Diseq...Application of Bayesian and Sparse Network Models for Assessing Linkage Diseq...
Application of Bayesian and Sparse Network Models for Assessing Linkage Diseq...
 
Fol
FolFol
Fol
 
SOFIE - A Unified Approach To Ontology-Based Information Extraction Using Rea...
SOFIE - A Unified Approach To Ontology-Based Information Extraction Using Rea...SOFIE - A Unified Approach To Ontology-Based Information Extraction Using Rea...
SOFIE - A Unified Approach To Ontology-Based Information Extraction Using Rea...
 
Module_5_1.pptx
Module_5_1.pptxModule_5_1.pptx
Module_5_1.pptx
 
Prolog Programming : Basics
Prolog Programming : BasicsProlog Programming : Basics
Prolog Programming : Basics
 
PredicateLogic (1).ppt
PredicateLogic (1).pptPredicateLogic (1).ppt
PredicateLogic (1).ppt
 
PredicateLogic.pptx
PredicateLogic.pptxPredicateLogic.pptx
PredicateLogic.pptx
 
PROLOG: Introduction To Prolog
PROLOG: Introduction To PrologPROLOG: Introduction To Prolog
PROLOG: Introduction To Prolog
 
Lecture 2 fuzzy inference system
Lecture 2  fuzzy inference systemLecture 2  fuzzy inference system
Lecture 2 fuzzy inference system
 
L03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicL03 ai - knowledge representation using logic
L03 ai - knowledge representation using logic
 

Recently uploaded

DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

#8 formal methods – pro logic

  • 1. Prepared by: Sharif Omar Salem – ssalemg@gmail.com Formal Logic: PROgramming in LOGic 0
  • 2. Declarative Programming Languages • A declarative language is based on predicate logic. • A program written in a declarative language consists only of statements (clauses) (actually predicate wffs) that are declared as hypotheses. • Execution of a declarative program allows the user to pose queries, asking for information about possible conclusions that can be derived from the hypotheses. • After obtaining the user’s query, the language turns on its “inference engine” and applies its rules of inference to the hypotheses to see which conclusions fit the user’s query. 1
  • 3. Prolog • Prolog (PROgramming in LOGic) is a declarative programming language. • Structure of programs – Programs consist of procedures. – Procedures consist of clauses. – Each clause is a fact or a rule. – Programs are executed by posing queries. • The set of declarations that constitutes a Prolog program is also known as a Prolog database. • Items in a Prolog database are either facts or rules. 2
  • 4. Prolog • Example of Prolog facts (a binary predicate called “eat(x,y)”): – eat (bear, fish) – eat (bear, fox) – eat (deer, grass) – “bear,” “fish,” “fox,” “deer,” and “grass” are constants because they represent specific elements in the domain. • Other facts that we could add to the Prolog database: – animal (bear) – animal (fish) – animal (fox) – animal (deer) – plant (grass) 3
  • 5. Prolog • We can now pose some simple queries. – is (eat (deer, grass)) • yes – is (eat (bear, rabbit)) • no • “is” asks if the fact exists in the database. • Queries may include variables, for example: – which(x: eat(bear, x)) • produces: – fish – Fox 4
  • 6. Example elephant(george). elephant(mary). elephant(X) :- grey(X), mammal(X), hasTrunk(X). 5 Procedure for elephant Predicate Clauses Rule Facts
  • 8. Prolog 7  The second type of item in a Prolog database is a Prolog rule.  A rule is a description of a predicate by means of an implication.  Prolog rule structure can be as  Head if G1 and G2 and G3…..and Gn.  Head :- G1, G2, G3,……………...., Gn.  Where head is the predicate like Prey(x)  G1…..Gn are the body and it is the conditional rule of the head predicate. Like { eat (y,x) and animal(x) }.
  • 9. Prolog Rules • For example, we might use a rule to define a predicate of prey: – prey(x)  Prolog Predicate. – prey(x) if eat(y, x) and animal(x)  If eat(y, x) and animal(x) , then Prey(x)  Prolog Rule. Can be written prey(x) :- eat(y, x), animal(x). – This says that x is a prey if it is an animal that is eaten. • If we add this rule to our database, then in response to the query: – which(x: prey(x)) • we would get: • fish • fox 8
  • 10. Exercise male(bertram). male(percival). female(lucinda). female(camilla). pair(X, Y) :- male(X), female(Y). 9 ?- pair(percival, Y). ?- pair(apollo, daphne). ?- pair(camilla, Y). ?- pair(X, lucinda). ?- pair(X, X). ?- pair(bertram, lucinda). ?- pair(X, daphne). ?- pair(X, Y).
  • 11. Exercise drinks(john, martini). drinks(mary, gin). drinks(susan, vodka). drinks(john, gin). drinks(fred, gin). pair(X, Y, Z) :- drinks(X, Z), drinks(Y, Z). 10 ?- pair(X, john, martini). ?- pair(mary, susan, gin). ?- pair(john, mary, gin). ?- pair(john, john, gin). ?- pair(X, Y, gin). ?- pair(bertram, lucinda). ?- pair(bertram, lucinda, vodka). ?- pair(X, Y, Z). This definition forces X and Y to be distinct: pair(X, Y, Z) :- drinks(X, Z), drinks(Y, Z), X == Y.
  • 12. Exercise 11 berkshire wiltshire surrey hampshire sussex kent How to represent this relation? Note that borders are symmetric (two directions). (a) Representing a symmetric relation. (b) Implementing a strange ticket condition.
  • 13. SEE TUTORIAL 1 FOR MORE DETAILS 12
  • 14. Recursion • Prolog rules are implications. • Their antecedents may depend on facts or other rules. • The antecedent of a rule may also depend on that rule itself, in which case the rule is defined in terms of itself. • For example, we can then define a binary relation in-food-chain(x, y), meaning “y is in x’s food chain.” This means one of two things: 1. x eats y directly.  food-chain(x,y) . No recursion. 2. x eats something that eats something that eats something .. that eats y. x eats z and y is in z’s food chain. recursion  food-chain(x,z) ^ food-chain(z,y) 13
  • 15. Recursion • Case (1) is simple to test from our existing facts, in-food-chain means nothing different than eat. • On the other hand, Case (2) without (1) sends us down an infinite path of something eating something eating something and so on, with nothing telling us when to stop. • Recursive definitions always need a stopping point that consists of specific information. • The Prolog rule for in-food-chain incorporates (1) and (2): – in-food-chain(x, y) if eat(x, y) – in-food-chain(x, y) if eat(x, z) and in-food-chain(z, y) • is a recursive rule because it defines the predicate in-food-chain in terms of in-food-chain. 14
  • 16. ?- path(f, f). ?- path(a, c). ?- path(g, e). ?- path(g, X). ?- path(X, h). path(X, Y) :- t(X, Y). path(X, Y) :- t(X, Z), path(Z, Y). t(g, h). t(g, d). t(e, d). t(h, f). t(e, f). t(a, e). t(a, b). t(b, f). t(b, c). t(f, c). Example 15 arc a ed g h f c b
  • 22. Horn Clauses and Resolution Prolog clauses as Predicate logic wffs. • We can describe the facts in prolog by the wffs in predicate logic. As example  animal(fox) in Prolog could be written as A(f) in Predicate logic .  partents(john, diana) in Prolog ………. P(j,d) in Predicate logic. • And describe the rules as a predicate formula. with the rule: E(y, x) Λ A(x)  Pr (x) – Prolog treats the rule as being universally quantified and uses universal instantiation to strip off the universal quantifiers: – ( y)( x)[E(y, x) Λ A(x)  Pr(x)] 21
  • 23. Horn Clauses and Resolution • A Horn clause is a wff composed of predicates and the negations of predicates joined by disjunctions, where, at most, one predicate is un- negated. • Example of Horn clause: [E(y, x)] V [A(x)] V Pr(x) • This can be rewritten using DeMorgan’s law as [E(y, x) Λ A(x)]’ V Pr(x) • Using Implication rule the formula is equivalent to: E(y, x) Λ A(x)  Pr(x) • The above is a rule in the Prolog programming. 22
  • 24. Horn Clauses and Resolution • The rule of inference used by Prolog is called resolution ( proof sequence). • Two Horn clauses in a Prolog database are resolved into a new Horn clause if one contains an unnegated predicate that matches a negated predicate in the other clause. • For example: A(a) , [A(a)] V B(b) A(a) Λ [A(a)] V B(b)  A(a), A(a)  B(b) B(b) • which is just an application of modus ponens. • Therefore, Prolog’s rule of inference includes modus ponens as a special case. 23
  • 25. Expert Systems • Many interesting applications programs have been developed, in Prolog and similar logic programming languages, that gather a database of facts and rules about some domain and then use this database to draw conclusions. • Such programs are known as expert systems, knowledge- based systems, or rule-based systems. • The database in an expert system attempts to capture the knowledge (“elicit the expertise”) of a human expert in a particular field. • This includes both the facts known to the expert and the expert’s reasoning path in reaching conclusions from those facts. 24
  • 26. Prepared by: Sharif Omar Salem – ssalemg@gmail.com End Of Lecture 25
  • 27. Prepared by: Sharif Omar Salem – ssalemg@gmail.com Next Lecture: ProLogic_Tutorial 26