Chapter on TLA+ Software Specification Methods

Chapter on TLA+ Software Specification Methods

1 Leslie Lamport Chapter on TLA+ from Software Speci¯cation Methods An Overview Using a Case Study Henri Habrias and Marc Frappier, editors Hermes, April 2006 Contents 7.1 Overview of TLA+ .............................................121 7.1.1 TLA . 121 7.1.2 TLA+ versus Z . 122 7.2 A Speci¯cation of Case 2 . 123 7.3 The Problematic Case 1 . 130 7.4 Validation of the Speci¯cation . 131 7.5 Satisfying the Speci¯cation . 132 7.6 The Natural Language Description . 133 7.7 Conclusion . 134 Chapter 7 TLA+ Leslie Lamport 7.1 Overview of TLA+ TLA+ is a formal speci¯cation language based on set theory, ¯rst-order logic, and the Temporal Logic of Actions (TLA) [6,4]. In spirit, TLA+ is close to Z. In fact, some aspects of TLA+ were inspired by Z. I will therefore assume that the reader has read the chapter on Z, and I will explain the TLA+ speci¯cation largely in terms of how it di®ers from the Z speci¯cation. For reasons explained below, Case 1 is problematic. I will therefore ¯rst present a complete speci¯cation for Case 2 and only afterwards discuss Case 1. A complete description of TLA+ and its tools can be found in [7]. Here I begin with a brief description of TLA and then describe the major di®erences between TLA+ and Z. 7.1.1 TLA A TLA speci¯cation is a temporal formula, often named Spec. The meaning of a temporal formula is a predicate on behaviors. A behavior represents a con- ceivable execution of a system. The behaviors satisfying Spec are the ones that represent correct behaviors of the system. More precisely, a behavior represents a conceivable history of a universe that may contain the system. A behavior satisfying speci¯cation Spec represents a history of the universe in which the system behaves correctly. To make this precise, we need some terminology. A state is an assignment of values to variables. A step is a pair of states. A behavior is an in¯nite sequence of states; the steps of a behavior are its successive pairs of states. A state predicate is a formula whose meaning is a predicate (Boolean-valued function) on states. An action is a formula whose meaning is a predicate on steps. We often conflate a formula and its meaning. For example, if A is an action, then an A-step is de¯ned to be a step that satis¯es A. (Formally, the step satis¯es the meaning of A, not the formula A.) In TLA, actions are written as formulas containing primed and unprimed variables. Unprimed variables refer to the variables' values in the ¯rst state of the step; primed variables refer to their values in the second state. State predicates are actions with no primed variables. 122 Software Speci¯cation Methods Like most industrial speci¯cations I have seen, the invoice system has the simplest possible nontrivial TLA speci¯cation|namely, it is a temporal formula Spec de¯ned by ¢ Spec = Init ^ 2[Next]hv 1;:::;v n i where Init is a state predicate, Next an action, and the v i are the speci¯ca- tion's variables. Formula Spec is true of a behavior σ i® Init is true of the ¯rst state of σ and every step (successive pair of states) of σ is either a Next step (one that satis¯es Next) or a \stuttering step" that leaves all the variables v i unchanged. Nothing happens in a stuttering step, so it is impossible to observe that such a step has occurred. Hence, a speci¯cation should not be able to forbid stuttering steps. Allowing them permits implementation/re¯nement to be simple implication [5], and it permits composition to be conjunction [1]. However, since the speci¯cation exercise includes neither re¯nement nor composition, stutter- ing steps are irrelevant and can be ignored|except when a behavior ends in an in¯nite sequence of such steps. A behavior that ends this way represents an execution that terminates. Formula Spec allows terminating executions. Forbid- ding termination requires conjoining a liveness property [2] to the de¯nition of Spec. Since there is no liveness requirement for the invoice system, I will ignore liveness. A TLA speci¯cation consists of the de¯nition of the formula Spec|that is, the one-line de¯nition given above preceded by the de¯nitions of Init and Next. These are ordinary mathematical formulas, involving no temporal logic. The 2 in the line above is the only temporal-logic operator in the entire speci¯cation. (If we were specifying liveness properties, temporal operators would appear in the de¯nitions of those properties as well.) 7.1.2 TLA+ versus Z The invoice system example reveals the following di®erences between the usual way of writing speci¯cations in TLA+ and Z. (There is another style of Z speci¯- cation, not used in this book, in which sequences of states are described explicitly with ordinary mathematics.) ² A TLA+ speci¯cation is a single temporal-logic formula. In Z, there is no single formula or object that mathematically constitutes the speci¯cation. ² One can assert in TLA+ that a speci¯cation satis¯es a property; Z has no mechanism for making such an assertion. ² Unlike Z, TLA+ is untyped. Type correctness of a TLA+ speci¯cation Spec is an invariance property asserting that, in every state reached during every possible execution satisfying Spec, each state variable is an element of an appropriate set (its type). One ¯nds type errors by checking that invariance property. In principle, being untyped makes TLA+ signi¯cantly more ex- pressive than Z. In practice, the inexpressiveness of Z's type system is at Software Speci¯cation Methods 123 worst a minor nuisance for writing the speci¯cations that typically arise in industry. There are advantages to a typed language, but I have found them not to be worth the extra complexity that types introduce. (Type checking is discussed in Section 7.4.) However, eliminating types eliminates type decla- rations that can contain information helpful to the reader; such information needs to be included in comments. ² In Z, schemas are distinct from formulas and have their own logic. In TLA+, there are only formulas. What would be a schema in a Z speci¯cation usually becomes the de¯nition of a formula in the corresponding TLA+ speci¯cation. ² While both TLA+ and Z use sets and functions, they have di®erent built-in operators for describing them. For example, TLA+ has constructs for ma- nipulating records that Z lacks; Z has a panoply of operators for describing sets of relations that TLA+ lacks. While TLA+ can easily de¯ne Z's mathe- matical operators, the Z syntax for them can be more convenient. Syntactic di®erences lead to stylistic di®erences in the speci¯cations. A TLA+ speci¯- cation might use records where a Z speci¯cation uses tuples or a schema, and it might use total functions where a Z speci¯cation uses partial functions. ² A TLA+ speci¯cation can distinguish between the system's interface, which must be implemented, and its internal state, which serves only to specify the behavior of the interface. This distinction can be made only informally in Z. The following additional di®erences between ordinary TLA+ and Z speci¯cations are not revealed by this simple example. ² TLA+ can be used to specify both safety and liveness properties [2]. Z lacks anything corresponding to the TLA+ operators for expressing liveness. ² TLA provides a simple mathematical de¯nition of what it means for one speci¯cation to implement another. Implementation is implication. A spec- i¯cation S1 implements a speci¯cation S2 i® S1 ) S2 is a valid formula. (There is no formal di®erence between a property and a speci¯cation; satis- fying a property and implementing a speci¯cation are synonymous.) For an engineer, the most signi¯cant di®erence between Z and TLA+ is probably the set of tools they provide for checking a speci¯cation. The tools currently available for checking TLA+ speci¯cations are the SANY syntactic analyzer and the TLC model checker, which is described in Section 7.4 below. 7.2 A Speci¯cation of Case 2 There is no such thing as the speci¯cation of a system. A speci¯cation is an abstraction that describes some aspects of the system and ignores others. It is like a map. One wants a di®erent map of Texas for driving from Amarillo to Houston than for ¯nding new deposits of helium. So the ¯rst question one should ask is: 124 Software Speci¯cation Methods Question 1: What is the purpose of the speci¯cation? Answer: This question does not seem to have an answer. The invoice example is arti¯cial because it does not indicate what the speci¯cation is to be used for. In my experience, engineers are most interested in speci¯cations as a way of ¯nding errors early in the design process. For that purpose, one writes a speci¯cation of a high-level design and checks that it satis¯es certain prop- erties. The description of the invoice system gives no nontrivial properties to be checked. Since I am just copying the Z speci¯cation, I do not have to answer this question. I will accept whatever answer is implicit in the Z speci¯cation. The ¯rst question engineers who sit down to write a speci¯cation usually ask is: Question 2: How do we begin? Answer: Knowing how to begin is probably the hardest part of writing a spec- i¯cation.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    18 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us