Transcript (¬p).
Part-2: Propositional Logic
By
Dr. Syed Noman Hasany
“The beginning of knowledge is the
discovery of something that we do
not understand.”
–Frank Herbert
Knowledge Pyramid
Knowledge – the integration of MetaKnowledge
Knowledge
- assigns
a purpose and/or action
to information
the information
into a knowledge
base to be effectively utilized
Knowledge Integration and Usage
Information
the
Information –
- interpreted
data “within a context set by a priori
interpretation of artifacts in Information Information
knowledge and the current environment”
some context
Interpretation in Context
Data
Data
raw
digital
material
or
the
“artifacts which exist as a
Data – collected symbols and
Data
vehicle
for conveying information”
artifacts
Noise
Knowledge bases
• Knowledge base = set of sentences in a formal language
Knowledge-base System
KB
sentences
inference
engine
Sys
percept
Describing a KB...
What it knows
Knowledge level
How it knows
Logical level
Knowledge implementation
ask/result
tell
Implementation level
Propositional Logic
• The syntax of propositional logic is made
up of propositions and connectives.
Proposition
• A statement in some language that can be evaluated to
either true or false (but it cannot be both).
Example propositions:
•
•
•
•
It is raining.
5 + 5 = 10.
Turkey is in Asia.
Riyadh is the capital of KSA.
Not propositions:
• Where are you?
• Oh no!
• Liverpool is not.
Propositions
• Of the valid propositions, each can be evaluated
to either true or false.
• e.g. It is true that it is raining
• e.g. It is false that Turkey is in Asia.
• An easy way to determine whether or not a
statement is a proposition is to see if you can
prefix it with “it is true that” or “it is false that”;
and if it subsequently still makes sense.
Propositions
• we represent propositions using the
propositional variables p, q, r etc.
• The previous examples of propositions are
all atomic. We can combine these atomic
propositions to form compound
propositions…
Connectives
• Propositions are combined through connectives.
The main connectives of propositional logic are:
• Conjunction (and): Λ
• Disjunction (or): v
• Negation (not): ¬
• Implication (if..then): →
• Equivalence (if and only if): ↔
Material Implication
• For the implication truth table, p → q is
false only when p is true and q is false.
• The last two cases, where p is false, we
cannot say whether q will be true, but as
we cannot say it will definitely be false,
then we evaluate these cases to true.
Implication
Example:
Using the implication
connective we can
express that if “you give
me your mobile phone”
then “I will be your best
friend”, as:
p→q
where p represents the
proposition “you give me
your mobile phone” and q
represents the
proposition “I will be your
best friend”.
Truth Table
p
q
p→q
T
T
F
F
T
F
T
F
T
F
T
T
Implication
• We need to be careful with → as it may not
quite capture our intuitions about implication.
• In particular (taking the previous example),
p → q is true in the following situations:
– I study hard and I get rich; or
– I don't study hard and I get rich; or
– I don't study hard and I don't get rich.
• Note the last two situations, where the
implication is true regardless of the truth of p.
• The one thing we can say is that if I've studied
hard but failed to become rich then the
proposition is clearly false.
Equivalence OR Bi-implication
Example:
Using the equivalence
connective we can express
that “Asim will get a first
class degree” iff “his
average is higher than
70%”, as:
p↔q
where p represents the
proposition “Asim will get a
first class degree” and q
represents the proposition
“his average is higher than
70%”.
Truth Table
p
q
p↔q
T
T
F
F
T
F
T
F
T
F
F
T
Compound Statements
• Connectives can be combined to form
compound statements or formulae.
• e.g.:
¬(p Λ ¬ q)
pΛq↔r
Example
The truth table for ¬(p Λ ¬q) is as follows:
p
q
¬q
T
T
F
F
T
F
T
F
F
T
F
T
T
F
F
T
F
F
T
T
(p Λ ¬q) ¬(p Λ ¬q)
Example
This table is derived by a number of steps:
p
q
¬q
T
T
F
F
T
F
T
F
F
T
F
T
T
F
F
T
F
F
T
T
(p Λ ¬q) ¬(p Λ ¬q)
Tautologies and Contradictions
• For the truth tables of some formulae we find only Ts in
the last column. Such formulae are called “tautologies”
(or valid formulae).
• Conversely, the truth tables of other formulae contain
only Fs in the last column. Such formulae are called
“contradictions” (or unsatisfiable formulae).
• Negation of a tautology is a contradiction, and vice
versa.
• A formula that is neither a tautology nor a contradiction
(i.e. contains both Fs and Ts in the last column) is known
as a “contingency” (or a satisfiable formula).
Tautology Example
The truth table for: p → (p V q), is a
tautology, as shown below.
p
q
(p V q)
T
T
F
F
T
F
T
F
T
T
T
F
p → (p V q)
T
T
T
T
Contradiction Example
The truth table for: (p V q) Λ (¬p Λ ¬q), is
a contradiction, as shown below.
p
q
T
T
F
F
T
F
T
F
(p V q) ¬p ¬q ¬p Λ ¬q (p V q) Λ (¬p Λ ¬q)
T
F
F
F
F
T
T
F
F
T
T
T
F
T
F
F
F
F
F
T
Contingency Example
The truth table for: (p Λ q) → ¬p , is a
contingency, as shown below.
p
q (p Λ q) ¬p
T
T
F
F
T
F
T
F
T
F
F
F
F
F
T
T
(p Λ q) → ¬p
F
T
T
T
Equivalences
• It is worth noting that there are a number of equivalences
between the logical connectives.
Thus:
p q is equivalent to ¬p V q
p Λ q is equivalent to ¬(¬p V ¬q)
p V q is equivalent to ¬p q
• The symbol we use to denote equivalence is: ≡
e.g. p q ≡ ¬p V q
etc.
Equivalences
•We can check
to see if these
statements are equivalent
by examining
the appropriate
truth tables
p
T
T
F
F
p
T
T
F
F
p→q
T
F
T
T
q
T
F
T
F
q
T
F
T
F
¬p
F
F
T
T
¬p V q
T
F
T
T
Equivalence Laws
• There are a number of laws that state equivalence
relations. The following are a few of the most popular
ones:
• Associative laws:
(p V q) V r ≡ p V (q V r)
(p Λ q) Λ r ≡ p Λ (q Λ r)
• Commutative laws:
pVq ≡ qVp
pΛq ≡ qΛp
• Involution law:
¬¬p ≡ p
Equivalence Laws
• Distributive laws:
p V (q Λ r) ≡ (p V q) Λ (p V r)
p Λ (q V r) ≡ (p Λ q) V (p Λ r)
• DeMorgan’s laws:
¬(p V q) ≡ ¬p Λ ¬q
¬(p Λ q) ≡ ¬p V ¬q
• All these laws can be verified by checking the
appropriate truth tables to see that the
statements are equivalent.
Syntax semantics
Wumpus World description
Exploring the Wumpus World
1. The KB initially contains the rules of the environment.
2. (a) [1,1] The first percept is [none, none,none,none,none],
Move to safe cell e.g. 2,1
3. (b) [2,1] Breeze indicates that there is a pit in [2,2] or [3,1]
Return to [1,1] to try next safe cell
Exploring the Wumpus World
4. [1,2] Stench in cell: wumpus is in [1,3] or [2,2]
YET … not in [1,1]
Thus … not in [2,2] or stench would have been detected in [2,1]
Thus … wumpus is in [1,3]
Thus … [2,2] is safe because of lack of breeze in [1,2]
Thus … pit in [3,1]
Move to next safe cell [2,2]
Exploring the Wumpus World
5. [2,2] Detect nothing
Move to unvisited safe cell e.g. [2,3]
6. [2,3] Detect glitter , smell, breeze
Thus… pick up gold
Thus… pit in [3,3] or [2,4]
Logic in general
A Formal Approach
• Any logic comes in three parts:
• syntax: what are the well-formed formulae
(wffs)?
• semantics: what do formulae mean, how do we
interpret them?
• deduction: how to mechanically formulate
formulae, giving us for instance, the valid ones?
Or is concerned with manipulating formulae
according to certain rules (Also called the proof
theory)
Propositional logic grammar
S := <Sentence> ;
<Sentence> := <AtomicSentence> |
<ComplexSentence> ;
<AtomicSentence> := "TRUE" | "FALSE" |
"P" | "Q" | "S" ;
<ComplexSentence> := "(" <Sentence> ")" |
<Sentence> <Connective> <Sentence>
|"NOT" <Sentence> ;
<Connective> := "NOT" | "AND" | "OR" |
"IMPLIES" | "EQUIVALENT" ;
Argument and Proof in
Propositional Logic
• An argument is a relationship between a set of propositions
called premises and another proposition called the
conclusion.
• Proof is intended to show deductively that an argument is
sound (or valid).
– An argument is sound iff it cannot be the case that its premises are
true and its conclusion is false.
• An argument that is not sound is called a fallacy
• In addition to using truth tables, other forms of proof can be
used, such as derivation rules (or proof rules).
Entailment and Proof
• To clarify the difference between entailment and proof:
• Entailment: if we have a set of formulae which are true,
then as a logical consequence of this, some particular
formula must also be true.
• Proof: a formula is provable (derivable) in some logical
system if there are rules of inference that allow the
formula to be derived by performing some operations on
the formulae.
• Entailment is concerned with the semantics of formulae,
proof is concerned with syntax only.
Entailment
Example: {¬q, p q} ╞ ¬p
means that ¬p is true, iff
both ¬q and p q are
true. Thus, the premises
entail the conclusion.
Truth Table
p q ¬p ¬q
T
T
F
F
T
F
T
F
F
F
T
T
F
T
F
T
(p q)
T
F
T
T
Entailment
• Lines 1, 2 and 3 all have false truth assignments
so we disregard them.
• This means that we are left with one
assignment, where all assignments for the
formula are true.
– i.e. ¬q is true, p q is true and ¬p is true.
• Therefore, ¬p is entailed by {¬q, p q} , or
more formally: {¬q, p q} ╞ ¬p
Modus Ponens
• (Latin term means) Affirming the antecedent
• One particularly important derivation rule is
modus ponens, as shown on the previous slide.
• This takes the following form:
p → q, p ╞ q
• Essentially, this argument states that given the
premise p → q, and the premise p then we must
conclude q.
Modus Ponens Example
• An example argument of the form modus
ponens:
Premises:
- If it is raining then ground is wet (p → q),
- It is raining (p),
Conclusion:
- Therefore, the ground is wet (q).
Modus Tollens
• Denying the consequent
• Another important derivation rule is modus tollens
(also known as the contraposition) have the
following form:
p → q, ¬q ╞ ¬p
• Example:
Premises:
- If it is raining then the ground is wet (p → q),
- The ground is not wet (¬q)
Conclusion:
- Therefore, it is not raining (¬p).
Exercise
• Can we entail otherwise in modus tollens?
Soundness and Completeness
• Two important properties to consider in
inference systems are soundness and
completeness.
• A “logic is sound”, with respect to its semantics,
if only true formulae are derivable under the
inference rules, from premises which themselves
are all true. (i.e. the inference rules are correct)
• A “logic is complete” if all the true formulae are
provable from the rules of the logic. (i.e. no other
rules are required)
Proof System
• A proof system PS is a set of inference rules.
• A proof is a sequence of sentences where each
sentence can be inferred from a previous
sentence using one of the inference rules.
• A ├ PS B means that there exists a proof starting
with A (which might be a set of sentences),
ending with B, using the proof system PS.
Logical equivalence
• Two sentences are logically equivalent iff they are true in
same models: α ≡ ß iff α╞ β and β╞ α
Entailment
• Entailment means that one thing follows from
another:
KB ╞ α
• Knowledge base KB entails sentence α if and
only if α is true in all worlds where KB is true
Entailment in the wumpus
world
Situation after detecting
nothing in [1,1], moving
right, breeze in [2,1]
Consider possible models for
KB assuming only pits
3 Boolean choices 8
possible models
Wumpus models
Wumpus models
• KB = wumpus-world rules + observations
Wumpus models
• KB = wumpus-world rules + observations
• α1 = "[1,2] is safe", KB ╞ α1, proved by model checking
Wumpus models
• KB = wumpus-world rules + observations
Wumpus models
• KB = wumpus-world rules + observations
• α2 = "[2,2] is safe", KB ╞ α2
Inference
• KB ├i α = sentence α can be derived from
KB by procedure i
• Soundness: i is sound if whenever KB ├i α,
it is also true that KB╞ α
• Completeness: i is complete if whenever
KB╞ α, it is also true that KB ├i α
A simple knowledge base:
Wumpus world sentences
Let Pi,j be true if there is a pit in [i, j].
Let Bi,j be true if there is a breeze in [i, j].
α1: Is P1,2 entailed?
α2: Is P2,2 entailed?
R1:
R 4:
R 5:
P1,1
B1,1
B2,1
• "Pits cause breezes in adjacent squares"
R2:
R 3:
B1,1 (P1,2 P2,1)
B2,1 (P1,1 P2,2 P3,1)
(Question: what if instead of ? )
( R1 ^ R2 ^ R3 ^ R4 ^ R5 ) is the State of the Wumpus World
Truth tables for inference
KB is true if R1 through R5 are true, which is true in just 3 of 128 rows. In all
3 rows, P1,2 is false, so there is no pit in [1,2]. On the other hand, there might
(or might not) be a pit in [2,2]. Why not sure?
All True means “Yes”; All False means “No”; Contingent means “Un-known”
Inference Examples
• KB is true when the rules hold—only for three
rows in the table
– The three rows are models of KB
• Consider the value of P1,2 for these 3 rows
– P1,2 is false in all rows
(the rows are models of α1 = P1,2)
– Thus, there is no pit in room [1,2]
• Consider the value of P2,2 for these 3 rows
– P2,2 false in one row, true for 2 rows
– Thus, there may be a pit in room [2,2]
Resolution Inference Rule
The rule is established (when both are true, result is true)
Inference Rules for propositional logic
1.
Modus Ponens or Implication-Elimination: (From an implication
and the premise of the implication, you can infer the conclusion.)
2.
And-Elimination: (From a conjunction, you can infer any of the
conjuncts.)
3.
And-Introduction: (From a list of sentences, you can infer their
conjunction.)
4.
Or-Introduction: (From a sentence, you can infer its disjunction
with anything else at all.)
5.
Double-Negation Elimination: (From a doubly negated sentence,
you can infer a positive sentence.)
6.
Unit Resolution: (From a disjunction, if one of the disjuncts is false,
then you can infer the other one is true.)
7.
=> ,
1 2 … n
i
1, 2, …, n
1 2 … n
i
1 2 … n
,
Resolution: (Because cannot be both true and false, one of the other disjuncts must
be true in one of the premises. Equivalently, implication is transitive. a=b, b=c -> a=c)
,
or equivalently
=> , =>
=>
Suppose my knowledge base consists of the facts
S T (P R)
S
T
R
And I need to prove that P is entailed. I can use the rules of
inference to do this..
S T (P R) , S , T, R And-Introduction
S T (P R) , S T, R Double Negation Elimination
S T (P R) , (S T), R
Modus ponens
(P R), R
Apply negation
P R , R
Unit Resolution
P
Double Negation Elimination
P
So, P is entailed from the knowledge base.
Example: Proof
Prove?
Proving things
• The last sentence is the theorem (also called goal or query)
that we want to prove.
• Example for the “weather problem”:
1 Hu
Premise
“It is humid”
2 HuHo
Premise
“If it is humid, it is hot”
3 Ho
Modus Ponens(1,2)
“It is hot”
4 (HoHu)R
Premise
“If it’s hot & humid, it’s raining”
5 HoHu
And Introduction(1,2)
“It is hot and humid”
6R
Modus Ponens(4,5)
“It is raining”
Logical equivalence
• Two sentences are logically equivalent iff they are true in
same models: α ≡ ß iff α╞ β and β╞ α
A simple knowledge base:
Wumpus world sentences
Let Pi,j be true if there is a pit in [i, j].
Let Bi,j be true if there is a breeze in [i, j].
α1: Is P1,2 entailed?
α2: Is P2,2 entailed?
R1:
R 4:
R 5:
P1,1
B1,1
B2,1
• "Pits cause breezes in adjacent squares"
R2:
R 3:
B1,1 (P1,2 P2,1)
B2,1 (P1,1 P2,2 P3,1)
(Question: what if instead of ? )
( R1 ^ R2 ^ R3 ^ R4 ^ R5 ) is the State of the Wumpus World
Back to Wumpus World
• KB = ( R1 ^ R2 ^ R3 ^ R4 ^ R5 )
• Prove P2,1
Apply Bi-conditional Elim
R6: (B1,1 => (P1,2 V P2,1 )) ^ ( (P1,2 V P2,1 ) => B1,1 )
Apply And Elim
R7: ( (P1,2 V P2,1 ) => B1,1 )
Contrapositive
R8: ( B1,1 => (P1,2 V P2,1 ))
Apply Modus Ponens with R4 ( B1,1 )
R9: (P1,2 V P2,1 )
Apply De Morgans
R10: P1,2 ^ P2,1
proved?
• Finally?
– Which rule?
Assign: Q.1
Syntax. Say whether each of the following is a sentence of Propositional Logic.
Assign: Q.2
Validity, Satisfiability, Unsatisfiability. For each of the following sentences,
Indicate whether it is valid, satisfiable, or unsatisfiable..
Assign: Q.3
• Prove
{C A, A B, B} C