1 Introduction to Formal Methods Introduction to Formal Methods; Preconditions, Postconditions, and Invariants Revisited; Z language Example (Pressman)

Slides:



Advertisements
Similar presentations
CMSC 611: Advanced Computer Architecture
Advertisements

Addressing the Challenges of Current Software. Questions to Address Why? What? Where? How?
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
LIFE CYCLE MODELS FORMAL TRANSFORMATION
Software system modeling
ISBN Chapter 3 Describing Syntax and Semantics.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture 05.
The Z Specification Language
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor Formal Methods in Software Engineering1.
Introduction to Formal Methods
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 Formal Methods (continued) Formal Methods: Modifying a Formal Specification.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Developed by Robert Olson Chapter 28 Formal Methods.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
1 Introduction to Formal Methods Introduction to Formal Methods; Preconditions, Postconditions, and Invariants Revisited; Z language Example (Pressman)
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.
Software Issues Derived from Dr. Fawcett’s Slides Phil Pratt-Szeliga Fall 2009.
Formal verification Marco A. Peña Universitat Politècnica de Catalunya.
Principle of Functional Verification Chapter 1~3 Presenter : Fu-Ching Yang.
MCA –Software Engineering Kantipur City College. Topics include  Formal Methods Concept  Formal Specification Language Test plan creation Test-case.
What Exactly are the Techniques of Software Verification and Validation A Storehouse of Vast Knowledge on Software Testing.
Computer Science 340 Software Design & Testing Design By Contract.
1 These slides are designed to accompany Software Engineering: A Practitioner’s Approach, 7/e (McGraw-Hill 2009). Slides copyright 2009 by Roger Pressman.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1 Introduction to Software Engineering CEN 4010.
Formal Methods CIS 376 Bruce R. Maxim UM-Dearborn.
©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 1 Chapter 10 Formal Specification.
Verification and Validation Overview References: Shach, Object Oriented and Classical Software Engineering Pressman, Software Engineering: a Practitioner’s.
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.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Overview of Formal Methods. Topics Introduction and terminology FM and Software Engineering Applications of FM Propositional and Predicate Logic Program.
Foundations of Software Testing Chapter 1: Preliminaries Last update: September 3, 2007 These slides are copyrighted. They are for use with the Foundations.
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
1 C++ Plus Data Structures Nell Dale Chapter 1 Software Engineering Principles Modified from the Slides made by Sylvia Sorkin, Community College of Baltimore.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Formal Verification Lecture 9. Formal Verification Formal verification relies on Descriptions of the properties or requirements Descriptions of systems.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
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 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
Data Abstaraction Chapter 10.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Formal Methods in Software Engineering “And they made their lives bitter with hard bondage … all their service … was with rigour.” Ex 1:14.
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.
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Formal Methods in SE Software Verification Using Formal Methods By: Qaisar Javaid, Assistant Professor Formal Methods1.
Software Engineering 2 -Prakash Shrestha.
CSE Winter 2008 Introduction to Program Verification January 15 tautology checking.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
Computer Organization Instruction Set Architecture (ISA) Instruction Set Architecture (ISA), or simply Architecture, of a computer is the.
Requirements Engineering Methods for Requirements Engineering Lecture-31.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
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.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Chapter 25 Formal Methods. BASIC CONCEPTS A method is formal if it has a sound mathematical basis, typically given by a formal specification language.
Formal Specification.
Verification and Validation Overview
Unit# 8: Introduction to Computer Programming
Chapter 28 Formal Modeling and Verification
Intel Division Bug Scroll back to Autumn 1994 … The beginning…
Software system modeling
Presentation transcript:

1 Introduction to Formal Methods Introduction to Formal Methods; Preconditions, Postconditions, and Invariants Revisited; Z language Example (Pressman)

“engineering” hardware vs “engineering” software: example—a simple flipflop 2 clock D reset Q1 -- VHDL description of flipflop entity DFF is port (D, clock, reset: in std_logic; Q1: out std_logic;) end DFF: architecture behavior of DFF is begin process (reset, clock) begin if reset = ‘1’ then Q1 <= 0; elseif (clock ‘event and clock=‘1’) then Q1 <= D; endif; end process; end behavior; well-defined “part” with datasheet Just change one character…..

Software: ---is an abstract layer ---must be translated to hardware ---is very easily modified ---is often developed by a group ---often consists of multiple processes sharing resources What tools has “classical” software engineering developed to deal with the difficulties of producing robust software? 3

Some useful concepts: --“software life cycle” requirements  specifications  design  implement  test  maintain --well-defined development process matching project and resources --process maturity level: “CMM”—well-defined, improve each cycle --independence of testing, design for test, automated test --levels of development: system, unit (black box), code (glass box) --the object-oriented paradigm: promotes modularity, reuse, information hiding --design languages, e.g., Unified Modeling Language (UML) --”contracts”: preconditions, postconditions, invariants, “assert” precondition to divide: denominator is not zero postcondition to push onto stack: stack is not empty 4

But none of these “informal” tools or methods can guarantee fault-free software. For one thing, in most cases there is not enough time in the universe to test all possible states of a system and it may even be difficult to determine what “all possible states” are (“combinatorial explosion”: e.g., if there are n boolean inputs, there are 2 n possible states). Therefore, to increase the quality of software, we need to resort to “formal” methods, which are based on mathematics and are expressed in formal languages having well-defined syntax and semantics. The two main mathematical areas we need are Set theory: A ∩ B, A ∪ B, a ∉ X, ∅ Logic: ∄ n ∈ ℕ such that 0 × n = 2 5 ABAB

6 What are formal methods? Formal methods are mathematically based. They are an attempt to deal with contradictions, ambiguities, vagueness, incomplete statements, and mixed levels of abstraction. They are most valuable for systems which have: --safety concerns (e.g., airplane systems, medical devices) --security concerns

7 When are formal methods useful? Formal methods can be used to: --Mathematically PROVE correctness of a system --Reduce faults Formal methods can provide: --program specification: define program is supposed to do --program verification: PROVE program does what the specification says it will do Possible automated verification techniques: --automated theorem proving --model checking: exhaustively check all possible “states” of the model that has been developed

8 Formal techniques Formal techniques: --use set theory, logic to specify systems --increase probability of complete, consistent, unambiguous specifications --require specialized training for developers --have high start-up costs; may require high overhead; some concepts (e.g., timing, reliability) difficult or impossible to capture in formal systems --may be difficult for the customer to understand --do not replace more traditional approaches --may be “heavyweight” or “lightweight”

9 When are formal methods useful? Some examples*: --diagnosing subtle problems in a LAN recovery protocol --developing an aircraft collision avoidance system --developing process control systems --[hardware] verifying correct execution of Intel floating point hardware (formal methods adopted after the infamous Pentium division error incident) *G. Huling, Introduction to use of formal methods in software and hardware, WESCON/94, Sep 1994, pp , DOI /WESCON (available from IEEE Xplore) /WESCON Potentially useful for systems in domains such as: --security --avionics --medical devices

in 1994, Intel launched the first Pentium CPU, for use in personal computers this processor was the first Intel processor to incorporate a math coprocessor for floating-point arithmetic, or FPU –before that programs had to tell processors how to divide floating point numbers via integer arithmetic this was accomplished by providing instructions that were built into the FPU –much faster for numerical calculations Example: Intel Pentium Processor

this also makes the CPU more complex and expensive Intel produced these chips for almost a year before the error was caught and corrected the problem was that the FPU would incorrectly divide certain pairs of numbers –famous example is Coe’s numbers: – / –The answer is , while the Pentium returns (to 6 sig. figs) Example Continued

the error was discovered by Professor Nicely of Lynchburg College –he got values back from his Pentium machine which did not match his theoretical values, but his theoretical values matched values computed on a 486 machine. the probability of hitting input combinations to produce the error was tiny, but these inputs gave the wrong answer every time Example Continued

the divider in the FPU uses a radix 4 SRT algorithm –can compute two binary digits for a quotient every step, rather than one like other FPU’s this requires a stored division table, similar to a multiplication table –five values out of about a thousand were omitted from the table Reason for the Error

because the error was discussed in the academic community and the findings were posted on the web, this became a large story for the media –this subsequently caused bad publicity for Intel IBM halted the manufacture and sale of personal computers using the Pentium processor Intel was eventually forced to replace all bad Pentium chips for customers who wanted them replaced –this, along with having to perform changes to the hardware of the chip, cost Intel hundreds of millions of dollars (approx. $500 million) Consequences

just performing standard verification and testing of the system was not enough to catch this error –probability is very small and it is not possible to test all inputs to the chip if formal methods had been used from the beginning this error would have been caught –formal specifications and proofs would have shown which values should not have been allowed to be set to zero –this would have saved Intel money and corrected the error before it could ever become in error Why is this Important

today Intel uses formal specification and formal verification in their hardware design process –write all specifications in a formal language and then prove these specifications using an automated proof checker called HOL Light –incorporate verification algorithms such as square root and reciprocal algorithms which weed out errors like the one found in the Pentium FPU though this method is more tedious, it provides strict validation of the system, catching errors in the design before they become costly Intel Today

used by NASA to verify the software on the Deep Space 1 –spacecraft designed to test high risk technologies in deep space to lower costs and risks on future missions –formal methods verified the Remote Agent software found 5 concurrency errors in LISP that would not have been found otherwise and would have been fatal to the spacecraft an error occurred 24 hours after launch in software only tested using NASA’s test benchmark suite used in the development of Mondex –an electronic purse stored on a smart card –stores financial data for use in making transactions wirelessly Other Examples of Industrial Usage of Formal Methods

18 When are formal methods useful? “Heavyweight” formal methods vs “lightweight” formal methods (which use partial specification and focused application): “Many factors influence deciding when and where to use lightweight and heavyweight formal methods. For large complex projects, the application of a heavyweight formal method is virtually impossible thus the lightweight formal method is a good candidate. When we are dealing with safety-critical systems or even, perhaps, trusted systems (in the ISO sense), using the lightweight formal method is debatable. In these cases, it may be better to use a heavyweight formal specification and analysis if time and cost permit.” Application of Lightweight Formal Methods in Requirement Engineering1 V. George,and R. Vaughn, Crosstalk, The Journal of Defense Engineering accessed august 12, 2010

19 "Ten Commandments" of formal methods (Pressman, Software Engineering, A Practitioner's Approach): 1. Choose the appropriate notation 2. Formalize but don't overformalize 3. Estimate costs 4. Have a formal methods "guru" on call 5. Do not abandon traditional development methods 6. Document sufficiently 7. Don't compromise quality standards 8. Do not be dogmatic 9. Test, test, test, …. 10. Reuse

20 Preconditions, postconditions, invariants Earlier we looked at adding statements to ensure correct program behavior: precondition: logical condition that a caller of an operation guarantees before making the call postcondition: logical condition that an operation guarantees upon completion invariant: logical condition that is preserved by transformations These conditions are all expressed as logical statements --they can be quantified: --they can be used to support testing at different levels

21 We will also be concerned with how the STATE of a system or component changes: e.g., if the system or a component is in state S, it can be modified to a new state S’

22 What is Z? A complete formal system We will use an example formal specification language: Z system described through a set of "schemas”, which have data invariant(s) state(s)  S: represents change is state S; changed entity r is denoted by r’ operations-- with precondition(s) / postcondition(s)

23 Example (from Pressman, Software Engineering, A Practitioner’s Approach): “Block Handler” (note: this is just a simple example to demonstrate Z syntax, it is not meant to represent a “safety-critical system” which would be appropriate for strict formal specification) Unused (free) blocks Queued for entry into Unused Blocks released to queue when files deleted Used blocks

24 Z example (2) Z specification: BlockHandler used,free:  BLOCKS BlockQueue: seq P BLOCKS used  free =   used  free = AllBlocks   i: dom BlockQueue. BlockQueue i  used   i,j : dom BlockQueue. i  j  BlockQueue i  BlockQueue j = 

25 Some Z notation Z specification: BlockHandler used,free:  BLOCKS BlockQueue: seq P BLOCKS used  free =   used  free = AllBlocks   i: dom BlockQueue. BlockQueue i  used   i,j : dom BlockQueue. i  j  BlockQueue i  BlockQueue j =  set contained in and implies “then” in intersection for all empty set intersection union sequence

26 Z example (3) RemoveBlock  BlockHandler #BlockQueue > 0, used’ = used \ head BlockQueue  free’ = free  head BlockQueue  BlockQueue’ = tail BlockQueue AddBlock  BlockHandler Ablocks? : BLOCKS Ablocks?  used, used’ = used  free’ = free  BlockQueue’ = BlockQueue ^ (Ablocks?)

27 Modifications 1. What if BlockQueue is replaced by BlockStack? 2. What are postconditions for the operations?

28 Additional Z Notation

29 Z Sequence Notation

30 Z example revisited (1) Example (from Pressman, Software Engineering, A Practitioner’s Approach): “Block Handler” Unused (free) blocks Queued for entry into Unused Blocks released to queue when files deleted Used blocks

31 Modifying the example Examples: 1. Change BlockQueue to BlockStack: 2. Output size of BlockQueue in AddBlock or RemoveBlock 3. Make BlockQueue part of “free” instead of “used”

32 Modifying the example

33 Formal methods in project (exercise) Class exercise: --Describe a priority queue in Z notation --Are there operations you need which have not yet been defined in these slides on the Z notation?