Formal Methods in
Software Engineering
Lecture # 04
Propositional Logic
Instructor: Saima Zareen
Assistant Professor
Department of Software Engineering
[email protected]
RECAP
My name is ………………………….
I remember …………………………..
The Island of Knights and Knaves
The island has two types of
inhabitants: I always speak the
'knights', truth
The Island of Knights and Knaves contd..
'knaves',
who always tell a lie.
If A is a knight S is true
If A is a Knave S is false
A S knight
~A ~S knave
Someone asks person A
“Are you a knight?”
He replies if I am a knight, I will eat my hat.
Prove that A has to eat his hat.
Solve it using logic.
A: A is a knight
H: A eats his Hat.
If A is a knight, A will eat his Hat
S=A=> H
We have seen that
A S
Therefore
For a knight
AA=>H
Two ways to solve problems
Truth tables
Logical deductions
Truth tables
Truth table becomes complex with the increasing
variables.
Logical deduction is more simpler.
P=>q= not p or q see lecture 03 slide 49
A(~A v H); PQ=(P˄Q)˅(~P ˄~Q)
((A^(~A v H) v (~A ^~(not A v H))
A^~A v A^H
False v (A ^ H)------ equation 1
v (~A ^~(not A v H))
V (~A^A) ^~H
False ^ ~H= False ----- equation 2
Combining equation 1 and equation 2 using OR
False v A^H V False
False v False v A^H
A^H
Activity
on the island of knights and knaves, it is rumored that there
is gold buried on the island. You ask one of the natives, A
,whether there is gold on the island. He makes the following
response: “there is gold on this island if and only if I am a
knight”
ASG, ~A~S,
G : There is gold on island
can it be determined whether A is a knight or a knave?
Can it be determined whether there is gold on the island?
Rules of Inference and
logical deduction
Syntax of rules of inference
// above the line are premises
// below the line is the conclusion
To the right of the line, we write the name of the rule, ∧i
is read ‘and-introduction.
Notice that we have introduced a ∧ (in the conclusion).
The rule for conjunction
(Introduction) Notice that we have introduced a ∧ (in the
conclusion) where there was none before (in the
premises).
Rules for elimination
It is important to engage in this kind of pattern matching before the
application of proof rules.
Elimination rule(rule for conjunction )
If we are given complex proposition, we can conclude a simple
proposition from it.
Given p and q
When p and q is true, it means we can conclude p is true.
P and Q
---------
p
When p and q is true, it means we can conclude q is true.
P and Q
---------
Q
Example
Prove the rule given P^Q, R Q^R
p∧q
r
q∧r
fill the gap between the premises and the conclusion by applying a suitable
sequence of proof rules.
Given conjunction rule of elimination
we apply ∧e2 to the first premise, giving us q
Then we apply ∧i to this q and to the second premise, r, giving us q ∧ r.
1. p∧q premise
2. r premise
3. q ∧e2 1
4. q∧r ∧i 3, 2
Practice task 1
(p ∧ q) ∧ r, s ∧ t |− q ∧ s
Questions
References
http://
people.hofstra.edu/stefan_waner/realworld/logic/logi
cex2.html
http://
www.mathgoodies.com/lessons/vol9/biconditional.ht
ml
Program construction calculating implementations
from specifications by roland backhouse