Propositional Logic & Reasoning: Vikram Pudi IIIT Hyderabad
Propositional Logic & Reasoning: Vikram Pudi IIIT Hyderabad
Vikram Pudi
IIIT Hyderabad
Knowledge Representation
2
Why is it important?
Reasoning: draw inferences from knowledge
answer queries
discover facts that follow from the knowledge base
decide what to do
etc.
3
Logic in General
Logics are formal languages for representing
information such that conclusions can be drawn
Syntax: Describes how to make sentences
Semantics: How sentences relate to reality.
The meaning of a sentence is not intrinsic to that
sentence.
Proof Theory: A set of rules for drawing
conclusions (inferences, deductions).
4
Logical Arguments
All humans have 2 eyes.
Kishore is a human.
Therefore Kishore has 2 eyes.
All humans have 4 eyes.
Kishore is a human.
Therefore Kishore has 4 eyes.
Both are (logically) valid arguments.
Which statements are true / false ?
5
Logical Arguments (contd)
All humans have 2 eyes.
Kishore has 2 eyes.
Therefore Kishore is a human.
No human has 4 eyes.
Kishore has 2 eyes.
Therefore Kishore is not human.
Both are (logically) invalid arguments.
Which statements are true / false ?
6
From English to Propositional
Formulae
“it is not the case that the lectures are dull”: D
(alternatively “the lectures are not dull”)
“the lectures are dull and the text is readable”: D R
“either the lectures are dull or the text is readable”:
DR
“if the lectures are dull, then the text is not readable”:
DR
“the lectures are dull if and only if (iif) the text is
readable”: D R
“if the lectures are dull, then if the text is not readable,
Kishore will not pass”: D (R P )
7
Why formal languages?
Natural languages exhibit ambiguity.
Examples:
The boy saw a girl with a telescope
Our shoes are guaranteed to give you a fit
Ambiguity makes reasoning difficult / incomplete
Formal languages promote rigour and thereby reduce
possibility of human error.
Formal languages help reduce implicit / unstated
assumptions by removing familiarity with subject matter
Formal languages help achieve generality due to
possibility of finding alternative interpretations for
sentences and arguments.
8
Propositional Logic
Use letters to stand for “basic” propositions
Complex sentences use operators for not, and, or,
implies, iff.
Brackets ( ) for grouping
(P (Q ((R))) vs. P (Q R)
Omitting brackets
precedence from highest to lowest is: , ,,,
Binary operators are left associative
(so P Q R is (P Q) R)
Questions:
Is (P Q) R same as P (Q R) ?
Is (P Q) R same as P (Q R) ?
9
Semantics (Truth Tables)
P Q P PQ PQ PQ PQ
True True False True True True True
True False False False True False False
False True True False True True False
False False True False False True True
10
Terminology
A sentence is valid if it is True under all possible
assignments of True/False to its propositional
variables (e.g. P P).
Valid sentences are also referred to as
tautologies
A sentence is satisfiable if and only if there is
some assignment of True/False to its
propositional variables for which the sentence is
True
A sentence is unsatisfiable if and only if it is not
satisfiable (e.g. P P).
11
Semantics (Complex Sentences)
R S (RS)(RS)
True True
True False
False True
False False
12
Semantics (Complex Sentences)
13
Material Implication
The only time PQ evaluates to False is when P is True
and Q is False
14
Exercises
Given: A and B are true; X and Y are false,
determine truth values of:
(AX)
A(XY)
A(X (BY))
(PQ) (AX)
[(XY) A] [X (YA)]
15
Entailment
S P — whenever all the formulae in the set S are
True, P is True
16
Entailment Example
P PQ Q
17
Exercises
Use truth tables to determine validity of:
18
Formal Proofs
Intend to formally capture the notion of proof that is
commonly applied in other fields (e.g. mathematics).
A proof of a formula from a set of premises is a
sequence of steps in which any step of the proof is:
1. An axiom or premise
2. A formula deduced from previous steps of the proof
using some rule of inference
The last step of the proof should deduce the formula
we wish to prove.
We say that S follows from (premises) P to denote that
the set of formulae P “prove” the formula S.
19
Soundness and Completeness
A logic is sound if it preserves truth (i.e. if a set
of premises are all true, any conclusion drawn
from those premises must also be true).
A logic is complete if it is capable of proving any
valid consequence.
A logic is decidable if there is a mechanical
procedure (computer program) to prove any
given consequence.
20
Inference Rules
Modus Ponens: P, PQ Q
Modus Tollens: PQ, Q P
Hypothetical Syllogism: PQ, QR PR
And-Elimination: P1P2 … Pn Pi
And-Introduction: P1, P2, … , Pn P1P2 … Pn
Or-Introduction: Pi P1P2 … Pn
Double-Negation Elimination: P P
Unit Resolution: PQ, Q P
Resolution: PQ, QR PR
21
Example Formal Proof
1. A(B D)
2. C (D E)
3. AC
4. C / B E
5. A 3,4 (Modus Tollens)
6. BD 1,5 (Unit Resolution)
7. DE 2,4 (Modus Ponens)
8. BE 6,7 (Hypothetical Syllogism)
22
Exercises
Construct formal proof of validity for:
If the investigation continues, then new evidence is
brought to light. If new evidence is brought to light, then
several leading citizens are implicated. If several leading
citizens are implicated, then the newspapers stop
publicizing the case. If continuation of the investigation
implies that the newspapers stop publicizing the case,
then the bringing to light of new evidence implies that the
investigation continues. The investigation does not
continue. Therefore, new evidence is not brought to light.
C: The investigation continues. N: New evidence is
brought to light. I: Several leading citizens are
implicated. S: The newspapers stop publicizing the case.
23
Solution
1. CN
2. NI
3. IS
4. (C S) (N C)
5. C / N
6. CI 1,2 (Hypothetical Syllogism)
7. CS 6,3 (Hypothetical Syllogism)
8. NC 7,4 (Modus Ponens)
9. N 8,5 (Modus Tollens)
24
Exercises (contd.)
If I study, I make good grades. If I do not
study, I enjoy myself. Therefore, either I
make good grades or I enjoy myself.
S, G, E
25
Solution
1. SG
2. S E / G E
3. S G 1
4. S E 2
5. SE 4
(DoubleNegationEliminate)
6. GE 3,5 (Resolution)
26
Complete Proof Systems
Truth Tables
Inference Rules
19 rules + Conditional Proof + Indirect Proof
Method of Resolution
27
Resolution
Better suited to computer implementation
Generalizes to first-order logic
The basis of Prolog’s inference method
To apply resolution, all formulae in the
knowledge base and the query must be in
clausal form
28
Normal Forms
A literal is a propositional letter or the negation of a
propositional letter
A clause is a disjunction of literals
Conjunctive Normal Form (CNF) – a conjunction of
clauses
e.g. (PQR) (SR)
Disjunctive Normal Form (DNF) – a disjunction of
conjunctions of literals
e.g. (PQR) (SR)
Every propositional logic formula can be converted to
CNF and DNF
29
Conversion to CNF
Eliminate rewriting PQ as (PQ) (QP)
Eliminate rewriting PQ as PQ
Use De Morgan’s laws to push inwards:
Rewrite (P Q) as P Q
Rewrite (P Q) as P Q
Eliminate double negations: rewrite P as P
Use the distributive laws to get CNF:
Rewrite (P Q) R as (P R) (Q R)
Rewrite (P Q) R as (P R) (Q R)
Exercise: Convert (P(QR)) to CNF
30
Solution
(P(QR))
(P(QR))
P (Q R)
P (Q R)
P (Q R)
Two clauses: P, Q R
31
Resolution Rule of Inference
AB BC
AC
32
Applying Resolution
How can we use the resolution rule?
One way:
Convert knowledge base into clausal form
Repeatedly apply resolution rule to the
resulting clauses
A query A follows from the knowledge base if
and only if each of the clauses in the CNF of
A can be derived using resolution
There is a better way . . .
33
Refutation Systems
To show that P follows from S (i.e. S P) using
refutation, start with S and P in clausal form and derive
a contradiction using resolution.
The “empty clause ” (a clause with no literals) is
unsatisfiable (always False) – a contradiction.
So if the empty clause is derived using resolution, the
original set of clauses is unsatisfiable.
That is, if we can derive from the clausal forms of S and
P, these clauses can never be all True together.
Hence whenever the clauses of S are all True, at least
one clause from P must be False, i.e. P must be
False and P must be True.
Hence, by definition, S P
34
Applying Resolution Refutation
Negate query to be proven.
Convert knowledge base and negated
conclusion into CNF and extract clauses.
Repeatedly apply resolution until either the
empty clause (contradiction) is derived or no
more clauses can be derived.
If the empty clause is derived, answer ‘yes’
(query follows from knowledge base), otherwise
answer ‘no’ (query does not follow from
knowledge base)
35
Resolution: Example 1
(GH)(JK), G J
Clausal form of (GH)(JK) is
{GJ, HJ, GK, HK}
1. GJ [Premise]
2. HJ [Premise]
3. GK [Premise]
4. HK [Premise]
5. G [Premise]
6. J [Conclusion]
7. G [1,6. Resolution]
8. [5,7. Resolution]
36
Problems
P Q, Q R P R
((P Q) P) Q
37
Soundness and Completeness
Resolution refutation is sound, i.e. it preserves
truth (if a set of premises are all true, any
conclusion drawn from those premises will also
be true).
Resolution refutation is complete, i.e. it is
capable of proving all valid consequences of any
knowledge base.
Resolution refutation is decidable, i.e. there is an
algorithm implementing resolution, which when
asked whether P S, can always answer ‘yes’
or ‘no’ (correctly).
38
Heuristics in Applying Resolution
Clause elimination — can disregard certain
types of clauses
Pure clauses: contain literal L where L doesn’t
appear elsewhere
Tautologies: clauses containing both L and L
Subsumed clauses: another clause exists containing
a subset of the literals
Ordering strategies
Resolve unit clauses (only one literal) first
Start with query clauses
Aim to shorten clauses
39
Conclusion
We have now investigated one knowledge
representation and reasoning formalism
This means we can draw new conclusions from the
knowledge we have: we can reason
Have enough to build a knowledge-based agent
However, propositional logic is a weak language; there
are many things that cannot be expressed
To express knowledge about objects, their properties
and the relationships that exist between objects, we
need a more expressive language: first-order logic
40