Formal Specification. Approaches to formal specification Functional –The system is described as a number of functions. –Unnatural and complex for large.

Slides:



Advertisements
Similar presentations
Formal Specifications
Advertisements

© Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.4 The Z Notation [Reference: M. Spivey: The Z Notation, Prentice Hall]
Building Bug-Free O-O Software: An Introduction to Design By Contract A presentation about Design By Contract and the Eiffel software development tool.
Semantics Static semantics Dynamic semantics attribute grammars
© Colin Potts C6-1 Some future trends in requirements engineering Colin Potts Georgia Tech.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Software Processes.
1 Chapter 4 - Part 1 Software Processes. 2 Software Processes is: Coherent (logically connected) sets of activities for specifying, designing, implementing,
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Software Processes.
Software Processes Coherent sets of activities for specifying, designing, implementing and testing software systems.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Software Engineering General Project Management Software Requirements
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Software Process Models.
©Ian Sommerville 2000 Software Engineering, 6th edition Slide 1 Software Processes l Coherent sets of activities for specifying, designing, implementing.
©Ian Sommerville 2000Software Engineering, 6/e, Chapter 91 Formal Specification l Techniques for the unambiguous specification of software.
Describing Syntax and Semantics
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 10 Slide 1 Formal Specification.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Software Processes.
MCA –Software Engineering Kantipur City College. Topics include  Formal Methods Concept  Formal Specification Language Test plan creation Test-case.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 10 Slide 1 Critical Systems Specification 3 Formal Specification.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 10 Slide 1 Formal Specification.
Chapter 3 Software Processes.
Formal Methods 1. Software Engineering and Formal Methods  Every software engineering methodology is based on a recommended development process  proceeding.
Language Evaluation Criteria
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques for the unambiguous specification of software.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Software Processes.
©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 1 Chapter 10 Formal Specification.
©Ian Sommerville 2000, Mejia-Alvarez 2009 Slide 1 Software Processes l Coherent sets of activities for specifying, designing, implementing and testing.
1 COSC 4406 Software Engineering COSC 4406 Software Engineering Haibin Zhu, Ph.D. Dept. of Computer Science and mathematics, Nipissing University, 100.
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
A Z Approach in Validating ORA-SS Data Models Scott Uk-Jin Lee Jing Sun Gillian Dobbie Yuan Fang Li.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 3 Slide 1 Software Processes l Coherent sets of activities for specifying, designing,
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Chapter 9 Formal Specifications.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor.
Model-Based Specification CIS 376 Bruce R. Maxim UM-Dearborn.
JavaScript, Fourth Edition
Overview of Formal Methods. Topics Introduction and terminology FM and Software Engineering Applications of FM Propositional and Predicate Logic Program.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
WXGE6103 Software Engineering Process and Practice Formal Specification.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Software Processes.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Requirements Engineering Methods for Requirements Engineering Lecture-30.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
ECSE Software Engineering 1I HO 4 © HY 2012 Lecture 4 Formal Methods A Library System Specification (Continued) From Specification to Design.
SWEN 5130Requirements Engineering Algebraic Specification Slide 1 Algebraic Specification u Specifying abstract types in terms of relationships between.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Notes on: Is Proof More Cost- Effective Than Testing? by Steve King, Jonathan Hammond, Rob Chapman, Andy Pryor Prepared by Stephen M. Thebaut, Ph.D. University.
©Ian Sommerville 1995/2000 (Modified by Spiros Mancoridis 1999) Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques.
1 Abstract Model Specification. 2 Explicitly describes behavior in terms of a model using well-defined types (viz. set, sequences, relations, functions)
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 4 Slide 1 Software Processes.
Requirements Engineering Methods for Requirements Engineering Lecture-31.
©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 1 Chapter 10 Formal Specification.
Slide 1 Introduction to the Z Formal Specifications Language.
Requirement Specification SRS document is a contract between the development team and the customer How do we communicate the Requirements to others? Firm.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Laurea Triennale in Informatica – Corso di Ingegneria del Software I – A.A. 2006/2007 Andrea Polini IX. System Models (III)
IS301 – Software Engineering V:
Formal Specification.
Software Processes (a)
(State) Model-Based Approaches II Software Specification Lecture 36
Formal Specification Techniques for the unambiguous specification of software.
Python Primer 1: Types and Operators
Sub-system interfaces
Algebraic Specification Software Specification Lecture 34
Presentation transcript:

Formal Specification

Approaches to formal specification Functional –The system is described as a number of functions. –Unnatural and complex for large systems Algebraic –The system is described in terms of operations and their relationships. Model-based –A model of the system is constructed using well- understood mathematical entities such as sets and sequences

Algebraic Specification Based on concept of abstract data types Large systems are usually decomposed into sub- systems which are accessed through a defined interface. Sub-system ASub-system B

Algebraic specification (2) Components of a specification: Specification name and generic parameter list Type name and declaration of imported specifications Informal description Operation signatures Axioms that define the operational semantics

Array specification ARRAY (Elem: [Undefined  Elem]) sort Array imports Integer Arrays are collections of elements of generic type Elem. They have a lower and upper bound… Create(Integer, Integer)  Array Assign(Array, Integer, Elem)  Array First(Array)  Integer Last(Array)  Integer Eval(Array, Integer)  Elem

Array specification axioms First(Create(x, y)) = x First(Assign(a, n, v)) = First(a) Last(Create(x, y)) = y Last(Assign(a, n, v)) = Last(a) Eval(Create(x, y), n) = Undefined Eval(Assign(a, n, v), m) = if m Last(a) then Undefined else if m = n then v else Eval(a,m) Eval( Assign( Create(1,10), 1, 5), 2, 10), 1) = 5

Binary Tree Specification Signatures: Create  BT Add(BT, Elem)  BT Left(BT)  BT Right(BT)  BT Data(BT)  Elem Empty(BT)  Boolean Contains(BT, Elem)  Boolean Build(BT, Elem, BT)  BT

Binary Tree Specification (2) Axioms: Add(Create, E) = Build(Create, E, Create) Add(B, E) = if E < Data then Add(Left(B), E) else Add(Right(B), E) Left(Create) = Create Data(Create) = Undefined Left(Build(L, D, R)) = L Data(Build(L, D, R)) = D Empty(Create) = true Empty(Build(L, D, R)) = false Contains(Create, E) = false Contains(Build(L, D, R), E) = if E = D then true else if E < D then Contains(L, D) else Contains(R,D)

Systematic specification Specification structuring –The informal interface specification is structured into a set of abstract data types with proposed operations. Specification naming –Name, generic parameters, type Operation selection –Constructors, Manipulators, Inspectors Informal operation specification Syntax definition Axiom definition

Structured specification: reuse Instantiation of generic specifications –Array, Array >, etc. Incremental development of specifications –Import specification of simple types and use them in the definition of more complex types, e.g. the specification of Coordinate might be used in the specification of Cursor. Enrichment of specifications –Inheritance of signatures and axioms from a base specification

Error specification Several approaches: A special constant operation, such as Undefined, may be defined. Operations may be defined to evaluate to tuples, where one element of the tuple is a boolean that indicates successful evaluation. The specification may include an exceptions section which defines conditions under which the axioms do not hold.

Model-based Specification with Z Formal specification of software by developing a mathematical model of the system

Objectives To introduce an approach to formal specification based on mathematical system models To present some features of the Z specification language The illustrate the use of Z using small examples To show how Z schemas may be used to develop incremental specifications

Model-based specification Defines a model of a system using well- understood mathematical entities such as sets and functions The state of the system is not hidden (unlike algebraic specification) State changes are straightforward to define

Z Specification Language Based on typed set theory Probably now the most widely-used specification language Includes schemas, an effective low-level structuring facility Schemas are specification building blocks Graphical presentation of schemas make Z specifications easier to understand

Z schemas Introduce specification entities and defines invariant predicates over these entities A schema includes –A name identifying the schema –A signature introducing entities and their types –A predicate part defining invariants over these entities Schemas can be included in other schemas and may act as type definitions Names are local to schemas

Z schema highlighting Container contents: N capacity: N contents  capacity Schema name Schema signature Schema predicate

An indicator specification Indicator light: { off, on } reading: N danger_level: N light = on  reading  danger_level

Storage tank specification Storage_tank Container Indicator reading = contents capacity = 5000 danger_level = 50

Full specification of a storage tank Storage_tank contents  capacity light = on  reading  danger_level reading = contents capacity = 5000 danger_level = 50 contents: N capacity: N light: { off, on } reading: N danger_level: N

Z conventions A variable name decorated with a dash (quote mark), N’, represents the value of the state variable N after an operation A schema name decorated with a dash introduces the dashed values of all names defined in the schema A variable name decorated with a ! represents an output

Z conventions A variable name decorated with a ? represents an input A schema name prefixed by the Greek letter Xi (  ) means that the defined operation does not change the values of state variables A schema name prefixed by the Greek letter Delta (  ) means that the operation changes some or all of the state variables introduced in that schema

Operation specification Operations may be specified incrementally as separate schema then the schema combined to produce the complete specification Define the ‘normal’ operation as a schema Define schemas for exceptional situations Combine all schemas using the disjunction (or) operator

A partial spec. of a fill operation Fill_OK  Storage_tank amount?: N contents + amount?  capacity contents’ = contents + amount?

Storage tank fill operation OverFill  Storage_tank amount?: N r!: seq CHAR capacity < contents + amount? r! = “Insufficient tank capacity – Fill canceled” Fill Fill_OK  OverFill

The Z specification process

Data dictionary specification A data dictionary will be used as an example. This is part of a CASE system and is used to keep track of system names Data dictionary structure –Item name –Description –Type. Assume in these examples that the allowed types are those used in E/R models –Creation date

Data dictionary modeling A data dictionary may be thought of as a mapping from a name (the key) to a value (the description in the dictionary) Operations are –Add. Makes a new entry in the dictionary or replaces an existing entry –Lookup. Given a name, returns the description. –Delete. Deletes an entry from the dictionary –Replace. Replaces the information associated with an entry

Given sets Z does not require everything to be defined at specification time Some entities may be ‘given’ and defined later The first stage in the specification process is to introduce these given sets –[NAME, DATE] –We don’t care about these representations at this stage

Type definitions There are a number of built-in types (such as INTEGER) in Z Other types may be defined by enumeration –Sem_model_types = { relation, entity, attribute } Schemas may also be used for type definition. The predicates serve as constraints on the type

Data dictionary entry DataDictionaryEntry name: NAME description: seq char type: sem_model_types creation_date: DATE #description  2000

Specification using functions A function is a mapping from an input value to an output value –SmallSquare = {1  1, 2  4, 3  9, 4  16, 5  25, 6  36, 7  49 } The domain of a function is the set of inputs over which the function has a defined result –domain SmallSquare = {1, 2, 3, 4, 5, 6, 7 } The range of a function is the set of results which the function can produce –range SmallSquare = {1, 4, 9, 16, 25, 36, 49 }

The function SmallSquare

Data dictionary as a function DataDictionary DataDictionaryEntry ddict: NAME  { DataDictionaryEntry }

Data dictionary initialization Init_DataDictionary DataDictionary’ ddict’ = { }

Add and lookup operations Add_OK  DataDictionary entry?: DataDictionaryEntry entry?.name  dom ddict ddict’ = ddict  { entry?.name  entry? } Lookup_OK  DataDictionary name?: NAME entry!: DataDictionaryEntry name?  dom ddict entry! = ddict(name?)

Add and lookup operations Add_Error  DataDictionary entry?: DataDictionaryEntry error!: seq char entry?.name  dom ddict error! = “Name already in dictionary” Lookup_Error  DataDictionary name?: NAME error!: seq char name?  dom ddict error! = “Name not in dictionary”

Function over-riding operator ReplaceEntry uses the function overriding operator (written  ). This adds a new entry or replaces and existing entry. –phone = { Ian  3390, Ray  3392, Steve  3427} –The domain of phone is {Ian, Ray, Steve} and the range is {3390, 3392, 3427}. –newphone = {Steve  3386, Ron  3427} –phone  newphone = { Ian  3390, Ray  3392, Steve  3386, Ron  3427}

Replace operation Replace_OK  DataDictionary entry?: DataDictionaryEntry entry?.name  dom ddict ddict’ = ddict  { entry?.name  entry? }

Deleting an entry Uses the domain subtraction operator (written ) which, given a name, removes that name from the domain of the function phone = { Ian  3390, Ray  3392, Steve  3427} {Ian} phone = {Ray  3392, Steve  3427}

Delete entry Delete_OK  DataDictionary name?: NAME name?  dom ddict ddict’ = { name? } ddict

Specifying ordered collections Specification using sets does not allow ordering to be specified Sequences are used for specifying ordered collections A sequence is a function mapping consecutive integers to associated values

A Z sequence cedbacedba Domain Range { (1,a), (2,b), (3,c), (4,d), (5,e) }

Data dictionary extract operation The Extract operation extracts from the data dictionary all those entries whose type is the same as the type input to the operation The extracted list is presented in alphabetical order A sequence is used to specify the ordered output of Extract

The Extract operation Extract DataDictionary rep!: seq {DataDictionaryEntry} in_type?: Sem_model_types  n  dom ddict: ddict(n).type = in_type?  ddict(n)  rng rep!  1  i  #rep!: rep!(i).type = in_type?  1  i  #rep!: rep!(i)  rng ddict  i,j  dom rep!: (i < j)  rep!(i).name < NAME rep!(j).name

Extract predicate For all entries in the data dictionary whose type is in_type?, there is an entry in the output sequence The type of all members of the output sequence is in_type? All members of the output sequence are members of the range of ddict The output sequence is ordered by entry name

Data dictionary specification The_Data_Dictionary DataDictionary Init_DataDictionary Add Lookup Delete Replace Extract

Key points Model-based specification relies on building a system model using well-understood mathematical entities Z specifications are made up of mathematical model of the system state and a definition of operations on that state A Z specification is presented as a number of schemas Schemas may be combined to make new schemas

Key points Operations are specified by defining their effect on the system state. Operations may be specified incrementally then different schemas combined to complete the specification Z functions are a set of pairs where the domain of the function is the set of valid inputs. The range is the set of associated outputs. A sequence is a special type of function whose domain is the consecutive integers

Objectives What is the role of formal software specification in the software process? What are the pros and cons of formal specification? When can formal specification be cost effective?

Software Process As specification is developed in detail, understanding of the specification increases. Creating a formal specification usually reveals errors in the informal specification, that are fed back to allow correction. Requirement s specification Formal specification High-level design

Why no formal specifications? Management is unwilling to adopt techniques without an obvious payoff. Software engineers lack training in discrete math and logic. Customers are unfamiliar with formal techniques. Certain classes of software systems are difficult to specify using existing techniques. Practicality of techniques is not well known. Little effort has been devoted to method and tool support for formal techniques.

Why no formal specifications? (2) The move to interactive systems –Most formal specification languages are unable to cope with interactive graphical interfaces. –Difficult to integrate formal methods with rapid prototyping. Successful software engineering –If major progress is being made in improving software quality without using formal methods, why should they be introduced now?

Pros of formal specification Provides insight into understanding requirements and the software design. –Reduces requirement errors. May be analyzed using mathematical methods. –Ability to reason about the specification May be automatically processed. –Development and debugging tools May guide testing. –Identifying appropriate test cases

Transformational development Easier to prove correctness incrementally: Formal specification Executable program R1R1 R2R2 RnRn P0P0 P1P1 P2P2 PnPn T0T0 T1T1 T2T2 TnTn

Myths of formal methods (Hall 1990) Formal methods result in perfect software Formal methods mean program proving Formal methods increase development costs Formal methods require a high level of mathematical skill Customers cannot understand formal specifications Formal methods have only been used for trivial system development

Development costs

Verdict on formal specification For a large class of systems, particularly highly interactive systems, formal specification is probably not cost effective for the foreseeable future. Where system dependability (safety, reliability, security, etc.) is critical, formal methods will probably become common. Formal specifications may also be very useful in defining standards where precision and unambiguity are essential.