1 / 65

Formal Specification Sets

Formal Specification Sets. Based on chapter 2 of Formal Specification Using Z David Lightfoot. Problems in the creation of computer systems.

raoul
Télécharger la présentation

Formal Specification Sets

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 Specification Sets Based on chapter 2 of Formal Specification Using Z David Lightfoot

  2. Problems in the creation of computer systems • There are long-standing problems in the development of computer systems: often they take too much time to produce, cost more than estimated and fail to satisfy the customer. Central to the problem is the fact that errors and inadequacies are more expensive to correct the later in the development process they are discovered. Furthermore, it is extremely difficult to clarify exactly what is required of a very complex system.

  3. Formal Specifications • Formal specifications use mathematical notation to describe in a precise way the properties which an information system must have. • The process of producing a formal specification for an information system has three major steps: • 1) We try to understand what the user requires. • 2) This understanding is then translated into a ‘formal specification’. • 3) We attempt to show that the specification does indeed capture the user requirement. • Given the informal nature of user requirements we may not identify or translate them correctly into our formal specification. Often use our intuition and experience for these two tasks.

  4. Formal Specifications • Since , by their very nature, user requirements must be expressed informally, there are no formal methods for showing that a specification satisfies the user requirements. However, we can convince ourselves that a specification is satisfactory by using the following techniques: • 1) Simply inspect the specification and see that it does meet the requirement. • 2)We can prove that the specification has certain properties which are are are to be expected of a solution to the problem. • Both of these activities are much simpler if we have an abstract specification. An abstract specification supplies essential information and is not oriented towards implementation. • These techniques are analogous to how any formalization of a mathematical concept is checked.

  5. Formal Specifications • When constructing a mathematical model of a real world systems there is a certain amount of arbitrariness in the information included in the mathematical formulation. This is just a matter of judgement; inevitably, we are sure to include either too much or too little detail in our specification, and so we will have to go back at some stage and modify it. Mathematics provides no solution to that problem all it can do is ensure that what we do include is unambiguous.

  6. Formal Specifications What rather than How • Formal specifications use mathematical notation to describe in a precise way the properties which an information system must have, without unduly constraining the way in which these properties are achieved. They describe what the system must do without saying how it is to be done. This abstraction makes formal specifications useful in the process of developing a computer system, because they allow questions about what the system does to be answered confidently, without the need to disentangle the information from a mass of detailed program code, or to speculate about the meaning of phrases in an imprecisely­worded prose description.

  7. Formal Specifications • A formal specification can serve as a single, reliable reference point for 1) those who investigate the customer's needs, 2) those who implement programs to satisfy those needs, 3) those who test the results, and 4) those who write instruction manuals for the system. Because it is independent of the program code, a formal specification of a system can be completed early in its development. Although it might need to be changed as the design team gains in understanding and the perceived needs of the customer evolve, it can be a valuable means of promoting a common understanding among all those concerned with the system.

  8. Z Specifications • The language of Z specifications is grounded in mathematics, and we will give a description of the world in terms of mathematical objects. We describe what objects exist, and how relationships between them may be made into specifications. We will look at the Z language and how it can be used to express specifications, and extend the vocabulary of mathematical objects into a collection of powerful data types.

  9. Z Specifications • The Z method uses the notation of predicate logic to describe abstractly the effect of each operation of our system, in a way that enables us to reason about its behaviour. The other main ingredient in Z is a way of decomposing a specification into small pieces called schemas. By splitting the specification into schemas, we can present it piece by piece. Each piece can be linked with a commentary which explains informally the significance of the formal mathematics.

  10. Z Specifications • In Z, schemas are used to describe both static and dynamic aspects of a system. The static aspects include: • the states it can occupy; • the invariant relationships that are maintained as the system moves from state to state. • The dynamic aspects include: • the operations that are possible; • the relationship between their inputs and outputs; • the changes of state that happen.

  11. Z Issues • Z specifications can appear excessively long in relation to their implementation. • Z needs software tools to keep track of the variables and schemas. • A Z specification is not easily communicated to the user. • Many software engineers do not have the mathematical training to write a Z specification. • The precision Z gives a very high degree of confidence in the fedility of the implementation, that is, that the implementation behaves precisely as the specification.

  12. Z Issues • Verification provides an alternative to testing. To verify an implementation is to demonstrate that it will perform as specified in all cases. This can be done using mathemarical proof. Verification of large systems is not easy. The process of performing a proof is not something that can be completely automated. Although software tools can help, the task seems to be inherently creative in a way that cannot be caputred within a systematic procedure.

  13. Sets • A set is a collection of elements or members. The Z notation uses typed set theory: All the possible values of a set are considered to have something in common, they are said to be the same type. For example sets of persons, sets of numbers. We are not too interested in sets that can contain any sort of element. We will concentrate on typed set theory.

  14. Subsets • Any set is considered to be a subset of its type. Example even numbers are a subset of integers. • A subset is any collection of values from a set.

  15. The Z built-in types • The designated Integer symbol is: Z • …,-3,-2,-1,0,1,2,3… • The designated symbol for Natural numbers including zero is N • 0,1,2,3… • The designated symbol for Natural numbers excluding zero is N1 • 1,2,3..

  16. Operations on Integers Z • The following operators are defined for the type Integer (Z) and its subsets: • + - * div mod

  17. Relations on Integers • The following relational operators are applicable to Integers:

  18. Basic Types • Basic types are called given types. The basic types of a specification are declared without concern for how the elements are represented. Example: • [REGISTRATION] the set of all possible car registrations • [PERSON] the set of all persons • Basic types are written completely in capital letters. It is assumed that the elements are uniquely identifiable. Combined types: • [REGISTRATION,PERSON]

  19. Free Types • There is a need to invent names when creating a formal specification. The rules for constructing such identifiers are similar to those of computer programming languages. Sometimes it is convenient to introduce a type by listing the identifiers of its elements.

  20. Free Types • The general format of a free type is: • freeType ::= element1 | element2 |...| elementn • Examples: • RESPONSE ::= yes | no • STATUS ::= inUse | free | onHold • The symbol ::= means ‘is defined as’

  21. Declaring Variables • Each variable name designating a value must be declared. That means it must be introduced and the type of value it refers must be stated. For example, to introduce a variable chauffeur to the basic type PERSON we write: • chauffeur :PERSON • chauffeur is one of the set of values of PERSON

  22. Example set • Let the set EU be the set of all countries in the European Union. It could have been declared as a basic type, a variable sized set • [EU] the set of all countries in the European Union. • It could also be declared as a fixed sizefree type: • EU ::= A | B | DK | F | SF | D | GB | GR | IRL | I | L | NL | P | E | S • The variable homeland can refer to one element in the set EU • homeland:EU

  23. Set values • The value of a set can be written by listing its values within braces {}. For example: • benelux={B,NL,L} • Sets are not ordered. There are no duplicates, each element is unique.

  24. The Empty Set Singleton • It is possible to have a set with no values, it is called the empty set and denoted as: 0 or { } • A set that contains only one element is called a singleton set. For example: {IRL} • Note the difference between the set {IRL} and element IRL.

  25. Ranges of Integers • A range of values is denoted as m…n, where m and n are integers, stands for the set of integers m to n inclusive. • If m>n then m..n = 0 • Examples: • 3..5 = { 3, 4, 5} • 2..2 = {2} • 3..2 = 0

  26. Set Operators • Set Equivalence • Two values of the same type can be tested to see if they are the same by using the equals sign, as in: • x = y • Two sets are equal if they contain exactly the same elements. For example the two sets below are equal: • {B,NL,L} = {NL, B, L}

  27. Set Operators • Set Non-Equivalence • Two values of the same type can be tested to see if they are not the same by using the not-equals sign Two sets are not equal if they do not contain exactly the same elements • {B,NL} {B,NL,L}

  28. Set Operators • The membership operator is written: e • NL e {B, NL, L}it is true; the Netherlands is a Benelux country • General case below: [X] S:PX x:X xeS .x S X

  29. Set Operators • The non-membership operator is written: • IRL {B, NL, L}it is true; Ireland is not a Benelux country [X] S:PX x:X x S General case S .x X

  30. Set Operators • The validity of membership test. • The value to be tested for membership must be an element of the underlying type of the set. For example: • USA e {B, NL, L} • is illegal, since USA is not an element of the type EU.

  31. Set Operators • Size Cardinality: The number of values in a set is called its size, or cardinality, and is signified with the has sign: • #{B,NL,L} = 3 • #{IRL} = 1 • #IRL illegal, IRL is not a set • #0 = 0

  32. Set Operators • Powersets: The powerset of a set is written PS • It is the set of all subsets of S. For example the powerset of the Benelux countries is: P{B,NL,L} = { 0, {B},{NL},{L}, {B,NL},{B,L},{NL,L}, {B,NL,L}}

  33. Set Operators:Powersets • When a variable is to be declared to have a type that is a set of elements, the type is the powerset of the type of the elements: • benelux: PEU • This can be read as ‘the variable benelux is a subset of the set of countries EU’ or ‘the variable benelux is a set of EU countries’

  34. Set Operators:Powersets • The size of the powerset of a set is equal to two raised to the power of the size of the set. • #(PS) = 2#s • #{B,NL,L} = 3 • #(P{B,NL,L}) = 8

  35. Set Operators: Set inclusion • The ‘is a sub set of’ operator is: • set1 z set2 • The subset operator is true if the first set is included in the second set, that is every element of the first set must be in the second set

  36. Set Operators: Set inclusion The following statements are true: {B,NL} z {B,NL,L} 0z{B,NL,L} {B,NL,L} z{B,NL,L} [X] S:PX T:PX T z S General case T S X

  37. Set Operators: Set inclusion • The empty set is a subset of every set, including itself. • The empty set is not a member of every set. • The empty set can only be a member of a set of sets. • Elements of set EU that border the Pacific (none) 0z S is true for all sets S 0z 0is true • When checking for singleton inclusion: • ({x}z S) (xeS)

  38. Set Operators: Union • The union of two sets is the set containing all the elements that are in either the first set or the second set or both. [X] S:PX T:PX T U S T U S = T U S S U 0 = S S T X

  39. Set Operators: Intersection • The intersection of two sets is the set containing all the elements that are in the first set and in the second set. [X] S:PX T:PX T I S T I S = S I T S I 0 = 0 S T X

  40. Set Operators: Difference • The difference of two sets is the set containing all the elements that are in the first set and are not in the second set. The shaded area is the difference of S and T. [X] S:PX T:PX S \ T S \ T T \ S S \0 = S 0 \ S = 0 S T X

  41. Set Operators: Distributed Union • The distributed union of a set of sets is the set containing just those elements that occur in at least one of the component sets. [X] S:PX R:PX T:PX {R,S,T} R S T X

  42. Set Operators: Distributed Intersection • The distributed intersection of a set of sets is the set containing just those elements that occur in all of the component sets. [X] S:PX R:PX T:PX {R,S,T} R T S X

  43. Disjoint Sets • Sets that are disjoint have no elements in common; their intersection is the empty set. • For disjoint sets T and S the following expression is true: • T I S = 0.

  44. More than 2 Disjoint Sets • For more that two sets it becomes longer, since every pair must have an empty intersection. For example for sets A, B and C to be disjoint the following must be true: • A I B = 0 and • B I C = 0 and • C I A = 0

  45. Disjoint Sets • In Z, we often write: • Example 1 • disjoint<S,T> disjoint<A,B,C> • Example 2 • [PERSON] • male, female: PERSON • disjoint<female,male>

  46. Partition • A sequence of sets is said to partition another larger set if the sets are disjoint and their distributed union is the entire larger set if the sets are disjoint. For example: • if disjoint<A,B,C> and {A,B,C} = T • then <A,B,C> partition T • E.G. <male,female> partition PERSON.

  47. Example • Edward, Fleur, and Gareth have each been given an assignment consisting of 7 questions. Edward has attempted the questions numbered 1, 2, and 4; Fleur has attempted all but questions 5 and 6; Gareth has attempted only those questions with even numbers.

  48. Example • Express these facts using Z typed set theory. • Q1 Which questions have been attempted by these three students. • Q2 Which questions were attempted by all three students.

  49. Example • Base types • [Student] the set of all students (not actually needed) • [Questions] the set of all exam questions • Variables • edward, fleur gareth: Student • edwardsQuestions : PQuestions • fluersQuestions : PQuestions • garethsQuestions: PQuestions

  50. Q1 Which questions have been attempted by these three students. • edwardsQuestions ={ 1, 2, 4} • fluersQuestions ={ 1, 2, 3, 4, 7} • garethsQuestions={ 2, 4, 6 } Answer: The specification of Query 1 is: {edwardsQuestions, fluersQuestions , garethsQuestions} The computed answer for Query 1 is: {1, 2, 3, 4, 6, 7}

More Related