Rajib Mall Lecture Notes
Rajib Mall Lecture Notes
Dr. R. Mall
some subtle problems may remain in the SRS document inconsistency, incompleteness, and ambiguity
SRS Document
For many types of projects subtle problems are acceptable For one class of projects called as safety-critical projects
even minor problems are not acceptable though might lead to later rework
Formal Specification
Any failure of a safety-critical product How can we ensure that specification is trouble free?
formal specification
Introduction
We will first discuss some important concepts in formal methods:
verify whether a specification is realizable, verify that an implementation satisfies its specification, prove properties of a system without necessarily running the system, etc.
Formal Methods
Each stage in this hierarchy:
Specification
Implementation an implementation Specification of its preceding stage. a specification of the Implementation Specification succeeding stage. Implementation
Specification
Implementation
Formal Methods
The mathematical basis of a formal method
provided by its specification language. two sets syn and sem, and a relation sat between them.
Formal Methods
The set syn is called the syntactic domain, The set sem is called the semantic domain The relation sat
is called the satisfaction relation.
Formal Methods
For a given specification syn, and model of the system sem, if sat(syn, sem):
syn is said to be the specification of sem sem is the specificand of syn
Syntactic Domains
The syntactic domain of a formal specification language consists of:
an alphabet of symbols a set of formation rules to construct wellformed formulas. The well-formed formulas are used to specify a system.
Semantic Domains
Formal techniques can have different semantic domains:
Abstract data type specification languages languages for specification of concurrent/distributed systems,etc.
Semantic Domains
Concurrent and distributed system specification languages are used to specify:
state-transition sequences, event sequences, synchronization trees, partial orders, etc.
Satisfaction Relation
Given the model of a system, it is important to determine:
whether an element of the semantic domain satisfies the specifications.
Model-Oriented Style
System specified by constructing its model:
in terms of mathematical structures:
tuples, relations, functions, sets, sequences, etc. Also, state machines, Petri nets, etc.
Property-oriented style
The system's behavior is defined indirectly:
by stating its properties:
usually in the form of a set of axioms. Examples: logic-based, algebraic specification, etc.
Property-oriented specification
Producing ==> No items exist for consumption consuming ==> Item exists for consumption
In a model-oriented approach:
Define the basic operations, p (produce) and c (consume). Then state that
S ==>S1+p, S1 ==> S+c.
Comparison
Property-oriented approaches are suitable for requirements specification:
model-oriented approaches are more suited to use in later phases of life cycle.
Comparison
Property-oriented approaches specify a system:
Comparison
Model-oriented methods do not support logical conjunctions (and) and disjunctions (or):
even minor changes to a specification may lead to drastic changes to the entire specification.
Operational Semantics
Operational semantics of a formal method:
the way it represents computations:
i.e. the exact sequence in which the different computations are carried out
Operational Semantics
There are different types of operational semantics:
according to what is meant by a single run of the system how the runs are grouped together to describe the behavior of the system.
Linear semantics
A run of a system:
described by a sequence (possibly infinite) of events or states. The concurrent activities are represented by non-deterministic interleavings of the atomic actions.
Branching semantics
The behavior of a system can be represented by a directed graph:
Nodes of the graph represent the possible states in the evolution of a system.
Branching semantics
Branching semantics
The descendants of each node of the graph:
represent states which can be generated by any of the atomic actions enabled at that state.
constrains some events to occur only after some other events have occurred; while the occurrence of other events is considered to be incomparable.
Merits of Formal Methods Facilitates precise formulation of specifications Formal specifications encourage rigor.
the process of developing rigorous specification is often more important than specification.
Merits of Formal Methods It is actually cost-effective to spend more effort at the specification stage.
Otherwise many flaws that go unnoticed will appear at later stages of software development.
Merits of Formal Methods For large and complex systems like real-time systems:
80% of project costs and most of cost overruns result from iterative changes required due to improper requirements specification.
formal specifications are precise can be used to mathematically reason about the properties of a specification
Merits of Formal Methods Informal specifications are useful in understanding a system and its documentation:
but they cannot serve as a basis of verification. Even carefully written informal specifications are prone to ambiguity and error.
provide immediate feedback on features of the specified system. The concept of executable specification is related to rapid prototyping.
Formal methods are difficult to learn and use. While using formal specifications
engineers tend to lose the overall perspective and get lost in the details.
Formal specifications:
General recommendation:
Mixed approach use formal techniques as a broad guideline for use of informal techniques.
but it is legitimate to apply informal reasoning in correctness arguments. Any doubt or query relating to an informal argument is resolved by formal proofs.
Axiomatic Specifications
Pre-conditions:
Post-conditions:
What are the requirements on the parameters of the function? What are the requirements when the function is completed?
Domain:
Co-domain (range):
What sort of things it acts upon? What sort of answer does it give?
Establish the range of input values over which the function should behave correctly:
establish input parameter constraints as a predicate.
returns array index of the number in array whose value equals key:
Example: Axiomatic Specification Function search(X: Integer Array; key: Integer): Integer pre: exists i in XFirst Xlast: x(i)=key post: X(search(X,key))=key and X=X Error: search(X,key)=Xlast+1
Algebraic Specification
Algebraic Specification Essentially algebraic specifications: define a system as a heterogeneous algebra; i.e a collection of different sets on which several operations are defined.
Traditional Algebra
Traditional algebra are homogeneous. A homogeneous algebra:
Algebraic Specification
In contrast, consider:
not homogeneous algebra, range of the length operation is the set of integers.
Algebraic Specification
Algebraic Specification
its signature, the involved operations, and their domains and ranges.
Algebraic Specification
Syntactic part
Names of different data types involved are listed Names of operators and their domains (signature) listed
Exception Section
Under normal conditions
the result of an operation may be of some sort. Under some exceptional conditions, the results may be something else.
Equations Section
meaning of interface procedures in terms of each other. Specifies what is always true about the behavior of operations.
each equation is implicitly universally quantified over all possible values of the variables. In simple words, holds good for all values of variables.
Algebraic Specification
Algebraic Specification
Algebraic specifications are usually presented in four parts:
types section exceptions section signature section rewrite rules section
Types Section
Types Section Lists:
sorts (or types) being specified sorts being imported Importing a sort:
Signature Section
Defines signatures of interface procedures:
stack element stack
e.g. PUSH takes a stack and an element and returns a new stack. push:
identify the set of required operations. e.g. for string identify operations:
create, compare, concatenate, length, etc.
Inspection Operations :
Operations which evaluate attributes of the sort, e.g., eval, get, etc.
A rule of thumb for writing algebraic specifications: first establish constructor and inspection operations
Example: Stack
Let us specify an unbounded stack supporting:
push, pop, newstack, top, empty.
Example: Stack
Types: defines stack uses boolean, element Exception: underflow, novalue
Example: stack
Syntax: push: pop:
Example: stack
top: stack element+{novalue} empty: stack boolean newstack:
stack
Equations: stack
pop(newstack)=underflow pop(push(s,e))=s top(newstack)=novalue top(push(s,e))=e empty(newstack)=true empty(push(s,e))=false
Rewrite rules
Empty(push(pop(push(newstack ,e1)),e2)):
you can eliminate the call on pop by observing:
it is of the form pop(push(s,e)).
Rewrite rules
After simplification:
empty(push(newstack,e1)) false
Algebraic Specification
For arbitrary algebraic equations:
If the r.h.s. of each rewrite rule has fewer terms than the left:
rewrite process must terminate.
convergence is undecidable.
Auxiliary Functions
Sometimes development of a specification requires:
to define the meaning of some interface procedures.
Bounded stack
In order to specify a bounded stack:
we need to make changes to different sections to include auxiliary functions.
Auxiliary Functions
Syntax: push: depth:
Auxiliary Functions
Equations:
depth(newstack)=0 depth(push(s,e))=depth(s)+1 push(s,e)=overflow if depth(s) >= Max
Example 2: coord
Types:
Example: coord
Signature:
create(integer,integer) coord X(coord) integer Y(coord) integer Eq(coord,coord) boolean
Example: coord
Rewrite rules:
X(create(x,y))=x Y(create(x,y))=y Eq(create(x1,y1),create(x2,y2)) = ((x1=x2) and (y1=y2))
Structured Specifications
Writing formal specifications is time consuming. To reduce effort, we need to reuse specifications:
instantiation of generic specifications incremental development of specifications
Summary
We started by discussing some general concepts in formal specification
techniques.
Summary
Formal specifications have several positive characteristics.
the major shortcoming of formal techniques is that they are hard to use.
Summary
It is possible that formal techniques will become more usable in future:
Summary
We discussed two sample specification techniques,
axiomatic specification algebraic specification give us a flavor of the issues involved in formal specification.