Docsity

Formal Specification of Software: Importance and Challenges - Prof. John Knight, Study notes of Computer Science

Toggle sidebar
bg1
Dependablel Computing
CS686 Fall 2007 1
Formal Specification © John C. Knight 2009, All Rights Reserved 1
Formal Software Specification
Formal Specification © John C. Knight 2009, All Rights Reserved 2
System
Design
Software
Specification
Remember,
software
specification
derives from
system
design.
Software Specification
Formal Specification © John C. Knight 2009, All Rights Reserved 3
What Goes Wrong?
Ambiguity:
“You meant what exactly??”
Incompleteness:
“You didn’t say what to do for that input.”
“It seemed like the right thing to do with that
condition.”
Inconsistency:
“When the user selects this menu item, do this.”
....
“If the user selects this menu item, do that.”
Formal Specification © John C. Knight 2009, All Rights Reserved 4
What Goes Wrong?
Wrong functionality:
“But we always display a dancing pig on the screen
when the aircraft misses the carrier deck. What are we
supposed to do?”
Naivety:
“Implement a company wide e-mail system on that 10-
year-old PC in the corner.”
Etc.
Software engineers are not qualified to make
important decisions about functionality.
Formal Specification © John C. Knight 2009, All Rights Reserved 5
Real Specification
As Opposed To Class Assignments
Real specifications are:
Large
Complex
Difficult to write correctly
Difficult to write clearly
In practice, specifications are:
Incomplete
Erroneous
Ambiguous
Often ignored
Let’s look at some real requirements
Formal Specification © John C. Knight 2009, All Rights Reserved 6
Pacemaker/Defib. Requirements
“The Guidant VENTAK® PRIZM™ AICD
automatic implantable cardioverter
defibrillators are designed to detect and
terminate ventricular tachycardia (VT) and
ventricular fibrillation (VF) and provide
bradycardia therapy (atrial and/or
ventricular pacing). Therapies include both
low- and high-energy shocks using either a
biphasic or monophasic waveform.”
pf3
pf4
pf5

Partial preview of the text

Download Formal Specification of Software: Importance and Challenges - Prof. John Knight and more Study notes Computer Science in PDF only on Docsity!

Formal Specification © John C. Knight 2009, All Rights Reserved 1

Formal Software Specification

Formal Specification © John C. Knight 2009, All Rights Reserved 2

SystemDesign

Software

Remember, Specification

software specification

derives from

system design.

Software Specification

Formal Specification © John C. Knight 2009, All Rights Reserved 3

What Goes Wrong?

„ Ambiguity:

„ “You meant what exactly??”

„ Incompleteness:

„ “You didn’t say what to do for that input.”

„ “It seemed like the right thing to do with that

condition.”

„ Inconsistency:

„ “When the user selects this menu item, do this.”

“If the user selects this menu item, do that.”

Formal Specification © John C. Knight 2009, All Rights Reserved 4

What Goes Wrong?

„ Wrong functionality:

„ “But we always display a dancing pig on the screen

when the aircraft misses the carrier deck. What are we

supposed to do?”

„ Naivety:

„ “Implement a company wide e-mail system on that 10-

year-old PC in the corner.”

„ Etc.

Software engineers are not qualified to make

important decisions about functionality.

Real Specification

As Opposed To Class Assignments

„ Real specifications are:

„ Large

„ Complex

„ Difficult to write correctly

„ Difficult to write clearly

„ In practice, specifications are:

„ Incomplete

„ Erroneous

„ Ambiguous

„ Often ignored

Let’s look at some real requirements

Pacemaker/Defib. Requirements

“The Guidant VENTAK® PRIZM™ AICD

automatic implantable cardioverter

defibrillators are designed to detect and

terminate ventricular tachycardia (VT) and

ventricular fibrillation (VF) and provide

bradycardia therapy (atrial and/or

ventricular pacing). Therapies include both

low- and high-energy shocks using either a

biphasic or monophasic waveform.”

Formal Specification © John C. Knight 2009, All Rights Reserved 7

„ Monitoring the heart:

„ Pacingas necessary

„ Defibrillatingas necessary

„ Operational parameterization

„ Communication with “programmer”

„ Hardware fault tolerance management

„ Extensive patient data recording

Pacemaker/Defib. Requirements

Formal Specification © John C. Knight 2009, All Rights Reserved 8

Pacemaker/Defibrillator

Images courtesy of Guidant Corporation

Formal Specification © John C. Knight 2009, All Rights Reserved 9

Why Do Software Systems Fail?

To a first approximation, requirements

specification is the dominant source of

problems in safety-critical and high-

assurance software systems

Formal Specification © John C. Knight 2009, All Rights Reserved 10

Why Do Software Systems Fail?

„ “Majority of safety-critical defects derive

from poor requirements” --Lutz

„ “Majority ofall defects derive from poor

requirements” --AF Rome

Laboratory

„ “The hardest single part of building a

software system is deciding precisely what

to build” --Brooks

Why Do Software Systems Fail?

„ “It is not the internal complexity of a module

but the complexity of the module’s connection

to its environment that yields the persistent

safety-related errors seen” --Lutz

„ “More has been screwed up on the battlefield

and misunderstood at the Pentagon because

of the lack of understanding of the English

language than any other single factor”

--Vessey

Why Are Specifications Important?

Formal Specification © John C. Knight 2009, All Rights Reserved 19

Notations For Formal Specification

„ Any notation with precise semantics can be used

„ Formalism typically applied to just part of a

specification

„ Notations use discrete mathematics, some graphics

„ Several notations are sometimes used in the same

specification:

„ Z or VDM for data manipulation

„ Statecharts for system states and transitions

„ Natural language for non-functional specifications

Formal Specification © John C. Knight 2009, All Rights Reserved 20

Formal Specification

„ There are lots of good notations, e.g.:

• PVS

• Statecharts

• Z

• SCR

• RSML

• Larch

„ Benefits of use turn out to be:

„ Communication

„ Analysis

„ Clearer thinking by specifier

Formal Specification © John C. Knight 2009, All Rights Reserved 21

Recall—Formal Specification

Formal

Specification

Type Checking

Syntax Checking

Putative Theorems

Establish useful properties

of the specification

Improved accuracy

and completeness

Improved

understanding

Reader

Author

Formal Specification © John C. Knight 2009, All Rights Reserved 22

Formal Specification

„ Goals of formal specification:

„ Complete, consistent, concise, unambiguous

specifications

„ Valid specifications—state exactly what the

user wants

„ Specifications based on formal semantic model

„ Formal semantics permitdependable

communication between all parties

„ Case studies show a variety of advantages

Types Of Languages

„ Procedural :

„ Computation defined by desired sequence of actions

computer is to perform

„ Most high-level languages are procedural

„ Declarative :

„ Computation defined by desired state that computer

should be in

„ Many specification languages are declarative

„ Functional :

„ Computation defined as desired function computer is to evaluate

„ Most functional languages derive from LISP

„ High-level language programs are actually

specifications!

„ Compilers write the program for you

„ So you have been specifying programs, not writing them

„ The big difference in languages is:

„ Declarative:

„ Says nothing about HOW , just WHAT

„ Procedural:

„ Says nothing about WHAT , just HOW

Types Of Languages

Formal Specification © John C. Knight 2009, All Rights Reserved 25

Types Of Languages—Examples

„ Procedural:

integer y; read (x); if x > 0 then y := x; while y**2 > x loop y := y – 1; end loop; print (y);

„ Declarative:

integer y; x > 0 AND y2 <= x AND (y+1)2 > x

„ Natural language:

The program shall read one positive input and write one output

that is the integer square root of the input. The output squared

shall be less than or equal to the input and the output+1 squared shall be greater than the input.

Formal Specification © John C. Knight 2009, All Rights Reserved 26

Model-Based Specification

„ Do not confuse with model-based development

„ Literally build a model of the system you want

„ Components:

„ System state Sets and functions

„ State changes Pre- & Post Conditions

Predicate Calculus

„ A model-based specification is much like a program

But a model-based specification is NOT

a procedural program

Formal Specification © John C. Knight 2009, All Rights Reserved 27

Model-Based Specifications

Operation Name

& Pre/Post Condx

(Pred Calculus)

Pre Condition

What Has To Be TrueBefore An Operation Can Be Applied

Post Condition

What Has To Be TrueAfter An Operation Is Applied

REALLY Important REALLY Important

State Description

(Sets, relations, etc)

Invariants (Predicate Calculus)

Formal Specification © John C. Knight 2009, All Rights Reserved 28

General Forms

Sets

Relations

Functions

Bags

System State

Preconditions

Postconditions

(Predicates)

System Operation

Similar To

Variables

Methods

Specification Programming

When = Means Equals

„ In procedural language, assignment means:

„ Use values of variables on RHS to compute value of

variable on LHS

„ Example: a := b + c;

„ What about: a := a + b;

„ Old value of a used to compute new value

„ There are two as

„ Declarative languages have predicates with

equality , not assignment

When = Means Equals

„ In operations, need to be able to refer to:

„ Before state values for preconditions

(what must be true before operation is applied)

„ After state values for postconditions

(what must be true after operation is applied)

„ Special notation,primed variables:

„ Variable name is before state

„ Variable name ’ is after state

„ Example:

„ Precondition: a < 10

„ Postcondition: a’ = a + b

Predicates!

Note!

Not

Assignment

Formal Specification

State upon which operations act:

Autopilot

Desired_Alt?, Actual_Alt? : £

Elev_setting! : £ Maximum_error : £

Iterative development!

„ Development process:

„ Define main part of state

„ Add operations in partial form

„ Expand both as specification issues become clearer

Formal Specification

ControlAC

Single operation:

((Actual_Alt? < (Desired_Alt? - Max_error) Û Elev_setting! = 1) Ú

(Actual_Alt? > (Desired_Alt? + Max_error) Û Elev_setting! = -1)

Ú (Actual_Alt? < (Desired_Alt? + Max_error) Ù Actual_Alt? > (Desired_Alt? - Max_error) Û Elev_setting! = 0))

óAutopilot