Sequences At the end of this lecture you should be able to: provide a definition of a VDM sequence; utilize and interpret sequence notation; make appropriate.

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Stacks, Queues, and Linked Lists
Sets for system modelling. At the end of this lecture you should be able to: Identify when it is appropriate to use a set for system modelling Define.
Comp 205: Comparative Programming Languages Functional Programming Languages: More Haskell Nested definitions Lists Lecture notes, exercises, etc., can.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
Chapter 3: Abstract Data Types Lists, Stacks Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Vienna Development Method SIM5104. one of the longest-established Formal Methods for the development of computer- based systemsFormal Methods Originating.
1 Lecture 24 Abstract Data Types (ADT) –I Overview  What is an Abstract Data type?  What is Stack ADT?  Stack ADT Specifications  Array Implementation.
CS 206 Introduction to Computer Science II 10 / 15 / 2008 Instructor: Michael Eckmann.
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
CHAPTER 6 Stacks Array Implementation. 2 Stacks A stack is a linear collection whose elements are added and removed from one end The last element to be.
CHAPTER 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Sequences for system modelling. At the end of this lecture you should be able to: provide a definition of a VDM sequence; identify situations in which.
Sequences At the end of this lecture you should be able to: provide a definition of a VDM sequence; utilize and interpret sequence notation; make appropriate.
1 COSC 4406 Software Engineering COSC 4406 Software Engineering Haibin Zhu, Ph.D. Dept. of Computer Science and mathematics, Nipissing University, 100.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
Analyzing the Requirements with Formal Specifications Vienna Development Method Specification Language (VDM-SL) Book: Formal Software Development From.
Sets Learning Outcomes At the end of this lecture you should be able to: Identify when it is appropriate to use a set for system modelling Define a set.
The Java Collections Framework (JCF) Introduction and review 1.
Information and Computer Sciences University of Hawaii, Manoa
An introduction to specification in VDM-SL At the end of this lecture you should be able to: write a formal specification of a system in VDM-SL; correlate.
VDM-SL Case Study Learning Outcomes At the end of this lecture you should be able to: Analyse and informally specify a complete system using UML class.
TIVDM1Modelling ordered collections1 Peter Gorm Larsen.
TIVDM1Modelling ordered collections1 Peter Gorm Larsen.
CSC264 Modelling and Computation 10. Modelling State Steve Riddle, John Fitzgerald, Maciej Koutny Computing Science Semester /06.
Introduction to VDM Copyright, 2003 © Jerzy R. Nawrocki Models and Analysis of Software.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
Introduction to Z Copyright, 2002 © Jerzy R. Nawrocki Models and Analysis of Software.
A Introduction to Computing II Lecture 6: Lists, Stacks, and Queues Fall Session 2000.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Mohammad Amin Kuhail M.Sc. (York, UK) University of Palestine Faculty of Engineering and Urban planning Software Engineering Department Computer Science.
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
Built-in Data Structures in Python An Introduction.
Composite Objects Learning Outcomes At the end of this lecture you should be able to: Identify when it is appropriate to use a composite object type Use.
An introduction to specification in VDM-SL At the end of this lecture you should be able to: write a formal specification of a system in VDM-SL; correlate.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Formal Methods in Software Engineering “And they made their lives bitter with hard bondage … all their service … was with rigour.” Ex 1:14.
1 Modelling using Sequences Sequences The finite sequence constructor Value definitions: enumeration, subsequence Operators on Sequences Case Study: the.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
Click to edit Master text styles Stacks Data Structure.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
1 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
Linked Data Structures
String and Lists Dr. José M. Reyes Álamo.
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Review Array Array Elements Accessing array elements
Data Structure By Amee Trivedi.
QueueStack CS1020.
Stacks and Queues Chapter 4.
VDM: Vienna Development Method
Containers and Lists CIS 40 – Introduction to Programming in Python
Sequences 8/2/ :13 AM Linked Lists Linked Lists.
Stacks and Queues.
Queues Queues Queues.
VDM - Part II Models and Analysis of Software Lecture 4
Bryan Burlingame 03 October 2018
Sequences 12/8/2018 3:02 AM Linked Lists Linked Lists.
Queues: Implemented using Arrays
String and Lists Dr. José M. Reyes Álamo.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Python: Stacks and Queues (as an Array)
Algebraic Specification Software Specification Lecture 34
CS210- Lecture 6 Jun 13, 2005 Announcements
Getting queues right … finally (?)
Introduction to Computer Science
Presentation transcript:

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

Introduction A sequence is an ordered collection of objects; In a sequence, repetitions are significant. Examples The queue of patients waiting for a doctor. Planes circling an airport.

Notation A sequence is specified by enclosing its members in square brackets; queue = [ michael, varinder, elizabeth, winston, judith ] s = [ a, d, f, a, d, d, c ] [ a, d, f ]  [ a, f, d ] [ ]

Retrieving items from the sequence s = [ a, d, f, a, d, d, c ] queue = [ michael, varinder, elizabeth, winston, judith ] s(3) = queue(4) = s(10) = f winston undefined

Sequence operators len operator:Returns the length of a sequence s = [ a, d, f, a, d, d, c ] queue = [ michael, varinder, elizabeth, winston, judith ] len s = len queue = 7 5

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 = elems queue = { a, d, f, c } {michael, varinder, elizabeth, winston, judith}

Sequence operators inds operator :Returns a set of all the indices of the sequence s = [ a, d, f, a, d, d, c ] queue = [ michael, varinder, elizabeth, winston, judith ] inds s = inds queue = {1, 2, 3, 4, 5, 6, 7 } {1, 2, 3, 4, 5} inds [] ={ }

Sequence operators head (hd) operator :Returns the first element in the sequence s = [ a, d, f, a, d, d, c ] queue = [ michael, varinder, elizabeth, winston, judith ] hd s = hd queue = a michael hd [] =undefined

Sequence operators tail (tl) operator :Returns a sequence containing all but the first element s = [ a, d, f, a, d, d, c ] queue = [ michael, varinder, elizabeth, winston, judith ] tl s = tl queue = [d, f, a, d, d, c ] [varinder, elizabeth, winston, judith ] tl [] =undefinedtl [a] =[ ]

Sequence operators concatenation operator ( ^ ) operator: operates on two sequences, and returns a sequence that consists of the two sequences joined together first = [ w, e, r, w ]second = [ t, w, q ] first ^ second =[ w, e, r, w, t, w, q ] second ^ first =[t, w, q, w, e, r, w ] first ^ [ ] =[ w, e, r, w ]

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

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(1,...,0) = [ ]s(8,..., 7) = [ ] s(2,..., 2) =[d] s(2,..., 13) =undefined

Sequence by comprehension [ expression(a) | a  SomeSet  test (a) ] [ a | a  {1,…,10}  is-odd(a)] [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] s1 = [2, 3, 4, 7, 9, 11, 6, 7, 8, 14, 39, 45, 3] s2 = [ s1(i) | i  inds s1  s1(i) > 10] [11, 14, 39, 45]

Using the sequence type in VDM-SL 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 *

Specifying a stack Stack stack : Element[*] push(Element) pop() : Element isEmpty(): Boolean

Specifying the state of the stack types Element = TOKEN state Stack of stack : init mk-Stack(s)  end Element* s = [ ]

The push operation push( ) ext pre post itemIn : Element stack : Element* wr stack = [itemIn] ^ stack TRUE

The pop operation pop( ) ext pre post itemRemoved : Element stack : Element* wr stack = tl stack stack  [ ] itemRemoved = hd stack 

The isEmpty operation isEmpty( ) ext pre post query :  stack : Element* rd TRUE  querystack = [ ]

Re-thinking the Airport system In the new system, when an aircraft approaches the airport it is placed in a queue, and must circle the airport until a runway becomes available; Only aircraft that have permission to land are allowed to circle; The circling aircraft are landed on a first-come-first served basis.

Re-specifying the state types state Airport2 of init mk-Airport2 ( )  end Aircraft = TOKEN permission: Aircraft-set landed: Aircraft-set circling: Aircraft* p, l, cp = { }  l = { }  c = [ ] inv mk-Airport2(p,l,c)  ?

The new invariant inv mk-Airport2(p,l,c)  1.Landed planes must have permission 2.Circling planes must have permission 3.Circling planes can not be landed 4.All circling planes are unique 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)

Re-specifying the operations The following operations access only the permission and landed components, and do not therefore need to be changed: givePermission recordTakeOff numberWaiting atAirport getPermission getLanded The meaning of recordLanding will change in the new specification; Two new operations are required getCircling allowToCircle

allowToCircle ( ) ext pre post allowToCircle operation craftIn : Aircraft circling : Aircraft*wr permission : Aircraft-set rd landed : Aircraft-set rd circling = circling ^ [craftIn] craftIn  permission  craftIn  elems circling  craftIn  landed

The modified recordLanding operation recordLanding( ) ext pre post circling : Aircraft* landed : Aircraft-set wr  circling = tl circling landed = landed  {hd circling } circling  [ ]

Some useful functions to use with sequences A function that returns the last element in a sequence: last( ) pre post sequenceIn : Element* elementOut : Element elementOut = sequenceIn(len sequenceIn) sequenceIn  [ ]

Some useful functions to use with sequences A function that returns the sequence with the last element removed. allButLast( ) pre post sequenceIn : Element*sequenceOut : Element* sequenceOut = sequenceIn(1,..., (len sequenceIn - 1)) sequenceIn  [ ]

Some useful functions to use with sequences A find function Returns the index of a particular element; Assuming elements are unique: find( ) pre post sequenceIn : Element*, element : Element position :  sequenceIn(position) = element element  elems sequencIn

Some useful functions to use with sequences A find function Returns the index of a particular element; Assuming elements are not unique: find( ) pre post sequenceIn : Element*, element : Element position :  sequenceIn(position) = element element  elems sequencIn   i  inds sequenceIn  sequenceIn(i) = element  position  i