You are on page 1of 36

Z (Conti…)

REMAT ULLAH
“Conformance to requirements”
“Conformance to requirements”
“Conformance to requirements”
Formal Methods
 The notation used in a formal method is called a formal
specification language or 'notation‘.

 The language is 'formal' in that it has a formal semantics and


consequently can be used to express specifications in a clear
and unambiguous manner.
Programming languages are formal
languages?

Programming languages are formal languages, but are not


considered appropri-ate for use in formal specifications for a
number of reasons:
Programming languages are formal
languages?

 Firstly, very few programming languages have been given a


complete formal se-mantics (Ada and Modula-2 are
exceptions), which makes it difficult to prove programs correct
and to reason about them.
 Too much detail at an early stage in the development can lead
to a bias towards a particular implementation, and can result in
a system that does not meet the original requirements.
 Software Development Life Cycle:
 • Requirements analysis
 • Requirements specification
– As a process: when the functionality of the software is specified
– As a product: where the expected functionality is recorded
 • Architectural design
 • Detailed design
 • Implementation
 • Testing
Essential Properties of a Specification
Document

 • Correctness
 • Completeness
 • Unambiguous (one interpretation)
 • Precision (unnecessary detail suppressed)
 • Verifiable and traceable
 • Independent from design
 • Consistent (no conflicting features)
 • Concise (lack of noise, irrelevant features)
Z schema
Z schema Inclusion
Z schema Inclusion
Types
Types
Types

 A new basic type T is introduced to a specification by putting its name


in square brackets:
[T]
 This allows us to name the types of a specification without saying what
kind of objects they contain. For example, a specification of an address
book might introduce the basic types Name and Address without
worrying about the structure of these types:
[ Name, Address ]
 If we know the exact values of a type we use an enumerated type
declaration:
Direction == north | south | east | west
Predicates
Global Defination
Universal Quantification

(∀x : T •A)

This is true when A holds for all values x of type T. Here x is a said to be a
quantified or bound variable.
Existential Quantification

(∃x : T •A)

This is true when A holds for some value x of type T.


Quantifiers and declarations

In the Z notation, the two kinds of quantified expressions have a


similar syntax:
Qx : a |p •q
where
1. Q is the quantifier;
2. x is the bound variable;
3. a is the range of x;
4. p is the constraint;
5. q is the predicate.
Quantifiers and declarations

Consider the following quantified expression, which states that


every natural number x is greater than or equal to zero:
∀num : N•num ≥0

The choice of ‘num’ as the variable name is not important; the


following expression has the same meaning:
∀nat : N•nat ≥0
Relations

A Relation is simply a set of order pairs. An ordered pair of


values is written: (x,y)
Relations
Relations

A Relation is simply a set of order pairs. An ordered pair of


values is written: (x,y)
For example, a database relating names to telephone numbers can
be modelled as a set of ordered pairs:
directory = {(mary,287573), (mary,398620),
(john,829483), (jim,493028),
(jane,493028)}
The set directory has type,
directory : P(Person×Number)
Relations

Note that it is possible for a name to be related to more than one


number (mary may have a home number and a mobile number)
It is possible for two people to be related to the same number (jim
and jane may live together).
Because relations are commonly used in specification, they have
their own special symbol:
T ↔ S == P(T ×S)
So we can write:
directory : Person ↔ Number
Relations
Relations

Relations
Phone Directory Specification
Add Number
Get & Remove Entry
Combining Schemas

 Schemas may be combined using conjunction and disjunction


to form new schemas. Suppose we have the following two
schemas
Combining Schemas

 We can now define Schema3 to be the conjunction of Schema1


and Schema2
 we can define Schema4 to be the disjunction of these:
Schema3 == Schema1∧ Schema2
Schema4 == Schema1∨ Schema2
Combining Schemas

You might also like