©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 1 Chapter 10 Formal Specification.

Slides:



Advertisements
Similar presentations
Formal Specifications
Advertisements

1 Note content copyright © 2004 Ian Sommerville. NU-specific content © 2004 M. E. Kabay. All rights reserved. Formal Specification IS301 – Software Engineering.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 20 Slide 1 Critical systems development.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
Formal Specification - Techniques for the unambiguous specification of software Objectives: To explain why formal specification techniques help discover.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Modified from Sommerville’s originalsSoftware Engineering, 7th edition. Chapter 10 Slide 1 Formal Specification.
Software Testing and Quality Assurance
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
Modified from Sommerville’s originalsSoftware Engineering, 7th edition. Chapter 10 Slide 1 Formal Specification.
©Ian Sommerville 2000Software Engineering, 6/e, Chapter 91 Formal Specification l Techniques for the unambiguous specification of software.
Describing Syntax and Semantics
School of Computer ScienceG53FSP Formal Specification1 Dr. Rong Qu Introduction to Formal Specification
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 10 Slide 1 Formal Specification.
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.
An example of a critical system
Formal Methods 1. Software Engineering and Formal Methods  Every software engineering methodology is based on a recommended development process  proceeding.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques for the unambiguous specification of software.
Software Models (Cont.) 9/22/2015ICS 413 – Software Engineering1 -Component-based software engineering -Formal Development Model.
©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.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 3 Slide 1 Software Processes l Coherent sets of activities for specifying, designing,
1 Program Correctness CIS 375 Bruce R. Maxim UM-Dearborn.
©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.
Proofs of Correctness: An Introduction to Axiomatic Verification Prepared by Stephen M. Thebaut, Ph.D. University of Florida CEN 5035 Software Engineering.
Overview of Formal Methods. Topics Introduction and terminology FM and Software Engineering Applications of FM Propositional and Predicate Logic Program.
WXGE6103 Software Engineering Process and Practice Formal Specification.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Software Processes.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
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.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
SWEN 5130Requirements Engineering Algebraic Specification Slide 1 Algebraic Specification u Specifying abstract types in terms of relationships between.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor.
Software Engineering Chapter 10 Formal Specification Ku-Yaw Chang Assistant Professor Department of Computer Science and Information.
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.
Formal Methods in SE Software Verification Using Formal Methods By: Qaisar Javaid, Assistant Professor Formal Methods1.
Software Engineering 2 -Prakash Shrestha.
©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.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
An insulin pump. Needle Assembly: Connected to pump. Component used to deliver insulin into the diabetic body.
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.
(State) Model-Based Approaches I Software Specification Lecture 35
(State) Model-Based Approaches II Software Specification Lecture 36
Chapter 27 Formal Specification.
Formal Specifications
Semantics In Text: Chapter 3.
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Algebraic Specification Software Specification Lecture 34
Activities of Formal Methods
Presentation transcript:

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 1 Chapter 10 Formal Specification

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 2 Objectives l To explain why formal specification helps discover problems in system requirements. l To describe the use of:  Algebraic specification techniques, and  Model-based specification techniques (including simple pre- and post-conditions).

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 3 Formal methods l Formal specification is part of a more general collection of techniques known as “formal methods.” l All are based on the mathematical rep- resentations and analysis of requirements and software.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 4 Formal methods (cont’d) l Formal methods include:  Formal specification  Specification analysis and property proofs  Transformational development  Program verification (program correctness proofs) l Specifications are expressed with precisely defined vocabulary, syntax, and semantics. (e.g., “model checking”) (axiomatic, function theoretic)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 5 Acceptance and use l Formal methods have not become main-stream as was once predicted, especially in the US. Some reasons why: 1.Less costly techniques (e.g., inspections / reviews) have been successful at increasing system quality. (Hence, the need for formal methods has been reduced.) (Cont’d)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 6 Acceptance and use (cont’d) 2.Market changes have made time-to- market rather than quality the key issue for many systems. (Formal methods do not reduce time-to- market.) 3.Limited scope of formal methods. They’re not well-suited to specifying user interfaces. (Many interactive applications are “GUI-heavy” today.) (Cont’d)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 7 Acceptance and use (cont’d) 4.Formal methods are hard to scale up for very large systems. (Although this is rarely necessary.) 5.Start-up costs are high. 6.Thus, the risks of adopting formal methods on most projects outweigh the benefits.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 8 Acceptance and use (cont’d) l However, formal specification is an excellent way to find (at least some types of) requirements errors and to express requirements unambiguously. l Projects which use formal methods invariably report fewer errors in the delivered software.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 9 Acceptance and use (cont’d) l In systems where failure must be avoided, the use of formal methods is justified and likely to be cost-effective. l Thus, the use of formal methods is increasing in critical system development where safety, reliability, and security are important.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 10 Formal specification in the software process elicitation a “back-end” element of requirements elicitation/analysis/specification/validation

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 11 Formal specification techniques l Algebraic approach – system is specified in terms of its operations and their relationships via axioms. l Model-based approach (including simple pre- and post-conditions) – system is specified in terms of a state model and operations are defined in terms of changes to system state.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 12 Formal specification languages

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 13 Use of formal specification l Formal specification is a rigorous process and requires more effort in the early phases of software development. l This reduces requirements errors as ambiguities, incompleteness, and inconsistencies are discovered and resolved. l Hence, rework due to requirements problems is greatly reduced.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 14 Development costs with formal specification

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 15 Algebraic Specification of sub-system interfaces l Large systems are normally comprised of sub-systems with well-defined interfaces. l Specification of these interfaces allows for their independent development. l Interfaces are often defined as abstract data types (“sorts”) or objects. l The algebraic approach is particularly well- suited to the specification of such interfaces.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 16 Sub-system interfaces

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 17 The structure of an algebraic specification sort imports < LIST OF SPECIFICATION NAMES > Informal description of the sort and its operations Operation signatures setting out the names and the types of the parameters to the operations defined over the sort Axioms defining the operations over the sort < SPECIFICATION NAME > (Generic Parameter)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 18 Algebraic specification components l Introduction – defines the sort (type name) and declares other specifications that are used l Description – informally describes the operations on the type l Signature – defines the syntax of the operations in the interface and their parameters l Axioms – defines the operation semantics by defining axioms which characterize behavior

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 19 Types of operations l Constructor operations: operations which create / modify entities of the type l Inspection operations: operations which evaluate entities of the type being specified l Rule of thumb for defining axioms: define an axiom which sets out what is always true for each inspection operation over each (primitive) constructor operation.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 20 Operations on a (FIFO linear) “List” abstract data type l Constructor operations which create or modify sort List: Create, Cons and Tail l Inspection operations which discover attributes of sort List: Head and Length ( LISP fans: Tail = CDR, Head = CAR) l Tail is not a primitive operation since it can be defined using Create and Cons. (Thus, axioms are not required for Head and Length over Tail.)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 21 List specification Head (Create) = Undefined exception (empty list) Head (Cons (L, v)) = if L =Create then v else Head (L) Length (Create) = 0 Length (Cons (L, v)) = Length (L) + 1 Tail (Create ) = Create Tail (Cons (L, v)) = if L =Createthen Createelse Cons (Tail (L), v) sort List imports INTEGER Create → List Cons (List, Elem) → List Head (List) → Elem Length (List) → Integer Tail (List) → List LIST ( Elem ) Defines a list where elements are added at the end and removed from the front. The operations are Create, which brings an empty list into existence; Cons, which creates a new list with an added member; Length, which evaluates the list size; Head, which evaluates the front element of the list; and Tail, which creates a list by removing the head from its input list. Undefined represents an undefined value of type Elem. A FIFO linear list Operator names + type info for argument(s) & result Defines Tail in terms of Create and Cons

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 22 Recursion in specifications l Tail (Cons (L, v)) = if L = Create then Create else Cons (Tail (L), v) Tail (Cons ( [5, 7], 9)) = ? = Cons (Tail ( [5, 7] ), 9) (axiom 6) = Cons (Tail (Cons ([5], 7) ), 9) = Cons (Cons (Tail ([5]), 7), 9) (axiom 6) = Cons (Cons (Tail (Cons ([ ], 5) ), 7), 9) = Cons (Cons (Create, 7), 9) (axiom 6) = Cons ( [7], 9) = [7, 9]

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 23 Exercise What does Head (Tail (L)) do? L Head (Tail (L)) [ ] [a] [a, b] [a, b, c] undefined b b

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 24 Exercise Are axioms 1-6 sufficient to prove ANY true assertion of the form Head (Tail (L) ) = v ? Consider ONE EXAMPLE: Head (Tail ([a, b]) = b

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 25 Proof that Head (Tail ([a, b]) = b Head (Tail ([a, b])) = Head (Tail (Cons ([a], b))) = Head (Cons (Tail ([a]), b)) (axiom 6) = Head (Cons (Tail (Cons ([ ], a)), b)) = Head (Cons ([ ], b)) (axiom 6) = b (axiom 2)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 26 Question So, we can prove Head (Tail ([a, b]) = b using the given axioms, but how could one show that the axioms are sufficient to prove ANY true assertion of the form Head (Tail (L) ) = v ? Moral: Showing correctness and completeness of algebraic specifications can be very tricky!

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 27 Model-based specification l Algebraic specification can be cumber- some when object operations are not independent of object state (i.e., the result of previous operations). l (System State) Model-based specification exposes the system state and defines operations in terms of changes to that state.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 28 Model-based specification l Z is a mature notation for model-based specification. It combines formal and informal descriptions and incorporates graphical highlighting. l The basic building blocks of Z-based specifications are schemas. l Schemas identify state variables and define constraints and operations in terms of those variables.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 29 The structure of a Z schema Container contents: N capacity: N contents ≤ capacity NAME SIGNATURE PREDICATE N atural numbers (0, 1, 2, …) (defines scheme state) (invariants, pre- & post- conditions)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 30 An insulin pump insulin delivery glucose level text messagesdose delivered

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 31 Modelling the insulin pump l The schema models the insulin pump as a number of state variables  reading? from glucose level sensor  dose, cumulative_dose  r0, r1, r2 last 3 glucose level readings  capacity insulin pump reservoir level  alarm! signals exceptional conditions  pump! output for insulin pump device  display1!, display2! text messages & dose l Names followed by a ? are inputs, names followed by a ! are outputs.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 32 Insulin pump schema signature

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 33 Insulin pump schema signature (cont'd)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 34 Schema predicates l Each Z schema has an predicate part which defines conditions that are always true (schema invariants) l For the insulin pump schema, for example, it is always true that:  The dose must be less than or equal to the capacity (= level) of the insulin reservoir.  No single dose may be more than 4 units of insulin and the total dose delivered in a time period must not exceed 25 units of insulin. This is a safety constraint.  display2! shows the amount of insulin to be delivered.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 35 Insulin pump schema predicate

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 36 The dosage computation l The insulin pump computes the amount of insulin required by comparing the current reading with two previous readings. l If these suggest that blood glucose is rising then insulin is delivered. l Information about the total dose delivered is maintained to allow the safety check invariant to be applied. l Note that this invariant always applies - there is no need to repeat it in the dosage computation.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 37 RUN schema operations change state imports state & predicates x ′ - value of x after operation

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 38 RUN schema (cont'd)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 39 Sugar OK schema

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 40 Specification via Pre- and Post- Conditions l Predicates that (when considered together) reflect a program’s intended functional behavior are defined over its state variables. l Pre-condition: expresses constraints on program variables before program execution. An implementer may assume these will hold BEFORE program execution.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 41 Specification via Pre- and Post- Conditions (cont’d) l Post-condition: expresses conditions / relationships among program variables after execution. These capture any obligatory conditions AFTER program execution. l Language: predicate calculus  Predicates (X>4)  Connectives ( &, V, →, , NOT)  Universal and existential quantifiers (“for every…”, “there exists…”)  Rules of inference (if A & (A → B) then B)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 42 Example 1 Sort a non-empty array LIST[1..N] into increasing order. Pre-cond: N ≥ 1 Post-cond: For_Every i, 1 ≤ i ≤ N-1, LIST[i] ≤ LIST[i+1] & PERM(LIST,LIST’)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 43 Example 2 Search a non-empty, ordered array LIST[1..N] for the value stored in KEY. If present, set FOUND to true and J to an index of LIST which corresponds to KEY. Otherwise, set FOUND to false.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 44 Example 2 Pre-cond: N ≥ 1 & [(“LIST is in increasing order”) V (“LIST is in decreasing order”)] (Exercise: express the “ordered” predicates above FORMALLY.) Post-cond: [(FOUND & There_Exists i, 1 ≤ i ≤ N | J=i & LIST[J]=Key) V (NOT FOUND & For_Every i, 1 ≤ i ≤ N, LIST[i]≠KEY)] & UNCH(LIST,KEY)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 45 Exercise l See PRE- AND POST-CONDITION SPECIFICATION EXERCISE on course website

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 46 Key points l Formal system specification complements informal specification techniques. l Formal specifications are precise and unambiguous. They remove areas of doubt in a specification. l Formal specification forces an analysis of the system requirements at an early stage. Correcting errors at this stage is cheaper than modifying a delivered system. (Cont’d)

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 47 Key points (cont’d) l Formal specification techniques are most applicable in the development of critical systems. l Algebraic techniques are particularly suited to specifying interfaces of objects and abstract data types. l In model-based specification, operations are defined in terms of changes to system state.

©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 48 Chapter 10 Formal Specification