0% found this document useful (0 votes)
14 views19 pages

SFS Lab2

The document outlines the concept of sets in programming, including their initialization methods such as enumeration, number ranges, and comprehension. It details various set operations like union, intersection, difference, subset, and cardinality, along with a case study for a patient registration system using VDM-SL. The patient register is designed to manage a maximum of 200 unique patients, allowing for adding, removing, and querying patient information.

Uploaded by

salmamaher2323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views19 pages

SFS Lab2

The document outlines the concept of sets in programming, including their initialization methods such as enumeration, number ranges, and comprehension. It details various set operations like union, intersection, difference, subset, and cardinality, along with a case study for a patient registration system using VDM-SL. The patient register is designed to manage a maximum of 200 unique patients, allowing for adding, removing, and querying patient information.

Uploaded by

salmamaher2323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Software

Formal
Specificati
Eng/TA Maiada Alaa
Sets
is an unordered collection of objects in without repetition.

● Collection of patients registered on the books of a doctor's surgery


● The queue of patients waiting for a doctor?
● The set of courses a student is enrolled in.
● The members of a group
● A telephone help-line
● The set of employees in a company
Ways to initialize
value of sets
• Enumeration
• Number ranges
• Comprehension
Enumeration
Listing the elements individually, separated by commas, and
enclosed in brackets.

Ex: someNumbers = {2, 4, 28, 19, 10}

importantDays = {<FRI>,<SAT> ,<SUN> }


Number
Ranges
A set of continuous integers is required

Ex: someRange = {5, … ,15}

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”

Defining one set by means of another.


General format :

someSet = { expression (x) | x ∈ someOtherSet ● test(x) }

EX: someNumbers = { x | x ∈ {2,…,6} isEven(x)} is the set { 2, 4, 6 }

while, someOtherNumbers = { | x ∈ {2,…,6}} is the set { 4, 9, 16,


25, 36 }
Set
Membershipoperations

Element set

• Returns true if the element is a member of the


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.

Ex: j = { <MON>,<TUE> ,<WED> ,<SUN> } and


k = { < MON >,<FRI> ,<TUE> } then
j ∪ k = {<MON>,<TUE> ,<WED> , <SUN>,
<FRI>}
Set
operations
set intersection

j∩k

Returns a set that contains all the elements that are common to
both j and k. .

Ex: j = { <MON>,<TUE> ,<WED> ,<SUN> } and


k = { < MON >,<FRI> ,<TUE> } then
j ∩ k = {<MON>,<TUE>}
Set
operations
Set difference

j\k

Returns the set that contains all the elements that belong to j but
do not belong to k.

Ex: j = { <MON>,<TUE> ,<WED> ,<SUN> } and


k = { < MON >,<FRI> ,<TUE> } then
j \ k = {<WED>,<SUN>}
Set
set Subset operations

j⊆k
• Returns true if all elements that belong to j also belong to k.

Ex: {a, d, e} ⊆ {a, b, c, d, e, f} is true


{a, d, e} ⊆ {d, a, e} is true
Set
set proper operations

j⊂k
• Returns true if all elements that belong to j also belong to k
but false if sets j and k are equal.

Ex: {a, d, e} ⊂ {a, b, c, d, e, f} is true


{a, d, e} ⊂ {a, d, e} is false
{a, d, e} ⊄ {a, d, e} is true
Set
operations
set cardinality

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.

● It will be necessary to add and remove patients from the register.

● The register must be able to be interrogated so that the list of


patients and the number of patients registered can be returned.

● Also, a check can be made to see if a given patient is registered .


Patient Register UML class
VDM-SL
types
Patient = TOKEN
values
LIMIT : N = 200

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, { }

removePatient ( patientIn: Patient )


ext wr reg: Patient-set
pre patientIn ∈ reg
Post reg = reg \ { patientIn }
VDM-SL
getPatients ( ) output : Patient-set
ext rd reg: Patient-set
pre TRUE
post output = reg

isRegistered ( patientIn : Patient ) query : B


ext rd reg: Patient-set
pre TRUE
post query ⇔ patientIn ∈ reg

numberRegistered ( ) total : N
ext rd reg: Patient-set
pre TRUE
post total = card reg
Thank
s

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy