Formal Methods of S/W Development: Department of Computer Science
Formal Methods of S/W Development: Department of Computer Science
2
Logic
Propositional: uses declarative statements or assertions
𝑝 ¬𝑝 p∧𝑞 p∨𝑞 p→𝑞 p≡𝑞
3
Sets
Collection of Elements
Elements do not repeat {a, a, b}
Elements are not ordered {a, b, c} is same as {b, a, c}
Special Sets
ℕ = {0, 1, 2, 3, … } natural numbers
ℤ = {… , −2, −1, 0, 1, 2, … } integers
∅ empty set
Set Membership
𝑥 ∈ 𝑋 is true if 𝑥 is in the set 𝑋, otherwise 𝑥 ∉ 𝑋
4
Set Expressions
Can express a set by listing its elements
𝐴 = {𝑎, 𝑏, 𝑐}
Impractical for large sets, impossible for infinite sets
Cardinality
If 𝐴 is a finite set then |𝐴| is a natural number denoting the
number of elements in 𝐴. For example, 𝑎, 𝑏, 𝑐 = 3
Notation
𝑐, 𝑧 ∈ 𝑅
𝑐↦𝑧∈𝑅
𝑐𝑅𝑧 𝑅 = { 𝑐, 𝑥 , 𝑐, 𝑧 , 𝑑, 𝑥 , 𝑑, 𝑦 , (𝑑, 𝑧)}
Domain and Range
𝑑𝑜𝑚 𝑅 = 𝑎 ∶ 𝐴 ∃𝑏 ∶ 𝐵 ⋅ 𝑎 𝑅 𝑏 }
𝑟𝑎𝑛 𝑅 = 𝑏 ∶ 𝐵 ∃𝑎 ∶ 𝐴 ⋅ 𝑎 𝑅 𝑏 } 10
Functions
A partial function 𝑓 from 𝐴 to 𝐵, denoted 𝑓 ∶ 𝐴 ⟶ 𝐵, is a
subset of 𝐴 × 𝐵 with the property that for each 𝑎 ∈ 𝐴 there
is at most one 𝑏 ∈ 𝐵 with 𝑎, 𝑏 ∈ 𝑓
𝑑𝑜𝑚 𝑓 𝑟𝑎𝑛 𝑓
𝑎 ∶ 𝐴 ∃𝑏 ∶ 𝐵 ⋅ 𝑎, 𝑏 ∈ 𝑓 } 𝑏 ∶ 𝐵 ∃𝑎 ∶ 𝐴 ⋅ 𝑎, 𝑏 ∈ 𝑓 }
11
Functions (cont’d)
Function Application
Suppose 𝑎 ∈ 𝑑𝑜𝑚 𝑓,
then 𝑓(𝑎) denotes the
unique image in 𝐵 that
a is mapped to by 𝑓
Notation
𝑎, 𝑏 ∈ 𝑓 and 𝑓 𝑎 = 𝑏 are equivalent
Total Functions
A function 𝑓 is a total function, denoted 𝑓 ∶ 𝐴 ⟶ 𝐵
if and only if 𝑑𝑜𝑚 𝑓 is the set 𝐴 12
Z Example: A Birthday Book
Description
A system that records people’s birthdays and is able to
issue a reminder when the day comes around
Spivey - Z Reference Manual, chapter one (pages 1-10)
13
States
Initial State Schema
15
Operations (cont’d)
Specify an operation to find (retrieve) a person’s birthday
Consider: convention, inputs, outputs, and pre/post-
16
Operations (cont’d)
Specify an operation to remind you who’s birthday is it today
Consider: convention, inputs, outputs, and pre/post-
Remind Operation
17
Considering All Scenarios
An implementation of the Birthday Book specification will
work as long as there are no mistakes in the input, i.e., if
the pre-conditions have been met.
Grading:
(1) Provide a brief and clear description of the functionalities to be specified
and assumptions / restrictions made,
(2) Correct use of Z symbols / notations,
(3) Correct specification (completeness, consistency, preciseness etc.),
(4) Proper description and clear explanation.
22