Foundations
Conclusions
Ren Witte
Department of Computer Science
and Software Engineering
Concordia University
10.1
Key Points
Introduction
Foundations
Sets
Functions
State-based Specification Relations
Specification with Z
Z is a well-known formal specification language Data Schemas
Operation Schemas
model-based specification Reasoning
BirthdayBook Example
describe legal system states through pre-/post-conditions and invariants Strengthening the
Specification
Conclusions
first-order predicate logic and lambda calculus Notes and Further
Reading
ISO Standard (2002) 13568
10.2
1 Introduction
Key Points
Introduction
2 Foundations Foundations
Sets Sets
Functions
Functions Relations
3 Specification with Z
Reasoning
BirthdayBook Example
Reasoning Conclusions
4 Conclusions
10.3
Requirements Specification & Documentation Ren Witte
Key Points
Introduction
Foundations
Sets
Functions
Relations
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
10.4
Key Points
Introduction
Foundations
Sets
Logic-based specification for requirements, assumptions, and domain properties: Specification with Z
Data Schemas
Pre-Condition: Must hold before an operation can be applied Operation Schemas
Reasoning
Post-Condition: Must hold after executing an operation BirthdayBook Example
Strengthening the
Invariant: Must always hold (at defined snapshots) during an operation Specification
Combining Schemas
Core idea: define a system through a set of types (a schema) and operations Conclusions
10.5
The BirthdayBook schema defines the state space of the birthday book system: Introduction
Foundations
[NAME, DATE]
Sets
Functions
Relations
BirthdayBook Specification with Z
known : PNAME Data Schemas
Operation Schemas
birthday : NAME
7 DATE Reasoning
BirthdayBook Example
Conclusions
10.6
Example System State Ren Witte
Introduction
BirthdayBook Foundations
Sets
known : PNAME Functions
birthday : NAME
7 DATE
Relations
Specification with Z
Data Schemas
known = dom birthday Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
birthday: function; when applied to a name, gives the corresponding birthday Conclusions
10.7
Key Points
Introduction
Foundations
Observations Sets
Functions
There is: Relations
Specification with Z
No limit on the number of entries Data Schemas
Operation Schemas
No implied order of entries Reasoning
BirthdayBook Example
No restriction on format Strengthening the
Specification
Conclusions
Each person has only one birthday Notes and Further
Reading
Two people may share a birthday
Some people may not be in the database
10.8
Key Points
1 Introduction Introduction
Foundations
Sets
2 Foundations
Functions
Relations
Functions
Data Schemas
Operation Schemas
Relations Reasoning
BirthdayBook Example
Strengthening the
Specification
3 Specification with Z
Combining Schemas
Conclusions
10.9
Set membership Ren Witte
Key Points
Introduction
x S denotes that x is contained in S. Foundations
Sets
Functions
Relations
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
10.10
Key Points
Foundations
Sets
Functions
Relations
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
For example,
N Z Q R.
10.11
Key Points
The inference rules for propositional logic give identities for set theory. For example, Introduction
p pq
Sets
Functions
Relations
10.12
Union and Intersection Ren Witte
Introduction
Foundations
Sets
Functions
Relations
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
10.13
Foundations
Sets
Functions
Relations
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
Note that we could also write A0 = {x U | (x A)} to make the use of the Notes and Further
connective explicit. Reading
De Morgans Laws
Let A and B be sets. Then
1 (A B)0 = A0 B 0
2 (A B)0 = A0 B 0
10.14
Key Points
Introduction
Cartesian Product Foundations
The Cartesian product A B of two sets A and B is the set of all ordered pairs Sets
Functions
where the first item comes from the first set and the second item comes from the Relations
The power set P(S) of the set S is the set of all subsets of S: Notes and Further
Reading
P(S) = {X | X S}.
(Note: the power set of S is written as PS in the van Lamsweerde [vL09] textbook).
10.15
Function Ren Witte
Key Points
Introduction
Foundations
Sets
Functions
Definition Relations
A function from a set X to a set Y is a well-defined rule that assigns a single Specification with Z
Data Schemas
element of Y to every element of X . If f is such a function, we write Operation Schemas
Reasoning
BirthdayBook Example
f : X Y Strengthening the
Specification
Combining Schemas
and we denote the element of Y assigned to x X by f (x). The set X is called the Conclusions
domain of the function (written dom), and the set Y is called the codomain or range Notes and Further
Reading
(written ran).
10.16
Key Points
Introduction
Foundations
Let X = {1, 2, 3} and Y = {1, 2, 3, 4}. The formula f (x) = x + 1 defines a function Relations
Specification with Z
f : X Y . For this function, f (1) = 2, f (2) = 3 and f (3) = 4. Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
10.17
Key Points
Introduction
Foundations
Sets
Functions
Relations
Specification with Z
Definition Data Schemas
10.18
Relations (II) Ren Witte
Key Points
Introduction
Examples of Relations Foundations
Sets
The symbols =, <, >, , all define relations on Z (or on any set of numbers). Functions
Relations
For example, if S = {1, 2, 3}, then the relation on S defined by < is the set Specification with Z
Let P be the set of all people, living or dead. For any a, b P, let a R b if a and Reasoning
BirthdayBook Example
b are (or were) siblings. Then R is a relation on P, and the ordered pair Strengthening the
Specification
Conclusions
Let W be the set of all web pages. Then Notes and Further
Reading
10.19
Key Points
Introduction
Domain and Range Foundations
Sets
dom R Functions
Relations
If R is a binary relation between X and Y , then the domain of R (dom R) is the set of Operation Schemas
Reasoning
all members of X which are related to at least one member of Y by R. BirthdayBook Example
The range of R (ran R) is the set of all members of Y to which at least one member
Strengthening the
Specification
of X is related by R.
Combining Schemas
Conclusions
(| |) Relational image
The relational image R(| S |) of a set S through a relation R is the set of all objects y
to which R relates some member x of S.
10.20
Key Points
Restriction Introduction
The domain restriction S C R of a relation R to a set S relates x to y if and only if R Specification with Z
Data Schemas
Conclusions
C Domain anti-restriction
Notes and Further
Reading
B Range anti-restriction
These two operations are the complemented counterparts of the restriction
operations C and B. An object x is related to an object y by the relation S C R if
and only if x is related to y by R and x is not a member of S. Similarly, x is related
B T if and only if x is related to y by R and y is not a member of T .
to y by R
10.21
Outline Ren Witte
Introduction
Foundations
2 Foundations Sets
Functions
Relations
Specification with Z
3 Specification with Z Data Schemas
4 Conclusions
10.22
Key Points
Introduction
Z Specification Foundations
Specification with Z
Declaration Part: variables used in the schema are declared Data Schemas
Operation Schemas
Assertion Part: contains assertions constraining state space Reasoning
BirthdayBook Example
Strengthening the
Specification
Z Schema Types Combining Schemas
Operation Schema: Systems operations, each with input and output variables and
pre- and post-conditions
Additionally, initialization schemas define initial system state.
10.23
Key Points
Foundations
SchemaName Sets
Functions
declarations Relations
Specification with Z
Conclusions
known : PNAME
birthday : NAME
7 DATE
known = dom birthday
10.24
Operation Schemas Ren Witte
Operations
A state transition of a system is also described by a schema: Key Points
Introduction
SchemaName Foundations
Sets
State Functions
Specification with Z
postconditions Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
Example: Add a birthday
Notes and Further
Reading
AddBirthday
BirthdayBook
name? : NAME
date? : DATE
name? 6 known
birthday 0 = birthday {name? 7 date?}
10.25
AddBirthday Introduction
Foundations
BirthdayBook Sets
Conclusions
Z Syntax Notes and Further
Reading
prefix modifier: indicates an operation that changes (some) state variables
in a schema
prefix observer: indicates read-only operation (query state) of a schema
? suffix input variable, e.g., name?
! suffix output variable, e.g., date!
suffix used in postconditions to indicate state change, e.g., birthday 0
10.26
Key Points
Introduction
Pre-Condition
Foundations
A necessary condition on input variables Sets
Functions
captures operations applicability Relations
In SRS, we are interested in the least restrictive applicability condition (i.e., the
Operation Schemas
Reasoning
10.27
Pre- and Postcondition Example Ren Witte
Key Points
AddBirthday Introduction
Foundations
AddBirthday Sets
Functions
BirthdayBook Relations
Conclusions
Postcondition
birthday 0 = birthday {name? 7 date?}
10.28
AddBirthday
Key Points
AddBirthday Introduction
BirthdayBook Foundations
Specification with Z
name? 6 known Data Schemas
Operation Schemas
birthday 0 = birthday {name? 7 date?} Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
AddBirthday Conclusions
BirthdayBook
name? : NAME
date? : DATE
name? 6 known
{name? 7 date?} birthday 0
10.29
Key Points
Specification with Z
Data Schemas
But what about known? Shouldnt we add Operation Schemas
Reasoning
BirthdayBook Example
as well? Conclusions
10.30
Deriving change of known Ren Witte
Foundations
Sets
Proof using invariant Functions
Relations
Conclusions
10.31
Key Points
Introduction
Foundations
Sets
InitBirthdayBook Functions
Relations
This InitBirthdayBook specifies the initial state of the birthday book system. Specification with Z
Data Schemas
InitBirthdayBook
Operation Schemas
Reasoning
Conclusions
10.32
Key Points
AddBirthday Introduction
Foundations
Next we have several operation schemas to define the normal (non-error) behaviour Sets
Specification with Z
AddBirthday Data Schemas
Operation Schemas
BirthdayBook Reasoning
Conclusions
name? 6 known Notes and Further
birthday 0 = birthday {name? 7 date?} Reading
Z Notation
indicates an operation that changes the state of the variables
10.33
More Operations Ren Witte
Introduction
FindBirthday
Foundations
BirthdayBook Sets
Remind
Combining Schemas
Conclusions
BirthdayBook Notes and Further
today ? : DATE Reading
cards! : PNAME
cards! = {n : known | birthday (n) = today ?}
Z Notation
indicates an operation that does not change the state.
10.34
Key Points
Introduction
Foundations
RemindOne Sets
Functions
RemindOne reminds us of just one person who has a birthday on the given day. Relations
Specification with Z
Data Schemas
RemindOne Operation Schemas
Reasoning
BirthdayBook BirthdayBook Example
Conclusions
10.35
Introduction
Write the Z specification for RemoveBirthday Foundations
input variable is the name to be removed Sets
Functions
Relations
Specification with Z
Solution Data Schemas
Operation Schemas
Reasoning
RemoveBirthday BirthdayBook Example
Strengthening the
BirthdayBook Specification
Conclusions
10.36
Error Handling Ren Witte
Key Points
Conclusions
10.37
Key Points
Introduction
Foundations
Adding Error Handling Sets
Functions
Now we strengthen the specification by adding error handling. Relations
Specification with Z
Success Conclusions
result! = ok
10.38
Introduction
AlreadyKnown Foundations
BirthdayBook Sets
Functions
name? : NAME Relations
Conclusions
10.39
Robust Operations Ren Witte
Introduction
Finally, we define robust versions of all the operations by specifying how errors are
Foundations
handled. For illustration purposes, we leave the RemindOne operation non-robust. Sets
Functions
Specification with Z
RFindBirthday = (FindBirthday Success) NotKnown Data Schemas
Note how we defined a new schema (e.g., RAddBirthday ) through logical Conclusions
combination of existing schemas (e.g., (AddBirthday Success) AlreadyKnown). Notes and Further
Reading
10.40
date? : DATE
result! : REPORT
name? 6 known
birthday 0 = birthday {name? 7 date?}
result! = ok
10.41
Key Points
General Approach Introduction
Example
Reasoning
BirthdayBook Example
For NewSchema = (Schema1 Schema2) Schema3 we obtain the specification Strengthening the
Specification
Combining Schemas
NewSchema Conclusions
(AssertionSchema1 AssertionSchema2)
AssertionSchema3
10.42
Outline Ren Witte
Key Points
Introduction
1 Introduction Foundations
Sets
Functions
Relations
3 Specification with Z
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
4 Conclusions Conclusions
10.43
Key Points
Introduction
Foundations
Sets
Functions
Features Relations
describe systems (as state machines) abstractly yet precisely Operation Schemas
Reasoning
Conclusions
reason about properties of a system
Notes and Further
relate views of a system Reading
10.44
Z Tools
Lack of (good) tool support has been a major hindrance to wider adoption of Z.
Key Points
Z proof environment Isabelle/HOL-Z Introduction
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
10.45
Z Community Tools (CZT): BirthdayBook Example in Eclipse Ren Witte
Key Points
Introduction
Foundations
Sets
Functions
Relations
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
10.46
Key Points
Introduction
Foundations
Sets
Functions
Relations
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
10.47
Copyright P. Malik and M. Utting, A Framework for Z Tools, http://czt.sourceforge.net/
Key Points
Introduction
Foundations
Sets
Functions
Relations
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
Key Points
Introduction
W3C Standard WSDL
Foundations
The World Wide Web Consortium (W3C) standard for the Web Services Description Sets
Specification with Z
Data Schemas
Operation Schemas
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
Conclusions
(see http://www.w3.org/TR/wsdl20/wsdl20-z.html)
10.49
Key Points
Introduction
1 Introduction Foundations
Sets
Functions
Relations
3 Specification with Z
Reasoning
BirthdayBook Example
Strengthening the
Specification
Combining Schemas
4 Conclusions Conclusions
10.50
Key Points
Introduction
Foundations
Sets
Required Functions
Relations
Conclusions
[Spi92, Chapter 1: Tutorial Introduction] Notes and Further
Reading
[czt, The Community Z Tools (CZT) project]
10.51
References Ren Witte
Key Points
http://czt.sourceforge.net. Foundations
Sets
Functions
10.52