1 Z Schemas Chapter 6 Formal Specification using Z.

Slides:



Advertisements
Similar presentations
AN EDITABLE PAGE HOW TO EDIT COURSE PAGES AND THE LECTURE DATABASE You can ask for editing rights to pages in EEVeC. Pages that you may wish to edit include.
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Introduction to FX Equation 4. The Basic Idea FX Equation is DIFFERENT. Most equation editors use a point and click interface that has you searching for.
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
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.
Lecture 2 Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
Chapter 4 Systems of Linear Equations; Matrices Section 6 Matrix Equations and Systems of Linear Equations.
Cosc 2150: Computer Organization Chapter 3: Boolean Algebra and Digital Logic.
The Z Specification Language
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Schema Operators. State We can use the language of schemas to describe the state of a system, and operations upon it. Different aspects of the state --
1 Z Schemas Chapter 7 Formal Specification using Z Example of Z specification Document.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Schema Operators. State We can use the language of schemas to describe the state of a system, and operations upon it. Different aspects of the state --
An Introduction to formal methods using Z An aircraft example
1 Predicates and quantifiers Chapter 8 Formal Specification using Z.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
©Ian Sommerville 2000Software Engineering, 6/e, Chapter 91 Formal Specification l Techniques for the unambiguous specification of software.
School of Technology 1 Z: Operations on Schemas David Lightfoot based on work of Andrew Simpson.
Introduction to C Programming
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Chapter 2: Algorithm Discovery and Design
Propositional Calculus Math Foundations of Computer Science.
CSCD343- Introduction to databases- A. Vaisman1 Relational Algebra.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 10 Slide 1 Formal Specification.
COMPUTER SCIENCE I C++ INTRODUCTION
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques for the unambiguous specification of software.
Logic Specification and Z Schema 3K04 McMaster. Basic Logic Operators Logical negation ( ¬ ) Logical conjunction ( Λ or & ) Logical disjunction ( V or.
A Z Approach in Validating ORA-SS Data Models Scott Uk-Jin Lee Jing Sun Gillian Dobbie Yuan Fang Li.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
INTRODUCTION TO THE THEORY OF COMPUTATION INTRODUCTION MICHAEL SIPSER, SECOND EDITION 1.
Model-Based Specification CIS 376 Bruce R. Maxim UM-Dearborn.
17 May 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Course: Software Engineering ©Alessandra RussoUnit 2: States and Operations, slide number 1 States and Operations This unit aims to:  Define: State schemas.
Week 1 Algorithmization and Programming Languages.
1 Relational Algebra and Calculas Chapter 4, Part A.
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Aliya Farheen October 29,2015.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 5 – September 4 th,
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Bioinformatics Introduction to Perl. Introduction What is Perl Basic concepts in Perl syntax: – variables, strings, – Use of strict (explicit variables)
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
The Z Specification Language Based on J. M. Spivey. An Introduction to Z and formal specifications, Software Engineering Journal, 4(1):40-50, January,
Chapter 4 Systems of Linear Equations; Matrices
User-Written Functions
Chapter 6: Real-Time Logic
(State) Model-Based Approaches II Software Specification Lecture 36
IDENTIFIERS CSC 111.
Introduction to C++ Programming
Chapter 2: Intro to Relational Model
Department of Computer Science
Software Development Techniques
Presentation transcript:

1 Z Schemas Chapter 6 Formal Specification using Z

2 Schemas A specification document in Z consists of narrative text interspersed with formal Z notation called schemas.  S _________  a,b: N  ________  a < b  __________ This schema is called S and it declares two variables a and b. It contains a constraining predicate which states that a must be less than b.

3 Schemas The general form of a schema is.  SchemaName _____  Declarations  ________  Predicate  __________ A schema can also be written in a linear form: SchemaName == [ Declarations | Predicate] The previous example would be written in linear form as: S == [a,b: N | a<b]

4 Schemas It is possible to have an anonymous schema, no name. It is possible to have a schema with no predicate. Variables are local to a schema. If you require variables from another schema you must include it in your current schema. Global variables are available to all schemas, they are introduced by axiomatic definition and cannot be changed by any operation. For example: | capacity: N If you wish to constrain a variable, the general form is  Declarations  ________  Predicate  __________

5 Schemas For example  MaxOnCourse  ________  MaxOnCourse 6…30  __________ Schemas can make reference to capacity and MaxOnCourse without explicitly including their defining schemas.  Course _____  numberEnrolled:  ________  numberEnrolled MaxOnCourse  __________

6 Schemas Each line of declaration part is separated by a semicolon. Each line of predicate part is connected with the ‘and’ operation  Class _____  lecturer: PERSON  student: P PERSON  ________  lecturer student  #student MaxOnCourse  __________ Is an abbreviation for:  Class _____  lecturer: PERSON;  student: P PERSON;  ________  lecturer student L  #student MaxOnCourse  __________

7 Schema Calculus Schemas can be regarded as units and manipulated by various operators that are analogous to the logical operators ( L, v, ¬ etc. ) The schema name S decorated with a prime (S’) is defined to be the same as the schema S with all its variables decorated with a prime. It is used to signify the value of a schema after some operation. Before operation  S ______  a,b: N  ______  a < b  ______ _ After operation  S’ ______   a’,b’: N  ______  a’ < b’  _______ _

8 Inclusion The name of a schema can be included in the declaration of another schema. When a schema is textually imported its declarations are merged with those of the including schema and its predicate part is conjoined (anded) with that of the including schema. Any variables that have the same name must have the same type.

9 Inclusion Including a schema  IncludeS ___  c: N  S  ______  c < 10  _______ Is a short way of writing  includeS _  c: N  a,b: N   ______  c < 10  a < b  ________

10 Schema Conjunction Definition of S  S ___  a,b: N  ______  a < b  _______ SandT == S L T  SandT _  a,b,c: N   ______  a < b  b < c  ________ Definition of T  T ___  b,c: N  ______  b < c  _____

11 Schema Disjunction Definition of S  S ___  a,b: N  ______  a < b  _______ SorT == S v T  SorT ___  a,b,c: N   ______  ( a < b) v  ( b < c)  ________ Definition of T  T ___  b,c: N  ______  b < c  _____

12 Delta Convention Definition of Delta S  D S ___  a,b: N  a’,b’: N  ______  a < b  a’ < b’  _______ The convention that a value of a variable before an operation is denoted by an undecorated name of the variable, and the value after an operation is decorated by a prime (‘) is used in the delta naming convention. A schema with a capital delta ( D often denotes some change) as the first character of its name is defined as:

13 Xi Convention Definition of Xi S  X S ___  a,b: N  a’,b’: N  ______  a < b  a’ < b’  a’ = a  b’ = b  _______ The convention a schema with the Greek capital letter xi ( X ) as the first character of its name, such as X S, is defined as the same as D S but with the constraint that the new value of every variable is the same as the old. The state of does not change. For example a query is an operation that produces a result that should not change the state of a database.

14 Schema Input Output Definition of Add  Add ___  a?,b?: N  sum!: N  ______  sum! = a? + b?  _______ Finishing variable names with a question mark (?) indicates input to the schema. Finishing variable names with a exclamation mark (!) indicates output from the schema.

15 Schema Example KEY ::= home | return | left | right | up | down  numLines: N  numColumns: N  ______  1 numLines  1 numColumns  _______ A computer display shows lines of characters with each line consisting of a fixed number of columns containing a character in a fixed-width typeface. A cursor marks the current position of interest on the display. The user can press cursor-control keys on the keyboard, some of which directly control the position of the cursor.

16 Schema Example The lines are numbered from 1 to numLines down the display and the columns are numbered 1 to numColumns across the display. 1 1 numLines numColumns line column cursor

17 The State At any time the cursor is within the bounds of the display. The state of the cursor can be described by the schema Cursor.  Cursor ___  line: N  column: N  ______  line 1..numLines  column 1..numColumns  _______

18 Home Key The operations for moving the cursor can be built up one at a time. The simplest is to respond to the home key. It causes the cursor to the top left corner of the display.  HomeKey ___  D Cursor  key?: KEY  ______  key? = home  line’ = 1  column’ = 1  ________

19 Home Key We are using the delta convention with D cursor defined as:  D Cursor ___  line, line’ : N  column, column’ : N  ______  line 1..numLines  line’ 1..numLines  column 1..numColumns  column’ 1..numColumns  _______

20 Down Key The operation for moving the cursor down, in the normal case, can be defined as:  DownKeyNormal ___  D Cursor  key?: Key  ______  key? = down  line < numLines  line’ = line + 1  column’ = column  ________

21 Down Key The operations for moving the cursor down, when the cursor is at the bottom of the display, can be defined as:  DownKeyAtBottom ___  D Cursor  key?: KEY  ______  key? = down  line = numLines  line’ = 1  column’ = column  ________

22 Down Key The operation for moving the cursor down is defined to ‘wrap round’ to the top of the display. The full behaviour is given by: DownKey == DownKeyNormal v DownKeyAtBottom The operation defined by oring the two behaviours.

23 Return Key The response to the return key is to move the cursor to the leftmost column of the next line down or the top of the screen if the cursor is already on the bottom line. This can be defined as:  ReturnKey ___  D Cursor  key?: KEY  ______  key? = return  column’ = 1  (( line < numLines L line’ = line’+1)  v  ( line = numLines L line’=1))  ________

24 Right Key First we deal with the case where the cursor is not at the far right of the display:  RightKeyNormal ___  D Cursor  key?: KEY  ______  key? = right  column < numColumns  column’ = column+1  line’ = line  ________

25 Right Key Next we deal with the case where the cursor is at the far right of the display:  RightKeyAtEnd ___  D Cursor  key?: KEY  ______  key? = right  column = numColumns  column’ = 1  line < numLines  line’ = line + 1  ________

26 Right Key Finally we deal with the case where the cursor is at the far right of the bottom line of the display:  RightKeyAtBottom ___  D Cursor  key?: KEY  ______  key? = right  column = numColumns  column’ = 1  line = numLines  line’ = 1  ________

27 Right Key These three schemas can be combined to form one schema that defines the response of the cursor to the right key being pressed in all initial positions of the cursor: RightKey= RightKeyNormal v RightKeyAtEnd v RightKeyAtBottom

28 Cursor-control key action The action of the cursor on pressing any of these cursor- control keys can be defined as: CursorControlKey= RightKey v HomeKey v ReturnKey UpKey v DownKey v LeftKey

29 Schema Composition The composition of a schema S with schema T is written: S ; T and signifies the effect of doing S, and then doing T. For example, to show the effect of pressing the right-key and then the left-key on the display using the existing definition of CursorControlKey. We first write the definitions of pressing the left and right keys. PressRight == CursorControlKey L [k?=right] PressLeft == CursorControlKey L [k?=left] The composition of the two actions is written PressRight ; PressLeft

30 The overall structure of a Z specification A Z specification document consists of mathematical text in Z notation, interleaved with explanatory text in natural language. The text should be expressed in terms of the problem and should not refer directly to the mathematical formulation, however for tutorial work this restriction is relaxed.

31 Sections of a Z specification Introduction. The types used. The state and its invariant properties An initialisation operation. Operations and queries. Error handling. Final versions of operations and enquiries.

32 Chapter 6 Exercises Q1 Define schema linesRemaining which delivers the number of lines below the cursor as output.

33 Chapter 6 Exercises Q1 Define schema linesRemaining which delivers the number of lines below the cursor as output.  LinesRemaining ___  X Cursor  lines! : N  ______  lines! = numLines - line  ________

34 Chapter 6 Exercises Q2 Define schema UpKey to define the operation of pressing the up key.

35 Chapter 6 Exercises Q2 Define schema UpKey to define the operation of pressing the up key.  UpKeyAtTop ___  D Cursor  key?: KEY  ______  key? = up  line = 1  line’ = numLines  column’ = column  ________  UpKeyNormal ___  D Cursor  key?: KEY  ______  key? = up  line > 1  line’ = line - 1  column’ = column  ________ UpKey == UpkeyNormal v UpKeyAtTop The cursor wraps around to the bottom of the display.

36 Chapter 6 Exercises Q3 Define schema LeftKey to define the operation of pressing the up key.

37 Chapter 6 Exercises Q3 Solution Define schema LeftKey to define the operation of pressing the up key.  LeftKeyAtStart ___  D Cursor  key?: KEY  ______  key? = left  column =1  column’ = numColumns  line > 1  line’ = line - 1  ________  LeftKeyNormal ___  D Cursor  key?: KEY  ______  key? = left  column > 1  column’ = columns -1  line’ = line  ________ LeftKey == LeftKeyNormal v LeftKeyAtStart v LeftKeyAtTop The cursor wraps around to the bottom of the display.  LeftKeyAtTop ___  D Cursor  key?: KEY  ______  key? = left  column =1  column’ = numColumns  line = 1  line’ = numLines  ________