Sequences for system modelling - PowerPoint PPT Presentation

1 / 54
About This Presentation
Title:

Sequences for system modelling

Description:

A group of planes circling an airport. Declaring sequences in VDM-SL ... Circling planes must have permission. Circling planes can not be landed ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 55
Provided by: aaron63
Category:

less

Transcript and Presenter's Notes

Title: Sequences for system modelling


1
Sequences for system modelling
2
At the end of this lecture you should be able to
  • provide a definition of a VDM sequence
  • identify situations in which a sequence is an
    appropriate data type
  • utilize and interpret sequence notation
  • make appropriate use of the VDM sequence
    operators
  • define a sequence by comprehension
  • write VDM specifications using the sequence type.

3
A sequence is an ordered collection of objects in
which repetitions are significant.
A queue of jobs waiting for a printer
4
A sequence is an ordered collection of objects in
which repetitions are significant.
A group of planes circling an airport
5
Declaring sequences in VDM-SL
6
To declare a variable to be of type sequence we
place an asterisk after the name of the type
contained within the sequence.

seq ?

convoy SpaceCraft
7
Sequence Notation
s a, d, f, a, d, d, c
queue michael, varinder, elizabeth, winston,
judith
a, d, f ? a, f, d

8
Retrieving items from the sequence
s a, d, f, a, d, d, c
queue michael, varinder, elizabeth, winston,
judith
s(3)
f
queue(4)
winston
s(10)
undefined
9
Sequence operators
s a, d, f, a, d, d, c
queue michael, varinder, elizabeth, winston,
judith
len operator
Returns the length of a sequence
len s
7
len queue
5
10
Sequence operators
s a, d, f, a, d, d, c
queue michael, varinder, elizabeth, winston,
judith
elems operator
Returns a set that contains all the members of
the sequence
elems s
a, d, f, c
elems queue
michael, varinder, elizabeth, winston, judith
11
Sequence operators
s a, d, f, a, d, d, c
queue michael, varinder, elizabeth, winston,
judith
inds operator
Returns a set of all the indices of the sequence
inds s
1, 2, 3, 4, 5, 6, 7
inds queue
1, 2, 3, 4, 5
inds

12
Sequence operators
s a, d, f, a, d, d, c
queue michael, varinder, elizabeth, winston,
judith
head (hd) operator
Returns the first element in the sequence
hd s
a
hd queue
michael
hd
undefined
13
Sequence operators
s a, d, f, a, d, d, c
queue michael, varinder, elizabeth, winston,
judith
tail (tl) operator
Returns a sequence containing all but the first
element
tl s
d, f, a, d, d, c
tl queue
varinder, elizabeth, winston, judith
tl
undefined
tl a

14
Sequence operators
first w, e, r, w
second t, w, q
concatenation operator ( ) operator
operates on two sequences, and returns a sequence
that consists of the two sequences joined
together
first second
w, e, r, w, t, w, q
second first
t, w, q, w, e, r, w
first
w, e, r, w
15
Sequence operators
the override operator ()
Takes a sequence and gives us a new sequence with
a particular element of the old sequence
overridden by a new element
a, c, d, e 1 ? z
z, c, d, e
a, c, d, e 2 ? x, 4 ? y
a, x, d, y
a, c, d, e 7 ? g
undefined
16
Sequence operators
subsequence operator
allow us to extract a part of a sequence between
two indices
s a, d, f, a, d, d, c
s(2, ... , 5)
d, f, a, d
s(2, ... , 2)
d
s(2, ... , 13)
undefined
s(1, ... ,0)
s(8, ... , 7)
17
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
18
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
19
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
a a ? 1,,10 ? is-odd(a)
20
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
a a ? 1,,10 ? is-odd(a)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
21
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
a a ? 1,,10 ? is-odd(a)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
22
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
a a ? 1,,10 ? is-odd(a)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
23
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
Lets filter this sequence so that we only have
values greater than 10
24
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
39, 11, 45, 39
25
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
s2 s1(i) i ? inds s1 ? s1(i) gt 10
26
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
s2 i ? elems s1 ?

2, 3, 4, 6, 7, 8, 9, 11, 39, 45
27
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
s2 i ? inds s1 ?

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13
28
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
s2 i ? inds s1 ? s1(i)
gt 10
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13
29
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
s2 s1(i) i ? inds s1 ? s1(i) gt
10
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 14
30
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
s2 s1(i) i ? inds s1 ? s1(i) gt
10
1, 2, 3, 4, 5, 39, 7, 8, 9, 10, 11,
12, 14
31
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
s2 s1(i) i ? inds s1 ? s1(i) gt
10
1, 2, 3, 4, 5, 39, 7, 8, 9, 11, 11,
12, 14
32
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
s2 s1(i) i ? inds s1 ? s1(i) gt
10
1, 2, 3, 4, 5, 39, 7, 8, 9, 11, 45,
12, 14
33
Sequence comprehension
expression(a) a ? SomeSet ? test (a)
s1 2, 3, 4, 7, 9, 39, 6, 7, 8, 11, 45, 39, 3
s2 s1(i) i ? inds s1 ? s1(i) gt
10
1, 2, 3, 4, 5, 39, 7, 8, 9, 11, 45,
39, 14
34
Specifying a stack
35
Stack stack Element push(Element) pop()
Element isEmpty() Boolean
36
Stack stack Element push(Element) pop()
Element isEmpty() Boolean
37
types Element
TOKEN
state Stack of stack init mk-Stack(s) ? end
Element
s
38
Stack stack Element push(Element) pop()
Element isEmpty() Boolean
39
push( ) ext pre
post
itemIn Element
stack Element
wr
TRUE
40
Stack stack Element push(Element) pop()
Element isEmpty() Boolean
41
pop( ) ext pre post
itemRemoved Element
stack Element
wr
stack ?
?
42
Stack stack Element push(Element) pop()
Element isEmpty() Boolean
43
isEmpty( ) ext pre post
query ?
stack Element
rd
TRUE
?
query
stack
44
Re-thinking the Airport system
45
Airport2 permission Aircraft landed
Aircraft circling Aircraft
givePermission(Aircraft) recordLanding(
) recordTakeOff(Aircraft) getPermission( )
Aircraft getLanded( ) Aircraft
numberWaiting() Integer getCircling( )
Aircraft allowToCircle (Aircraft)
46
types state Airport2 of
init mk-Airport2 ( ) ? end
Aircraft TOKEN
permission Aircraft-set landed
Aircraft-set circling
Aircraft
inv mk-Airport2(p,l,c) ? ?
p, l, c
p ? l
? c
47
The new invariant
  • Landed planes must have permission
  • Circling planes must have permission
  • Circling planes can not be landed
  • All circling planes are unique

inv mk-Airport2(p,l,c) ?
l ? p
? elems c ? p
? elems c ? l
? isUnique(c)
isUnique(seqIn Aircraft) query ? pre
true post query ? len seqIn card elems seqIn
48
The new invariant
  • Landed planes must have permission
  • Circling planes must have permission
  • Circling planes can not be landed
  • All circling planes are unique

inv mk-Airport2(p,l,c) ?
l ? p
? elems c ? p
? elems c ? l
? isUnique(c)
isUnique(seqIn Aircraft) query ? pre
true post query ? ? i1 ,i2 ?
inds seqIn ? i1 ? i2 ? seqIn(i1) ? seqIn(i2)
49
? i1 ,i2 ? inds seqIn ? i1 ? i2 ? seqIn(i1) ?
seqIn(i2)
50
Airport2 permission Aircraft landed
Aircraft circling Aircraft
givePermission(Aircraft) recordLanding(
) recordTakeOff(Aircraft) getPermission( )
Aircraft getLanded( ) Aircraft
numberWaiting() Integer getCircling( )
Aircraft allowToCircle (Aircraft)
51
allowToCircle (
) ext pre post
craftIn Aircraft
circling Aircraft
wr
rd
permission Aircraft-set
rd
landed Aircraft-set
craftIn ? permission
? craftIn ? elems circling
? craftIn ? landed
52
Airport2 permission Aircraft landed
Aircraft circling Aircraft
givePermission(Aircraft) recordLanding(
) recordTakeOff(Aircraft) getPermission( )
Aircraft getLanded( ) Aircraft
numberWaiting() Integer getCircling( )
Aircraft allowToCircle (Aircraft)
53
recordLanding( ) ext pre post
circling Aircraft
wr
wr
landed Aircraft-set
circling ?
54
See you next week!
Write a Comment
User Comments (0)
About PowerShow.com