CH 9
CH 9
CH 9
● Techniques for the
unambiguous specification of
software
D esign
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 8
R
edqufirnem n R
e
q
u
s
p
c
ttosm
S
y i
r
fe ma
sodtlem n
t
s
i
o F
o
s
p
e
c
hr
i
f
i
t
em
ca
l
t
i
o
n
u
r
a
l H
i
g
h
l
e
d
s
i
gv
l
n
Specification in the software process
A
r
c
ing dsgn
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 9
Specification techniques
● Algebraic approach
• The system is specified in terms of its operations and their
relationships
● Modelbased approach
• The system is specified in terms of a state model that is
constructed using mathematical constructs such as sets and
sequences. Operations are defined by modifications to the
system’s state
S
pecifation
W
isptho
©Ian Sommerville 2000
u
teci faorim anl sW ipecth form
ationl
Software Engineering, 6th edition. Chapter 9 Slide 13
Interface specification
● Large systems are decomposed into subsystems
with welldefined interfaces between these
subsystems
● Specification of subsystem interfaces allows
independent development of the different
subsystems
● Interfaces may be defined as abstract data types
or object classes
● The algebraic approach to formal specification is
particularly wellsuited to interface specification
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 14
S
ubsA I
n
t
e
r
f
a
o
b
jc
e
t
s
ytem S ubsB
Subsystem interfaces
ytem
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 15
< SP
TIO
sort
< na
impo
< L
OF
Inf
or ic
TIO
mal ar
am
iptio
Opet a
ation at
the p
Axio
atio
vetr
The structure of an algebraic specification
Create
→→
Ηεαδ
→
Head
Τ
α Λιστ
Ελεµ
Λενγτη
Ιντεγ
exce
if
L (em
Λιστ
ιλthen(Λ
else
= Cr
v
He (
Length
T
aif
©Ian Sommerville 2000
il (Cr
then
L else
il (Co
= Cr
Cre
Co
ail
Software Engineering, 6th edition. Chapter 9 Slide 21
Recursion in specifications
● Operations are often specified recursively
● Tail (Cons (L, v)) = if L = Create then Create
else Cons (Tail (L), v)
• Cons ([5, 7], 9) = [5, 7, 9]
• Tail ([5, 7, 9]) = Tail (Cons ( [5, 7], 9)) =
• Cons (Tail ([5, 7]), 9) = Cons (Tail (Cons ([5], 7)), 9) =
• Cons (Cons (Tail ([5]), 7), 9) =
• Cons (Cons (Tail (Cons ([], 5)), 7), 9) =
• Cons (Cons ([Create], 7), 9) = Cons ([7], 9) = [7, 9]
IO tE
n
c
iΛ
tΧ
rΠ
εΜe
s
n
Ινρ
(υ α a
p ϖ e
εde
S
( Σcs
εr
e
χa
n
h
c
t
o
τ
r
οe
,
ρs
i
r
k
C
,
Χa
cs
an
f
i
l
α
λm
t
a
n
g
−
σ
ι o
γp
a
s
p
n
,
νy
i
r
c
e
H
)s
→ e
ac
t
o
r
f
i
s
e
d
i
g
t
Σ
ε
h
)
χw
ai
l
→
τ
οt
h
n
r
e
a
d
g
Σ
ρo
y
s
ε
χc
τn
i
v
ο
ρas
t
r
a
i
e
c
l
bn
t
c
o
rh
e
ck
s
(E ο
−ε σ κ
α
π υ
τ
Σεπ χ→το
ρ
(Σ
,ε
Χ χ
τ
αο
λρ
−
,σ
ι
γ
Χν
,
α
λ −,
Η
σΗ
ε
ι
νγ ε ι
γ
η
Η
η
τ
) )
→
Βιγ
οη
Σ
ε
χ
λ
ατ
ο
νρ
t e
L Οnie
fa
χ e
rlvis
fe
(eS
, ( C
ι P
εδ
ISC
,u
n
O
c
e
t
=S
rP
Σ
s
a
(
C
ε
p
u
t
(
SH
a
,)
χ
τ
c
i
S
,
C
1
ο
e
t=
ρ
d
C
S
h
Η
(
S
)
1
,
e
ε
,
C
=
H
n
ι
C
1
S
γ
η
S
H
r
)
τ
)
)
e
a
,
C
l
s tt
→
e
Sh
e
n
x
)
=
P
u
c
t S
e
(
Le
x
p
t
i
o
a
vc
e
n
ep
t
i
(
A
So
i
,n
(
A
H
e
r
c
a
f
C
S
)i
r
c
g
h
t
n
o
,
C
Sa
f
t
o
t
i
n
1
,
Ha
l
r
e
a
n
f
i
c
t
)
s
e
c
t
o
1
)d
y
i
r
)n
s
e
ct
o
r
)
M
L o
e
io
fN v
(lO e
,s e
,H
E n
O
P
Io
c
GS
=
t
HC
I
u
(
TH
n
L)
r
e
s
i
e
i
sa=
a
p
dt
c
(
v
e
ct
h
S
,
o ne
n
(
S
H
C
s
C
,
t
)
t
ah
n r
S
te
a
t
)
n
S
C
i
dhe
,
c
n
H
ax
c
e
S
)
t
i
n
gp
x
t
hti
o
c
e
a
t
n
(
N
o
p
t
i
n
H
e
v
a
l
a
i
r
(
A
g
h
t
i
d
h
ec
a
f
o
i
g
ht
i
n
s
o
l
c
)
t
c
a
ne
c
t
i
n
o
to
r
)
s
e
c
t
b
e
ro
r
)
t
u
r
ne
d
i In
O
i ip k
fcs e
u
ffl au
C
pp
(s
e
CS
e
(C
P
d=
Or
u
C
P
H
ce
1a
(
S
r
e
u
>t
1
t,
a
(
S
H
p
i
t
eC
h
dS
1
e
,
H
C
n
()
=
,
n
)
S
1
d H
=
N
1
f
,
HO
)
,
e
a
1
C
l
)
sH
E
I
S
)
e
L
,
H
)
²
3=G
o
=
0 He
T
k
u
p
o
r
)
x
(
S
(
Hce
p
,
C
> t
o
n
S
)
a
H
1
(
A
n
d
r
c
a
H
f
o
H
1
t
i
²
3
0s
c
o
t
)
)
h
e
n
t
r
u
e
cS e (C
=Pre
u at,h
(1
S CS
)e
1
,n =
fe
tru
Ha
)ls, e
1 C
S
I n
)=
sp
a
ce
(S
, C
S
)
Specification commentary
● Use the basic constructors Create and Put to
specify other operations
● Define Occupied and Inspace using Create and
Put and use them to make checks in other
operation definitions
● All operations that result in changes to the sector
must check that the safety criterion holds
Dis
Disp
Pow
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 30
Modelling the insulin pump
● The schema models the insulin pump as a number
of state variables
• reading?
• dose, cumulative_dose
• r0, r1, r2
• capacity
• alarm!
• pump!
• display1!, display2!
● Names followed by a ? are inputs, names
followed by a ! are outputs
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 31
Schema invariant
● Each Z schema has an invariant part which
defines conditions that are always true
● For the insulin pump schema it is always true that
• The dose must be less than or equal to the capacity of the
insulin reservoir
• No single dose may be more than 5 units of insulin and the total
dose delivered in a time period must not exceed 50 units of
insulin. This is a safety constraint (see Chapters 16 and 17)
• display1! shows the status of the insulin reservoir.
ρ
2=ρ ψ
εα ≥
4
″
30
⇒
9
χ
δινγ?ι
α
λ
ρ
µπ
λ
α
ψ
χ
τ
!
=1
!
=
≥
0
ο
ν
∧∀
⇒
δ
δ
ι
σ
πσ
π
ψ
1
λ
α
ψ
1
!
=!
=
∀
Ι
ν
σ∀
Ι
ν
σ
υ
λ
ι
ν
υ
λ
ι
ϖ
εο
ω
ρ
ψ
λ∀
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 33
The dosage computation
● The insulin pump computes the amount of insulin
required by comparing the current reading with
two previous readings
● If these suggest that blood glucose is rising then
insulin is delivered
● Information about the total dose delivered is
maintained to allow the safety check invariant to
be applied
● Note that this invariant always applies there is
no need to repeat it in the dosage computation
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 34
D
∆ O
Ι(δο
ν S
σ
εA
G
υ
λ
ισ
ν
=E
_
Π
υ
0
∧
(
ρµ
1π
≥ρ
0
)
∧
(
ρ2
=
ρ
1)
∨
>
< ″
1
−
2>
(
ρ
0
−1
)
DOSAGE schema
)δδο
()χο σ
()σ
ε∨
ε
=
∨
=4
∧
(
ρ
(
ρ
2
−
ρ1
1″
<
)ρ
0
)
∧
(
ρ
∗
4
∧2
=
ρ
1
)
−
2∨
″
(
ρ
0
−1
)
)ρ α π
ι0υ
µ
∋=ρχ
τ
λ
α(
ρ
ψ
∋
=
χ
ϖ
ε
_
1∧
ρ1
α
δ″
>
π
ορ
0
)
(
∧
χ
ι
τ
ψ
−
δ
σ
ε
∋
=
χ
υ
µ
1∋=ρ
2ρ
2
>
ρ
1
−
ο
σ
ε
υ
λ
α
τ
ι)
∨
≥
(
ρ
1
ϖ
ε
_
δ
ο−
ρ
0
)
σ
ε
+
δο
σ
ε
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 35
Output schemas
● The output schemas model the system displays
and the alarm that indicates some potentially
dangerous condition
● The output displays show the dose computed and
a warning message
● The alarm is activated if blood sugar is very low
this indicates that the user should eat something
to increase their blood sugar level
∆
Ι(ρν
ιεασ
υλν _
Πυ
µ
δινγ?<
3π
∨
ρ
ε
α
δ
ιν
γ
?
>3
0
)
⇒α
λ
ρ
µ
!
≥∧″ φ∋
=
ο
ν
∨
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 9 Slide 37
Schema consistency
● It is important that schemas are consistent.
Inconsistency suggests a problem with the system
requirements
● The INSULIN_PUMP schema and the
DISPLAYare inconsistent
• display1! shows a warning message about the insulin reservoir
(INSULIN_PUMP)
• display1! Shows the state of the blood sugar (DISPLAY)
● This must be resolved before implementation of
the system