Professional Documents
Culture Documents
Instructions to Candidates:
Answer ALL questions in Section A and TWO
questions from Section B.
Section A is worth a total of 50 marks.
Each question in section B is worth 25 marks.
You may wish to consult Appendix C.
Section A
Answer ALL questions from this section
Question 1
Given the following two schemas:
Sets
S1 , S2 : P N
x, y : N
x <y
x ∈ S1
y 6∈ S2
Sequences
S1 , S3 : seq N
z :N
S1 prefix S3
h1, 2, z i in S1
• ∆Sets
• ΞSequences
[7 marks]
(b) By referring to your answer to part (a) explain the role of each part of the
expanded version of the ΞSequences schema. [3 marks]
(c) Explain why it would not be possible to combine the two schemas using
either of the schema calculus operations conjunction (S ∧ T ) or disjunc-
tion (S ∨ T ). If it was necessary to combine these two schemas what
modifications would be required to allow this to be done. [3 marks]
Question 2
Given the following Z type definition representing the days of the week:
(a) Define a tomorrow relation that relates each day to the following day,
within a single week, i.e., from Sunday to Monday to ... to Saturday. [6 marks]
(b) Using the tomorrow relation define a before relation that relates two days
of the week if the first is “before” the second within a single week, starting
from Sunday and ending at Saturday. [7 marks]
(c) Define a relation similar to before but that is only concerned with just the
working days Monday to Friday, called WorkdaysBefore. [7 marks]
Question 3
Define the generic Z operator domain anti-restriction “−
C”, using a generic
schema. Its textual definition is given below.
Question 4
The following:
add (3, 5) = 8
sub(11, 5) = 6
inc(4) = 5
dec(1) = 0
are examples of the standard mathematical functions for addition, subtraction,
increment and decrement respectively, for natural numbers (N). Define the
signatures of these functions. Note you are not required to give their definitions. [10 marks]
Section B
Answer TWO questions from this section
Question 5
The following is part of a Library specification.
The following definitions represent the set of books, copies (i.e. instances) of
books and borrowers.
maxloans : N
LibraryDataBase
stock : COPY → 7 BOOK
registeredborrowers : F BORROWER
LibraryLoans
onloan : COPY → 7 BORROWER
inlibrary : F COPY
∀ b : BORROWER • #(onloan B { b }) ≤ maxloans
inlibrary ∩ dom onloan = ∅
Library
LibraryDataBase
LibraryLoans
dom stock = inlibrary ∪ dom onloan
ran onloan ⊆ registeredborrowers
[Continued Overleaf]
IssueBook
∆Library
c? : COPY
b? : BORROWER
c? ∈ inlibrary
stock 0 = stock
inlibrary 0 = inlibrary \ { c? }
#(onloan B { b? }) < maxloans
registeredborrowers 0 = registeredborrowers
b? ∈ registeredborrowers
onloan 0 = onloan ⊕ { c? 7→ b? }
(a) Explain in “plain English” (i.e. do not give a literal translation) the meaning
of each line of the following schemas:
(b) Explain in “plain English” the meaning of each line of the constraint part
of the IssueBook schema and the role it plays in the specification of the
operation. [7 marks]
(c) Specify the ReturnBook operation which is used when a borrower returns
a book to the library. The specification of this operation must be total and
output appropriate success and error reports. In addition the specification
should be as modular as possible and make full use of the schema calculus. [12 marks]
Question 6
Write a Z specification for a queue of people waiting to be “served”. For example,
at a bank, checkout, etc. Due to the lack of available space the queue has a
maximum permitted length.
Your specification should deal with error handling where required and should
include the following:
(a) Any types, states and invariants that the queue requires. [6 marks]
(i) Join – a new person joins the end of the queue. [8 marks]
(ii) GetServed – the next person gets “served”, i.e., leaves the front of
the queue. [7 marks]
(iii) QueueStatus – reports via a suitable message whether the queue is
empty, full or neither full or empty. [4 marks]
Question 7
Part of a Z specification for a University’s Computing degree course in particular
module registration and de-registration is given in Appendix A.
(a) The ZTC type checker output for the Module specification is given in
Appendix B. For each error reported give an explanation and the necessary
corrections. [10 marks]
(b) Once all of the errors detailed in part (a) have been eliminated from the
Module specification, explain what additions and modifications must be
made to the specification to permit it to be animated by the ZANS ani-
mator. [10 marks]
(c) Assuming all of the necessary modifications required in part (b) have been
made, an attempt is made to animate the Module specification in ZANS.
However, ZANS indicates that it can not animate the two operations
RegisterForModule_Ok and DeregisterFromModule_Ok, by reporting
that they are “not explicit”.
Give a brief explanation of what “not explicit” means in this context and
state what modifications need to be made to these two operation schemas
to correct this problem. [5 marks]
[STUDENT ]
TITLE ::= Formal Methods | Compilers | Networks
STAFF ::= P Howells | A Lecturer | M Mouse
MODULE LIMIT : N
Module
title : TITLE
leader : STAFF
numbstudents : N
students : P STUDENT
leader ∈ ACADEMIC STAFF
numbstudents ≤ MODULE LIMIT
numbstudents = students
InitialModule
Module
title = Formal Methods
leader = P Howells
numbstudents = 0
students =
RegisterForModule Ok
∆Module
newstudent? : STUDENT
newstudent? 6∈ students
numbstudents < MODULE LIMIT
students 0 = students ∪ newstudent?
numbstudents 0 = numbstudents + 1
b RegisterForModule Ok ∧ ReportSuccess
RegisterForModule Success =
AlreadyRegistered Error
ΞModule
newstudent? : STUDENT
report! : REPORT
newstudent? ∈ students
report! = ERROR Already Registered
ModuleFull Error
ΞModule
newstudent? : STUDENT
report! : REPORT
numbstudents = MODULE LIMIT
report! = ERROR Module Full
RegisterForModule =
b RegisterForModule Success
∨ AlreadyRegistered Error
∨ ModuleFull ERROR
DeregisterFromModule Ok
Module
deregstudent? : STUDENT
deregstudent? ∈ students
students 0 = students \ {deregstudent?}
numbstudents 0 = numbstudents − 1
DeregisterFromModule Success =
b DeregisterFromModule Ok
∧ ReportSuccess
DeregisterFromModule =
b DeregisterFromModule Success
∨ Student Not Registered Error
PlacesLeftOnModule Ok
ΞModule
placesleft! : N
placesleft = MODULE LIMIT − numbstudents
b PlacesLeftOnModule Ok ∧ ReportSuccess
PlacesLeftOnModule =
C.1 Sets
Notation Description
N Set of natural numbers from 0
N1 Set of natural numbers from 1
Z Set of integers
x ∈S x is an element of S
x 6∈ S x is not an element of S
S ⊆T S is a subset of T
S ⊂T S is a strict subset of T
∅, { } Empty set
PS Power set of S
FS Finite power set of S
F1 S Non-empty finite subsets of S
S ∪T Union of S and T
S ∩T Intersection of S and T
S \T Set difference of S and T
#S Number of elements in set S
{D |P •t } Set comprehension
S
SS Distributed union of SS
T
SS Distributed intersection of SS
C.2 Logic
Notation Description
¬P not P
P ∧Q P and Q
P ∨Q P or Q
P ⇒Q P implies Q
P ⇔Q P is equivalent to Q
∀x : T • P All elements x of type T satisfy P
∃x : T • P There exists an element x of type T which satisfies P
∃1 x : T • P There exists a unique element x of type T which satisfies P
C.4 Relations
Notation Description
P(X × Y ) Set of relations between X and Y
X ↔Y Set of relations between X and Y
dom R Domain of relation R
ran R Range of relation R
S CR Domain restriction of R to the set S
S−CR Domain anti-restriction of R by the set S
RBS Range restriction of R to the set S
R− BS Range anti-restriction of R by the set S
R1 ⊕ R2 R1 overridden by relation R2
R o9 Q Relational composition
R(| S |) Relational Image of the set S of relation R
id X Identity relation
R −1 Inverse relation
R+ Transitive closure of R
R∗ Reflexive-transitive closure of R
C.5 Functions
Notation Description
→77 Finite function
77 Finite injection
→7 Partial function
→ Total function
7 Partial injection
Total injection
→→ 7 Partial surjection
→→ Total surjection
→ Bijection
C.6 Sequences
Notation Description
seq X Finite sequences of type X
seq1 X Non-empty finite sequences of type X
iseq X Injective finite sequences of type X
hi Empty sequence
s at Concatenation of the sequences s and t
head s First element of a non empty sequence
tail s All but first element of a non empty sequence
last s Last element of a non empty sequence
front s All but last element of a non empty sequence
rev s Sequence Reversal
squash s Sequence Compaction
s prefix t s is a prefix of t
s suffix t s is a suffix of t
s in t s is a sub-sequence of t
C.7 Bags
Notation Description
bag X Bag of type X
[[ ]] Empty bag
x@ −B Bag membership
x@ 6− B Bag non-membership
B1 v B2 Sub-bag
B1 @ B2 Strict Sub-bag
B1 ] B2 Bag Union
B1 ∪- B2 Bag Difference
count B x Bag Count of x
B ]x Bag Count of x
n ⊗B Bag Scaling
items s Bag of the sequence s
C.8 Schemas
Schema Type Schema Box
declarations
Axiom
constraints
[X , . . .]
Generic declarations
constraints
S
State/Operation declarations
constraints