Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 56

Formal Methods in

Software Engineering
Lecture # 03
Logic of Propositions
Instructor: Saima Zareen
Assistant Professor
Department of Software Engineering
saima.zareen@uettaxila.edu.pk
RECAP

My name is ………………………….

I remember …………………………..
Outline
Logical reasoning
Logical connectives
Boolean Equality
Important tools for Mathematical Models
Logic
Set Theroy
Propositional Calculus play an important role in logic.
Logical Reasoning
Logic is the glue that binds together the properties of
the data.
Logical Reasoning contd..
Computer programmer uses logic
An excellent understanding of logical reasoning is
vital to building reliable software.
Logical Reasoning contd..
It is the part of Mathematics.
Traditionally, logic has been conducted in natural language.
Mathematical statements are combined with phrases or
sentences like
'a necessary condition is...', 'therefore...', 'because', 'if and only if,
'every number can be factorized into a product of prime numbers',
etc.
Therefore logic is the glue that binds together the other
Mathematical statements.
The logic consists of two boolean values
True
False
Logic: Propositions
These are statements that are either true or false
Examples
It is raining
I live in Lahore
Statements which are not propositions
Do it, as I say
You must work hard
Atomic propositions
That cannot be broken down into simpler propositions
Propositional logic
Motivation for studying Logic:
To acquire the ability to model real-life situations in a
way that would allow us to reason about them formally.
Example 1: If the train arrives late and there are no taxis
at the station, then John is late for his meeting. John is
not late for his meeting. The train did arrive late.
Therefore, there were taxis at the station.
Example 2: If it is raining and Jane does not have her
umbrella with her, then she will get wet. Jane is not wet.
It is raining. Therefore, Jane has her umbrella with her.
Can we verify the validity of these arguments
formally?
 We need to turn the English sentences into formulas
(modeling).
Then, we can apply mathematical reasoning to
formula
Modelling
Declarative Sentences
Turning English phrases into Formulas
Logic: Propositions contd..
Logic is not concerned with the truth.
It is concerned of the problem domain being
discussed.
Logic is concerned with whether the combination of
atomic propositions leads to a valid or logical
conclusion e.g.
“The knowledge in universities grows and grows. Each
new student brings a little in and the graduates do not
take any away.”
Logic: Propositions contd..
Argument has two parts
Each new student brings a little [knowledge] in.
And
The graduates do not take any [knowledge] away
And one conclusion
The knowledge of universities grows and grows.
The argument is illogical why?
Natural Deduction Rules ---Conjunction
Suppose we have a set of formulas φ1, φ2, φ3, ... , φn,
which we will call premises.
and another formula, ψ, which we will call a
conclusion.
Natural Deduction
Logical Connectives
Logical connectives are functions from Booleans to
Booleans
Their domain and range are finite sets,
We can give them a precise mathematical meaning by
simply enumerating all possible combinations of input
and output value.
This is done in a truth table.
Propositional variable’s truth tables
Logical Connectives contd..

One propositional value can be simplified to either true,


p, ~p, or false.
There are 16 binary functions from boolean to boolean.
8 correspond to most frequently used ones.
6 binary operators.
2 constant true and false functions
Logical Connectives contd..
Logical connectors
And
Or
 nor
Xor
Implication
If only if ….
Logical Connectives contd..
Boolean Equality =
It is used for equality of numbers, sets, functions.
It is used rarely for equality of propositions.
Equality on the domain of values has a numbers of
characteristic properties.
1. Reflexive
x=x

2. Symmetric
x=y, y=x

3. Transitive
x=y, y=z, z=x
Associativity of Equivalence
If x=y and f is any function, then f.x=f.y
Leibniz rule substitution of equals for equals.
Equality is a binary relation.
Equality is a binary function, with range the boolean
values.
Binary relation
x=x, y=y, x=y and y=z, then x=z.
Binary Function
(x+y)+z=x+(y+z)
x+y=y+x
Associativity of Equivalence contd..
Associative property of Equivalence
((p = q)=r) = (p = (q = r ) )
If x=y=z and x=true,y=false, z=false
It means true=false=false
If (x=y)=z then (true=false)=false
If x=(y=z) then true=(false=false)
Associativity of Equivalence contd..
 The meaning of a sequence of expressions separated
by equality symbols would depend on the type of the
expressions.
use two different symbols to denote equality of
boolean values—
the symbol '=' when the transitivity of the equality
relation is to be emphasized and
the symbol 's' when its associativity is to be exploited.
Associativity of Equivalence contd..
 When p and q are expressions denoting boolean
values, these both mean the same.
 But a continued expression comprising more than
two boolean expressions connected by the '' symbol,
 is to be evaluated associatively— i.e.
 as (or whichever is the most convenient
whereas a continued expression p=q=r is to be evaluated
conjunctionally i.e as p = q and q= r
Associativity of Equivalence contd..
Example
 
 m+n is even m is even n is even
m+n is even (m is even n is even) ,
it states that the number m+n is even ,exactly when the
parities of m and n are both the same
Parenthesizing it as
(m+n is even m is even) n is even
it states that the operation of adding a number n to a
number m does not change the parity of m exactly
when n is even.
Associativity of Equivalence contd..

the property captures four different cases:


((m+n is even) and (m is even) and (n is even))
or ((m+n is odd) and (m is odd) and (n is even))
or ((m+n is odd) and (m is even) and (n is odd))
or ((m+n is even) and (m is odd) and (n is odd)) .
Associativity of Equivalence contd..

Exercise
 
The sign of a number says whether or not the number is
positive.
For non-zero numbers x and y, the product x*y is positive if
the signs of x and y are equal.
If the signs of x and y are different, the product x*y is negative.
Assuming that x and y are non-zero, this rule is expressed as
x*y is positive x is positive y is positive .
Interpret the two different ways of parenthesizing the
equivalences and enumerate the different properties of the
sign of a number that this one equivalence captures.
Half adder and full adder
https://www.youtube.com/watch?v=mZ9VWA4cTbE
Associativity of Equivalence contd..
C: c=1 A: a=1 B: b=1

Full Adder
D: d=1

 D=A
(associativity of boolean Equality
Continued Equivalence
 Laws of proposition
A first example is the law
[Constant true] true p p .
Two ways to parenthesize formula
true =(p p )
(true p) =p
Suppose we want to p p q p r q
p p p q q r
Continued Equivalence contd..
 Symmetry of Equivalence provides an easy way to
replace occurrences of p p and q q by true obtaining
True p true r
p
An expression of the form
P1 p2 p3…..pn
It is simplified by replacing any term that is repeated
an odd number of times by a single occurrence of the
term and,
Continued Equivalence contd..
 any term that is repeated an even number of times by
removing all occurrences of the term (replacing the
original expression by true if all terms are repeated an
even number of times).
Applying this process, the expression
p p q p r q q r p
The result is q
Continued Equivalence contd..
 Simplify the following.
i. p p p p p.
ii. p true q p .
iii. q p q p q p.
iv. false false false .
v. p≡p p.
vi. (false false) false = false .
vii. (p p) p p .
Negation ~
 [Negation] p
Reading this as
p
Reading it the other way,
p
the symmetry of equivalence means that we can
rearrange the terms in a continued equivalence in any
order we like.
So, we also get the property:
Negation ~ contd..
 
It provides the way of simplifying continued
equivalences in which one or more terms are repeated
and/or negated.
Suppose

Rearranging terms


Or (disjunction)
And (conjunction)
Implication =>
The claim that if P is
true, then Q is also true.
This is written as P=>Q,
pronounces P implies
Q.
It can also be written as
Q<= P (Q is implied by
P.)
It is a conditional
statement (if -else) that
we use in programming
languages.
Implication => contd..
if P is true only than we can argue about Q.
If P is false, we do not look at value of Q, Q is always
true
Example
Ahmad and Babar are cousins if their fathers are
brothers
P:Ahmad and Babar are Cousins
Q: Their fathers are brothers
P=>Q
If and only if ()
P  Q is true only when P and Q are both true, or
both are false
Inverse of xor.
It is a bidirectional operator and is used for
equivalences.
If and only if (p => Q (if) and Q => P (only if))
bidirectional implication.
It can be defined as (P=>Q)^(Q=>P)
A polygon is a triangle.
q: A polygon has exactly 3 sides
aq
a: x + 2 = 7
b: x = 5
Ab
r:You passed the exam.
s: You scored 65% or higher
Rs
if and only if iff
A polygon is a triangle if and only if it A polygon is a triangle iff it has exactly 3
has exactly 3 sides. sides.
I am breathing if and only if I am alive. I am breathing iff I am alive.
x + 2 = 7 if and only if x = 5. x + 2 = 7 iff x = 5.
You passed the exam if and only if you You passed the exam iff you scored
scored 65% or higher. 65% or higher.
If and only if () contd..

Tautology
 
A compound proposition which is always true P or ~P is always
true.
P or ~P
Contradiction
a proposition which is always false
P^~P
Logically Equivalent
If PQ is always true then P and Q are said to be logically
equivalent.
We write PQ.
For example
Some useful Equivalences
 

P
PQ=(P˄Q)˅(~P ˄~Q)
Associativity of ˅,˄, and 

Commutativity of ˅,˄, and 

Demorgan’s law
Implication
If and only if
Distributivity of
And over or
Or over and
Or over =>
=> over and
=> over or
=> over =>
=> over 
There are other properties, similar to DE Morgan's Laws in that they relate various
expressions. The first is called transposition, and the third is called exportation.
There are also two implications which might at first sight seem incorrect, but their
truth tables prove otherwise:
•(p & q) → p
•p → (~p | q)

p→q is equivalent to ~q → ~p
p→q is equivalent to ~p | q
(p & q) → r is equivalent to p → (q → r)
p↔q is equivalent to (p & q) | (~p & ~q)
Exercise 01
 Use truth tables to verify the following logical
equivalences:
 p˅(q˄(~q))  p
~(p ˄(~q))   (~p) ˅ q
Exercise 02
Use truth tables to check whether the following are
tautologies, contradictions or neither.
p˅~(p˅q)
q ˅ ~(p˄(~p))
p ˅ ~(p ˄ q)
Exercise 03
Apply the stated logical equivalence to each of the
following statements:
 p˅(~p); the Commutative law
~(p˄(~q)); De Morgan's Law
p˅((~p)˄q); the Distributive Law
Exercise 04
Use logical equivalences to rewrite each of the
following sentences. If possible, rewrite more simply.
It is not true that both I am Julius Caesar and you are a
fool
P: I am Julius Caesar
Q: you are a fool
P˄ Q is false
P˅Q // either im a Julis Caesar or you are a fool
Either it's raining and I have forgotten my umbrella, or
it's raining and I have forgotten my hat.
Exercise 05
Either Mary gives Peter her toy or Peter is going to cry
Mary does not give Peter her toy
 Can an atomic statement be a tautology or a
contradiction? Explain
A logical expression which evaluates to true for any
values of its constituent propositions is a tautology.
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
Summary

You might also like