Académique Documents
Professionnel Documents
Culture Documents
M. Sc. Mathematics:
Quaid-i-Azam University, Islamabad, 1991
M. Phil Mathematics:
Quaid-i-Azam University, Islamabad, 1993,
M. Sc. Nuclear Engineering:
Quaid-i-Azam University, Islamabad,1994,
PhD. Computer Science:
Kyushu University, Japan, 2004.
Dr. Nazir A. Zafar
Formal Methods
Formal Methods
Formal Methods
Lecture No. 1
Introduction
Formal Methods
Formal Methods
Formal Methods
Formal Methods
Formal Methods
Formal Methods
Formal Methods
An Introduction to Z Notations
Abstract data types and sequential programs
Describes state space of a system, operations over it
Operation are relations over pair of state spaces
Advancing to object oriented-ness
Z is based upon set theory and mathematical logic.
Set theory used includes set operators, set
comprehensions, cartesian products, power sets.
Mathematical logic is a first order predicate
calculus.
Together, they make up a mathematical language that
is easy to learn and to apply.
However, this language is only one aspect of Z.
Dr. Nazir A. Zafar
Formal Methods
An Introduction to Z Notations
Another aspect is the way in which the
mathematics can be structured.
Mathematical objects and their properties can be
collected together in schemas which are
patterns of declaration and constraint.
The schema language can be used to describe
the state of a system, and the ways in which that
state may change.
It is also used to describe system properties, and
to reason about possible refinements
Dr. Nazir A. Zafar
Formal Methods
An Introduction to Z Notations
A characteristic feature of Z is: types
Every object in mathematical language has a
unique type, represented as a maximal set in the
current specification.
This provides a useful link to programming
Notion of types means, in an algorithm, type of
object can be checked in specification
Several type-checking tools exist e.g. Z/eves
A third aspect is, we use natural languages to
relate the mathematics to objects in real world
A well-written specification should be perfectly
obvious to the reader
Dr. Nazir A. Zafar
Formal Methods
An Introduction to Z Notations
A fourth aspect is refinement.
We may develop a system by constructing a
model of a design, using simple mathematical
data types to identify the desired behavior.
We may then refine this description by
constructing another model which respects the
design decisions made, and yet is closer to
implementation.
This process of refinement can be continued
until executable code is produced.
Dr. Nazir A. Zafar
Formal Methods
An Introduction to Z Notations
Z is not intended for the description of nonfunctional
properties,
such
as
usability,
performance, size, and reliability.
Neither it is intended for the description of timed or
concurrent behavior.
However, there are other formal methods that are
well suited for these purposes.
We may use these methods combining with Z to
relate state and state-change information as a
complement
Formal Methods
OR [NAME, DATE]
Given
Formal Methods
Requirements
Formal Specification
1. Define a book
2. Possible operations
Formal Methods
[NAME, DATE ]
BirthdayBook
known : P NAME
birthday : NAME DATE
known = dom birthday
Formal Methods
Changing State
Decoration
BirthdayBook
known : P NAME
birthday : NAME DATE
known = dom birthday
Formal Methods
AddBirthday
BirthdayBook
BirthdayBook
name? : NAME
date? : DATE
name? known
birthday = birthday U {name? date?}
Dr. Nazir A. Zafar
Formal Methods
AddBirthday
BirthdayBook
name? : NAME
date? : DATE
name? known
birthday = birthday U {name? date?}
Formal Methods
AddBirthday
known : P NAME
birthday : NAME DATE
Known : P NAME
Birthday : NAME DATE
name? : NAME
date? : DATE
known = dom birthday
Known = dom birthday
name? known
birthday = birthday U {name? date?}
Dr. Nazir A. Zafar
Formal Methods
FindBirthday
known : P NAME
birthday : NAME DATE
name? : NAME
date! : DATE
name? known
date! = birthday (name?)
Dr. Nazir A. Zafar
Formal Methods
Issuing a Reminder
Remind
known : P NAME
birthday : NAME DATE
today? : DATE
cards! : P NAME
cards! = {n : known | birthday (n) = today?}
Note: today? Is (Input variable) and
cards! (output variable)
Dr. Nazir A. Zafar
Formal Methods
Chapter No. 2
Propositional Logic
Formal Methods
Propositional Logic
Definition: Propositional logic deals with the
statement of alleged facts which must be either
true or false, but not both.
Example 2.1: The following statements
propositions:
A tomato is a fruit.
An orange is a fruit.
Oranges are not the only fruit.
are
Formal Methods
Logical Connectives
In logical language, propositions may be
connected in various ways.
Table shows five propositional connectives, in
descending order of operator precedence
Symbol
Name
Pronunciation
negation
conjunction
disjunction
implication
equivalence
not
and
or
implies
if and only if
Formal Methods
Formal Methods
Conjunction
The conjunction p q is true only if p and q both
are true otherwise false
The conjunction follows the commutative
property i.e. p q = q p
pq
t
t
f
f
t
f
t
f
t
f
f
f
Formal Methods
Disjunctions
The disjunction p q is false if both p and q are
false otherwise true
The disjunction follows the commutative
property as well, i.e., p q = q p
pq
t
t
f
f
t
f
t
f
t
t
t
f
Formal Methods
Implications
The p is antecedent and q is consequent
The antecedent is stronger than consequent.
Commutative property does not hold, i.e.,
(p q) (q p)
p
t
t
f
f
Dr. Nazir A. Zafar
q
t
f
t
f
pq
t
f
t
t
Formal Methods
q
t
t
f
f
t
t
f
f
r
t
f
t
f
t
f
t
f
(p q r)
t t
t
f
f
t
f
t
f
t
f
t
f
t
f
t
(p (q r))
t
t
tt
t
f
ft
t
t
tt
t
t
tt
t
t
tt
t
t
ft
t
t
tt
t
t
tt
Formal Methods
Equivalence
The equivalence p q means p q & q p
Commutative property does hold, i.e.,
(p q) = (q p)
p
t
t
f
f
Dr. Nazir A. Zafar
q
t
f
t
f
pq
t
f
f
t
Formal Methods
Negation
p is true if and only if p is false. The truth table is
simple
It is to be noted that
(p p) = false
(p p) = true
t
Formal Methods
de Morgans Laws
1. (p q) = p q)
p
t
t
f
f
t
f
t
f
p q (p q) p
t
f
f
f
f
t
t
t
f
f
t
t
p q
f
t
f
t
f
t
t
t
Formal Methods
de Morgans Laws
2. (p q) = p q)
t
t
f
f
t
f
t
f
p q (p q) p
t
t
t
f
f
f
f
t
f
f
t
t
p q
f
t
f
t
f
f
f
t
Formal Methods
Formal Methods
Examples 2.12
Examples of Tautologies:
1. p p
2. p p
3. p (q p)
Examples of Contradiction
1. p p)
2. p p
3. (p (q p))
Dr. Nazir A. Zafar
Formal Methods
Examples 2.13
Prove that following are tautologies
pqpq
(p q) p q
(p q) p q
Formal Methods