VDM specification language
From Wikipedia, the free encyclopedia
VDM Specification Language (VDM-SL) is a model-oriented specification language, upon which the Vienna Development Method for computer software is based. An ISO Standard for the language was released in 1996 (ISO, 1996).
The origins of VDM-SL lie in the IBM Laboratory in Vienna where the first version of the language, then called Meta-IV (Bjørner et al. 1978), was used to describe the PL/I programming language. Other programming languages described, or partially described, using Meta-IV and VDM-SL include the BASIC programming language, FORTRAN, the APL programming language, ALGOL 60, the Ada programming language and the Pascal programming language. Meta-IV evolved into several variants, generally described as the Danish, English and Irish Schools.
The "English School" derived from work by Cliff Jones on the aspects of VDM not specifically related to language definition and compiler design (Jones 1980, 1990). It stresses modelling persistent state through the use of data types constructed from a rich collection of base types. Functionality is typically described through operations which may have side-effects on the state and which are mostly specified implicitly using a precondition and postcondition. The "Danish School" (Bjørner et al. 1982) has tended to stress a constructive approach with explicit operational specification used to a greater extent. Portuguese work led to the first European validated Ada compiler.
Contents |
[edit] Language
[edit] Symbols
Basic Symbols | |
---|---|
Is defined as | |
(The set of) Booleans | |
(the set of) natural numbers (including zero) | |
(The set of) natural numbers (excluding zero) | |
(The set of) integers | |
(The set of) rational numbers | |
(The set of) real numbers | |
: | Of type |
ext |
External clause |
rd |
Read access |
wr |
Write access |
pre |
Pre-condition |
post |
Post-condition |
The original value of |
Sets | |
---|---|
X-set | The type of sets of elements of X |
{a,b,c} | The set of elements a, b and c |
{x | P(x)} | The set of x such that P(x) |
{i,...,j} | The set of integers in the range i to j |
Is an element of | |
Is not an element of | |
Union | |
Intersection | |
— | Set difference |
Distributed union of | |
Is a (strict) subset of | |
Is a (weak) subset of | |
card |
The cardinality of |
Composite Types | |
---|---|
:: |
Composite type of |
mk-Name |
make Name |
inv-Name |
invariant of Name |
[...] |
optional |
Maps | |
---|---|
Y the type of maps from X to Y | |
a maps to r, b maps to s | |
x maps to f(x) such that P(x) | |
dom |
The domain of |
rng |
The range of |
m(x) | m applied to x |
Overrides |
Sequences | |
---|---|
X * | The type of sequences of elements of X |
[a, b, c] | The sequence of elements a, b and c |
hd |
The head of |
tl |
The tail of |
len |
The length of |
elems |
The elements of |
s(i) | The ith element of s |
(curvy arrow thing) | concatenated with |
[edit] Syntax
VDM-SL makes use of propositional calculus and predicate logic.
In BNF notation, the available operators for propositional logic are:
Precidence is in the order:
- Brackets
- (not)
- (and)
- (or)
- (implies)
- (equivanence)
The syntax for predicate logic is:
[edit] Functions
VDM functions are defined as:
- Signature
- Pre-conditions
- Post-conditions
The whole point of VDM is to prove that functions are correct; this is called a proof obligation.
Suppose that we have an implicit specification:
- f(p:Tp)r:Tr
- pre pre-f(p)
- post post-f(p, r)
When we define an explicit function:
we say it satisfies the specification iff it obeys the proof obligation:
So, "f is a correct implementation" should be interpreted as "f satisfies the specification".
[edit] States and operations
In VDM-SL, functions are not allowed to have side-effects (such as changing the state of a global variable). This is a useful ability in many programming languages, so a similar concept exists; instead of functions, operators are used to change states (AKA globals).
For example, if we have a state consisting of a single variable , we could define this in VDM-SL as:
An operation to load a value into this variable might be specified as:
The exterior clause (ext
) specifies which parts of the state can be accessed by the operation; rd
meaning read access and wr
being read/write access.
Sometimes it is important to refer to the value of a state before it was modified; for example, an operation to add a value to the variable may be specified as:
Where the symbol tells one to use the initial state of (in this case) someStateRegister.
[edit] Composite Types
The general form of a composite type definition is:
- Name::
- s1:T1
- s2:T2
- sn:Tn
- s1:T1
(Where "Name" is the name of the type, not the string literal "Name"). A type has an associated constructor:
and selector functions:
- Name::
- s1:Name − > T1
- s2:Name − > T2
- sn:Name − > Tn
- s1:Name − > T1
[edit] Example
- Date::
This might be called with mk − Date(45,2003).
Note that this would also need some extra checking, as day 366 is only valid on leap years. For example, the function may be implemented as:
(Note: this definition of leap year works only because of the limits on the range of the year variable, demonstrating that it is still entirely possible to introduce errors into VDM systems).
[edit] Optional Fields
Optional fields are allowed in composite types, denoted by [...]
, and an omitted field is denoted by nil
.
For example, the composite type "Record" may be defined with:
- Record::
- valid:[ERROR]
which may be called with:
Optional fields allow composite types to be recursive.
[edit] Maps
A map is similar to a function defined on a finite set, except that the argument/result pairs are given explicitly, e.g. . See map (mathematics) for more information.
Maps in VDM-SL are denoted by the form X − m − > Y, e.g. .
For example, {a,b} − m − > {1,2} is the set of maps:
If m is a map, dom
m is the domain of m, rng
m is the range of m and m(x) means m applied to x, e.g., if then dom m = {a,b,c,d}, rng m = {1,3,5,7}, m(a) = 1, m(b) = 3, etc.
[edit] Map Overriding
Overriding is a map operation, denoted by , which causes the elements of m2 to override the elements of m1. For example, given:
then .
[edit] Bank system example
Customers are modelled by customer numbers (CustNum), accounts are modelled by account numbers (AccNum).
- Bank::
where
- AccData::
- owner:CustNum
- balance:Balance
- owner:CustNum
With operations: NEWC allocates a new customer number:
- NEWC(od:Overdraft)r:CustNum
NEWAC allocates a new account number and sets the balance to zero:
- NEWAC(cu:CustNum)r:AccNum
- pre cue dom overdraftMap
ACINF returns all the balances of all the accounts of a customer, as a map of account number to balance:
[edit] Sequences
It is possible to have sequences of elements of some type X. The type of such a sequence is denoted by X*, while the sequences themselves are denoted by, e.g., [a, b, c]
where . The empty sequence is []
.
The order and repetition of items in a sequence is significant, so , and , which means that X* is infinite even when X itself is finite (e.g. ).
[edit] Sequence operations
VDL-SL has the following sequence operations:
hd _ | head (first element) | |
lt _ | tail (remainder) | |
len _ | length | |
elems _ | set of elements | |
_(_) | element selection | |
_(curvearrow)_ | concatenation |
Provided 1 ≤ i ≤ len
s, s(i) is the ith element of s.
[edit] Examples
[edit] The max function
[edit] Natural number multiplication
Applying the proof obligation to an explicit definition of multip:
Then the proof obligation becomes:
This can be shown correct by the following steps:
- Proving that the recursion ends (this in turn requires proving that the numbers become smaller at each step)
- Mathematical induction
[edit] Mathematical operators
The following notation describe partially the operators +, mod, and /; and also the function is divisible by?:
Note that unlike most porgramming languages, VDM does not allow the negative operands for the mod operator | |
[edit] Queue abstract data type
- types
- Qelt = To Be Defined
- Queue = Quelt *
- Qelt = To Be Defined
- state TheQueue of
- q:Queue
- q:Queue
- end
- operations
- ENQUEUE(e:Qelt)
- ext wr q:Queue
- ENQUEUE(e:Qelt)
-
- DEQUEUE()e:Qelt
- ext wr q:Queue
- DEQUEUE()e:Qelt
-
- ext rd q:Queue
[edit] See also
- Formal methods
- Formal specification
- Predicate logic
- Propositional calculus
- Vienna Development Method
- Z specification language, the main alternative to VDM-SL (compare)
- Pidgin code
[edit] External links
[edit] References
- D. Bjørner and C. B. Jones (eds.), The Vienna Development Method: The Meta-Language, Lecture Notes in Computer Science, Vol. 61, Springer-Verlag 1978. ISBN 0-387-08766-4
- D. Bjørner and C. B. Jones, Formal Specification and Software Development Prentice Hall International, 1982. ISBN 0-13-880733-7
- J. Dawes, The VDM-SL Reference Guide, Pitman 1991. ISBN 0-273-03151-1
- J. S. Fitzgerald and P. G. Larsen, Modelling Systems: Practical Tools and Techniques for Software Development, Cambridge University Press, 1998, ISBN 0-521-62348-0
- J. S. Fitzgerald, P. G. Larsen, P. Mukherjee, N. Plat and M. Verhoef. Validated Designs for Object-oriented Systems, Springer-Verlag, 2005. ISBN 1-85233-881-4
- International Organization for Standardisation, Information technology — Programming languages, their environments and system software interfaces — Vienna Development Method — Specification Language — Part 1: Base language International Standard ISO/IEC 13817-1, December 1996.
- C. B. Jones, Systematic Software Development Using VDM, Prentice Hall International, 1990. ISBN 0-13-880725-6
- C. B. Jones, Software Development: A Rigorous Approach, Prentice Hall International, 1980. ISBN 0-13-821884-6
- C. B. Jones and R. Shaw (eds.), Case Studies in Systematic Software Development, Prentice Hall International, 1990. ISBN 0-13-880733-7
This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.