SFS Lab2
SFS Lab2
Formal
Specificati
Eng/TA Maiada Alaa
Sets
is an unordered collection of objects in without repetition.
is equivalent to: someRange = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
When the second number in the range is smaller than the first, the
empty set is returned. {7, … , 6} is returned as an empty set, { }
Comprehensi
on The symbol ‘|’ is read
as “such that”
Element set
• a {a, b, c, d, e, f} is true
• a {f, g, h} is false
But:
• a {a, b, c, d, e, f} is false
Set
set union operations
j∪k
• Returns a set that contains all the elements of the set j and all
the elements of the set k.
j∩k
Returns a set that contains all the elements that are common to
both j and k. .
j\k
Returns the set that contains all the elements that belong to j but
do not belong to k.
j⊆k
• Returns true if all elements that belong to j also belong to k.
j⊂k
• Returns true if all elements that belong to j also belong to k
but false if sets j and k are equal.
Cardinality: card
• Returns the number of elements in a given set.
card { 7, 2, 12 } = 3
card { 7, 2, 2, 12, 12 } = card {7, 2, 12} =
3
card { 4,…,10 } = 7
card {}=0
Patient Register Example
(using VDMSL)
Patient Register Case Study
● Consider a system that registers patients at a doctor’s surgery.
● Assume that the surgery can deal with a maximum of 200 patients
on its register.
state PatientRegister of
reg: Patient-set • The register is a set of Patients
inv mk-PatientRegister (r) ∆ card r ≤ LIMIT • TOKEN means it's a unique identifier.
init mk-PatientRegister (r) ∆ r = { } as each patient has a unique ID.
End • Note the use of the cardinality
Operations operation to ensure that the number
addPatient ( patientIn: Patient ) of patients is no more than LIMIT,
ext wr reg: Patient-set which is set as a constant
Pre patientIn ∉ reg ∧ card reg < LIMIT • Note that the patient register is
post reg = reg ∪ { patientIn } initialized to the empty set, { }
numberRegistered ( ) total : N
ext rd reg: Patient-set
pre TRUE
post total = card reg
Thank
s