1 / 36

Formal Specifications

Formal Specifications. Formal Methods. Formal specification is part of a more general collection of techniques that are known as ‘formal methods’ These are all based on mathematical representation and analysis of software Formal methods include Formal specification

noah
Download Presentation

Formal Specifications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Formal Specifications

  2. Formal Methods • Formal specification is part of a more general collection of techniques that are known as ‘formal methods’ These are all based on mathematical representation and analysis of software • Formal methods include • Formal specification • Specification analysis and proof • Transformational development • Program verification

  3. Acceptance of Formal Methods • Formal methods have not become mainstream software development techniques as was once predicted • Other software engineering techniques have been successful at increasing system quality. Hence the need for formal methods has been reduced • Market changes have made time-to-market rather than software with a low error count the key factor. Formal methods do not reduce time to market • The scope of formal methods is limited. They are not well-suited to specifying and analyzing user interfaces and user interaction • Formal methods are hard to scale up to large systems

  4. Use of Formal Methods • Their principal benefits are in reducing the number of errors in systems so their main area of applicability is critical systems: • Air traffic control information systems • Railway signalling systems • Spacecraft systems • Medical control systems • In this area, the use of formal methods is most likely to be cost-effective • Formal methods have limited practical applicability

  5. Specification in the Software Process • Specification and designare inextricably mixed. • Architectural designis essential to structure a specification. • Formal specifications are expressed in a mathematical notation with precisely definedvocabulary, syntax and semantics.

  6. Specification and Design

  7. Specification in the Software Process

  8. Specification Techniques • Algebraic Approach • The system is specified in terms of its operations and their relationships • Model-Based Approach • The system is specified in terms of a state model that is constructed using mathematical constructs such as sets and sequences • Operations are defined by modifications to the system’s state

  9. Formal Specification Languages

  10. Z (“zed”) Notation • Formal specification language • most successful one -> easy to find faults, can prove correctness • Requires set theory, functions, and discrete math • also difficult to learn because of special symbols • Z specifications consists of 4 sections • given sets, data types, and constants • sets that get defined in detail • state definition • variable declarations & predicates that constrain values • initial state • operations

  11. Use of Formal Specification • Formal specification involves investing more effort in the early phases of software development This reduces requirements errors as it forces a detailed analysis of the requirements • Incompleteness and inconsistencies can be discovered and resolved!!! Hence, savings as made as the amount of rework due to requirements problems is reduced

  12. Development Costs with Formal Specification

  13. Interface Specification • Large systems are decomposed into subsystems with well-defined interfaces between these subsystems • Specification of subsystem interfacesallows independent development of the different subsystems • Interfaces may be defined as abstract data types or object classes The algebraic approach to formal specification is particularly well-suited to interface specification

  14. Sub-System Interfaces

  15. The Structure of an Algebraic Specification < SPECIFICA TION NAME > (Gener ic P ar ameter) sort < name > introduction imports < LIST OF SPECIFICA TION NAMES > description Inf or mal descr iption of the sor t and its oper ations Oper ation signatures setting out the names and the types of signature the parameters to the operations defined over the sort Axioms defining the oper ations o v er the sor t axioms

  16. Specification in Z • Scenario: We maintain a membership list and an associated phone database. [Person, Phone] |----PhoneDB----------------------------------- |members: P Person (‘set of’ person) |phones : Person  Phone (relation) |------------------------------------------------------- |dom phones ⊆ members (invariant) |---------------------------------------------------

  17. Z Operation: Assign a Phone • Scenario: Someone would like a phone. (Note: Missing precondition) |----Assign----------------------------------- | p? : Person; n? : Phone |  PhoneDB |------------------------------------------------------- | phone’ = phone union  { p?  n? } | members’ = members |---------------------------------------------------

  18. Example • members  {jim, sue} • phones {(jim, 1231), (sue, 3956)} • Assign(alice, 1231) • Cool Z property: Can calculate minimal preconditions!! • Simple analysis: Leave out preconditions and find minimum constraint to maintain invariants!

  19. Behavioural Specification • Algebraic specificationcan be cumbersome when the object operations are not independent of the object state • Model-based specificationexposes the system state and defines the operations in terms of changes to that state

  20. Abstract State Machine Language (AsmL) • AsmL is a language for modeling the structure and behaviour of digital systems • AsmL can be used to faithfully capture the abstract structure and step-wise behaviour of any discrete systems, including very complex ones such as: Integrated circuits, software components, and devices that combine both hardware and software

  21. Abstract State • An AsmL modelis said to be abstractbecause it encodes only those aspects of the system’s structure that affect the behaviour being modeled The goal is to use the minimum amount of detail that accurately reproduces (or predicts) the behaviour of the system • Abstractionhelps us reduce complex problems into manageable units and prevents us from getting lost in a sea of details AsmL provides a variety of features that allow you to describe the relevant state of a system in a very economical, high-level way

  22. Abstract State Machine and Turing Machine • An abstract state machine is a particular kind of mathematical machine, like the Turing machine (TM) • But unlike a TM, ASMs may be defined a very high level of abstraction • An easy way to understand ASMs is to see them as defining a succession of states that may follow an initial state

  23. paint in green A B paint in red State Transitions • The behaviour of a machine (its run) can always be depicted as a sequence of states linked by state transitions • Moving from state A to state B is a state transition

  24. Configurations • Each state is a particular “configuration” of the machine • The state may be simple or it may be very large, with complex structure • But no matter how complex the state might be, each step of the machine’s operation can be seen as a well-defined transition from one particular state to another

  25. paint in green A B paint in red Evolution of State Variables We can view any machine’s state as a dictionary of (Name, Value) pairs, called state variables (Colour, Red) is a variable, where “Colour” is the name of variable, “Red” is the value

  26. Evolution of State Variables • Names are given by the machine’s symbolic vocabulary • Valuesare fixed elements, like numbers and strings of characters The run of a machine is a series of states and state transitions that results from applying operations to each state in succession

  27. S1 Mode = “Initial” Orders = 0 Balance = $0 S3 Mode = “Final” Orders = 0 Balance = $500 S2 Mode = “Active” Orders = 2 Balance = $200 Initialise Process All Orders Example Diagram shows the run of a machine that models how orders might be processed • Each transition operation: • can be seen as the result of invoking the machine’s control logicon the current state • calculates the subsequence state as output

  28. Control Logic The machine’s control logic behaves like a fix set of transition rules that say how state may evolve Typical form of the operational text is: “ if condition then update ” We can think of the control logic as a text that precisely specifies, for any given state, what the values of the machine’s variables will be in the following step

  29. The Machine’s Control Logic … if mode = “Initial” then mode := “Active” Control Logic as a Black Box • The two dictionaries S1 and S2 have the same set of keys, but the values associated with each variable name may differ between S1 and S2 • The machine control logic is a black box that takes as input a state dictionary S1 and gives as output a new dictionary S2 input output

  30. Run of the Machine • The run of the machine can be seen as what happens when the control logic is applied to each state in turn • The run starts form initial state S1  S2  S3  … S1 is given to the black box yielding S2, processing S2 results in S3, and so on … • When no more changes to state are possible, the run is complete

  31. Update Operations • We use the symbol “: =” (reads as “gets”) to indicate the value that a name will have in the resulting state For example: mode:=“Active” • Update can be seen only during the following step (this is in contrast to Java, C, Pascal, …) • All changes happen simultaneously, when you moving from one step to another. Then, all updates happen at once. (atomic transaction)

  32. Programs Example 1. Hello, world Main() step WriteLine(“hello, world!”) ASML uses indentations to denote block structure, and blocks can be places inside other blocks Statement block affect the scope of variables White space includes blanks and new-line character, ASML does not recognize tab character for indentation!!!!!!! An operation names run() gives the top-level operational definition of the model (Main() is like main() in Java and C )

  33. Example 2. Reading a File var F as File? = undef var Fcontents as String = “” var Mode as String = “Initial” Main() step until fixpoint if Mode = “Initial” then F :=open(“mfile.txt”) Mode :=“Reading” if Mode = “Reading” and length(FContents) =0 then FContents :=fread (F,1) if Mode = “Reading” and length(FContents) =1 then FContents := FContents + fread (F,1) if Mode = “Reading” and length(FContents) >1 then WriteLine (FContents) Mode :=“Finished”

  34. S1 F= undef Fcontents =“” Mode = Initial S3 F= <open file 1> Fcontents =“a” Mode = Reading S2 F= <open file 1> Fcontents =“” Mode = Reading S4 F= <open file 1> Fcontents =“ab” Mode = Reading S5 F= <open file 1> Fcontents =“ab” Mode = Finished Example 2. Graph Representation Step 1 Step 2 Step 3 Step5 Step 4

  35. Key Points • Formal system specification complements informal specification and modeling techniques. • Formal specifications are precise and unambiguous. They remove areas of doubt in a specification, but still depend on interpretation of terms, inputs and outputs. • Formal specification forces a very detailed analysis of the system requirements at an early stage. Correcting errors at this stage is cheaper.

  36. Key Points • Formal specification techniques are most applicable in the development of critical systems and standards. • Algebraic techniques are suited to interface specification where the interface is defined as a set of object classes. • Model-based techniques model the system using sets and functions. This simplifies some types of behavioural specification. • Its not for the faint of heart, you’ll need some special training to go down this path.

More Related