SlideShare a Scribd company logo
1
Lecture 5
Knowledge Representation ,
Logic, and inference
1. Knowledge-based Agents
2. Knowledge Representation Schemas
2-1 Propositional Logic
2-2 First order logic
2-3 Inference
2
Knowledge-based Agent
Central component of a knowledge-based agent
is its knowledge-base (KB)
A KB is a set of representations of facts about
the world
Each individual representation is called a
sentence
The sentences are expressed in a language
called a knowledge representation language
A knowledge-based agent should be able to
infer. Inference mechanism generates new
sentences that are necessarily true given that
the old sentences are true.
3
The Intelligent Agent as Black Box
Prior
knowledge
Past
Experience
Goals and
Values
Observations
ActionsReasoning (inference)
and Representation
System (RRS)
4
Inference example
Given:
“The red block is above the blue block”
“The green block is above the red block”
Infer:
“The green block is above the blue block”
“The blocks form a tower”
5
Knowledge Representation Schemas
(Symbolic)
1-Logic based representation – propositional
logic, first order predicate logic, Prolog
2-Procedural representation – rules, production
system
3-Network representation – semantic
networks, conceptual graphs
4-Structural representation – scripts, frames,
objects
6
Representation of Knowledge
There is no single most adequate knowledge
representation formalism/scheme for
everything.
Main points for selecting a representation
formalism: what should be represented, how
should the knowledge be processed.
There are many more representation formalisms.
All the above mentioned are symbolic. There
are non-symbolic ones, e.g. Neural networks.
7
What is Knowledge?
Data – primitive verifiable facts, of any
representation. Data reflects the current
world.
Knowledge – relation among sets of data
(information), that is very often used for
further information deduction.
Knowledge contain information about
behaviour of abstract models of the world.
8
Knowledge Representation
The object of KR is to express knowledge in a
computer-tractable form, so that it can be
used to help agents perform well.
A KR language is defined by two aspects:
Syntax: describes how to make sentences OR
describes the possible configurations that can
constitute sentences.
Semantics: determine the facts (meaning) in the
world to which the sentences refer OR the “things”
in the sentence.
9
Knowledge Representation
Example
The syntax of the language of arithmetic expressions
says that x and y are expressions denoting numbers,
the x  y is a sentence. The semantics of the
language say that x  y is false when y is a bigger
number than x, and true otherwise.
Inference:
The terms “inference” and “reasoning” are generally
used to cover any process by which conclusions are
reached.
Logical inference  deduction
10
Types of logic
Logic is a language for KR which tells us how to build up sentences in the
language.
Ontological commitment: what exists - facts? objects? time? beliefs?
Epistemological commitment: what states of knowledge?
Language
Ontological
Commitment
Epistemological
Commitment
Propositional
Logic
Facts True/false/unknown
First order logic
Facts, objects,
relations
True/false/unknown
Temporal logic
Facts, objects,
relations, time
True/false/unknown
Probability theory Facts Degree of belief 0…1
Fuzzy logic Degree of truth Degree of belief 0…1
11
Knowledge Representation
1- Logic
•Propositional Logic (Propositional Calculus):
Propositional Logic has limitations, - it is not
expressive enough.
•First-order Logic (First-order Predicate Calculus):
First-Order Logic is an improvement and is
useful.
12
Propositions(‫افتراض‬)
Statements that can be either true or false
The sky is blue
The moon is made of cheese
Artificial intelligence is my favourite subject
Each statement takes one of the truth-
values T or F (or, 1 and 0)
Each statement is represented by a
propositional variable such as p, q, r, …
13
Logical operators
We can use logical operators (or
connectives) to build more complex
statements from our simple propositions
The moon is not made of cheese
I am bored and I am tired
You are a man or you are a mouse
If it is snowing then it is cold
14
Negation
p represents “It is snowing”
The negation of p represents “It is not
snowing”
This is written p
pronounced “not p”
If p takes the value T then p takes the
value F, and vice versa
15
Conjunction
p represents “It is snowing”
q represents “It is cold”
The conjunction of p and q represents “It
is snowing and it is cold”
This is written as p  q
pronounced “p and q”
Commutative, associative
16
Disjunction
q represents “It is cold”
r represents “It is raining”
The disjunction of q and r represents “It is
cold or it is raining”
This is written as q  r
pronounced “q or r”
Commutative (q  r = r  q),
Associative (q  (r  p))=(q  r)  (q  p)
17
Implication
p represents “It is snowing”
q represents “It is cold”
Implication gives statements such as “If it
is snowing then it is cold”
This is written p  q
pronounced “p implies q”
Not commutative, not associative
18
19
Propositional Calculus -
example
Let, Fact P: "Ali likes chips''
Let, Fact Q: "Ali eats chips''
Other possible facts:
P  Q : "Ali likes chips or Ali eats chips”
P  Q : "Ali likes chips and Ali eats chips'’
 Q : "Ali doesn't eat chips'’
P  Q : "If Ali likes chips then Ali eats chips''
Read: Logic    
Nat. Lang. Or And Implies Not
20
Truth tables for logical connectives
TTFFTFF
FTTFTTF
FFTFFFT
TTTTFTT
~ QPQPQPQPPQP 
Ex: Give the truth table for: (p  q)  (p  q)
(p  q)  (p  q)
false
true
true
true
Solu:
21
Examples of PL sentences
P means "It is hot"
Q means "It is humid"
R means "It is raining"
P ^ Q => R
"If it is hot and humid, then it is raining"
Q => P
"If it is humid, then it is hot"
Q
"It is humid."
22
Propositional formulae
A formula can be built from propositions and
operators to represent a more complex
statement
We can construct a truth-table for any formula
Upper-case letters are used to represent
formulae
e.g. P might represent (p  q)  r
An interpretation of P is an assignment of truth-
values to all the propositional variables
i.e. it is a single row of the truth table
23
Example formula and truth-table
(p  q)  r
p q r q p  q (p  q)  r
T T T F T T
T T F F T F
T F T T T T
T F F T T F
F T T F F T
F T F F F T
F F T T T T
F F F T T F
24
Tautologies(‫المعنى‬ ‫تكرار‬)
A propositional formula P that takes the
truth-value T for every possible
interpretation is called a tautology.
This is written using the metasymbol╞
like this: ╞ P
e.g. ╞ ( p  p )
Any formula that is a tautology is said to
be a valid formula.
25
Establishing tautologies
An easy way to determine whether or not a
proposition is a tautology is to substitute
truth values for the atomic propositions.
For example, given the proposition p  p, if
we substitute true for p, then the overall
proposition is equivalent to true and if we
substitute false for p then the overall
proposition is equivalent to true
Therefore we conclude that p  p is a
tautology.
26
Questions
Which of the following
propositions are tautologies?
p  (p  q)
p  (q  p)
(p  q)  (q  p)
(p  q)  (p  q)
27
Contradictions and
contingencies(‫طارئ‬)
A proposition that is always false
is called contradiction
If a proposition is neither a
tautology nor a contradiction
then it is called a contingency
28
Propositional Inference: Enumeration Method
Let    and KB = (  C)  B  C)
Is it the case that KB  ?
I.e.,  is true in all worlds where KB is true.
Check all possible models --  must be true whenever KB is
true.
TrueTrueTrue
FalseTrueTrue
TrueFalseTrue
FalseFalseTrue
TrueTrueFalse
FalseTrueFalse
TrueFalseFalse
FalseFalseFalse
=
  
KB=
(  C) 
B  C)
CBA
╞
29 TrueTrueTrueTrue
TrueFalseTrueTrue
FalseTrueFalseTrue
TrueFalseFalseTrue
TrueTrueTrueFalse
FalseFalseTrueFalse
FalseTrueFalseFalse
FalseFalseFalseFalse

  
KB
(  C) 
B  C)
CBA
Propositional Inference: Enumeration Method
Let    and KB = (  C)  B  C)
Is it the case that KB  ?
I.e.,  is true in all worlds where KB is true
Check all possible models --  must be true whenever KB is true
╞
30
Propositional Inference: Enumeration Method
Let    and KB = (  C)  B  C)
Is it the case that KB  ?
Check all possible models --  must be true whenever KB is true
A B C
KB
(  C) 
B  C)

  
False False False False False
False False True False False
False True False False True
False True True True True
True False False True True
True False True False True
True True False True True
True True True True True
╞
31
Propositional Inference: Enumeration Method
Let    and KB = (  C)  B  C)
Is it the case that KB ╞  ?
Check all possible models --  must be true whenever KB is true
A B C
KB
(  C) 
B  C)

  
False False False False False
False False True False False
False True False False True
False True True True True
True False False True True
True False True False True
True True False True True
True True True True True
32
Reasoning in Propositional Logic
Similarly, if we assume a few things, we can
determine if something follows.
E.g., if we assume P, then PQ, say, degenerates
into True  Q, which a truth table will tell us is
always true.
So, we can always draw valid conclusions from
premises, regardless of what any of this
means
33
Rules of inference
There are rules of inference which can be
applied to logic, These follow the syntax:
A
B
When something in the knowledge base
matches the pattern above the line, then the
system concludes that the part below the line
is true.
or, sometimes we may write it, as
, , … |-  meaning, if we know , , …, it is
okay to conclude .
(‫المنطقية‬ ‫المقدمة‬)Premise
Conclusion
34
An Inference Rule: And - Elimination
From a conjunction, you can infer any of the
conjuncts.
1 2 … nPremise
_______________
iConclusion
An inference rule is sound if the conclusion is
true in all cases where the premises are true.
35
An Inference Rule: Modus Ponens
From an implication and the premise of the
implication, you can infer the conclusion.
  Premise
___________
Conclusion
An inference rule is sound if the conclusion is true in all
cases where the premises are true.
i.e. If    is true, and  is true, then  is true.
Generalized Modus Ponens (GMP)
36
Common Inference Rules
Modus Ponens:
,  |- 
And-Elimination:
1  2 |- i
And-Introduction:
1,2 |- 1  2
Or-Introduction:
 |-   
Double-Negation Elimination:
¬¬  |- 
Resolution:
   , ¬    |-   
37
Propositional Logic: Rules of Inference (cont.)
Or-Introduction:
From a sentence, you can infer its disjunction with anything
else at all.
i
1  2  ...  n
Double-Negation Elimination:
From a doubly negated sentence, you can infer a positive
sentence


And-Introduction:
From a list you can infer their conjunction.
1, 2 , ... , n
1  2  ...  n
38
Predicate Logic
or First-order logic (FOL)
39
Limitations of Propositional Logic
p represents ‘My car is red’
q represents ‘This pen is red’
r represents ‘The planet Mars is red’
Cannot work with lower-level objects like ‘my
car’, ‘this pen’, ‘the planet Mars’
For most practical applications, we need to be
able to talk about objects and properties
within our logical system
40
First-order logic
First-order logic (FOL) models the world in terms of
Objects, which are things with individual identities
Properties of objects that distinguish them from other
objects
Relations that hold among sets of objects
Functions, which are a subset of relations where there is
only one “value” for any given “input”
Examples:
Objects: Students, lectures, companies, cars ...
Properties: blue, oval, even, large, ...
Relations: Brother-of, bigger-than, outside, part-of, has-
color, occurs-after, owns, visits, precedes, ...
Functions: father-of, best-friend, second-half, one-more-
than ...
41
Syntax of FOL
Predicates: P(x[1], ..., x[n])
P: predicate name; (x[1], ..., x[n]):
argument list
Examples: human(x), /* x is a human */
father(x, y) /* x is the father of y */
When all arguments of a predicate is
assigned values , the predicate becomes
either true or false, i.e., it becomes a
proposition. Ex. Father(Fred, Joe)
42
Quantifiers
Quantification allows us to make statements
about more than one object at a time ,
Universal quantification  (or forall)
(x)P(x) means that P holds for all values of x in the
domain associated with that variable.
E.g., (x) dolphin(x) => mammal(x)
(x) human(x) => mortal(x)
Universal quantifiers often used with "implication (=>)"
to form "rules" about properties of a class
(x) student(x) => smart(x) (All students are smart)
Often associated with English words “all”, “everyone”,
“always”, etc.
43
Existential quantification 
This means “there exists at least one object x such that x
is a king and x is a person”
(x)P(x) means that P holds for some value(s) of x in the
domain associated with that variable.
E.g., (x) mammal(x) ^ lays-eggs(x)
(x) taller(x, Fred)
Existential quantifiers usually used with “^ (and)" to
specify a list of properties about an individual.
(x) student(x) ^ smart(x) (there is a student who is
smart.)
(x) student(x) => smart(x)
Mean that if there is a student x then he is smart
(wrong).
44
Nested Quantifiers
Same quantifier: Can reduce to one
x y Brother(x, y)  Brother(y, x)
Same as: x, y Brother(x, y)  Brother(y, x)
Same as: y, x Brother(x, y)  Brother(y, x)
Same as: y, x Brother(x, y)  Brother(y, x)
Example; Some dogs bark
 x. Dog x  Barks x
xy . Dog x  Bark y  makes_sound x
All barking dogs are irritating.
 x . Dog x  Barking x  Irritating x
45
Forward Chaining
Example: KB = All men like apples, men buy everything they
like, and Socrates is a man. In FOL, the KB is
1- (x) man(x) => likes(x, apples)
2- (x)(y) (man(x) ^ likes(x,y)) => buys(x,y)
3- Man(Socrates)
Goal query: Does Socrates buy apples?
Proof:
Use GMP with (1) and (3) to derive: “(4) likes(Socrates, apples)”
Use GMP with (3), (4) and (2)
man(Socrates) ^ likes(Socrates, apples) => buys(Socrates, apples)
to derive “(5) buys(Socrates, apples)”
Result: Yes, Socrates buys apples
Used to produce new facts Start from atomic sentences and fire rules
until no further inference is possible,
46
Example: KB = All cats like fish, cats eat
everything they like, and Ziggy is a cat.
In FOL, KB =
1. x cat(x) => likes(x, Fish)
2. x y (cat(x) ^ likes(x,y)) => eats(x,y)
3. cat(Ziggy)
Goal query: Does Ziggy eat fish?
Proof:
Use GMP with (1) and (3) to derive: 4. likes(Ziggy, Fish)
Use GMP with (3), (4) and (2) to derive eats(Ziggy, Fish)
So, Yes, Ziggy eats fish.
47
Backward chaining
Used to deduce whether statements are true
or not
Start backwards from the goal to find known
facts that support the goal
Used in advisory expert systems
User asks questions
System asks leading questions, then produces
answer if it can,
Backward chaining is the basis for “logic programming,” e.g.,
Prolog.

More Related Content

PPT
First order logic in knowledge representation
PPT
Introduction to Natural Language Processing
PDF
SARCASM DETECTION: A COMPUTATIONAL AND COGNITIVE STUDY
PPT
chapter2.ppt
PPTX
Textlinguistik: Illokutionsidentifikation
PPSX
CONTENT ANALYSIS (Quantitative Research Methods)
PPT
PPTX
Presentation on Breadth First Search (BFS)
First order logic in knowledge representation
Introduction to Natural Language Processing
SARCASM DETECTION: A COMPUTATIONAL AND COGNITIVE STUDY
chapter2.ppt
Textlinguistik: Illokutionsidentifikation
CONTENT ANALYSIS (Quantitative Research Methods)
Presentation on Breadth First Search (BFS)

What's hot (20)

PDF
Evaluation in Information Retrieval
PDF
6 shallow parsing introduction
PDF
Ontology 101 - Kendall & McGuiness
PDF
Chapter1 Formal Language and Automata Theory
PPT
Interdisciplinary research theories & thoughts
PPTX
Natural language processing
PPTX
Branch and bound technique
PPTX
Treebank annotation
PDF
Natural Language Processing with Python
PPTX
Probabilistic retrieval model
PPTX
Dbscan algorithom
PDF
Introduction to Information Retrieval & Models
PPTX
Language models
PDF
Summary of Multilingual Natural Language Processing Applications: From Theory...
PPTX
JOURNAL suggestion tools.pptx
PDF
AI_ 3 & 4 Knowledge Representation issues
PPTX
Literature review and the PhD
PPTX
Propositional logic
PPT
Data mining basic fundamentals
DOCX
PhD Annual Report first page & detailed table of contents
Evaluation in Information Retrieval
6 shallow parsing introduction
Ontology 101 - Kendall & McGuiness
Chapter1 Formal Language and Automata Theory
Interdisciplinary research theories & thoughts
Natural language processing
Branch and bound technique
Treebank annotation
Natural Language Processing with Python
Probabilistic retrieval model
Dbscan algorithom
Introduction to Information Retrieval & Models
Language models
Summary of Multilingual Natural Language Processing Applications: From Theory...
JOURNAL suggestion tools.pptx
AI_ 3 & 4 Knowledge Representation issues
Literature review and the PhD
Propositional logic
Data mining basic fundamentals
PhD Annual Report first page & detailed table of contents
Ad

Similar to Artificial intelligent Lec 5-logic (20)

PPT
Best presentation about discrete structure
PPTX
Drinkfromme.pptx
PPT
good teaching skills and other beautiful things
PDF
Chapter 01 - p1.pdf
PPTX
Chapter1p1
PPT
Discrete Maths141 - Course Outline and Lecture Slides
PDF
Chapter1p1.pdf
PPT
Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو
PPTX
20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx
PPTX
DM(1).pptx
PPT
Per3 logika&pembuktian
PDF
logicproof-141212042039-conversion-gate01.pdf
PPT
Logic&proof
PPT
lectures in prolog in order to advance in artificial intelligence
PPT
Chapter 1: The Foundations: Logic and Proofs
PPTX
Logic in Computer Science Unit 2 (1).pptx
PPT
Discrete mathematics Chapter1 presentation.ppt
PDF
Dscrete structure
PDF
Knowledge base artificial intelligence.pdf
PPT
Basic Connectives and Truth Tables.ppt
Best presentation about discrete structure
Drinkfromme.pptx
good teaching skills and other beautiful things
Chapter 01 - p1.pdf
Chapter1p1
Discrete Maths141 - Course Outline and Lecture Slides
Chapter1p1.pdf
Discrete mathematics Ch2 Propositional Logic_Dr.khaled.Bakro د. خالد بكرو
20220818151924_PPT01 - The Logic of Compound and Quantitative Statement.pptx
DM(1).pptx
Per3 logika&pembuktian
logicproof-141212042039-conversion-gate01.pdf
Logic&proof
lectures in prolog in order to advance in artificial intelligence
Chapter 1: The Foundations: Logic and Proofs
Logic in Computer Science Unit 2 (1).pptx
Discrete mathematics Chapter1 presentation.ppt
Dscrete structure
Knowledge base artificial intelligence.pdf
Basic Connectives and Truth Tables.ppt
Ad

More from Taymoor Nazmy (20)

PPTX
Cognitive systems
PPTX
Cognitive systems
PPT
Artificial intelligent Lec 3-ai chapter3-search
PPT
Lec 2-agents
PPT
Artificial intelligent Lec 1-ai-introduction-
PPTX
Image processing 2
PPT
Image processing 1-lectures
PPT
Software Engineering Lec 10 -software testing--
PPT
Software Engineering Lec 8-design-
PPT
Software Engineering Lec 7-uml-
PPT
Software Engineering Lec5 oop-uml-i
PPT
Software Engineering Lec 4-requirments
PPT
Software Engineering Lec 3-project managment
PPT
Software Engineering Lec 2
PPT
Software Engineering Lec 1-introduction
PPT
PPT
presentation skill
PPT
PPT
PPT
Cognitive systems
Cognitive systems
Artificial intelligent Lec 3-ai chapter3-search
Lec 2-agents
Artificial intelligent Lec 1-ai-introduction-
Image processing 2
Image processing 1-lectures
Software Engineering Lec 10 -software testing--
Software Engineering Lec 8-design-
Software Engineering Lec 7-uml-
Software Engineering Lec5 oop-uml-i
Software Engineering Lec 4-requirments
Software Engineering Lec 3-project managment
Software Engineering Lec 2
Software Engineering Lec 1-introduction
presentation skill

Recently uploaded (20)

PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Institutional Correction lecture only . . .
PPTX
Lesson notes of climatology university.
PDF
Basic Mud Logging Guide for educational purpose
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
master seminar digital applications in india
PDF
Computing-Curriculum for Schools in Ghana
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPH.pptx obstetrics and gynecology in nursing
Institutional Correction lecture only . . .
Lesson notes of climatology university.
Basic Mud Logging Guide for educational purpose
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
TR - Agricultural Crops Production NC III.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
O7-L3 Supply Chain Operations - ICLT Program
master seminar digital applications in india
Computing-Curriculum for Schools in Ghana
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
human mycosis Human fungal infections are called human mycosis..pptx
O5-L3 Freight Transport Ops (International) V1.pdf
01-Introduction-to-Information-Management.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
Cell Types and Its function , kingdom of life
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
GDM (1) (1).pptx small presentation for students

Artificial intelligent Lec 5-logic

  • 1. 1 Lecture 5 Knowledge Representation , Logic, and inference 1. Knowledge-based Agents 2. Knowledge Representation Schemas 2-1 Propositional Logic 2-2 First order logic 2-3 Inference
  • 2. 2 Knowledge-based Agent Central component of a knowledge-based agent is its knowledge-base (KB) A KB is a set of representations of facts about the world Each individual representation is called a sentence The sentences are expressed in a language called a knowledge representation language A knowledge-based agent should be able to infer. Inference mechanism generates new sentences that are necessarily true given that the old sentences are true.
  • 3. 3 The Intelligent Agent as Black Box Prior knowledge Past Experience Goals and Values Observations ActionsReasoning (inference) and Representation System (RRS)
  • 4. 4 Inference example Given: “The red block is above the blue block” “The green block is above the red block” Infer: “The green block is above the blue block” “The blocks form a tower”
  • 5. 5 Knowledge Representation Schemas (Symbolic) 1-Logic based representation – propositional logic, first order predicate logic, Prolog 2-Procedural representation – rules, production system 3-Network representation – semantic networks, conceptual graphs 4-Structural representation – scripts, frames, objects
  • 6. 6 Representation of Knowledge There is no single most adequate knowledge representation formalism/scheme for everything. Main points for selecting a representation formalism: what should be represented, how should the knowledge be processed. There are many more representation formalisms. All the above mentioned are symbolic. There are non-symbolic ones, e.g. Neural networks.
  • 7. 7 What is Knowledge? Data – primitive verifiable facts, of any representation. Data reflects the current world. Knowledge – relation among sets of data (information), that is very often used for further information deduction. Knowledge contain information about behaviour of abstract models of the world.
  • 8. 8 Knowledge Representation The object of KR is to express knowledge in a computer-tractable form, so that it can be used to help agents perform well. A KR language is defined by two aspects: Syntax: describes how to make sentences OR describes the possible configurations that can constitute sentences. Semantics: determine the facts (meaning) in the world to which the sentences refer OR the “things” in the sentence.
  • 9. 9 Knowledge Representation Example The syntax of the language of arithmetic expressions says that x and y are expressions denoting numbers, the x  y is a sentence. The semantics of the language say that x  y is false when y is a bigger number than x, and true otherwise. Inference: The terms “inference” and “reasoning” are generally used to cover any process by which conclusions are reached. Logical inference  deduction
  • 10. 10 Types of logic Logic is a language for KR which tells us how to build up sentences in the language. Ontological commitment: what exists - facts? objects? time? beliefs? Epistemological commitment: what states of knowledge? Language Ontological Commitment Epistemological Commitment Propositional Logic Facts True/false/unknown First order logic Facts, objects, relations True/false/unknown Temporal logic Facts, objects, relations, time True/false/unknown Probability theory Facts Degree of belief 0…1 Fuzzy logic Degree of truth Degree of belief 0…1
  • 11. 11 Knowledge Representation 1- Logic •Propositional Logic (Propositional Calculus): Propositional Logic has limitations, - it is not expressive enough. •First-order Logic (First-order Predicate Calculus): First-Order Logic is an improvement and is useful.
  • 12. 12 Propositions(‫افتراض‬) Statements that can be either true or false The sky is blue The moon is made of cheese Artificial intelligence is my favourite subject Each statement takes one of the truth- values T or F (or, 1 and 0) Each statement is represented by a propositional variable such as p, q, r, …
  • 13. 13 Logical operators We can use logical operators (or connectives) to build more complex statements from our simple propositions The moon is not made of cheese I am bored and I am tired You are a man or you are a mouse If it is snowing then it is cold
  • 14. 14 Negation p represents “It is snowing” The negation of p represents “It is not snowing” This is written p pronounced “not p” If p takes the value T then p takes the value F, and vice versa
  • 15. 15 Conjunction p represents “It is snowing” q represents “It is cold” The conjunction of p and q represents “It is snowing and it is cold” This is written as p  q pronounced “p and q” Commutative, associative
  • 16. 16 Disjunction q represents “It is cold” r represents “It is raining” The disjunction of q and r represents “It is cold or it is raining” This is written as q  r pronounced “q or r” Commutative (q  r = r  q), Associative (q  (r  p))=(q  r)  (q  p)
  • 17. 17 Implication p represents “It is snowing” q represents “It is cold” Implication gives statements such as “If it is snowing then it is cold” This is written p  q pronounced “p implies q” Not commutative, not associative
  • 18. 18
  • 19. 19 Propositional Calculus - example Let, Fact P: "Ali likes chips'' Let, Fact Q: "Ali eats chips'' Other possible facts: P  Q : "Ali likes chips or Ali eats chips” P  Q : "Ali likes chips and Ali eats chips'’  Q : "Ali doesn't eat chips'’ P  Q : "If Ali likes chips then Ali eats chips'' Read: Logic     Nat. Lang. Or And Implies Not
  • 20. 20 Truth tables for logical connectives TTFFTFF FTTFTTF FFTFFFT TTTTFTT ~ QPQPQPQPPQP  Ex: Give the truth table for: (p  q)  (p  q) (p  q)  (p  q) false true true true Solu:
  • 21. 21 Examples of PL sentences P means "It is hot" Q means "It is humid" R means "It is raining" P ^ Q => R "If it is hot and humid, then it is raining" Q => P "If it is humid, then it is hot" Q "It is humid."
  • 22. 22 Propositional formulae A formula can be built from propositions and operators to represent a more complex statement We can construct a truth-table for any formula Upper-case letters are used to represent formulae e.g. P might represent (p  q)  r An interpretation of P is an assignment of truth- values to all the propositional variables i.e. it is a single row of the truth table
  • 23. 23 Example formula and truth-table (p  q)  r p q r q p  q (p  q)  r T T T F T T T T F F T F T F T T T T T F F T T F F T T F F T F T F F F T F F T T T T F F F T T F
  • 24. 24 Tautologies(‫المعنى‬ ‫تكرار‬) A propositional formula P that takes the truth-value T for every possible interpretation is called a tautology. This is written using the metasymbol╞ like this: ╞ P e.g. ╞ ( p  p ) Any formula that is a tautology is said to be a valid formula.
  • 25. 25 Establishing tautologies An easy way to determine whether or not a proposition is a tautology is to substitute truth values for the atomic propositions. For example, given the proposition p  p, if we substitute true for p, then the overall proposition is equivalent to true and if we substitute false for p then the overall proposition is equivalent to true Therefore we conclude that p  p is a tautology.
  • 26. 26 Questions Which of the following propositions are tautologies? p  (p  q) p  (q  p) (p  q)  (q  p) (p  q)  (p  q)
  • 27. 27 Contradictions and contingencies(‫طارئ‬) A proposition that is always false is called contradiction If a proposition is neither a tautology nor a contradiction then it is called a contingency
  • 28. 28 Propositional Inference: Enumeration Method Let    and KB = (  C)  B  C) Is it the case that KB  ? I.e.,  is true in all worlds where KB is true. Check all possible models --  must be true whenever KB is true. TrueTrueTrue FalseTrueTrue TrueFalseTrue FalseFalseTrue TrueTrueFalse FalseTrueFalse TrueFalseFalse FalseFalseFalse =    KB= (  C)  B  C) CBA ╞
  • 29. 29 TrueTrueTrueTrue TrueFalseTrueTrue FalseTrueFalseTrue TrueFalseFalseTrue TrueTrueTrueFalse FalseFalseTrueFalse FalseTrueFalseFalse FalseFalseFalseFalse     KB (  C)  B  C) CBA Propositional Inference: Enumeration Method Let    and KB = (  C)  B  C) Is it the case that KB  ? I.e.,  is true in all worlds where KB is true Check all possible models --  must be true whenever KB is true ╞
  • 30. 30 Propositional Inference: Enumeration Method Let    and KB = (  C)  B  C) Is it the case that KB  ? Check all possible models --  must be true whenever KB is true A B C KB (  C)  B  C)     False False False False False False False True False False False True False False True False True True True True True False False True True True False True False True True True False True True True True True True True ╞
  • 31. 31 Propositional Inference: Enumeration Method Let    and KB = (  C)  B  C) Is it the case that KB ╞  ? Check all possible models --  must be true whenever KB is true A B C KB (  C)  B  C)     False False False False False False False True False False False True False False True False True True True True True False False True True True False True False True True True False True True True True True True True
  • 32. 32 Reasoning in Propositional Logic Similarly, if we assume a few things, we can determine if something follows. E.g., if we assume P, then PQ, say, degenerates into True  Q, which a truth table will tell us is always true. So, we can always draw valid conclusions from premises, regardless of what any of this means
  • 33. 33 Rules of inference There are rules of inference which can be applied to logic, These follow the syntax: A B When something in the knowledge base matches the pattern above the line, then the system concludes that the part below the line is true. or, sometimes we may write it, as , , … |-  meaning, if we know , , …, it is okay to conclude . (‫المنطقية‬ ‫المقدمة‬)Premise Conclusion
  • 34. 34 An Inference Rule: And - Elimination From a conjunction, you can infer any of the conjuncts. 1 2 … nPremise _______________ iConclusion An inference rule is sound if the conclusion is true in all cases where the premises are true.
  • 35. 35 An Inference Rule: Modus Ponens From an implication and the premise of the implication, you can infer the conclusion.   Premise ___________ Conclusion An inference rule is sound if the conclusion is true in all cases where the premises are true. i.e. If    is true, and  is true, then  is true. Generalized Modus Ponens (GMP)
  • 36. 36 Common Inference Rules Modus Ponens: ,  |-  And-Elimination: 1  2 |- i And-Introduction: 1,2 |- 1  2 Or-Introduction:  |-    Double-Negation Elimination: ¬¬  |-  Resolution:    , ¬    |-   
  • 37. 37 Propositional Logic: Rules of Inference (cont.) Or-Introduction: From a sentence, you can infer its disjunction with anything else at all. i 1  2  ...  n Double-Negation Elimination: From a doubly negated sentence, you can infer a positive sentence   And-Introduction: From a list you can infer their conjunction. 1, 2 , ... , n 1  2  ...  n
  • 39. 39 Limitations of Propositional Logic p represents ‘My car is red’ q represents ‘This pen is red’ r represents ‘The planet Mars is red’ Cannot work with lower-level objects like ‘my car’, ‘this pen’, ‘the planet Mars’ For most practical applications, we need to be able to talk about objects and properties within our logical system
  • 40. 40 First-order logic First-order logic (FOL) models the world in terms of Objects, which are things with individual identities Properties of objects that distinguish them from other objects Relations that hold among sets of objects Functions, which are a subset of relations where there is only one “value” for any given “input” Examples: Objects: Students, lectures, companies, cars ... Properties: blue, oval, even, large, ... Relations: Brother-of, bigger-than, outside, part-of, has- color, occurs-after, owns, visits, precedes, ... Functions: father-of, best-friend, second-half, one-more- than ...
  • 41. 41 Syntax of FOL Predicates: P(x[1], ..., x[n]) P: predicate name; (x[1], ..., x[n]): argument list Examples: human(x), /* x is a human */ father(x, y) /* x is the father of y */ When all arguments of a predicate is assigned values , the predicate becomes either true or false, i.e., it becomes a proposition. Ex. Father(Fred, Joe)
  • 42. 42 Quantifiers Quantification allows us to make statements about more than one object at a time , Universal quantification  (or forall) (x)P(x) means that P holds for all values of x in the domain associated with that variable. E.g., (x) dolphin(x) => mammal(x) (x) human(x) => mortal(x) Universal quantifiers often used with "implication (=>)" to form "rules" about properties of a class (x) student(x) => smart(x) (All students are smart) Often associated with English words “all”, “everyone”, “always”, etc.
  • 43. 43 Existential quantification  This means “there exists at least one object x such that x is a king and x is a person” (x)P(x) means that P holds for some value(s) of x in the domain associated with that variable. E.g., (x) mammal(x) ^ lays-eggs(x) (x) taller(x, Fred) Existential quantifiers usually used with “^ (and)" to specify a list of properties about an individual. (x) student(x) ^ smart(x) (there is a student who is smart.) (x) student(x) => smart(x) Mean that if there is a student x then he is smart (wrong).
  • 44. 44 Nested Quantifiers Same quantifier: Can reduce to one x y Brother(x, y)  Brother(y, x) Same as: x, y Brother(x, y)  Brother(y, x) Same as: y, x Brother(x, y)  Brother(y, x) Same as: y, x Brother(x, y)  Brother(y, x) Example; Some dogs bark  x. Dog x  Barks x xy . Dog x  Bark y  makes_sound x All barking dogs are irritating.  x . Dog x  Barking x  Irritating x
  • 45. 45 Forward Chaining Example: KB = All men like apples, men buy everything they like, and Socrates is a man. In FOL, the KB is 1- (x) man(x) => likes(x, apples) 2- (x)(y) (man(x) ^ likes(x,y)) => buys(x,y) 3- Man(Socrates) Goal query: Does Socrates buy apples? Proof: Use GMP with (1) and (3) to derive: “(4) likes(Socrates, apples)” Use GMP with (3), (4) and (2) man(Socrates) ^ likes(Socrates, apples) => buys(Socrates, apples) to derive “(5) buys(Socrates, apples)” Result: Yes, Socrates buys apples Used to produce new facts Start from atomic sentences and fire rules until no further inference is possible,
  • 46. 46 Example: KB = All cats like fish, cats eat everything they like, and Ziggy is a cat. In FOL, KB = 1. x cat(x) => likes(x, Fish) 2. x y (cat(x) ^ likes(x,y)) => eats(x,y) 3. cat(Ziggy) Goal query: Does Ziggy eat fish? Proof: Use GMP with (1) and (3) to derive: 4. likes(Ziggy, Fish) Use GMP with (3), (4) and (2) to derive eats(Ziggy, Fish) So, Yes, Ziggy eats fish.
  • 47. 47 Backward chaining Used to deduce whether statements are true or not Start backwards from the goal to find known facts that support the goal Used in advisory expert systems User asks questions System asks leading questions, then produces answer if it can, Backward chaining is the basis for “logic programming,” e.g., Prolog.