CSC264 Modelling and Computation 10. Modelling State Steve Riddle, John Fitzgerald, Maciej Koutny Computing Science Semester 2 2005/06.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Formal Methods in Software Engineering
1 Modelling using sets Sets: The finite set type constructor Value definitions: enumeration, subrange, comprehension Operators on sets Case Study: the.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
CS 355 – Programming Languages
Inheritance Inheritance Reserved word protected Reserved word super
Chapter 8 Designing Classes. Assignment Chapter 9 Review Exercises (Written)  R8.1 – 8.3, 8.5 – 8.7, 8. 10, 8.11, 8.13, 8.15, 8.19, 8.20 Due Friday,
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
1 Lecture 1:Modelling in VDM-SL (adapted from Fitzgerald & Larsen, 1998) Deriving a Model The Chemical Plant Alarm System: Requirements Data Types and.
1 Specifying Object Interfaces. 2 Major tasks in this stage: --are there any missing attributes or operations? --how can we reduce coupling, make interface.
Vienna Development Method SIM5104. one of the longest-established Formal Methods for the development of computer- based systemsFormal Methods Originating.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Describing Syntax and Semantics
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Ranga Rodrigo. Class is central to object oriented programming.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
BASE CLASSES AND INHERITANCE CHAPTER 4. Engineer Class.
Comp 249 Programming Methodology Chapter 8 - Polymorphism Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal,
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
5. Hierarchical CDFDs and Modules The motivation for building hierarchical CDFDs: It is almost impossible to construct only one level CDFD and module for.
VIENNA DEVELOPMENT METHOD -II. Improving the Incubator System  The software will not only record the current temperature of the system, but will also.
Analyzing the Requirements with Formal Specifications Vienna Development Method Specification Language (VDM-SL) Book: Formal Software Development From.
Cs205: engineering software university of virginia fall 2006 Data Abstraction David Evans
Model-Based Specification CIS 376 Bruce R. Maxim UM-Dearborn.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
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.
9a(1)CSC264 Satisfiability example – from 9(13) Proof obligation is now: forall o:Object, s:Store, p:Point & pre_Place(o,s,p) => inv_Store(Place(o,s,p))
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Slide: 1 Copyright © AdaCore Subprograms Presented by Quentin Ochem university.adacore.com.
VDM++ Tutorial Model Quality. Overview Introduction Assessing internal consistency Assessing external consistency.
Agenda Object Oriented Programming Reading: Chapter 14.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Chapter 3 Part II Describing Syntax and Semantics.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
ECSE Software Engineering 1I HO 4 © HY 2012 Lecture 4 Formal Methods A Library System Specification (Continued) From Specification to Design.
Functions Overview Functions are sequence of statements with its own local variables supports modularity, reduces code duplication Data transfer between.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Protocols Software Engineering II Wirfs Brock et al, Designing Object-Oriented Software, Prentice Hall, Mitchell, R., and McKim, Design by Contract,
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
/ PSWLAB Evidence-Based Analysis and Inferring Preconditions for Bug Detection By D. Brand, M. Buss, V. C. Sreedhar published in ICSM 2007.
1 Lecture 8 b Data Structures b Abstraction b The “Structures” package b Preconditions and postconditions b Interfaces b Polymorphism b Vector class b.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
SWEN421 – Lecture 3 Building High Integrity Software with SPARK Ada
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Learning to Program D is for Digital.
Arab Open University 2nd Semester, M301 Unit 5
B (The language of B-Method )
Slides by Steve Armstrong LeTourneau University Longview, TX
Software Design CMSC 345, Version 1/11.
Defining Classes and Methods
ISpec: A Compositional Approach to Interface Specification
Information Management
Improving the Performance of Functions
Presentation transcript:

CSC264 Modelling and Computation 10. Modelling State Steve Riddle, John Fitzgerald, Maciej Koutny Computing Science Semester /06

10(2)CSC264 State-Based Modelling Limitations of functional style Persistent state State and Operation definitions Case study: Explosives Store revisited

10(3)CSC264 Limitations of functional style So far, the models we have looked at have used a high level of abstraction. Functionality has been largely modelled by explicit functions, e.g. Update: System * Input -> System Update(oldsys, val) == mk_System( … ) Few computing systems are implemented using only pure functions

10(4)CSC264 Persistent state More often, “real” systems have variables holding data, which may be modified by operations invoked by a user VDM-SL provides facilities for state-based modelling:  state definition  operations  auxiliary definitions (types, functions)

10(5)CSC264 Example: Alarm Clock An alarm clock keeps track of current time and allows user to set an alarm time The alarm could be represented as a record type: Time = nat Clock :: now : Time alarm: Time alarmOn: bool Instead, we will use a state-based model

10(6)CSC264 State definition State is defined with the following syntax: state Name of component-name : type … component-name : type inv optional-invariant init initial-state-definition end Definition introduces a new type ( Name ) treated as a record type, with state variables as fields

10(7)CSC264 State definition Variables which represent the state of the system are collected into a state definition This represents the persistent data, to be read or modified by operations state Clock of now : Time alarm : Time alarmOn : bool init cl == cl = mk_Clock(0,0,false) end A model has only one state definition Init clause sets initial values for persistent data

10(8)CSC264 Operations Procedures which can be invoked by the system’s users – human or other systems – are operations Operations (can) take input and generate output Operations have side effects – can read, and modify, state variables Operations may be implicit or explicit, just as with functions

10(9)CSC264 Explicit Operations An explicit operation has signature and body just like an explicit function, but the body need not return a value: e.g. alarm is set to a given time, which must be in the future: SetAlarm: Time ==> () SetAlarm(t) == (alarm :=t ; alarmOn := true) pre t > now Note features:  no return value (in this case)  sequence of assignments to state variables

10(10)CSC264 Implicit Operations Explicit operations produce a relatively concrete model Normally in state-based model, begin with implicit operations  better abstraction  not executable e.g. implicit version of SetAlarm operation: SetAlarm(t: Time) ext wr alarm: Time wr alarmOn: bool rd now: Time pre t > now post alarm = t and alarmOn

10(11)CSC264 Implicit operations Implicit operations have the following components: header with operation name, names and types of input and any result parameters externals clause lists the state components used by the operation, and whether they are read-only or may be modified by the operation pre-condition recording the conditions assumed to hold when the operation is applied post-condition relates state and result value after the operation is completed, to the initial state and input values. Post-condition must respect restrictions in the externals clause, and define “after” values of all writeable state components

10(12)CSC264 Implicit operation syntax OpName(param:type, param:type, …) result:type ext wr/rd state-variable:type wr/rd state-variable:type... wr/rd state-variable:type pre logical-expression post logical-expression Operation definition is a specification for a piece of code with input/output parameters and side effects on state components

10(13)CSC264 Alarm clock: modelling time We might also model the passing of time: Implicit operation: Tick() ext wr now: Time post now = now~ + 1 Explicit operation: Tick: () ==> () Tick() == now := now + 1;

10(14)CSC264 State-based modelling Development usually proceeds from abstract to concrete  identify state and persistent state variables  define implicit operations in terms of their access to state variables, pre and postconditions  complete definitions of types, functions noting any restrictions to be captured as invariants and preconditions, check internal consistency  transform implicit operations to explicit (and to code) by provably correct steps

10(15)CSC264 Case Study: Explosives Store revisited System is part of a controller for a robot that positions explosives in a store. The store is a rectangular building. Positions are represented as coordinates with respect to the origin. The store’s dimensions are represented as maximum x and y coordinates. Objects in the store are rectangular, aligned with the walls of the store. Each object has x and y dimensions. The position of an object is represented as the coordinates of its lower left corner. All objects must fit within the store and there must be no overlap between objects. y x

10(16)CSC264 Explosives Store Recall functionality: 1.Return number of objects in a store 2.Suggest a position where an object may be placed in a given store 3.Update the store to record placing of an object in a position 4.Update the store to record removal of all objects at a given set of positions

10(17)CSC264 Explosives Store: Pure Functional Model Types: Store :: contents : set of Object xbound : nat ybound : nat inv mk_Store = … Object :: position : Point xlength : nat ylength : nat Point :: x : nat y : nat Function signatures NumObjects: Store -> nat SuggestPos: nat * nat * Store -> Point Place: Object * Store * Point -> Store Remove: Store * set of Point -> Store

10(18)CSC264 Explosives Store: State definition The state is defined as: state Store of contents : set of Object xbound : nat ybound : nat inv mk_Store(contents, xbound, ybound) == (forall o in set contents & InBounds(o,xbound,ybound)) and not exists o1,o2 in set contents & o1 <> o2 and Overlap(o1,o2) init s == s = mk_Store({},50,50) end

10(19)CSC264 Explosives Store: Operations 1. Return the number of objects in a store  In functional model, we had a function with this signature: NumObjects: Store -> nat  In state based model we define an implicit operation which uses state component contents, returning a natural number result: NumObjects() r: nat ext rd contents : set of Object post r = card contents

10(20)CSC264 Place Operation 3. Update the store to record placing of an object in a position. Store is to be modified, therefore read and write access to state component is needed. Place(o: Object, p:Point) ext pre post … wr contents : set of Object rd xbound : nat rd ybound : nat RoomAt(o, contents, xbound, ybound, p)

10(21)CSC264 Place Operation: Postcondition After the operation, the store’s contents will be the same as the old contents, but with the new object added. Use “ ~ ” notation to refer to state component before the operation is applied. post let new_o = mk_Object(p,o.xlength, o.ylength) in contents = contents~ union {new_o}

10(22)CSC264 Review State-based models are used where we need to represent persistent data and operations with side-effects on state variables Appropriate if model’s purpose is to document design of a software system with global variables Operations are normally recorded implicitly, defining access to state variables (read-only or read-write), post-conditions and pre-conditions