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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Modules Program is built out of components. Each component defines a set of logically related entities (strong internal coupling) A component has a public.
1 Modelling using sets Sets: The finite set type constructor Value definitions: enumeration, subrange, comprehension Operators on sets Case Study: the.
Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout
Vienna Development Method SIM5104. one of the longest-established Formal Methods for the development of computer- based systemsFormal Methods Originating.
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.
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.
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.
Introduction to Z Copyright, 2002 © Jerzy R. Nawrocki Models and Analysis of Software.
TIVDM1Modelling unordered collections1 Peter Gorm Larsen.
Arrays “Array, I'm bound array, 'cross the wide Missouri.” ‒ Old Programmer’s Folk Song © Copyright 2014, Fred McClurg All Rights Reserved.
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.
Programming Fundamentals. Today’s Lecture The Conditional Operator Logical Operators Structures Enumerations.
ELEMENTARY SET THEORY.
Chapter SETS DEFINITION OF SET METHODS FOR SPECIFYING SET SUBSETS VENN DIAGRAM SET IDENTITIES SET OPERATIONS.
8. The set types The set types are one of the compound types available in SOFL, and usually used for the abstraction of data items that have a collection.
Basic Definitions of Set Theory Lecture 23 Section 5.1 Wed, Mar 8, 2006.
Basic Definitions of Set Theory Lecture 24 Section 5.1 Fri, Mar 2, 2007.
Basic Definitions of Set Theory Lecture 23 Section 5.1 Mon, Feb 21, 2005.
Programming Fundamentals Enumerations and Functions.
Thinking Mathematically Basic Set Concepts. A “set” is a collection of objects. Each object is called an “element” of the set. Often the objects in a.
1.1 – SETS AND SYMBOLS. Goals SWBAT understand basic set notation and set symbols SWBAT solve simple sentences with a given domain SWBAT graph sets of.
5 Day Forecast Mon Tues Wed Thu Fri.
CHAPTER 3 SETS, BOOLEAN ALGEBRA & LOGIC CIRCUITS
VDM: Vienna Development Method
GANTT CHARTS Example Example Example Example text Tasks Example 1
Mon – 2Tue – 3Wed – 4Thu - 5Fri - 6Sat - 7Sun - 8 Mon – 9Tue – 10Wed – 11Thu - 12Fri – 13Sat – 14Sun -15 Mon – 16Tue – 17Wed – 18Thu - 19Fri – 20Sat –
JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER
JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER
MON TUE WED THU
1   1.テキストの入れ替え テキストを自由に入れ替えることができます。 フチなし全面印刷がおすすめです。 印刷のポイント.
JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
2017 Jan Sun Mon Tue Wed Thu Fri Sat
January Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
Jan Sun Mon Tue Wed Thu Fri Sat
2008 Calendar.
S M T W F S M T W F
January MON TUE WED THU FRI SAT SUN
Sun Mon Tue Wed Thu Fri Sat
2 0 X X s c h e d u l e 1 MON TUE WED THU JANUARY 20XX FRI SAT SUN MEMO.
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
Calendar
Calendar – 2010 (October, November & December)
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
Lecture Sets 2.2 Set Operations.
Sun Mon Tue Wed Thu Fri Sat
1/○~1/○ weekly schedule MON TUE WED THU FRI SAT SUN MEMO
January MON TUE WED THU FRI SAT SUN
S M T W F S M T W F
2016 | 10 OCT SUN MON TUE WED THU FRI SAT
Sun Mon Tue Wed Thu Fri Sat
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
1 January 2018 Sun Mon Tue Wed Thu Fri Sat
1 January MON TUE WED THU FRI SAT SUN MEMO 2 February MON TUE WED THU FRI SAT SUN.
Structures Chapter 4.
2008 Calendar.
S M T W F S M T W F
CS100A Lect. 12, 8 Oct More About Arrays
S M T W F S M T W F
1 January MON TUE WED THU FRI SAT SUN MEMO 2 February MON TUE WED THU FRI SAT SUN.
Presentation transcript:

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 using enumeration, number ranges and comprehension Use the set operators (union, intersection, difference, subset and cardinality) Apply the set type to model systems in VDM-SL

So far we have looked at specifications involving simple scalar types enumerated types Most systems manipulate complex data structures like lists. To model such data structures, VDM-SL provides several data type constructors. The first abstract structured type of VDM-SL that we will look at is the familiar notion of a set. Data Type Constructors ( ,  and so on) (e.g. <BROKEN> |<WORKING> | < IDLE> )

Sets for system modelling A set is an unordered collection of objects in which repetition is not significant. Collection of patients registered on the books of a doctor's surgery? When to use a set? The queue of patients waiting for a doctor?  

Declaring sets in VDM-SL To indicate a variable to be of the set type: variableName: ElementType For example Day = <MON> | <TUE> | <WED> | <THU> | <FRI> | <SAT> | <SUN> aNumber:  aDay : Day someNumbers:  -set someOtherNumbers:  -set importantDays : Day-set -set

Defining sets in VDM-SL Three ways to initialise the values of a set: by enumeration; by number ranges; by comprehension.

Defining sets by enumeration Involves listing the elements individually, separated by commas,,, and enclosed in braces { } For example: someNumbers = {2, 4, 28, 19,10 } importantDays = {<FRI>, <SAT>, <SUN>}

Defining sets by number ranges Can be used when a set of continuous integers required: someRange = {5, …,15} equal to someRange = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} When the second number in the range is smaller than the first, the empty set is returned. {7,…,6} = { }

Defining a set by comprehension Allows one set to be defined by means of another: someSet = { expression (x) | x  someOtherSet  test(x) } Examples: someNumbers= { x | x  {2,…,6}  isEven(x)} someOtherNumbers = { x 2 | x  {2,…,6}} { 2, 3, 4, 5, 6 } { 2, 3, 4, 5, 6 } 4,9,16,25,36

Set operations Set union: j  k Returns a set that contains all the elements of the set j and all the elements of the set k. if j = { <MON>, <TUE>, <WED>, <SUN> } and k = { < MON >, <FRI>, < TUE > } then j  k = {<MON>, <TUE>, <WED>, <SUN>, <FRI>}

Set operations…. cont’d Set intersection:j  k Returns a set that contains all the elements that are common to both j and k. if j = { <MON>, <TUE>, <WED>, <SUN> } and k = { < MON >, <FRI>, < TUE > } thenj  k = {<MON>, <TUE>}

Set operations…. cont’d Set difference:j \ k Returns the set that contains all the elements that belong to j but do not belong to k. if j = { <MON>, <TUE>, <WED>, <SUN> } and k = { < MON >, <FRI>, < TUE > } then j \ k = {<WED>, <SUN> }

Set operations…. cont’d Subset:j  k Returns true if all elements that belong to j also belong to k. {a, d, e}  {a, b, c, d, e, f} {a, d, e}  {d, a, e} Proper subset:j  k Returns true if all elements that belong to j also belong to k but false if sets j and k are equal. {a, d, e}  {a, b, c, d, e, f} {a, d, e}  {d, a, e}

Set operations…. cont’d Cardinality:card j Returns the number of elements in a given set. card { 7, 2, 12} card { 7, 2, 2, 12, 12} card { 4,…,10} card { } = 3 = 3 = 7 = 0

The PatientRegister class PatientRegister reg: Patient [*] addPatient (Patient) removePatient (Patient) getPatients ( ): Patient [*] isRegistered (Patient): Boolean numberRegistered ( ):Integer

Modelling the PatientRegister class in VDM-SL types Patient values LIMIT state PatientRegister of reg: init mk-PatientRegister ( )  end Patient-set inv mk-PatientRegister (r)  card r  LIMIT r = { } = TOKEN :  = 200 r

The addPatient operation addPatient ( ) ext pre post reg =  { patientIn} patientIn  regcard reg < LIMIT  patientIn: Patient reg: Patient-setwr patientIn  reg

The removePatient operation removePatient ( ) ext pre post patientIn: Patient wrreg: Patient-set reg = \ { patientIn}patientIn  reg patientIn  reg

getPatients ( ) ext pre post The getPatients operation output: Patient-set rd reg: Patient-set output = reg TRUE

isRegistered ( ) ext pre post The isRegistered operation patientIn: Patient query:  rdreg: Patient-set  query patientIn  reg TRUE

numberRegistered () ext pre post The numberRegistered operation total:  rdreg: Patient-set total = card reg TRUE

The Airport Flight Control System " A system is to be developed that keeps track of planes that are allowed to land at a particular airport. Planes must apply for permission to land at the airport prior to landing. When a plane arrives to land at the airport it is only allowed to do so if it has previously been given permission. When a plane leaves the airport its permission to land is also removed "

A UML specification of the Airport class Airport permission: Aircraft [*] landed: Aircraft [*] givePermission(Aircraft) recordLanding(Aircraft) recordTakeOff(Aircraft) getPermission( ): Aircraft [*] getLanded( ): Aircraft [*] numberWaiting(): Integer

types state Airport of init mk-Airport ( )  end Modelling the Airport class in VDM-SL Aircraft = TOKEN permission: Aircraft-set landed: Aircraft -set inv mk-Airport(p,l)  l  p p = { } l = { }  p, l

The givePermission operation givePermission( ) ext pre post craftIn: Aircraft permission: Aircraft - set wr permission =  {craftIn } craftIn  permission

The recordLanding operation recordLanding ( ) ext pre post craftIn: Aircraft permission: Aircraft -set landed: Aircraft -set rd wr landed =  {craftIn} craftIn  permission craftIn  landed 

recordTakeOff ( ) ext pre post The recordTakeOff operation craftIn: Aircraft permission: Aircraft -set landed: Aircraft -set wr wr landed = \ {craftIn }permission = \ { craftIn }  craftIn  landed

getPermission( ) ext pre post The getPermission operation out: Aircraft-set permission: Aircraft -setrd out = permission TRUE

getLanded( ) ext pre post The getLanded operation out: Aircraft -set landed: Aircraft -set rd out = landed TRUE

numberWaiting( ) ext pre post The numberWaiting operation total:  permission: Aircraft -set landed: Aircraft -set rd rd card (permission \ landed)total =