An Introduction To Specification in VDM-SL: at The End of This Lecture You Should Be Able To
An Introduction To Specification in VDM-SL: at The End of This Lecture You Should Be Able To
An Introduction To Specification in VDM-SL: at The End of This Lecture You Should Be Able To
-10 Celsius
TEMPERATURE
+10 Celsius
1 :
UML
VDM-SL
IncubatorMonitor
state IncubatorMonitor of
temp :
temp : Integer
increment()
decrement()
getTemp() : Integer
end
IncubatorMonitor
temp : Integer
increment()
decrement()
getTemp() : Integer
temp + 1 = temp
temp - temp = 1
temp = temp - 1
post ?
rd
?
temp :
pre
TRUE
?
= temp
post currentTemp
?
Declaring constants
It is possible in VDM-SL to specify constants;
It is done by using the keyword values;
The declaration would come immediately before the state definition:
values
MAX : = 10
MIN : = -10
decrement()
ext
wr
temp :
pre
MIN
temp > -10
post
temp =
temp
-1
Specifying functions
A function is a set of assignments from one set to another;
The function receives an input value (or values) and maps this
to an output value according to some rule;
46
79
hasPassed
FALSE
TRUE
50
add:
add(x, y) x + y
signature
definition
add( x : , y : ) z :
pre ?TRUE
z=x+y
post ?
abs(z : ) r :
pre TRUE
?
post z<0
? r = -z z 0 r = z
Recursive functions
Some functions can be neatly specified by a recursive definition,
whereby the function calls itself.
Example
a factorial function:
factorial:
factorial(n) if n = 0
then 1
else n x factorial(n - 1)
State invariants
Before we specified local constraint with preconditions.
We can also specify a global constraint.
In VDM-SL we incorporate such a restriction into the specification
with a function called a state invariant;
The invariant definition uses the keyword inv.
Its signature will be:
inv : State
-10 Celsius
TEMPERATURE
+10 Celsius
init mk-IncubatorMonitor(t) t = 5
Enumerated types
The signal sent to the hardware could be one of 3 possible values:
1.
2.
3.
types
Signal = <INCREASE>|< DECREASE>|< DO_NOTHING>
values
..
state
..
end
integers or nil.
When the incubator system first comes into being, the actual and
requested values will be undefined, and must therefore be set to nil;
state IncubatorController of
requestedTemp : []
actualTemp : []
The invariant
The actual temperature must not be allowed to go outside the
range of -10 to +10 degrees;
However we need now to allow for the possibility that it could be
equal to the nil value;
The same is true for the requested temperature.
r = nil a = nil
setInitialTemp( tempIn : )
ext
wr actualTemp : []
pre
wr requestedTemp : []
rd
actualTemp : []
pre
post
requestedTemp = tempIn
( tempIn > actualTemp signalOut = <INCREASE>
actualTemp
pre
rd
requestedTemp : []
wr
actualTemp : []
getRequestedTemp() currentRequested : []
ext
rd
requestedTemp : []
pre
TRUE
post
currentRequested = requestedTemp
getActualTemp() currentActual : []
ext
rd
actualTemp : []
pre
TRUE
post
currentActual = actualTemp