Formal Methods in Software Engineering: Propositional Logic
Formal Methods in Software Engineering: Propositional Logic
Software Engineering
Lecture # 04
Propositional Logic
Instructor: Saima Zareen
Assistant Professor
Department of Software Engineering
saima.zareen@uettaxila.edu.pk
RECAP
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
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