VDM Tools
VDM Tools
VDMTools Lite
Aims
The aim of this chapter is to introduce VDMTools Lite, the development
environment for VDM-SL models. This is done by providing a “hands-on” tour
of the tool’s functionality using the alarm example introduced in Chapter 2.
This chapter should enable the reader to use VDMTools Lite for exercises in the
remaining part of this book.
3.1 Introduction
Models in VDM are formal in the sense that their semantics are very
precisely described. This formality makes it possible to analyse models in order
to confirm or refute claims about them. Such an analysis often reveals gaps in the
understanding of the system, allowing these to be resolved before an expensive
commitment is made to program code. The process of analysing claims about
systems modelled in this way is termed validation and is discussed in greater
depth in Chapter 10.
Software tools play an important role in supporting validation. This book is
accompanied by an educational version of the VDM-SL version of VDMTools,
called VDMTools Lite, that provides most of the functionality of the commercial
tool1 .
This chapter introduces VDMTools Lite as a preparation for the examples and
exercises of later chapters. It takes the form of a tour through the facilities for
performing syntax checking, type checking, integrity checking, testing and de-
bugging of models, using the alarm example which was presented in Chapter 2.
The reader is encouraged to use the VDMTools Lite or the full VDM-SL version
of VDMTools for all the exercises in this and subsequent chapters.
VDMTools Lite exists for several operating system platforms including Win-
dows, Linux and MacOS. In the remainder of this book, we assume that the
1
Some features of the full version have been removed in the Lite version. These are
the CORBA-based Application Programmer Interface; the Dynamic Link facility in the
interpreter; and the automatic C++ code generation feature.
35
36 3 VDMTools Lite
reader is using the Windows platform; users of other platforms may notice mi-
nor deviations from the user interface screens shown.
the items in the “Project” menu. However, the menu additionally contains an
entry for recently accessed projects that may be convenient on occasion.
Initially an empty project will be present, so we need to add selected files to
the project. Pressing the small icon with a “+” sign will cause a file browser
will appear. Since we are following the chemical plant alarm example, select
alarm.vdm. The file name alarm.vdm will appear in the Project part of the
Manager sub-window. VDMTools performs a syntax check on the file when
loading it, so now that the check is complete, it is possible to press the Module
tab in the Manager sub-window to see whether the loaded model is structured
into any special module units. The symbol DefaultMod is used to indicate that
the alarm example has been presented as a collection of definitions without any
use of modular structuring. Modules are primarily intended for structuring large
models with re-usable components and is reviewed in Chapter 12. Modular
structuring will not be used in the majority of examples in this book. This com-
pletes the project setup of VDMTools Lite to the alarm example file. It is now
possible to start analysing the definitions made in this model.
38 3 VDMTools Lite
Button Explanation
reporting and correcting errors in VDMTools Lite. To illustrate this, a file called
alarmerr.vdm, containing deliberate mistakes, has also been supplied.
In order to examine this file we need to configure VDMTools Lite again. In
order to get rid of the definitions from alarm.vdm, select the file name in the
Project tab of the Manager sub-window and press the icon with the small minus
sign. Then alarmerr.vdm can be added instead using the icon with the small
plus sign. When this is done the alarmerr.vdm file will be parsed directly.
Since this version contains errors the Error List sub-window will pop up with
four error messages as shown in Figure 3.3. We can traverse through the errors
using the > and < buttons. The Source sub-window in Figure 3.4 will in-
dicate the precise location of the error indicated in the Error List sub-window.
In each case the syntax checker indicates what kind of construct was expected
and provides a qualified guess at how the error can be corrected. The suggested
corrections are often, but not always, correct. Note that the Source sub-window
is not an editor – the file should be modified with your preferred external edi-
40 3 VDMTools Lite
tor. In Section 3.8 we will see how it is possible to set up VDMTools Lite to
automatically invoke a favourite editor when required.
Exercise 3.1 Correct all the errors that have been discovered by the syntax
checker on the alarmerr.vdm file and syntax check your corrected file again
until no syntax errors appear.
When no more syntax errors are present the model can be type-checked. This
model contains some type errors, as is indicated by the slash through the T in the
3.4 Syntax and type checking models 41
Button Explanation
Button Explanation
Module tab of the Manager sub-window. In addition, the Error List sub-window
will appear again, this time containing type errors as shown in Figure 3.6. The
first one says: Error : Function is applied with wrong number of parameters.
This is because QualificationOK has been called with three parameters
instead of just two as indicated in its definition. The next error (Error : Un-
known identifier exss) is due to a typographical error which is easy to correct.
Altogether four errors and two warnings are reported. The type checker distin-
guishes between errors which are things that are definitely wrong and must be
corrected by the user, and warnings which are hints about things that could be
wrong.
Exercise 3.2 Correct all the errors that have been discovered by the type
checker on the alarmerr.vdm file and syntax and type check your corrected
file again until no syntax or type errors appear.
42 3 VDMTools Lite
To access the definitions that have been read into the current project, first press
the button that Initialises the interpreter (see Table 3.5) with all the definitions
from the current VDM-SL model. Whenever updates have been made to the
VDM-SL model, syntax checking the newest version does not update the inter-
preter’s internal representation. Thus, whenever the model has been modified, it
is necessary to press this initialisation button again.
The internal representation in the interpreter includes type definitions, func-
tions, as well as any value (constant) definitions and global state variables present
(we discuss state definitions in Chapter 11). The alarm example only has type
definitions and function definitions. Now that the interpreter has been initialised,
these definitions are all available for testing.
The top two panes of the interpreter sub-window are, respectively, the Re-
sponse and Dialogue panes. Commands are entered directly in the interpreter
in the Dialogue pane and output from the interpreter appears in the Response
pane. Commands are typed in the Dialogue pane and are submitted to the inter-
44 3 VDMTools Lite
Button Explanation
preter by hitting the return key on the keyboard. Typing functions will get
a list of explicit functions which have been read into VDMTools. For the alarm
example we provided three explicit function definitions and one implicit func-
tion definition. However, the list provided here contains nine function names.
The extra ones have special prefixes (inv , pre and post ). These functions
are automatically generated “for free” from the definitions containing invari-
ants, pre-conditions and post-conditions. We will describe them in more detail
in Chapter 5. Any of these functions returned using the functions command
can be executed if arguments are provided for them.
The file testalarm.vdm contains some value definitions for the alarm ex-
ample. The schedule used in these definitions reflects the schedule presented
in Figure 2.1 on page 20. All components from this figure have been given
a name as a value definition in testalarm.vdm and below we will refer
to these names. In order to get access to these definitions, the file contain-
ing them must be included in the project in the same way that alarm.vdm
and alarmerr.vdm were. In adding this file, do not remove the corrected
alarmerr.vdm file from the project setup. The new testalarm.vdm file
can be added using the small + icon button again (see Table 3.1). Then this file
can be syntax checked and type checked and we can reinitialise the interpreter
by pressing the Init button again (i.e. the flag icon in Table 3.5). In this way we
also get access to the value definitions provided by testalarm.vdm. In the
dialog part of the interpreter sub-window we can type values to see the list of
value definitions which are available.
3.5 Interpreting and debugging models 45
RESPONSE PANE
DIALOG PANE
No Step inside
the model by setting up break points. A break point is a point in the model
at which we wish the execution to be interrupted during interpretation. Set
up a break point by typing break NumberOfExperts. The consequence
of this break point is that the name DefaultMod’NumberOfExperts ap-
pears in the Break Points part of the interpreter sub-window. Type debug
NumberOfExperts(p3,plant) in the Dialogue pane and press return. The
Source sub-window will pop up and show where the execution has been stopped,
as shown in Figure 3.82 . Press Single Step a few times to see how the body of
the function is evaluated step by step. While debugging an expression, subex-
pressions can be evaluated by using the print command in the Dialog part of
the interpreter sub-window. When execution does not deliver the expected re-
sults, break points provide a useful aid to debugging models at the expression
level.
During debugging the stack trace of functions called is displayed in the Trace
2
The only difference between print and debug is that debug will stop when a break
point is reached whereas print will ignore break points.
3.5 Interpreting and debugging models 47
part of the interpreter sub-window (see Figure 3.7). The arguments to a function
are initially compressed into an ellipsis (three dots). An ellipsis can be unfolded
by clicking the left mouse button with the cursor on top of the dots; the value
can be folded back by pressing the left mouse button again. Press the Continue
button (the green arrow pointing forward) to end debugging. The interpreter will
continue either until the next break point is encountered or until the execution is
finished.
Notice that ExpertToPage did not appear in the list of functions returned
by the functions command. This is because it is an implicit function and
such functions cannot be executed directly3 . However, it is possible to execute
3
The only other kind of construct that cannot be executed by the interpreter is a type
binding which we will illustrate in the next chapter.
48 3 VDMTools Lite
times each function is called. Figure 3.9 illustrates how this can be done with the
alarm example. Even more detailed information at subexpression level can be
shown if the VDM model is pretty-printed but this requires special commands
depending upon the format used for the VDM model. In order to see how this is
done, refer to the user manual for VDMTools [UserMan].
be undefined if the value being applied to the mapping is not in the domain of
the mapping itself (this is equivalent to a run-time error). The integrity property
states that, in the context where it occurs in the body of the ExpertToPage
function, the period must be in the domain of the schedule mapping. This
requirement is stated as a logical expression:
forall a : Alarm, peri : Period, plant : Plant &
peri in set dom (plant.schedule) and
a in set plant.alarms =>
(forall r : Expert &
peri in set dom (plant.schedule))
This requires that, for all combinations of alarms, periods and plants, the period
must be in the domain of the plant’s schedule. This property is already guaran-
teed by the pre-condition, so the integrity property is trivially satisfied. If we
had omitted the requirement from the pre-condition, we would have discovered
the mistake by examining the integrity property in this way.
Summary
We have introduced the following features of VDMTools Lite:
• project setup of selected VDM-SL files;
• syntax checking of VDM-SL models;
• type checking of VDM-SL models;
• error reporting;
• executing and debugging VDM-SL models;
• checking the integrity of VDM-SL models; and
• setting options for projects and different actions.
Exercise 3.4 Imagine an extension to the alarm example which would en-
able experts to swap duties. This function is called ChangeExpert. Given a
plant, two experts and a period it will yield a new plant where the plan has been
changed so that the first expert will be replaced by the second expert in the given
period. A first version of this function could be formulated as
ChangeExpert: Plant * Expert * Expert * Period -> Plant
ChangeExpert(mk_Plant(plan,alarms),ex1,ex2,peri) ==
mk_Plant(plan ++ {peri |-> plan(peri)\{ex1} union {ex2}},
alarms)
where the \ symbol removes the ex1 value from the schedule for the given
period peri and union adds the ex2 value.
Do you see any problems with this function? This definition is placed in the
file changeexpert.vdm so you should configure your project once again by
adding this file. When it has been syntax checked and type checked (the latter
is not strictly required) the interpreter can be initialised again. Now use the
interpreter to inspect the plant value returned from calls such as
ChangeExpert(plant,e4,e7,p3)
ChangeExpert(plant,e3,e7,p3)
3.8 Setting options 53
Will the invariant on the Plant data type be violated? Test this by setting the
option for invariant checking. If the invariant is broken it is possible to make
a break point for the invariant inv Plant itself and call that with a Plant
value which possibly satisfies the invariant. By single stepping inside this it
becomes easier to discover how the invariant is broken. If necessary, add the
pre-condition needed to complete the function.