Unit3 KR Propositional Logic PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 59

Unit 3 knowledge and

representation

Prepared by
Mrudang Pandya
Assistant Professor
Department of Information Technology
CSPIT,CHARUSAT
Why study KR?
 One of the major applications of AI is to design expert
system.(e.g. automated driving car, medical diagnosis and
many more)
 To build such a system, we need to build a “knowledge base”.
 To build a knowledge base, we need to represent information
in such a way that machine can understand

2
What is knowledge representation?
 Knowledge representation and reasoning (KR) is the field of
artificial intelligence (AI) dedicated to representing
information about the world in a form that a computer
system can utilize to solve complex tasks

3
Knowledge representation

4
Knowledge based agent
 A knowledge-based agent includes a knowledge base and an
inference system.
 The agent must be able to:
 Represent states and actions
 Incorporate new percepts
 Update internal representations of the world
 Deduce hidden properties of the world
 Deduce appropriate actions

5
Knowledge base
 Central component of a Knowledge-Based Agent is a
Knowledge-Base
 A set of sentences in a formal language
 Sentences are expressed using a knowledge representation language
 Two generic functions:
 TELL - add new sentences (facts) to the KB
 “Tell it what it needs to know”
 ASK - query what is known from the KB
 “Ask what to do next”

6
Methods to represent knowledge
 Propositional logic(PL)
 First order predicate logic(also known as Predicate logic-
FOPL)
 High order Predicate logic
 Fuzzy logic
 Description logic
 Semantic network
 Frame Representations

7
Propositional logic

8
What is proposition?
 In English language we have orders , questions, sentences and
assertions
 Assertion is a statement
 Proposition is an assertion. It is either true or false but not
both.You can associate 1 with true and 0 with false.
 Examples
 3+3=6 (true assertion)
 4 is a prime number (false assertion)
 The moon is made of cheese(false assertion)

9
Not propositions
 X+y>4( x can have any value)
 X=3( assignment)
 Are you leaving? (Question)
 Buy the books(Order)

10
Propositional variable
 Arbitrary proposition with any unspecified truth value
 Usually denoted with capital letters e.g. P,Q,R etc.
 It can have either of truth value

11
Logical connectives
 (not)/ negation
 ^ :(and)/Conjunction
 v (or): Disjunction/Inclusive or
 =>/implies/implication. A => B,
 A is called premise or antecedent or hypothesis,
 B is called conclusion or consequent.
 <=> : (if and only if)/Equivalence
 Priority of operators
1.
2. ^
3. v
4. =>
5. <=>

12
Truth tables
P Q P^Q PvQ P => Q P Q
0 0 0 0 1 1 0
0 1 0 1 1 0 1
1 0 0 1 0 0 0
1 1 1 1 1 1 1

13
Well formed formula(wff) &
Propositional Form
 Propositional form
 An assertion which contains at least one propositional variable is
called propositional form
 Well Formed Formula
 Any propositional form with connecting variables is called a
well formed formula
 E.g. P v Q
P^Q

14
Create truth table for following
expressions
 (Q ^ P ) => P
 [(P ^ Q) v R ]  P

15
 A propositional form whose Truth Value is true for all
possible values of its propositional variables is called
tautology e.g P v P
 A propositional form whose Truth Value is false for all
possible values of its propositional variables is called
Contradiction or absurdity e.g. P ^ P
 A propositional form which is neither tautology nor
contradiction is called contingency.

16
Logical identities
 P  P v P (idempotence of v)
 PP^P (idempotence of ^)
 Commutativity of v
 (P v Q)  (Q v P)
 Commutativity of ^
 (P ^ Q)  (Q ^ P)
 Associativity of v
 (P V Q) V R  P V (Q V R)
 Associativity of ^
 (P ^ Q) ^ R  P ^ (Q ^ R)

17
Logical identities
 DE Morgan's Laws
 (P v Q)  P ^ Q
 (P ^ Q)  P v Q
 Distributivity of ^ over v
 P ^ ( Q v R)  (P ^ Q) v (P ^ R)
 Distributivity of v over ^
 P v (Q ^ R)  (P v Q) ^ (P v R)

18
Logical identities
 Pv11
 P^1P
 Pv0P
 P^00
 P ( P) (Double Negation)

19
Rules of inference(tautologies)
 P => Q  ( P v Q) (Implication)
 P  Q  ( P => Q) ^ (Q => P) (Equivalence)
 [(P ^ Q) => R]  [P=>(Q=>R)] (Exportation)
 (P => Q) ^ (P =>Q)  P (Absurdity)
 P => Q  Q => P (Contrapositive)

20
Simplify the expression
 [(A=>B) v (A => D)] => (B v D)
 Answer
 AvBvD

21
 Consider the three sentences below
 P: It is snowing
 Q: I will go to town
 R: I have time
 Write WFF in propositional logic for below sentences
 If it is not snowing and I have time then I will go to town
 ( P ^ R) => Q
 I will go to town only if I have time
 Q=> R
 It is not snowing
 P
 It is snowing and I will not go to town
P^ Q
22
 Write sentence in English corresponding to each of
proposition
 Q  (R ^ P)
 I will go to town if and only if I have time and its not
raining
 R ^Q
 I have time and I will go to town
 (Q => R) ^ (R => Q)
 I will go to town if I have time and If I have time I
will go to town OR
 I will go to town if and only if I have time
 (R v Q)
 It is not true that I have time or I will go to town

23
Entailment
 Entailment: KB |= Q
 Q is entailed by KB (set sentences) iff there is no logically
possible world where Q is false while all the sentences in KB are
true
 Or, stated positively, Q is entailed by KB iff the conclusion is
true in every logically possible world in which all the premises
in KB are true
 E.g. P:Kasab was hanged
 Q:Kasab is dead
 P |=Q

24
Derivation
 KB |- Q
 We can derive Q from KB if there’s a proof consisting of a
sequence of valid inference steps starting from the premises in
KB and resulting in Q
 P:All humans are mortal
 Q:Chandni is human
 R:So, Chandni is mortal
 P,Q |- R

25
Inference
 Valid: A sentence that’s true in all situations.
 Satisfiability: A sentence that is true in at least one situation.
 Unsatisfiability: A sentence that isn’t satisfiable.

26
Inference
 A sentence (Q) is inferred by a set of sentences {p1, p2, ... }
if whenever Q is true, then {p1, p2, …} are all true.

27
Two important properties of inference
 Two important properties for inference
 Soundness: If KB |- Q then KB |= Q
 If Q is derived from KB using a given set of rules of inference,
then Q is entailed by KB
 Hence, inference produces only real entailments, or any
sentence that follows deductively from the premises is valid
 Completeness: If KB |= Q then KB |- Q
 If Q is entailed by KB, then Q can be derived from KB using the
rules of inference
 Hence, inference produces all entailments, or all valid sentences
can be proved from the premises

28
Rules of inference
 Modus Ponens
 if α ⇒ β, α
 then β
 If α ⇒ β and α are true then β must be true

29
Logical Implication(Rules of Inference)
 The modus ponens rule is written as the statement of a truth-
functional tautology or theorem of propositional logic as
below:
 Modus Ponen
 [P ^ (P =>Q)] =>Q
 Prove the Modus Ponen rule

30
Rules of inference
 And-Elimination/Conjunction elimination
 if α1∧α2∧...∧αn
 then αi
 If α1∧α2 is true then α1 is true and α2 is true

31
Rules of inference
 And-Introduction
 if α1, α2, α3, …, αn
 then α1∧ α2∧ α3∧... ∧ αn
 Or-Introduction
 if αi
 then α1∨ α2∨ α3∨... ∨ αn
 Double Negation Elimination
 if ¬ ¬ α
 then α
 Unit Resolution
 if α ∨ β, ¬β
 then α

32
Resolution algorithm
 Resolution
 if α ∨ β, ¬β ∨ γ
 then α ∨ γ

33
Resolution algorithm
 Resolution is a process to prove that a statement is valid
 Consider the negation of statement and prove that negation is
contradictory to the given statements

34
Steps of resolution
 Steps
 Convert to propositional logic
 Convert logical statement to Conjunctive Normal Form(CNF)
 A sentence expressed as a conjunction of disjunction of literals is said to
be in Conjuctive Normal Form( AND of OR’s)
 ( A v B) ∧ (B v C v D)
 Negate the statement
 Prove contradiction using negation process

35
Example of Resolution
 Given 1) P 2) ¬P v Q 3) ¬P v ¬Q v R
 Prove that R is true using Resolution theorem

 Given 1) P 2) (P ∧ Q) => R 3) (S vT)=> Q 4) T


 Prove that R is true using Resolution theorem

36
Example of resolution
 Given
 1) A 2) ¬A => B 3) B=>A 4)A=>(C ∧ D)
 Prove that A ∧ C ∧ D is true using Resolution theorem

37
The wumpus world example

38
Performance measure
 +1000 points for picking up the gold — this is the goal of
the agent
 −1000 points for dying = entering a square containing a pit
or a live Wumpus monster
 −1 point for each action taken, and
 −10 points for using the arrow trying to kill the Wumpus —
so that the agent should avoid performing unnecessary
actions

39
Environment
 A 4 × 4 grid of squares with. . .
 the agent starting from square [1, 1] facing right the gold in
one square
 the initially live Wumpus in one square, from which it never
moves
 maybe pits in some squares.
 The starting square [1, 1] has no Wumpus, no pit, and no
gold — so the agent neither dies nor succeeds straight away

40
Actuators
 The agent can. . .
 turn 90◦ left or right
 walk one square forward in the current direction
 grab an object in this square
 shoot the single arrow in the current direction, which flies in
a straight line until it hits a wall or the Wumpus

41
Sensors
 The agent has 5 true/false sensors which report a. .
 Stench: when the Wumpus is in an adjacent square directly,
not diagonally
 Breeze: when an adjacent square has a pit
 Glitter: when the agent perceives the glitter of the gold in
the current square
 Bump: when the agent walks into an enclosing wall (and then
the action had no effect)
 Scream: when the arrow hits the Wumpus, killing it.

42
Notations for our program
 A= Agent
 B= Breeze
 G= Glitter, Gold
 OK= Safe Square
 P= Pit
 S= Stench
 W=Wumpus

43
Step 1

S11 = None => S12 ∧ S21 =SAFE

44
Step 2

S21=Breeze => S31=Pit v S22=PIT

45
Step 3

S12=Stench => S13 =Wumpus V S22= Wumpus

S21= Breeze ∧ S12=Stench => S22=Safe

S22= None => S23=Safe and S32=Safe

46
Step 4

S23=Glitter => Find Gold


S23=Stench ∧ S12=stench ∧ S22= ¬ Wumpus
=>S13=Wumpus

47
Horn clause
 A horn clause is a disjunction of literals in which at most one
is positive
 E.g ¬A v ¬B v C is a horn clause
 ¬p v ¬q is a horn clause
 but ¬A v B v C is not a horn clause

48
Forward chaining and backward
chaining
 Forward chaining
 Idea: Whenever the premises of a rule are satisfied, infer the
conclusion. Continue with rules that became satisfied.
 Backward chaining (goal reduction)
 Idea: To prove the fact that appears in the conclusion of a rule
prove the premises of the rule. Continue recursively.

49
Forward chaining
 Forward chaining
 A KB normally contains rules and facts.
 Start with the given facts, find a matching premise for a given
fact.
 Once matching premise is found, infer the conclusion and add it
to list of facts.
 Continue with rules that became satisfied.
 Forward chaining uses Modus Ponen Rule
 Three main steps:-
 Match
 Resolve
 Execute(add conclusion to KB)

50
Forward chaining example 1
 KB:
 R1: A ∧ B ⇒ C
 R2: C ∧ D ⇒ E
 R3: C ∧ F ⇒ G
 F1: A
 F2: B
 F3: D
 Theorem: E ?

51
Forward chaining example 1solution
 Theorem E
 KB:
 R1: A ∧ B ⇒ C
 R2: C ∧ D ⇒ E
 R3: C ∧ F ⇒ G
 F1: A
 F2: B
 F3: D
 R1 is satisfied,
 F4:C
 R2 is satisfied,
 F5:E

52
Forward chaining example 2
 KB
 R1: A ∧ C => F
 R2: A ∧ E =>G
 R3:B=> E
 R4:G=>D
 F1: A
 F2:B
 Prove that A ∧ B =>D

53
Forward chaining example 3
 KB
 R1: P => Q
 R2: L ∧ M =>P
 R3: B ∧ L =>M
 R4: A ∧ P =>L
 R5:A ∧ B =>L
 F1:A
 F2:B
 Prove Q

54
Backward chaining
 Reasoning from goals back to fact
 Inference rule are applied by matching the goal of the search
to consequents of the relation stored in KB
 It uses Modus tollen or Reverse Modus tollen
Q
 P=>Q
 Therefore P is true

55
Backward chaining example
 KB
 R1: P => Q
 R2: L ∧ M =>P
 R3: B ∧ L =>M
 R4: A ∧ P =>L
 R5:A ∧ B =>L
 F1:A
 F2:B
 Prove Q

56
Problems of propositional logic

57
Problem
 Five persons A, B, C, D, E are in a compartment in a train. A, C, E
are men and B, D are women. The train passes through a tunnel
and when it emerges it is found that E is murdered and an enquiry
is held. And A, B, C, D makes the following statements:
 A says I am innocent B was talking to E when the train was passing
through the tunnel
 B says I am innocent I was not talking to E when the train was
passing through the tunnel
 C says I am innocent; D committed the murder,
 D says I am innocent and one of the men committed the murder.

58
 You have to assume that four of these eight statements are
true and four of them are false.
 Assuming only one person committed the murder. From
these statements you must find out who committed the
murder.

59

You might also like