Você está na página 1de 73

Knowledge Representation

Propositional Logic
Human Reasoning System

CLASS:

Assess your own


reasoning
method

• Humans know the Environment – Sun, tree, fish, pond, road


• Know the facts- fish live in water, pond has water, day is when there is Sun in the
sky, tree has leaves and so o
• Know the relationship between the facts- pond is near the tree, Sun is not on the
earth, road is behind the tree and so on
•Humans reason because they know the things and can infer the hidden facts as
well- Are fish flying in the sky? Are the fish alive? Is this day time? And so on

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 2
F407
Reasoning
 Common sense knowledge is finite
 But inferences can virtually be infinite

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 3
F407
Data, Information and Knowledge
 Facts exist as data.
Example: size, shape and colour describing a book;
four legs and a top describing a table
 Processed data gives information
BOOK, TABLE
 Knowledge is built on the pieces of information
related through various relationships
is-on relationship describes that the book is on the table

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 4
F407
Reasoning
 Is anything that is on the table a book?
 Does a structure with four legs and top
describe a table?
 Will book fall from the table?
 Which object is on the ground?
 And so on.....

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 5
F407
Knowledge Representation
 How do people represent knowledge?
 People use language to express and describe
objects and relationships within their brain.
 Example:
Inference: It will rain today.
Knowledge 1: if there are clouds in the sky and it is
humid, it will rain
Knowledge 2: if there are clouds in the sky and wind
is blowing, it may not rain

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 6
F407
Knowledge Representation
 Facts : a: there are clouds in the sky
b: it is humid
c: it will rain

 Logic and inference (reasoning)


a AND b ==> c
a AND ~b==> ~c
 A representation language is required to express
the facts and the relationships among them

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 7
F407
Knowledge Representation
 Knowledge representation is important to
facilitate reasoning
 It deals with methods to represent the facts using
set of symbols that express the fact correctly
which enable reasoning through processing of
the symbols.
 An effective KR system/language must provide
ways to express a fact easily such that algorithms
can be used to process facts and infer
information.
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 8
F407
Knowledge Based Agents
 Represent the world in
which it operates and
deduce what actions to Domain independent algorithms
take.
 A knowledge-based agent ASK Inference engine
can combine general Knowledge Base
knowledge with current TELL

percepts to infer hidden


aspects. Domain specific content
 Inference:
 It is a sunny day  It will
not rain today
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 9
F407
Knowledge Representation Techniques

 Representation of hierarchical Knowledge


 Lists
 Trees
 Relationship among the objects
 Semantic Nets (as nodes and links)
 Representation of Commonsense Knowledge
 Frames (Describes objects)
 Scripts (Describes events)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 10
F407
Knowledge Representation Techniques

 Problem Space Representations


 Initial and Goal State
 Moves and associated restrictions
 Representation of Logic
 Proposition Logic (boolean logic)
 Predicate Calculus (additional facts)
 Measures of certainty (fuzzy, probabilistic)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 11
F407
Propositional Logic
 It is a language to represent knowledge.
 It is a declarative language.
 Its semantics is based on truth relation
between facts.
 It is sufficiently expressive

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 12
F407
Propositions
 These are sentences that can have only one of
the two truth values- “true” and “false”
 Example:
a: The Sun rises in the East
b: 2+10=11
 a is true while b is false

 What is not a proposition


 show me the paper
 call me after 10 minutes
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 13
F407
Knowledge Base
 A Knowledge Base(KB) is a set of sentences
 Each sentence is expressed in a language
called a knowledge representation language.
 A KB must include a mechanism to add more
sentences (facts and rules)
 Also a KB must have a mechanism to facilitate
querying for a combination of facts.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 14
F407
How does a computer system interact
with the real world?
 Humans interact with the real world through
the sensory organs-eyes, nose, ears, skin,
tongue for receiving data/facts that humans
see, smell, hear, touch and taste.
 Artificially Intelligent Systems interact with
the real world through sensor devices, e.g.
Camera, smell sensors, microphone, touch
screens, heat sensors etc.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 15
F407
Propositional Logic
• It is a language that allows to represent
knowledge as propositions.
• The values of propositions can be either true or
false. If P is the set of propositions then V:P
{true, false} represents the value of the
proposition.
• The entire real world knowledge is represented
as propositions which can be combined further
using connectives in the language.
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 16
F407
Propositional Logic
• Literals are used to represent proposition.
• Each proposition can have only true or false
value.
• The logic processes sentences with a
combination of the symbols ˄, ˅, ˥,, 
and derives another sentence through
inference rules.
• Is less expressive and is voluminous.
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 17
F407
How does the data form the facts?
 Device Drivers attached with the computers
facilitate interactions with specific sensor.
 Simple computation based programs can
easily interpret the readings taken through
different sensors
 For example if the digital thermometer reads
45 degrees Celcius, the fact framed is
a: it is hot

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 18
F407
Propositional Logic- Syntax
• Sentenceatomic sentence | complex sentence
• Atomic sentence  true | false | symbol
• Symbol  P | Q | R |…………
• Complex sentence   sentence
| (sentence V sentence)
| (sentence Λ sentence)
| (sentence sentence)
|(sentence  sentence)
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 19
F407
Syntax of the representation language
• Grammar that describes the language
• Strict for parenthesis
• Example ((P V Q) Λ ~R)
• Class : Identify a real world scenario by P,
Q and R
• What is inferred ?

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 20
F407
Represent the given scenario using
appropriate proposition
• P: grass is dry
• Q: there is spark
• S: It is raining
• R: Forest caught Fire
• PΛ QR
• ~P Λ Q  ~R
• ((P Λ Q) Λ S) ~R

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 21
F407
Are these propositions?

1. The sun is shining.


2. The sum of two prime numbers is even.
3. 3+4=7
4. It rained in Austin, TX, on October 30, 1999.
5. x+y > 10
6. Is it raining?
7. Come to class!
8. n is a prime number.
9. The moon is made of green cheese.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 22
F407Source: Google
Example
• Statement1: Apples are blue or red.
• Statement2: Apples are not blue
• Conclusion: Apples are red

• Propositions:
P1: Apples are blue
P2: Apples are red
Statement1: P1 ᴠ P2
Statement2 : ~P1
Conclusion: P1
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 23
F407
Example
• P : It is sunny today
• Q: It is humid
• R: It will rail

• Formulate Propositions
1. It is sunny and humid today
2. It is humid but it will not rain today
3. It is sunny and it will not rain today
4. It is not sunny and is humid today therefore it
will rain today
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 24
F407
Example:
• A,B,C are friends of each other
– Requires 6 propositions to reason that they are
friends
• Propositions
• P1: A is friend of B
• P2: A is friend of C
• And so on

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 25
F407
Operators in proposition logic
• Negation 
• Disjunction ᴠ
• Conjunction ᴧ
• Implies 
• Biconditional 

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 26
F407
Truth table for propositional logic

P Q p PQ PQ PQ PQ

False False True False False True True

False True True False True True False

True False False False True False False

True True False True True True True

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 27
F407
Logical Equivalence
• When two sentences have the same values,
the value is said to be true
• P  Q is true when
– P and Q both are true
– P and Q both are false
P Q PQ
False False True
true false false
false true False
True True True

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 28
F407
Logical Equivalence
• PQ  PQ

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 29
F407
Standard Logical equivalences

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 30
F407
Sentences
• Simple sentences: Single propositional symbols
• Complex Sentences: Constructed from simple
sentences using logical connectives
• Example :
• P ᴧ Q ᴠ R ᴠ S T is a sentence
• The precedence of operators treat the above
as follows
• ((P ᴧ (Q )) ᴠ R ᴠ S) T

Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 31
F407
Reasoning Systems
• A language capable of representing and
processing logic and a set of inference rules
constitute a reasoning system.
• Languages: Propositional Logic, Predicate
Logic
• Inference rules: Modus Ponens, Modus
Tollens, And elimination, And introduction,
etc.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 32
F407
Inference Rules
• Standard Patterns that can be applied to derive the
chains of conclusions that lead to the desired goals are
called as inference rules.
• Modus Ponens: whenever the sentence is of the form
α β and α is true, then it can be concluded that β is
true.
• Modus Tollens: whenever the sentence is of the form
α β and β is false, then it can be concluded that α is
also false.
• And Elimination: α ˄β is true then α is true, β is true

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 33
F407
Model
• Model is the representation of the world in which
the logical agent works
• Example: m is the model of a sentence α
• Meaning : α is true in model m.
• Example : take two percepts “A” and “B” with
only two possible values T or F
• Then the model in which the sentence A ˄ B is
A=T and B = T
where the possible number of models with two
variables = 4

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 34
F407
Understanding model for a simple rain
forecast system
• Percepts wind, humidity, sun condition
– Wind = {slow, medium, fast}
– Humidity = {low, high}
– Sun_conditions = {sunny, cloudy}
• Models:
– [slow, low, sunny]
– [Slow, low, cloudy]
– [slow, high, sunny]
– [slow, high, cloudy]
– And so on (a total of 12 different models)
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 35
F407
Understanding model
• Then if a real world scenario is presented as
– If α : it rains
– Then the model [slow, high, cloudy] represented by a
sentence
(wind=slow) ˄ (humidity = high) ˄ (day =
cloudy)
• Is true in the given model.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 36
F407
Model
• Had there been only values “true” or “false”
Wind = {true, false}
Humidity = {true, false}
Cloudy = { true, false}
then it could be written in a simple form as
• ˥W ˄ H ˄ D
• And then the above sentence is true in the
model W=F, H=T, D = T

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 37
F407
Entailment
• If a logic(sentence) can be derived from a
given sentences of the KB, then it said to be
entailed from the KB.
α |= β
• This means that β must be true in every
model in which α is true.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 38
F407
Wumpus world example

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 39
F407
Wumpus world characterization
• Deterministic?

• Accessible?

• Static?

• Discrete?

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 40
F407
Wumpus world characterization
• Deterministic– Yes,outcome exactly specified.

• Accessible- No, only local perception.

• Static-Yes , Wumpus and pits do not move.

• Discrete-Yes

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 41
F407
Knowledge Base for Wumpus World
(initial KB)

A
(No Breeze,
No Stench)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 42
F407
Knowledge Base for Wumpus World
(initial KB)

????

A ??????
(Stench)

A
(No Breeze,
No Stench)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 43
F407
Knowledge Base for Wumpus World
(initial KB)

????

A ??????
(Stench)

A
(No Breeze,
No Stench)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 44
F407
Knowledge Base for Wumpus World
(initial KB)

A ??????
(Stench)

A A ????
(No Breeze, (Breeze)
No Stench)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 45
F407
Knowledge Base for Wumpus World
(initial KB)

A ??????
(Stench) P

A A ????
(No Breeze, (Breeze) P
No Stench)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 46
F407
Knowledge Base for Wumpus World
(initial KB)

A New percept
(Stench) NOT a PIT

A A ????
(No Breeze, (Breeze) P
No Stench)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 47
F407
Knowledge Base for Wumpus World
(initial KB)

A New percept
(Stench) NOT a PIT

A A ????
(No Breeze, (Breeze) P
No Stench)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 48
F407
Knowledge Base for Wumpus World
(initial KB)

Finds Gold

A New percept Breeze


(Stench) NOT a PIT

A A P
(No Breeze, (Breeze)
No Stench)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 49
F407
How to design propositions for the
Wumpus World
• Represent all percepts as different variables
corresponding to each block
• Bi,j : breeze in the i,j th square
• Pi,j : pit at the i,j the square
• Si,j: stench at the I,jth square
• Gi,j : glitter at the i,jth block
• Wi,j: wumpus in the i,jth block
• How is it represented/ logically derived that the
logical agent must move from the current square
<1,1> to the square<1,2>?
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 50
F407
• Given
– B[1,1] = false i.e ˥ B[1,1]
– P[1,1] = false
– W[1,1] = false
– S[1,1] = false
– G[1,1] =false
• What to perceive? How to reason where to
move?
– Whether move to right i.e. to 1,2
– Or move up i.e. to 2,1
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 51
F407
Relate presence of pits with breeze in the
neighboring squares

• B[1,1]  P[1,2] ˅ P[2,1]


• B[2,1]  P[1,1] ˅ P[3,1] ˅P
[2,2]
• ……

• Let there be 16 variables


representing breeze
• Then total no. of models = 216
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 52
F407
Truth table for the Wumpus World

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 53
F407
Logical Inference
• Direct Method
Given a KB, to infer whether  is true
Keep inferring and adding consequents to
the KB until  is added.
• Indirect Method
Proof by contradiction
() U KB |-- False

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 54
F407
Inference
• Given Premises
(P  Q) R
(Q  S) T
T  P
• To derive R
• Keep enriching the KB by applying rules of
inference

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 55
F407
Recap
• Propositional logic – language (syntax and semantics)
• Knowledge Base (KB) – facts and rules
• Models representing environment
• Number of environment variables (n) and truth
table complexity (2n)
• Entailment KB |= 
• Inference rules – Modus Ponens, Modus Tollens, And
introduction, And Elimination etc.
• Inference approaches – direct and by contradiction
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 56
F407
Validity and Satisfiability
• Validity: A sentence is valid if it is true in all
models.
– Example: A  A, A A, (A  (A  B))  B
• Satisfiability: A sentence is satisfiable if it is
true in some models. E.g. A  B, C etc.
• A sentence is unsatisfiable if it is true in no
models. E.g. A   A

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 57
F407
Entailment and its relation to validity
and satisfiability
• KB╞  if and only if (KB  ) is valid.
(inference via Deduction Theorem)
• KB╞  if and only if (KB  ) is
unsatisfiable. (inference via Deduction
Theorem)

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 58
F407
Proof
• A proof is a procedure of deriving a sentence
from the given knowledge base.
• A sequence of applications of inference rules
is a proof.
• Proof can be viewed as a search problem
where we must search for the sequence of
rules to be applied to reach a sentence.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 59
F407
Inference
• Given Premises
(P  Q) R
(Q  S) T
T  P
• To derive R
• Keep enriching the KB by applying rules of
inference
• Class Assignment: Work out the proof. Also give
the solution in terms of search space solution.
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 60
F407
Forward Chaining
• It is a technique for systematic reasoning
using a knowledge base of rules and facts
• The basis for the inference is repeated use of
the Modus Ponens.
• Modus Ponens rule states that if A is true and
If A then B, then it is inferred that B is true
A  B, A
B

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 61
F407
Forward Chaining
• Tests all rules in the KB for an available fact
whether the antecedent of the rule is true
given the fact, if yes then concludes that the
consequent part is true and adds to the KB.
• Repeats the step 1 for all available facts with
the latest set of rules in the KB
• A working memory or a storage maintains the
facts with true value which are either given
or are derived using Forward Chaining.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 62
F407
Forward Chaining
• Starts with the atomic sentences in the
knowledge base.
• Applies Modus Ponens in the forward
direction
• Adds new atomic sentences in the KB until
– The goal is reached
– Or no new consequent can be added to the KB.
• The forward chaining works with the definite
clauses.
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 63
F407
Definite Clauses
 A definite clause is either
 atomic or
 Is an implication whose antecedent is a
conjunction of positive literals and whose
consequent is a single positive literal.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 64
F407
Horn Clauses
• A Horn Clause is a disjunction of literals of which
at most one is positive
• While a definite clause has exactly one positive
literal.
• The positive literal is called the head and the
negative literals form the body of the clause.
• Example: A Λ C  F is written as  (A Λ C )  F
 AC F

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 65
F407
Example

• Rule Base Storage:


Rule 1: A Λ C  F Initial: A,C
Rule 2: F Λ C  Z Trigger rule 1: A, C, F
Rule 3: Z  Y Trigger rule 2: A, C, F, Z
• Facts (given) Trigger rule 3: A, C, F, Z, Y
Rule 7: A is true
Rule 8: C is true
• Query
Is Y true?
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 66
F407
Forward Chaining: graphical
representation

A C
Assert F

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 67
F407
Forward Chaining: graphical
representation

A C
Assert Z

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 68
F407
Forward Chaining: graphical
representation

A C
Assert Y is true: GOAL

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 69
F407
Forward Chaining(FC) Algorithm
• Data Structure used
– Agenda – keeps track of symbols known to be true in
the KB, but not yet ‘processed’.
– Count – table to keep track of how many premises of
each implication are yet unknown.
– Inferred- a table indexed by symbol, each entry
initially false
– When a new symbol (say p) from the agenda is
processed, the count is reduced by one for each
implication in whose premise p appears.
– Example: A Λ C  F given A, has a count = 1
Vandana, CSIS, BITS Pilani, BITS F444/ CS
September 2016 70
F407
Forward Chaining Algorithm

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 71
F407
Implementation of FC
• Uses AND –OR graph.
• Multiple links are joined by an arc to represent
conjunction (for AND)
• Each link must be proved.
• Known facts form the leaves and the inference
propagates up in the graph.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 72
F407
Limitations of Propositional Logic
• Can only deal with partial knowledge.
• Less Expressive to describe more complex
environments.
• Built on facts which have true or false values
only and is not able to describe a object or its
relationship to another object.

Vandana, CSIS, BITS Pilani, BITS F444/ CS


September 2016 73
F407

Você também pode gostar