Professional Documents
Culture Documents
Formal Methods in Software Engineering: Propositional Logic
Formal Methods in Software Engineering: Propositional Logic
Software Engineering
Lecture # 05
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=q using e2
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
Rule of double negation
there is no difference between a formula φ and its
double negation ¬¬φ,
which expresses no more and nothing less than φ
itself
‘It is not true that it does not rain.’
It is just a more contrived way of saying ‘It rains.’
we are free to state this fact in this more complicated
manner if we wish.
Thus, we obtain rules of elimination and introduction
for double negation.
¬¬φ /φ ¬¬e double negation elimination
φ/ ¬¬φ ¬¬i double negation introduction
In your proof of ψ, you can use φ and any of the other
formulas such as premises and provisional
conclusions.
The line immediately following a closed box has to
match the pattern of the conclusion of the rule that
uses the box.
For implies-introduction, this means that we have to
continue after the box with φ → ψ.
where φ was the first and ψ the last formula of that
box.
Consider two more rules involving proof boxes.
Prove ~q->~p|-p->~~q
1. ~q->~p premise
2. P assumption
3. ~q->~p, p =~(~q) MT (q-> p, ~p= ~q)
2. ~q--> ~p assumption
3. P assumption
4. ~q--> ~p, p== ~(~q) MT 2,3
5. ~~q==q ~~e
6. q, q --> r ==r e 5,1
7. pr I 3,6
8. (~q--> ~p) (pr) I 2,7
Given False
We can conclude p
Given False
We can conclude q
Rule of Negation (Introduction) contd..
This rule is called as proof rule bottom-elimination.
And written as
2. P assumption
3. ~p assumption
4. p^~p== (False ) ~e2,3
5. q e4
2. p q i 2,3
We apply these rules to show that ¬p ∨ q |−
p → q is valid:
Rule of Negation (Introduction)
Well, suppose we make an assumption which gets us
into a contradictory state of affairs, i.e. gets us ⊥.
Then our assumption cannot be true; so it must be false.
This intuition is the basis for the proof rule ¬i:
p → ¬p |- ¬p, contradiction
Rule of Negation (Introduction) contd..
It is different from previous rule due the placement of
negation symbol
It is also written as Proof By Contradiction (PBC)
Derived Rules: Law of the excluded middle
(LEM)
It says that φ ∨ ¬φ is true (tautology)
whatever φ is, it must be either true or false;
in the latter case, ¬φ is true.
There is no third possibility (hence excluded middle).
the sequent |- φ ∨ ¬φ is valid
Its validity is implicit, for example, whenever you write
an if-statement in a programming language:
‘if B {C1} else {C2}’ relies on the fact that B ∨ ¬B is
always true.
Practice Task 3
prove that the sequent p → (q → r), p, ¬r |− ¬q is
valid, without using MT rule.
Summary
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