Software Engineering I 1 Formal Methods: Requirements Techniques Formal Requirements Techniques – Finite State Machines – Petri Nets.

Slides:



Advertisements
Similar presentations
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
Advertisements

Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
LIFE CYCLE MODELS FORMAL TRANSFORMATION
Software system modeling
Requirement Analysis and Specification Mr. Manoj Kumar Kar.
Background information Formal verification methods based on theorem proving techniques and model­checking –to prove the absence of errors (in the formal.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor Formal Methods in Software Engineering1.
Software Testing and Quality Assurance
CSC 402 Requirements Engineering 1 Requirements Techniques, cont. Formal requirements analysis techniques include: – DFD (covered) – ERD (covered) – Finite.
Software Requirements
©Ian Sommerville 2000Software Engineering, 6/e, Chapter 91 Formal Specification l Techniques for the unambiguous specification of software.
Requirements Techniques, cont. Brief review Formal Requirements Techniques –Finite State Machines –Petri Nets.
Chapter 1 Principles of Programming and Software Engineering.
Describing Syntax and Semantics
School of Computer ScienceG53FSP Formal Specification1 Dr. Rong Qu Introduction to Formal Specification
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 10 Slide 1 Formal Specification.
S R S S ystem R equirements S pecification Specifying the Specifications.
©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.
Formal Methods 1. Software Engineering and Formal Methods  Every software engineering methodology is based on a recommended development process  proceeding.
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
The Software Development Life Cycle: An Overview
Requirements Expression and Modelling
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques for the unambiguous specification of software.
©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 1 Chapter 10 Formal Specification.
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
Requirements Definition and Specification. Outline Definition and specification Natural language Semi-formal techniques –Program description languages.
Introduction to Formal Methods Based on Jeannette M. Wing. A Specifier's Introduction to Formal Methods. IEEE Computer, 23(9):8-24, September,
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.
Approaching a Problem Where do we start? How do we proceed?
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Formal Verification Lecture 9. Formal Verification Formal verification relies on Descriptions of the properties or requirements Descriptions of systems.
Requirements Engineering Methods for Requirements Engineering Lecture-30.
Topic 5Summer ICS 52: Introduction to Software Engineering Lecture Notes for Summer Quarter, 2003 Michele Rousseau Topic 5 Partially based on lecture.
Requirements Specification. Welcome to Software Engineering: “Requirements Specification” “Requirements Specification”  Verb?  Noun?  “Specification”
1 Software Requirements l Specifying system functionality and constraints l Chapters 5 and 6 ++
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
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.
Formal Methods.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Architecture View Models A model is a complete, simplified description of a system from a particular perspective or viewpoint. There is no single view.
Formal Specification: a Roadmap Axel van Lamsweerde published on ICSE (International Conference on Software Engineering) Jing Ai 10/28/2003.
Formal Verification. Background Information Formal verification methods based on theorem proving techniques and model­checking –To prove the absence of.
Duminda WijesekeraSWSE 623: Introduction1 Introduction to Formal and Semi- formal Methods Based on A Specifier's Introduction to Formal Methods (J. Wing)
21/1/ Analysis - Model of real-world situation - What ? System Design - Overall architecture (sub-systems) Object Design - Refinement of Design.
©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 1 Chapter 10 Formal Specification.
Requirement Analysis SOFTWARE ENGINEERING. What are Requirements? Expression of desired behavior Deals with objects or entities, the states they can be.
1 Specification A broad term that means definition Used at different stages of software development for different purposes Generally, a statement of agreement.
Daniel Amyot, University of Ottawa Based on Powerpoint slides by Gunter Mussbacher (2009) with material from: Jo Atlee, Dan Berry (both University of Waterloo);
1 CEN 4020 Software Engineering PPT4: Requirement analysis.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Miguel Garzón, University of Ottawa Based on Powerpoint slides by Gunter Mussbacher (2009) with material from: Jo Atlee, Dan Berry (both University of.
1 Software Requirements Descriptions and specifications of a system.
Requirements Specification
Formal Specification.
Introduction to Formal Methods
Requirements Techniques, cont.
System Requirements Specification
Department of Computer Science Abdul Wali Khan University Mardan
Software system modeling
Presentation transcript:

Software Engineering I 1 Formal Methods: Requirements Techniques Formal Requirements Techniques – Finite State Machines – Petri Nets

Software Engineering I 2 Requirements Describe the “What” not the “How” – about phenomena of the appl. domain (not the machine) Requirements documents – Serve as a contract between client and developer – Identify functional capabilities of a system – Identify non-functional and environmental constraints A variety of techniques can be used to develop requirements specifications – natural language, data-flow diagrams, ER diagrams, etc...

Software Engineering I 3 Finite State Machines A requirements technique for modeling the states and transitions of a software system Finite state machines are used in other contexts – automata theory and compilers, for example More precise than data-flow diagrams – since data-flow diagrams specify only the nature of a system’s data flow (e.g. the what and the where) – whereas finite state machines provide information on how a system progresses from state to state

Software Engineering I 4 Formal Definition The definition of a finite state machine (FSM) consists of five parts – a set of states – a set of inputs – a transition function – the initial state – a set of final states

Software Engineering I 5 Simple Example States of a combination lock for a safe – Safe has a dial with three positions (1, 2, & 3) – The dial can be turned in two possible directions ¤ At any point six possible motions Turn left to 1 (1L) Turn right to 1 (1R) etc... – Combination is 1L, 3R, 2L – The possible states include the safe being locked and unlocked, sounding the alarm, and the steps along the combination (e.g. 1L and 3R)

Software Engineering I 6 Example, cont. Set of States (Locked, A, B, Unlocked, Alarm) Set of Inputs (1L, 1R, 2L, 2R, 3L, 3R) Transition Function (next two slides) Initial State (Locked) Final States (Unlocked, Alarm)

Software Engineering I 7 Example, cont. alarm lockedabunlocked 1L3R2L XXX any other input initial state final state X

Software Engineering I 8 Transition Table Input 1L 1R 2L 2R 3L 3R Locked A Alarm A B B Unlocked

Software Engineering I 9 Finite State Machine Wrap-Up More advanced examples in other textbooks – The infamous “Elevator Example” is a good one (Schach) Demonstrates – The specification power of FSMs Typical Problem – The number of states and transitions grows rapidly in large systems – Approach: decompose problem into smaller subsystems Tool support exists for this and related techniques (e.g. statecharts)

Software Engineering I 10 Petri Nets A formal technique suited for specifying the properties of concurrent or multithreaded systems Typical concurrency problems – race conditions ¤ X accesses Y before Z updates it – deadlock ¤ X is waiting on Y which is waiting on X Petri nets can be used to help avoid ambiguity in specifications that can lead to this class of problems in multithreaded systems

Software Engineering I 11 Formal Definition of Petri Nets A Petri net consists of four parts – A set of places – A set of transitions – An input function – An output function In the subsequent diagrams, the input and output functions are represented by arrows

Software Engineering I 12 Petri Net Parts Place Transition Token

Software Engineering I 13 Firing a transition A transition fires when it has a token at each input place; as a result a token is placed at each output place.

Software Engineering I 14 Simple Example A server cannot send an event to a client until the client has indicated that it is ready to receive one Approach – Map states into places – Map events into transitions States – Event waiting – Event received – Event processed – Client Ready Events – Generate Event – Send Event – Process Event – Notify server

Software Engineering I 15 Example, cont. Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server Three events; one being received

Software Engineering I 16 Example, cont. Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server An event gets generated

Software Engineering I 17 Example, cont. Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server An event gets processed; waiting event must wait since “Send Event” cannot fire.

Software Engineering I 18 Example, cont. Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server Another event gets generated

Software Engineering I 19 Example, cont. Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server The client notifies the server

Software Engineering I 20 Example, cont. Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server An event is sent...

Software Engineering I 21 Example, cont. Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server Second event is processed...

Software Engineering I 22 Example, cont. Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server The client notifies the server

Software Engineering I 23 Example, cont. Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server Final event is sent...and eventually processed

Software Engineering I 24 Final State Event GeneratorEvent WaitingEvent ReceivedEvent Processed Client Ready Generate Event Send Event Process Event Notify Server Client is ready for next event

Software Engineering I 25 Petri Net Wrap-Up Clean notation for specifying concurrent properties Graphical notation hides underlying formalism – Makes it easier to understand Tool support and execution engines exists for this technique – The latter can help in testing how well a Petri net specifies a property by running it on test cases

Software Engineering I 26 Overview - Formal Specifications Introduction to Formal Methods and Formal Specification Types of Formal Specification Abstract Model Specifications State Transition Specifications Algebraic Specifications Axiomatic Specifications

Software Engineering I 27 SpecificationImplementation synthesis analysis modeling What are Formal Methods? Formal Method (FM) = – specification language + formal reasoning Body of techniques supported by – precise mathematics – powerful analysis tools Rigorous effective mechanisms for system – modeling – synthesis – analysis

Software Engineering I 28 Formal Specifications: what and why? Use of formalisms – e.g., logic, discrete mathematics, finite state machines To describe systems – e.g., system models, constraints, specifications, designs For broad range of effects – e.g., highly reliable, secure, safe systems and more effective production With varying levels of use – guidance: structuring what to say – documentation: unambiguous communication – rigor: formal specification and proofs – mechanisms: proof assistance, testing

Software Engineering I 29 Formal Specification in Software Development Formal specifications ground the software development process in the well-defined basis of computer science Orientation goes from customer to developer Formal specification expressed in language whose syntax and semantics are formally defined – hierarchical decomposition – mathematical foundation – graphical presentation – accompanied by informal description

Software Engineering I 30 Goals and Objectives Requirements Specification – clarify customer's requirements – reveal ambiguity, inconsistency, incompleteness System/Software Design – decomposition structural specifications of component relations and behavioral specification of components – refinement demonstrating that next level of abstraction satisfies higher level Verification – proving a realization satisfies its specification Validation – testing and debugging Documentation – communication between specifier, implementor, customer, clients

Software Engineering I 31 Specification and Design Requirements- Analysis and Definition Requirements- Specification Design Increasing contractor involvement Decreasing client involvement Increasing formalism possible DESIGN SPECIFICATION

Software Engineering I 32 Benefits of Using Formal Specifications and Methods higher quality software verifiability of implementation insight and understanding minimized maintenance and cost automated assistance simulation, animation, execution formal analysis guidance for testing transformation technology reduced liability and risks standards satisfaction

Software Engineering I 33 Formal Methods are not yet widely used Reasons – emerging technology with unclear payoff – little experience – lack of automated support – not especially user friendly – too many in-place techniques and tools Excuses – high learning curve – mathematical sophistication required – techniques not widely applicable – ignorance of advances

Software Engineering I 34 Desirable Properties of Formal Specifications Consistency – an implementation exists that satisfies a specification Complete (incrementally) – all required aspects are specified Unambiguous – all implementations that satisfy the specification are satisfactory (tradeoffs with completeness) Inference – consequence relation used to prove properties about the implementations that satisfy a specification

Software Engineering I 35 Types of Formal Specifications Behavioral specifications describe constraints on behavior of implementation – e.g., – functionality – safety – security – performance Structural specifications describe constraints on internal composition of implementation – module interconnection – uses and is-composed-of – dependence relations

Software Engineering I 36 Characteristics of Specification & Support Model-oriented specifications – specify system behavior by constructing a model in terms of well- defined mathematical constructs Property-oriented specifications – specify system behavior in terms of properties that must be satisfied Visual specifications – specify system behavior and structure by graphical depictions Executable specifications – specify system behavior completely enough that specifications can run on a computer Tool support – syntactic checking – model checking – proof checking

Software Engineering I 37 Basic Types of Behavioral Specification Abstract Model Specifications – defines operations in terms of well-defined mathematical model Algebraic Specifications – defines operations by a collection of equivalence relations State Transition Specifications – defines operations in terms of states and transitions Axiomatic Specifications – defines operations by logical assertions

Software Engineering I 38 Formal Specification Languages: Clock Example +Initially, the time is midnight, the bell is off, and the alarm is disabled. +Whenever the current time is the same as the alarm time and the alarm is enabled, the bell starts ringing. This is the only condition under which the bell begins to ring. +The alarm time can be set at any time. +Only when the alarm is enabled can it be disabled. +If the alarm is disabled while the bell is ringing, the bell stops ringing. +Resetting the clock and enabling or disabling the alarm are considered to be done instantaneously.

Software Engineering I 39 Abstract Model Specifications Explicitly describes behavior in terms of a model using well- defined types (sets, sequences, relations, functions) and defines behavior by showing effects on model – State is explicit in the model – Objects can be built hierarchically Specification includes – type: syntax of object being specified – model: underlying structure – invariant: properties of modeled object – pre/post conditions: semantics of operations Pros and Cons – may suggest an implementation – widely applicable because of modeling orientation Various notations: VDM, Z, RAISE

Software Engineering I 40 Abstract Model Specifications: Process using Z Specification using Z abstract model specifications – 1. establish the object schemas (objects and attributes) ¤ including invariant properties of objects – 2. establish the operation schemas ¤ schema modifiability ( delta vs. E schema) ¤ operation signatures (input? vs. output!) ¤ state modifications (attribute vs. attribute' )

Software Engineering I 41 Abstract Model Specifications: the Z Notation specification name [generic parameters] signature predicate a Z specification is a collection of schemas a schema introduces some entities and invariant properties the signature may make a defined schema visible the schema signature defines each entity's name and type (syntax) the predicate defines the relationships between the entities that must always hold (semantics) should be supported by informal description

Software Engineering I 42 Abstract Model Specifications: Z Clock BellStatus: {quiet, ringing}, AlarmStatus: {disabled, enabled} Clock time, alarm_time: N bell: BellStatus alarm: AlarmStatus InitClock  Clock (time = midnight)  (bell = quiet)  (alarm = disabled) Tick  Clock (time = succ(time)) (alarm_time = time)  (alarm = enabled) => (bell = ringing) (~((alarm_time = time)  (alarm = enabled)) => (bell = bell) (alarm = alarm)  (alarm_time = alarm_time)

Software Engineering I 43 SetAlarmTime  Clock new_time   alarm_time  new_time?) ((alarm_time = time)  (alarm = enabled) => (bell = ringing)(~((alarm_time = time)  (alarm = enabled)) => (bell = bell) (time = time)  (alarm = alarm) EnableAlarm  Clock (alarm = disabled) => (alarm = enabled)  ( (alarm_time= time) => (bell = ringing)  (~(alarm_time = time)) => (bell  = bell) )  (time  = time)  (alarm_time  = alarm_time) DisableAlarm  Clock (alarm = enabled) => (alarm = disabled)  (bell = quiet)  (time = time)  (alarm  = alarm)  (alarm_time  = alarm_time) Abstract Model Specifications: Z Clock, continued

Software Engineering I 44 State Transition Specifications Explicitly describes system behavior by a set of states and defines operations as transitions between states or observations on state Specification includes – states: possible values – transitions: semantics by state transformations and observations Pros and Cons – free of representational details (except augmentations) – state explosion is common – extensions to minimize states and modularize – particularly applicable to control systems, languages, hardware Graphical as well as textual notations: StateCharts, ASLAN, Paisley,InaJo, Special

Software Engineering I 45 State Transition Specifications: State Charts Clock off ringing CLOCK tickalarm up quiet on [alarm_time = time] enabled disabled time' := succ(time) time' := midnight gettime disabled

Software Engineering I 46 Algebraic Specification Objects specified as algebraic sorts in terms of equivalence relations between associated operations – State is concealed in objects – Objects can be built hierarchically Specification includes – functionality: syntax and legal constructions – relations: semantics by equivalence classes Pros and Cons – only pure functions described (no side effects) – supports extensibility of data abstractions – often hard to comprehend and construct Various notations: OBJ, Larch, Clear, Anna

Software Engineering I 47 Algebraic Specifications: Process Specification using algebraic sorts – 1. establish the sorts (objects and attributes) – 2. establish the necessary operations ¤ constructor operations ¤ access operations – 3. establish the equivalence relations ¤ rule of thumb: a relation for each access over each constructor ¤ simplified when constructors defined in terms of imports

Software Engineering I 48 Algebraic Specifications: a simple notation specification name (generic parameters) sort name imports list of specification names operation signatures relations an algebraic specification is a collection of sorts a sort specifies an object class (or abstract data type) importing specifications makes their defined sorts visible the operation signatures define each operation's name and the sorts of parameters and results (syntax) the relations define the effect of applying operations (semantics) should be supported by informal description

Software Engineering I 49 Algebraic Specifications: Algebraic CLOCK operation signatures – init: –> CLOCK – tick: CLOCK –> CLOCK – setalarm: CLOCK x TIME –> CLOCK – enable: CLOCK –> CLOCK – disable: CLOCK –> CLOCK – time: CLOCK –> TIME – alarm_time: CLOCK –> TIME – bell: CLOCK –> {ringing, quiet} – alarm: CLOCK –> {on, off}

Software Engineering I 50 Algebraic Specifications: Algebraic CLOCK, continued relations – time(init) –> midnight – time(tick(C)) –> time(C) + 1 – time(setalarm(C,T)) –> time(C) – time(enable(C)) –> time(C) – time(disable(C)) –> time(C) – alarm_ time(init) –> midnight – alarm_ time(tick(C)) –> alarm_ time(C) – alarm_ time(setalarm(C,T)) –> T – alarm_ time(enable(C)) –> alarm_ time(C) – alarm_ time(disable(C)) –> alarm_ time(C)

Software Engineering I 51 Algebraic Specifications: Algebraic CLOCK, continued axioms bell(init) –> quiet bell(tick(C)) –> (if alarm_time(tick(C)) = time(tick(C)) and alarm(C) = on then ringing else quiet) bell(setalarm(C,T)) –> (if T = time(C) and alarm(C) = on then ringing else quiet) bell(enable(C)) –> (if alarm_time(C) = time(tick(C)) then ringing else quiet) bell(disable(C)) –> quiet alarm(init) –> off alarm(tick(C)) –> alarm(C) alarm(setalarm(C,T)) –> alarm(C) alarm(enable(C)) –> (if alarm(C) = off then on) alarm(disable(C)) –> (if alarm(C) = on then off)

Software Engineering I 52 Axiomatic Specifications Implicitly defines behavior in terms of [first-order] logic formulas specifying input/output assertions Specification includes – operation interfaces: input/output parameters – operation axioms: pre/post assertions on input/output ¤ possibly also intermediate assertions Pros and Cons – fairly easy to understand – widely applicable (although hard to scale up) – most widely used technique in proving (inductive assertion method) – foundation of mathematics in software development Many languages support this type of specification: – VDM, Anna – Extensions include various logics for specific application domains (e.g., temporal logic: RTIL, GIL)

Software Engineering I 53 Axiomatic Specifications: VDM Clock INIT() ext wr time: N, bell: {quiet, ringing}, alarm: {disabled, enabled} pre true post (time = midnight)  (bell = quiet)  (alarm= disabled) TICK() ext wr time: N, bell: {quiet, ringing} rd alarm_time: N, alarm: {disabled, enabled} pre true post (time = succ(time))  (if (alarm_time = time)  (alarm = enabled) then (bell = ringing) else (bell = bell)

Software Engineering I 54 Axiomatic Specifications: VDM Clock, continued SETALARMTIME(new_time: N) ext wr alarm_time: N, bell: {quiet, ringing} rd time: N, alarm: {disabled, enabled} pre true post (alarm_time  new_time)  (if (alarm_time = time)  (alarm = enabled) then (bell = ringing) else (bell = bell) ENABLEALARM() ext wr alarm: {disabled, enabled}, bell: {quiet, ringing} rd time: N, alarm_time: N pre alarm = disabled post (alarm = enabled)  (if (alarm_time = time) then (bell = ringing) else (bell = bell) DISABLEALARM() ext wr alarm: {disabled, enabled}, bell: {quiet, ringing} pre alarm = enabled post (alarm = disabled)  (bell = quiet)

Software Engineering I 55 Axiomatic Specifications: GIL Clock Initialization: initially the alarm is disabled and the bell is off Won’t Ring: the bell is off from disabled to (enabled and time=alarm) Will Ring: the bell is on from (enabled and time=alarm) to disabled

Software Engineering I 56 Formal Specification Comparison Discussion Formal Specification Languages differ in the qualities and application domains for which they are best suited Axiomatic Specifications State Transition Specifications Abstract Model Specifications Algebraic Specifications