Hybrid Systems in TLA^{+}

Leslie Lamport

Digital Equipment Corporation Systems Research Center

                           lamport@src.dec.com

6 April 1993

To appear in: Hans Rischel and Anders P. Ravn, editors, Hybrid Systems, Lecture Notes in Computer Science, Berlin, 1993. Springer-Verlag. (Proceedings of a Workshop on Theory of Hybrid Systems, held 19–21 October 1992 at Lyngby, Denmark.)

Hybrid Systems in TLA^{+}

Leslie Lamport

Digital Equipment Corporation Systems Research Center

Abstract. TLA^{+} is a general purpose, formal specification language based on the Temporal Logic of Actions, with no built-in primitives for specifying real-time properties. Here, we use TLA^{+} to define operators for specifying the temporal behavior of physical components obeying integral equations of evolution. These operators, together with previously defined operators for describing timing constraints, are used to specify a toy gas burner introduced by Ravn, Rischel, and Hansen. The burner is specified at three levels of abstraction, each of the two lower-level specifications implementing the next higher-level one. Correctness proofs are sketched.

1 Introduction

TLA^{+} is a formal specification language based on TLA, the Temporal Logic of Actions [5]. We use TLA^{+} to specify and verify a toy hybrid system—a gas burner described by Ravn, Rischel, and Hansen (RRH) [8]. The TLA^{+} specification and proof can be compared with the one by RRH that uses the Duration Calculus.

We do not expect TLA^{+} to permit the best possible specification of this or any other particular example. The specification of a gas burner is likely to be simpler in a formalism devised expressly for the class of hybrid systems that includes the gas burner. The specification of a Modula-3 procedure is likely to be simpler in a formalism for specifying Modula-3 procedures. But, while TLA^{+} may not be the best method for specifying any particular system, we believe it is quite good for specifying a very wide class of systems, including gas burners and Modula-3 procedures.

There are two reasons for using TLA^{+} instead of a language tailored to the specific problem. First, specialized languages often have limited realms of applicability. A language that permits a simple specification for one gas burner might require a very complicated one for a different kind of burner. The Duration Calculus seems to work well for real-time properties; but it cannot express simple liveness properties. A formalism like TLA^{+} that, with no built-in primitives for real-time systems or procedures, can easily specify gas burners and Modula-3 procedures, is not likely to have difficulty with a different kind of gas burner.

The second reason for using TLA^{+} is that formalisms are easy to invent, but practical methods are not. A practical method must have a precise language and robust tools. Building tools is not easy. It is hard to define a language that is powerful enough to handle practical problems and yet has a precise formal semantics. Such a language is a prerequisite for any sound, practical method. The advantage of not having to implement a new method for every problem domain is obvious.

An important criterion for choosing a formalism is how good it is for formal verification. A method based on a logic has an advantage over one based on an abstract programming language (such as CSP) because one does not have to translate from the specification language to a logic for reasoning. But, not all logics are equal. TLA works well in practice because most of the reasoning is in the domain of actions, which is the realm of “ordinary” mathematical reasoning. The use of temporal logic is minimal and highly ritualized. The temporal structure of the proofs are the same, regardless of whether one is reasoning about a mutual exclusion algorithm or a gas burner.

Modal logics, such as temporal logic and the Duration Calculus, are more difficult to use than ordinary logic. One reason is that the deduction principle, from which one deduces P ⇒ Q by assuming P and proving Q, is invalid for most modal logics. In our work on the mechanical verification of TLA [4], we have found formalizing temporal logic reasoning to be much more difficult than formalizing ordinary mathematical reasoning. Temporal logic proofs that look simple when done by hand can be tedious to check mechanically. We believe that mechanical verification of TLA proofs is feasible largely because it involves very little temporal logic. One should be skeptical of claims that reasoning in a modal logic is easy in the absence of experience with mechanically checked proofs.

TLA^{+} is a complete language, with a precise syntax and formal semantics. At the moment, only a few syntactic issues remain unresolved. Because it is completely formal, some things are a little more awkward to express in TLA^{+} than in “semi-formal” methods. For example, most semi-formal methods, such as Unity [2] and the temporal logic of Manna and Pnueli [7], allow Boolean-valued variables; TLA^{+} does not. In TLA^{+}, one cannot declare x to be a Boolean variable and write □x, one must instead write something like □(x = “T”). Although seemingly innocuous, Boolean variables pose the following problem. A specification may require an array x[1], …, x[17] of flexible variables. Formally, such an array is a variable x whose value is a function with domain {1, …, 17}. If one can declare Boolean variables, then one should also be able to declare that x is a Boolean-valued array variable, with index set {1, …, 17}. One can then write the formula □(x[14]). One can also write the formula □(x[i^{2} − 23]). In general, one could write the formula □(x[e]) for an arbitrary integer-valued expression e. Formalizing Boolean arrays presents the following options:

– Define the meaning of □(x[e]) for any value of e. Does one consider x[e] to have some special undefined value ⊥ if e is not in the domain of x? If so, what is the meaning of □⊥? Is the formula □(⊥ ⇒ ⊥) valid?

– Declare □(x[e]) not to be a wff (well formed formula) if e is not in the index set of x. This leads to two possibilities:

• The class of expressions e that can appear in the formula x[e] are restricted so it is syntactically impossible for the value of e not to be in the index set of x. This leads to unnatural restrictions on formulas.

• Whether or not a formula is a wff becomes a semantic rather than syntactic property. It is a strange formalism in which it is undecidable whether a formula is a wff.

TLA^{+} avoids this problem by not having Boolean-valued variables. Neither Manna and Pnueli [7] nor Misra and Chandy [2], in books that are hundreds of pages long, indicate how they formalize Boolean arrays.

There are dozens of similar issues that must be resolved in designing a complete language. A simple informal specification might not look so simple if it had to be written formally. Of particular concern are formalisms based on a type system. It is easy to introduce the informal notation that Length(s) denotes the length of the sequence s. But, will the type system really allow a formal language in which the user can define Length(s) to denote the length of any sequence s? It is easy to define such a Length operator in TLA^{+}. However, this ability is based on a distinction between a function and an operator—a distinction one won’t find in semi-formal methods.

Despite being completely formal, TLA^{+} is simple enough for practical applications. A general treatment of hybrid systems requires continuous mathematics. Specifying the gas burner requires defining the Riemann integral ∫_{a}^{b} f of the function f over the closed interval [[a, b]]. Assuming only the set of real numbers with the usual arithmetic operations and ordering relations, the entire definition takes about 15 lines. Our example is a toy one, and we do not claim to have formalized any significant fraction of the mathematics that will be needed in practical applications. We do claim that a language that can define the Riemann integral in 15 lines is powerful enough to express any mathematical concepts likely to arise in real specifications.

TLA^{+} specifications are written in ASCII. We hope eventually to write a program that converts an ASCII specification to input for a text formater that produces a “pretty-printed” version. The user will specify how individual operators are formated—for example, declaring that the Integral operator should be formated so Integral(a, b, f) is printed as ∫_{a}^{b} f, and that [|s|] should be printed as |s|. We have simulated such a program to produce pretty-printed TLA^{+} specifications.

2 Representing Hybrid Systems with TLA

This section describes the generic operators that can be used to specify hybrid systems. The precise TLA^{+} definitions of some operators is deferred to Section 3. Figure 1 contains a complete list of all the predefined TLA^{+} constant operators— the ones that describe data structures. The only additional operators are TLA’s action operators (such as Enabled) and temporal operators (such as □). The syntax and formal semantics of these operators, which fit on one page, can be found in [5].

Logic true false ∧ ∨ ¬ ⇒ ⇔ ∀ x : p ∃ x : p ∀ x ∈ S : p ∃ x ∈ S : p choose x : p [Equals some x satisfying p]

Sets = ≠ ∈ ∉ ∪ ∩ ⊆ \ [set difference] {e_{1}, …, e_{n}} [Set consisting of elements e_{i}] {x ∈ S : p} [Set of elements x in S satisfying p] {e : x ∈ S} [Set of elements e such that x in S] subset S [Set of subsets of S] union S [Union of all elements of S]

Functions domain f f[e] [Function application] [x ∈ S ↦ e] [Function f such that f[x] = e for x ∈ S] [S → T] [Set of functions f with f[x] ∈ T for x ∈ S] [f; e_{1} ↦ e_{2}] [Function f̂ equal to f except f̂[e_{1}] = e_{2}] [f; e : S] [Set of functions f̂ equal to f except f̂[e] ∈ S]

Records e.x [The x-component of record e] [[x_{1} ↦ e_{1}, …, x_{n} ↦ e_{n}]] [The record whose x_{i} component is e_{i}] [[x_{1} : S_{1}, …, x_{n} : S_{n}]] [Set of all records with x_{i} component in S_{i}] [[r; x ↦ e]] [Record r̂ equal to r except r̂.x = e] [[r; x : S]] [Set of records r̂ equal to r except r̂.x ∈ S]

Tuples e[i] [The i^{th} component of tuple e] ⟨e_{1}, …, e_{n}⟩ [The n-tuple whose i^{th} component is e_{i}] S_{1} × … × S_{n} [The set of all n-tuples with i^{th} component in S_{i}]

Miscellaneous “c_{1} … c_{n}” [A literal string of n characters] if p then e_{1} else e_{2} [Equals e_{1} if p true, else e_{2}] case p_{1} → e_{1}, …, p_{n} → e_{n} [Equals e_{i} if p_{i} true] let x_{1} =^{Δ} e_{1} … x_{n} =^{Δ} e_{n} in e [Equals e in the context of the definitions]

Fig. 1. The constant operators of TLA^{+}.

module RealTime

import Reals

parameters now : variable ∞ : constant

assumption

InfinityUnReal =^{Δ} ∞ ∉ R temporal

RT (v) =^{Δ} ∧ now ∈ Real ∧ □[\begin{matrix}∧ now′ ∈ \{r ∈ R : r > now\} \\ ∧ v′ = v ]_{now} \end{matrix}

VTimer(x : state fcn, A : action, δ, v : state fcn) =^{Δ} ∧ x = if Enabled⟨A⟩_{v} then now + δ else ∞

∧ □[x′ = if (Enabled⟨A⟩_{v})′ then if ⟨A⟩_{v} then now′ + δ else x else ∞ ]_{⟨x, v⟩}

MaxTimer(x) =^{Δ} □[(x ≠ ∞) ⇒ (now′ ≤ x)]_{now}

MinTimer(x : state fcn, A : action, v : state fcn) =^{Δ} □[⟨A⟩_{v} ⇒ (now ≥ x)]_{v}

Fig. 2. The RealTime module.

2.1 Real Time in TLA

A method for writing real-time specifications in TLA is described in [1]. We now review this approach and introduce TLA^{+} by defining the operators from [1] in the TLA^{+} module RealTime of Figure 2.

The RealTime module first imports the module Reals, which is assumed to define the set R of real numbers with its usual arithmetic operators.^{1} The module declares two parameters: the (flexible) variable now and the constant ∞. The value of now represents the current time, which can assume any value in R. The constant ∞ is the usual infinity of mathematicians. (All symbols that appear in a module’s formulas are either parameters or symbols that are defined in terms of parameters. The import statement includes the parameters of the module Reals as parameters of RealTime.)

Next comes an assumption, named InfinityUnReal, which asserts that ∞ is not a real number. The keyword temporal heads a list of definitions of temporal formulas. The first definition in the list defines RT (v) to be a formula asserting

1 Some people mistakenly think that, because the reals are uncountable, letting time be a real number complicates proofs. The axioms about the real numbers needed to prove such real-time properties as the correctness of Fischer’s protocol [1] form a decidable theory.

that now is initially in R, and every step either (i) sets the new value of now to a real number greater than its current value and (ii) leaves the value of v unchanged, or else it leaves now unchanged. (A list of formulas bulleted with ∧ denotes their conjunction. The formula [A]_{w} is defined to equal A ∨ (w′ = w); a [A]_{w} step is thus either an A step or a step that leaves w unchanged.) In representing a system by a TLA formula, the discrete variables of the system are considered to change instantaneously, meaning that when they change, now remains unchanged. This is asserted by the formula RT (v) when v is the tuple whose components are the system’s discrete variables.

In [1], timing constraints are expressed through the use of timer variables. The formula VTimer(x, A, δ, v) asserts that x is a timer whose value is initially either (i) δ greater than the initial value of now or (ii) ∞, depending on whether or not action ⟨A⟩_{v} is enabled. The value of x is set to now + δ when either (i) ⟨A⟩_{v} becomes enabled or (ii) an ⟨A⟩_{v} step occurs that leaves ⟨A⟩_{v} enabled, and it is set to ∞ when ⟨A⟩_{v} becomes disabled.^{2} (The action ⟨A⟩_{v} is defined to equal A ∧ (v′ ≠ v); an ⟨A⟩_{v} step is thus an A step that changes v.) The formula MaxTimer(x) asserts that changing now cannot make it greater than x. Thus, the formula VTimer(x, A, δ, v) ∧ MaxTimer(x) implies that an ⟨A⟩_{v} action cannot be continuously enabled for more than δ seconds without having occurred. The formula MinTimer(x, A, v) asserts that an ⟨A⟩_{v} action cannot occur unless now ≥ x, so VTimer(x, A, δ, v) ∧ MinTimer(x, A, v) implies that an ⟨A⟩_{v} action must be enabled for at least δ seconds before it can occur.

The definitions of VTimer and MinTimer explicitly indicate the sorts of the parameters. When no sort is specified, the sort state fcn, denoting a mapping from states to values, is assumed—except in the definitions of constants, where the default sort is constant, denoting a constant value.

There are many ways of defining timers for expressing real-time constraints, and they are all easily expressed in TLA^{+}. The method used in [1] is probably not optimal for the gas burner example. Although we might be able to simplify the specifications in this example by defining a new kind of timer, in practice one would use a fixed set of operators defined in a standard module like RealTime. To make the example more realistic, we have used a pre-existing set of operators.

2.2 Hybrid Systems

To represent hybrid systems in TLA, continuous system variables are represented by variables that change when now does. The gas-burner specification of RRH can be expressed using only the timers introduced in [1]. However, RRH’s specification is somewhat artificial, apparently chosen to avoid reasoning with continuous mathematics. Instead of the natural requirement that the concentration of unburned gas never exceeds some value, RRH require that unburned gas never be released for more than 4 seconds out of any 30-second period. Because it poses an interesting new challenge for TLA^{+}, we specify the more natural requirement and prove that it is implied by the requirement of RRH.

2 Another type of timer is also defined in [1], but it is not needed here.

The gas concentration g will satisfy an integral equation of the form

g(t) = ∫_{t_{0}}^{t} F (g(t)) dt

where the function F depends on the discrete variables. A more general situation is a continuous variable f that satisfies an equation of the form

f(t) = f_{0} + ∫_{t_{0}}^{t} G(f(t), t) dt  (1)

A further generalization is to let f be a function whose range is the set of n-tuples of reals. However, this generalization is straightforward and is omitted.

For specifying hybrid systems, we define a TLA formula, pretty-printed as [x=c+∫ G | A, v], having the following meaning:

– Initially, x equals c.

– In any step that changes now, the new value x′ of x equals f(now′), where f is the solution to f(t) = x + ∫_{now}^{t} G(f(s), s) ds.

– Any step that leaves now unchanged leaves x unchanged, unless it is an ⟨A⟩_{v} step, in which case x′ equals zero.

Thus, [x=c+∫ G | false, v] asserts that x represents the solution to (1) with f_{0} equal to c and t_{0} the initial value of now. The general formula [x=c+∫ G | A, v] adds the requirement that x is reset to 0 by an ⟨A⟩_{v} action. The precise definition of [x=c+∫ G | A, v] is given later, in the HybridSystems module.

It is often useful to describe the amount of time a predicate P has been true, which is the integral over time of a step function that equals 1 when P is true and zero when it is false. The formula [x=0+∫ χ(P) | false, v] asserts that the value of x always equals this integral, where the function χ(P) is defined by

χ(P)(r, s) = \{ \begin{matrix}1 & if P = true \\ 0 & if P = false \end{matrix}

The formal definition of χ appears in the HybridSystems module.

3 The Gas Burner

The example system is the gas burner shown in Figure 3. This is the toy example of RRH. Our goal is to write a specification that is in the spirit of RRH’s; the specification of a real gas burner might be much more complex.

The discrete state of the system consists of the states of the gas, the heatrequest signal, the flame, and the ignition—each of which can be either on or off. These state components are represented by the four variables declared in the module BurnerParameters of Figure 4. A physical state in which the gas is turned on or off will be represented by a state in which the value of the variable gas is the string “on” or “off”. The on and off values of the other variables are similarly denoted by the strings “on” and “off”. As is customary in TLA

[figure: Gas supply; Ignition transformer; Flame detector; Flame; Heatreq signal]

Fig. 3. The gas burner. (Figure taken from [8].)

module BurnerParameters

import HybridSystems, RealTime

parameters gas, heatReq, flame, ignition : variables

state function

v =^{Δ} ⟨gas, heatReq, flame, ignition⟩ predicates

Gas =^{Δ} gas = “on”

Flame =^{Δ} flame = “on”

Heatreq =^{Δ} heatReq = “on”

Ignition =^{Δ} ignition = “on”

Fig. 4. Module BurnerParameters

specifications, we define a state function v that equals the tuple of all relevant variables. (In TLA^{+}, angle brackets ⟨ ⟩ denote tuples.) To make it easier to compare our specification with theirs, we have also defined state predicates that correspond to the Boolean variables of RRH.

For convenience, the BurnerParameters module imports the modules HybridSystems and RealTime that define the operators described above. Since the RealTime module also imports the real numbers, they are transitively imported by the BurnerParameters module.

We now specify the requirement that the concentration of gas remains less than some value MaxCon. We assume that the gas concentration g is described by the integral equation

g(t) = ∫_{t_{0}}^{t} −δg(t) + \{ \begin{matrix}ρ & if gas on and flame off \\ 0 & otherwise \end{matrix} \} dt

where δ is the rate at which gas diffuses away from the burner and ρ is the rate

module GasConcentration

import BurnerParameters

parameters δ, ρ, MaxCon : {r ∈ R : r > 0} const

state function

accumRate[r, s : R] =^{Δ} (−δ) ∗ r + (if Gas ∧ ¬Flame then ρ else 0) temporal

Req0 =^{Δ} ∀ ∀ ∀ ∀ ∀ ∀ g : [g =0+∫ accumRate | false, v] ⇒ □(g < MaxCon)

Fig. 5. The specification of the gas-concentration requirement

at which gas flows when it is turned on.

Using the TLA formula [x=c+∫ G | A, v], it is easy to specify the requirement that the gas concentration is always less than MaxCon. First, the function accumRate that is substituted for G is defined as follows.

accumRate[r, s : R] =^{Δ} (−δ) ∗ r + (if Gas ∧ ¬Flame then ρ else 0)

This defines accumRate to be a function whose domain is R × R such that accumRate[r, s] equals the expression to the right of the =^{Δ}, for every pair ⟨r, s⟩ in R × R. (In TLA^{+}, square brackets denote function application.)

The formula [g =0+∫ accumRate | false, v] then asserts that g describes the gas concentration. As usual, the temporal formula □(g < MaxCon) asserts that g is always less than MaxCon, so the formula

[g =0+∫ accumRate | false, v] ⇒ □(g < MaxCon)

asserts that if g is the gas concentration, then g is always less than MaxCon. We want this formula to be true for an arbitrarily chosen, “fresh” variable g, so the desired property is obtained by universally quantifying g.^{3}

The complete definition of this property, which is called Req0 , is given in module GasConcentration, shown in Figure 5. This module imports the BurnerParameters module, which defines Gas and Flame, and declares δ, ρ, and MaxCon to be constant parameters whose values lie in the set of positive reals. This “type declaration” is a shorthand for the assumption

(δ ∈ {r ∈ R : r > 0}) ∧ (ρ ∈ {r ∈ R : r > 0}) ∧ (MaxCon ∈ {r ∈ R : r > 0})

Next, we define the three requirements given by RRH. The first requirement is

3 The symbols ∃ ∃ ∃ ∃ ∃ ∃ and ∀ ∀ ∀ ∀ ∀ ∀ denote quantification over flexible variables; ∃ and ∀ denote ordinary quantification over rigid variables.

For Safety, gas must never leak for more than 4 seconds in any period of at most 30 seconds.

This is a requirement for the 30-second interval beginning at time r, for every real r. It is expressed in terms of an array x of timers, where x[r] is the timer used to express the requirement for the interval beginning at r. The amount of gas that has leaked during the interval [[r, r + 30]] is obtained by “integrating” the function G(r) that is defined by

G(r)[s, t : R] =^{Δ} if Gas ∧ ¬Flame ∧ (t ∈ [[r, r + 30]]) then 1 else 0

This defines G to be an operator such that, for any r, the expression G(r) denotes a function with domain R × R.^{4}

Using x[r] as a timer, the requirement for this interval is expressed by

[x[r]=0+∫ G(r) | false, v] ⇒ □(x[r] ≤ 4))

The requirement Req1 is obtained by quantifying over all real numbers r, and then universally quantifying x. The complete definition is given in module BurnerRequirements in Figure 6. (Our formulas Req1 , Req2 , and Req3 correspond to the formulas □Req_{1}, □Req_{2}, and □Req_{3} of RRH.)

The second requirement is

Heat request off shall result in the flame being off after 60 seconds.

This condition is expressed by using a variable x that integrates the amount of time the flame has been on while the heat request was off, and is reset to zero whenever the flame goes off or the heat request comes back on.^{5} Such a variable x satisfies the formula

[x=0+∫ χ(Flame ∧ ¬HeatReq) | Heatreq′ ∨ ¬Flame′, v]

Asserting that x is always less than 60 and quantifying over x yields condition Req2 of Figure 6.

The final requirement is

4 A function f has a domain; it is an ordinary value. Thus G(7) and G(7)[\sqrt{2}, .5] both denote values; the first is a function, the second a real number. To define a function, one must specify its domain. However, G is an operator, not a function. It is not a value, and it does not have a domain; the symbol G by itself is not a syntactically correct expression. The definition above defines G(r) for any value of r, not just for real numbers. We had to define G(r) to be a function because it appears as a function, without any arguments, in subsequent formulas. We could have defined G to be a function by writing G[r : R][…], but there is no need to make G a function, and we didn’t feel like writing the “: R”. The distinction between operators and functions is another example of the details that arise in defining a precise language with a formal semantics. This distinction is what allows one easily to define in TLA^{+} an operator Length such that Length(s) is the length of any sequence s. One could not define Length to be a function, since its domain would not be a set. (Its domain would be isomorphic to the “set” of all sets.)

5 This requirement, which comes from RRH, is satisfied if the heat request is always off and the flame is always on except for flickering out briefly every 59.9 seconds.

module BurnerRequirements

import BurnerParameters

temporal

Req1 =^{Δ} let G(r)[s, t : R] =^{Δ}

if Gas ∧ ¬Flame ∧ (t ∈ [[r, r + 30]]) then 1 else 0 in ∀ ∀ ∀ ∀ ∀ ∀ x : ∀ r ∈ R : [x[r]=0+∫ G(r) | false, v] ⇒ □(x[r] ≤ 4))

Req2 =^{Δ} ∀ ∀ ∀ ∀ ∀ ∀ x : [x=0+∫ χ(Flame ∧ ¬HeatReq) | Heatreq′ ∨ ¬Flame′, v]

⇒ □(x ≤ 60)

actions IgniteFailAct(y) =^{Δ} ∧ Gas ∧ Ignition ∧ ¬Flame ∧ y′ ≠ y ∧ unchanged⟨v, now⟩

Req3Reset(y) =^{Δ} Flame′ ∨ (y′ ≠ y) ∨ ¬Heatreq′ temporal

IgniteFail(y) =^{Δ} ∃ ∃ ∃ ∃ ∃ ∃ z : ∧ □[IgniteFailAct(y)]_{y} ∧ VTimer(z, IgniteFailAct(y), 1/2, y) ∧ MaxTimer(z) ∧ MinTimer(z, IgniteFailAct(y), y)

Req3 =^{Δ} ∀ ∀ ∀ ∀ ∀ ∀ x, y : ∧ IgniteFail(y) ∧ [x=0+∫ χ(Heatreq) | Req3Reset(y), ⟨v, y⟩]

⇒ □(x ≤ 60)

Fig. 6. The three requirements of Ravn, Rischel, and Hansen.

.

Heat request shall after 60 seconds result in gas burning unless an ignite or flame failure has occurred. An ignite failure happens when gas does not ignite after 0.5 seconds. The flame fails if it disappears while gas is supplied.

A careful analysis of this condition reveals that replacing “after 60 seconds” by “within 60 seconds” makes the “or flame failure” redundant. We can therefore rewrite this requirement as

Heat request shall, within 60 seconds, result in gas burning unless an ignite failure has occurred.

The obvious approach is to define a variable x that integrates the time during which the heat request is on and is reset by the presence of a flame, an ignite failure, or the heat request being turned off. We would then define an IgniteFail action, define the action Req3Reset to be Flame′ ∨ IgniteFail ∨ ¬Heatreq′ and write the requirement as

∀ ∀ ∀ ∀ ∀ ∀ x : [x=0+∫ χ(Heatreq) | Req3Reset, v] ⇒ □(x ≤ 60)

However, there is no actual IgniteFail action. An ignite failure is not a change of the discrete state variables; it is something that is caused by the passage of time. So, we must introduce a variable y that is changed when an ignite failure occurs. Since y should not be a free variable of the formula, it must be “quantified away”. We want y to change when the ignition and the gas have been on for precisely .5 seconds while the flame has been off. This is accomplished with a .5-second “vtimer” for the action that changes y. We define IgniteFailAct(y) to be an action that changes y while leaving the other variables unchanged, and is enabled precisely when the gas and ignition are on and the flame is off. An ignition failure happens when this action has been continuously enabled for precisely .5 seconds. So, we let

IgniteFailAct(y) =^{Δ} ∧ Gas ∧ Ignition ∧ ¬Flame ∧ (y′ ≠ y) ∧ unchanged ⟨v, now⟩

where unchanged f denotes f′ = f. The TLA formula □[IgniteFailAct(y)]_{y} asserts that y changes only when Gas ∧Ignition ∧¬Flame is true. To assert that this change occurs only when the IgniteFailAct(y) action has been enabled for precisely .5 seconds, we add a timer z with both a MaxTimer and MinTimer condition. The temporal formula IgniteFail(y) defined in Figure 6 asserts that an ignition failure has occurred iff y has changed. The definition of the formula Req3 expressing the third requirement is now straightforward and appears in Figure 6.

We would like to prove the gas concentration condition Req0 from the three requirements of RRH. This condition actually follows from Req1 . The precise theorem, expressed in TLA^{+}, is that if

MaxCon ≥ 4 ∗ ρ ∗ (1 + (1/(1 − exp[(−30) ∗ δ])))

then RT (v)∧Req1 ⇒ Req0 , where exp is the usual exponential function. Before proving this, we finish the specification by defining the operators we have been assuming.

4 The Module HybridSystems

The HybridSystems module involves the solution to an integral equation. Defining this requires first defining the definite integral. The Riemann integral of a function f on an interval is the signed area under the graph of f. It is defined as the limit of approximations obtained by breaking the interval into subintervals, where the area under the graph of f from p to q is approximated by f(p)(q − p). The definition of ∫_{a}^{b} f appears in module Integration of Figure 7. The informal meanings of the defined operators are explained below.

R^{+} The set of positive reals. [[a, b]] The closed interval from a to b. This is an “unsigned” interval, where [[a, b]]

equals [[b, a]]. (To avoid writing explicit domains, we have defined [[−, −]] to

module Integration

import Reals

constants

R^{+} =^{Δ} {r ∈ R : 0 < r}

[[a, b]] =^{Δ} {r ∈ R : ((a ≤ r) ∧ (r ≤ b)) ∨ ((a ≥ r) ∧ (r ≥ b))}

|r| =^{Δ} if r < 0 then −r else r

{m … n} =^{Δ} {i ∈ Nat : (m ≤ i) ∧ (i ≤ n)}

Partition(a, b, n, δ) =^{Δ}

\{ p ∈ [\{0 … n+1\} → [[a, b]]] : \begin{matrix}∧ (p[0] = a) ∧ (p[n+1] = b) \\ ∧ ∀ i ∈ \{0 … n\} : \begin{matrix}∧ \begin{matrix}∨ (a ≤ b) ∧ (p[i] ≤ p[i+1]) \\ ∨ (a ≥ b) ∧ (p[i] ≥ p[i+1]) \end{matrix} \\ ∧ |p[i+1] − p[i]| < δ \} \end{matrix} \end{matrix}

Σ(f, p)[n : Nat] =^{Δ} f[p[n]] ∗ (p[n+1] − p[n])

+ if n = 0 then 0 else Σ(f, p)[n − 1]

∫_{a}^{b} f =^{Δ} choose r : ∧ r ∈ R ∧ ∀ ϵ ∈ R^{+} : ∃ δ ∈ R^{+} : ∀n ∈ Nat : ∀ p ∈ Partition(a, b, n, δ) : |r − Σ(f, p)[n]| < ϵ

[c+∫_{a} G][r : R] =^{Δ}

let f =^{Δ} choose f : \begin{matrix}∧ f ∈ [[[a, r]] → R] \\ ∧ ∀ t ∈ [[a, r]] : f[t] = c + ∫_{a}^{t}[s ∈ R ↦ G[f[s], s]] \end{matrix}

in f[r] theorem

IntegralOfStepFcn =^{Δ}
∀ G : ∀ a, b, δ ∈ R : ∀ n ∈ Nat : ∀ p ∈ Partition(a, b, n, δ) : ∀ f ∈ [R → R] :
(∀ s, t ∈ R : ∀ i ∈ {0 … n} : (p[i] < t) ∧ (t < p[i + 1]) ⇒ (G[s, t] = f(p[i])))
⇒ ([c+∫_{a} G][b] = Σ(f, p)[n])

Fig. 7. Defining integration in TLA^{+}.

be an operator, so [[a, b]] equals the expression to the right of the =^{Δ} even if a and b are not real numbers. However, it has the expected meaning only when a and b are real numbers. This remark applies to all the operators in this module.)

|r| The absolute value of r. {m … n} The set of natural numbers from m through n. (We assume that the

set Nat of natural numbers is imported with the Reals module.) Partition(a, b, n, δ) The set of all possible partitions of the interval [[a, b]] into

n + 1 subintervals each of length less than δ. Formally, a partition of an interval [[a, b]] into n+1 subintervals is a monotonic function p from {0 … n+1} to [[a, b]] such that p[0] = a and p[n + 1] = b. ([S → T] denotes the set of all functions whose domain equals S and whose range is a subset of T.)

module Exponentials

import Integration

constant

exp =^{Δ} [1+∫_{0}[r, s ∈ R ↦ r]]

theorems ExpFacts =^{Δ} ∧ exp ∈ [R ↦ R] ∧ exp[0] = 1 ∧ ∀ r ∈ R : (r > 0) ⇒ (1 − r < exp[−r]) ∧ (exp[−r] < 1) ∧ ∀ r, s ∈ R : exp[r] ∗ exp[s] = exp[r + s]

DiffusionSolution =^{Δ}

∀ p, q, a, c ∈ R : (p ≠ 0) ⇒

[c+∫_{a}[r, s ∈ R ↦ (p ∗ r) + q]] = [t ∈ R ↦ c ∗ exp[p ∗ (t − a)] + (q/p) ∗ (exp[p ∗ (t − a)] − 1)]

Fig. 8. The exponential function.

Σ(f, p) This is a function such that, if p is a partition of an interval into n + 1 subintervals, then Σ(f, p)[n] is the approximation ∑_{i=0}^{n} f[p[i]](p[i+1]−p[i]) to the area under f on that interval defined by the partition. We have defined Σ(f, p) to be a function with domain Nat to permit a recursive definition. (In TLA^{+}, only functions, not operators, can be defined recursively. A recursive function definition such as this can be expressed nonrecursively using TLA^{+}’s choose operator.)

∫_{a}^{b} f The Riemann integral^{6} of the function f is defined to be a real number r such that, for every ϵ, there is some δ such that the approximation for every partition with subintervals of length less than δ lies within ϵ of r. (The operator choose denotes Hilbert’s ε operator [6], so choose r : P (r) equals some value r such that P (r) is true, if such an r exists; otherwise, it has an unspecified value.)

[c+∫_{a} G] The function f such that f[r] equals c+∫_{a}^{r} G[f[t], t] dt. (The expression [s ∈ S ↦ e(s)] denotes the function g with domain S such that g[s] = e(s) for all s ∈ S.)

Finally, the module asserts the result from elementary calculus that if G is a step function on the interval [[a, b]], then [c+∫_{a} G][b] is equal to its approximation for the appropriate partition. This theorem is needed for the proof of property Req0 .

Proving Req0 also requires introducing the exponential function exp, where exp[t] = e^{t}. It is defined, and some theorems about exp are asserted, in the Exponentials module of Figure 8. The theorem named DiffusionSolution asserts

6 Although this integral is commonly written ∫_{a}^{b} f(t) dt, rigorous mathematicians usually write ∫_{a}^{b} f. For example, ∫_{a}^{b} t^{2} dt is just an informal way of denoting ∫_{a}^{b} f when f is the function defined by f(t) = t^{2}.

module HybridSystems

import Integration, RealTime

temporal

[x=c+∫ G | A : action, v] =^{Δ} ∧ x = c

∧ □[x′ = if now′ = now then if ⟨A⟩_{v} then 0 else x else [x+∫_{now} G][now′] ]_{⟨now, x, v⟩}

state function χ(P : predicate) =^{Δ} if P then 1 else 0

Fig. 9. The HybridSystems module.

that the solution to the equation f(t) = c + ∫_{a}^{t}(pf(t) + q) dt is

f(t) = ce^{p(t−a)} + \frac{q}{p}(e^{p(t−a)} − 1)

(Such theorems could be proved with the aid of a mathematical package such as Maple or Mathematica.) The HybridSystems module is now straightforward; it appears in Figure 9.

5 The Proof of Property Req0

We now sketch the proof of the result mentioned earlier, that Req1 implies Req0 . The proof requires only the theorems explicitly asserted in the modules defined above, plus the usual algebraic properties of arithmetic for the real numbers.

The proof is hierarchically structured, using the following notation. The theorem to be proved is statement ⟨0⟩1. The proof of statement ⟨i⟩j is either an ordinary paragraph-style proof or the sequence of statements ⟨i + 1⟩1, ⟨i + 1⟩2, … and their proofs. Within a proof, ⟨k⟩l denotes the most recent statement with that number. A statement has the form

Assume: Assumption Prove: Goal which is abbreviated to Goal if there is no assumption. The assertion Q.E.D. in statement number ⟨i + 1⟩k of the proof of statement ⟨i⟩j denotes the goal of statement ⟨i⟩j. The statement

Case: Assumption is an abbreviation for

Assume: Assumption Prove: Q.E.D. Within the proof of statement ⟨i⟩j, assumption ⟨i⟩ denotes that statement’s assumption.

We begin with the high-level proof, which essentially uses standard predicate logic to reduce the problem to proving a statement with no quantification over flexible variables. The resulting statement, ⟨1⟩2, is proved later.

Assume: MaxCon ≥ 4 ∗ ρ ∗ (1 + (1/(1 − exp[(−30) ∗ δ]))) Prove: RT (v) ∧ Req1 ⇒ Req0

⟨1⟩1. ∃ ∃ ∃ ∃ ∃ ∃x : ∀ r ∈ R : [x[r]=0+∫ G(r) | false, v] Proof: Follows from a standard theorem about the validity of adding history variables [1], which asserts the validity of ∃ ∃ ∃ ∃ ∃ ∃ x : (x = f) ∧ □[x′ = g]_{w} if x does not occur in f and x′ does not occur in g.

⟨1⟩2. ∧ now = a

∧ RT (v)

∧ ∀ r ∈ R : [x[r]=0+∫ G(r) | false, v] ∧ [g =0+∫ accumRate | false, v] ∧ ∀ r ∈ R : □(x[r] ≤ 4) ⇒ □(g < MaxCon)

Proof: Sketched below. ⟨1⟩3. Q.E.D.

⟨2⟩1. ∧ now = a

∧ RT (v)

∧ ∀ r ∈ R : [x[r]=0+∫ G(r) | false, v]

∧ ∀ r ∈ R : □(x[r] ≤ 4)

⇒ ([g =0+∫ accumRate | false, v] ⇒ □(g < MaxCon)) Proof: From ⟨1⟩2 by propositional logic.

⟨2⟩2. ∧ now = a

∧ RT (v)

∧ ∀ r ∈ R : [x[r]=0+∫ G(r) | false, v]

∧ ∀ r ∈ R : □(x[r] ≤ 4)

⇒ Req0 Proof: ⟨2⟩1, the definition of Req0 , and predicate logic, since g does not occur to the left of the ⇒.

⟨2⟩3. \begin{matrix}∧ now = a \\ ∧ RT (v) ∧ Req1 \end{matrix}

⇒ Req0 Proof: By ⟨1⟩1, ⟨2⟩2, the definition of Req1 , and simple predicate logic, since x does not occur free in RT (v) or Req0 .

⟨2⟩4. Q.E.D.

Proof: From ⟨2⟩3 by simple predicate logic, using the validity of ∃ a : now = a.

Because it involves quantification over flexible variables, this part of the proof cannot be handled by TLP, the mechanical verification system for TLA based on the LP theorem prover [4].^{7} The rest of the proof can, in principle, be verified using TLP. However, TLP does not yet contain the full definitional capability of TLA^{+}, so many of the definitions would have to be expanded by hand. In addition to being a possible source of error, this translation might make the

7 Mechanical checking of this kind of reasoning with quantifiers is not hard. However, such reasoning is always so simple that we have not felt mechanical verification to be worth the effort.

formulas so long that verification would be impractical. We hope that future versions of TLP will permit the necessary definitions.

We now prove ⟨1⟩2. From the definitions in modules HybridSystems and RealTime, we can write

[x[r]=0+∫ G(r) | false, v] =^{Δ} (x[r] = 0) ∧ □[N_{x}(r)]_{⟨now,x[r],v⟩}
[g =0+∫ accumRate | false, v] =^{Δ} (g = 0) ∧ □[N_{g}]_{⟨now,g,v⟩}
RT (v) =^{Δ} (now ∈ R) ∧ □[N_{now}]_{⟨now⟩}

for the appropriate actions N_{x}(r), N_{g}, and N_{now}. Let

Init =^{Δ} (now = a) ∧ (g = 0) ∧ (now ∈ R) ∧ (∀ r ∈ R : x[r] = 0)
N =^{Δ} [N_{g}]_{⟨now,g,v⟩} ∧ [N_{now}]_{⟨now⟩} ∧ (∀ r ∈ R : [N_{x}(r)]_{⟨now,x[r],v⟩})
J =^{Δ} ∀ r ∈ R : x[r] ≤ 4

Using the commutativity of conjunction and the fact that conjunction distributes over □, statement ⟨1⟩2 can be rewritten as^{8}

Init ∧ □N ∧ □J ⇒ □(g < MaxCon)

TLA formulas of this form are proved with the aid of an invariant. First, we define the trivial “type-correctness” part of the invariant:

T =^{Δ} \begin{matrix}∧ (now ∈ R) ∧ (g ∈ R) \\ ∧ ∀r ∈ R : (x[r] ∈ R) ∧ (0 ≤ x[r]) \end{matrix}

The nontrivial part I of the invariant is defined as follows, where we first define |⌊r⌋| to be the largest number less than or equal to r that is some multiple of 30 seconds later than a.

|⌊r⌋| =^{Δ} choose s ∈ R : \begin{matrix}∧ (s ≤ r) ∧ (r < s + 30) \\ ∧ |s − a|/30 ∈ Nat \end{matrix}
k =^{Δ} (4 ∗ ρ)/(1 − exp[−30 ∗ δ])
I =^{Δ} g ≤ (k ∗ exp[−δ ∗ (now − |⌊now⌋|)] + ρ ∗ x[|⌊now⌋|])

The proof of ⟨1⟩2 is a standard invariance proof, where we prove □I, using the hypothesis □J. The high-level structure of the proof is:

⟨2⟩1. Init ∧ □N ⇒ □T

Proof: This is a straightforward invariance proof and is omitted. ⟨2⟩2. Init ∧ □N ∧ □(J ∧ T) ⇒ □(g < MaxCon)

⟨3⟩1. Init ⇒ I Proof: Trivial, because Init implies g = 0.

8 This notation is rather sloppy, since □N is not a syntactically correct TLA formula. We must write □[N]_{w} for some state function w. However, it is easy to check that N equals [N]_{⟨now,g,X,v⟩}, where X =^{Δ} [r ∈ R ↦ x[r]].

⟨3⟩2. J ∧ J′ ∧ T ∧ I ∧ N ⇒ I′

Proof: Sketched below. ⟨3⟩3. J ∧ I ⇒ (g ≤ MaxCon)

Proof: Follows by simple algebra from the definition of k and assumption ⟨0⟩.

⟨3⟩4. Q.E.D.

⟨4⟩1. □(J ∧ T) ∧ I ∧ □N ⇒ □I

Proof: ⟨3⟩2 and the standard TLA invariance rule. ⟨4⟩2. □(J ∧ T) ∧ Init ∧ □N ⇒ □I

Proof: ⟨3⟩1 and ⟨4⟩1. ⟨4⟩3. □I ⇒ □(g ≤ MaxCon)

Proof: ⟨3⟩3 and simple temporal logic reasoning. ⟨4⟩4. Q.E.D.

Proof: ⟨4⟩2 and ⟨4⟩3. ⟨2⟩3. Q.E.D.

Proof: By ⟨2⟩1 and ⟨2⟩2.

We have reduced our goal to proving ⟨3⟩2, which is an assertion of ordinary mathematics, with no temporal operators. (In the reasoning, primed and unprimed variables are considered to be separate, unrelated values.) The proof of ⟨3⟩2 is sketched below. The “algebraic calculations”, which are omitted, constitute the heart of the proof. They are straightforward, but writing them out at the same level of detail as we have been using would be extremely tedious. Most mechanical verifiers would probably require that they be broken into extremely small steps, though they should not be hard to check with a mathematical package like Mathematica or Maple.

⟨3⟩2. Assume: J ∧ J′ ∧ T ∧ I ∧ N

Prove: I′ let mid =^{Δ} |⌊now⌋| + 30 ⟨4⟩1. Case: now′ = now

Proof: [N_{g}]_{⟨now,g,v⟩} ∧ (now′ = now) implies g′ = g, and (now′ = now) ∧ ∀ r : [N_{x}(r)]_{⟨now, x[r], v⟩} implies x[|⌊now⌋|]′ = x[|⌊now⌋|], so I′ equals I.

⟨4⟩2. Case: (now′ ≠ now) ∧ (v′ = v)

⟨5⟩1. now′ > now

Proof: By [N_{now}]_{⟨now⟩} (assumption ⟨3⟩). ⟨5⟩2. Case: Gas ∧ ¬Flame

let D(s, t) =^{Δ} s ∗ exp[−δ ∗ t] + (ρ/δ)(1 − exp[−δ ∗ t])

⟨6⟩1. g′ = D(g, now′ − now)

Proof: By [N_{g}]_{⟨now,g,v⟩} and Theorem DiffusionSolution of module Exponentials.

⟨6⟩2. Case: |⌊now′⌋| = |⌊now⌋|

⟨7⟩1. x′[|⌊now′⌋|] = x[|⌊now⌋|] + (now′ − now)

Proof: Case assumptions ⟨5⟩ and ⟨6⟩, [N_{x}(r)]_{⟨now,x[r],v⟩} with r = |⌊now⌋|, and Theorem IntegralOfStepFcn of module Integration, since now ∈ [[|⌊now⌋|, |⌊now⌋| + 30]].

⟨7⟩2. Q.E.D.

Proof: Algebraic calculation, using ⟨6⟩1, ⟨7⟩1, case assumption ⟨5⟩, and Theorem ExpFacts of module Exponentials.

⟨6⟩3. Case: |⌊now′⌋| ≠ |⌊now⌋|

⟨7⟩1. g′ = D(D(g, mid − now), now′ − mid)

Proof: By ⟨6⟩1, since an algebraic calculation using Theorem Exp-Facts shows that D(D(s, t_{1}), t_{2}) = D(s, t_{1} + t_{2}) for any s, t_{1}, t_{2} ∈ R.

⟨7⟩2. x′[|⌊now⌋|] = x[|⌊now⌋|] + mid − now Proof: Case assumption ⟨4⟩, [N_{x}(r)]_{⟨now,x[r],v⟩} with r = |⌊now⌋|, and Theorem IntegralOfStepFcn.

⟨7⟩3. D(g, mid − now) ≤ k Proof: Algebraic calculation using ⟨7⟩2, J′ ∧ I (Assumption ⟨3⟩), and Theorem ExpFacts.

⟨7⟩4. x′[mid] = now′ − mid

⟨8⟩1. x′[mid] = min(now′ − mid, 30)

Proof: Case assumption ⟨6⟩, [N_{x}(r)]_{⟨now,x[r],v⟩} with r = mid, and Theorem IntegralOfStepFcn.

⟨8⟩2. Q.E.D.

Proof: ⟨8⟩1 and J′ (Assumption ⟨3⟩). ⟨7⟩5. |⌊now′⌋| = mid

⟨8⟩1. (now′ − mid) ≤ 4

Proof: ⟨7⟩4 and J′ (assumption ⟨3⟩). ⟨8⟩2. Q.E.D.

Proof: ⟨5⟩1, ⟨8⟩1, and the definition of mid. ⟨7⟩6. Q.E.D.

Proof: Algebraic calculation using ⟨7⟩1, ⟨7⟩3, ⟨7⟩4, ⟨7⟩5, I (assumption ⟨3⟩), and Theorem ExpFacts.

⟨6⟩4. Q.E.D.

Proof: ⟨6⟩2 and ⟨6⟩3.

⟨5⟩3. Case: ¬(Gas ∧ ¬Flame)

⟨6⟩1. g′ = g ∗ exp[−δ ∗ (now′ − now)]

Proof: By [N_{g}]_{⟨now,g,v⟩} and Theorem DiffusionSolution. ⟨6⟩2. Case: |⌊now′⌋| = |⌊now⌋|

⟨7⟩1. x′[|⌊now⌋|] = x[|⌊now⌋|] Proof: By [N_{x}(r)]_{⟨now,x[r],v⟩} with r = |⌊now⌋|, case assumption ⟨6⟩, and Theorem IntegralOfStepFcn.

⟨7⟩2. Q.E.D.

Proof: Algebraic calculation using ⟨5⟩1, ⟨6⟩1, ⟨7⟩1, I, and Theorem ExpFacts.

⟨6⟩3. Case: |⌊now′⌋| ≠ |⌊now⌋|

⟨7⟩1. mid ≤ |⌊now′⌋|

Proof: ⟨5⟩1 and case assumption ⟨6⟩. ⟨7⟩2. g′ = g ∗ exp[−δ ∗ (mid − now)] ∗ exp[−δ ∗ (now′ − mid)]

Proof: ⟨6⟩1 and Theorem ExpFacts.

⟨7⟩3. g ∗ exp[−δ ∗ (mid − now)] ≤ k Proof: Algebraic calculation, using I, J (which implies x[|⌊now⌋|] ≤ 4), and Theorem ExpFacts (since mid > now).

⟨7⟩4. Q.E.D.

Proof: Algebraic calculation, using ⟨7⟩1, ⟨7⟩2, ⟨7⟩3, T, and Theorem ExpFacts.

⟨6⟩4. Q.E.D.

Proof: ⟨6⟩2 and ⟨6⟩3. ⟨5⟩4. Q.E.D.

Proof: ⟨5⟩2 and ⟨5⟩3. ⟨4⟩3. Q.E.D.

Proof: ⟨4⟩1, ⟨4⟩2, and assumption ⟨3⟩, since [N_{now}]_{now} ∧ (now′ ≠ now) implies v′ = v, by definition of N_{now}.

6 An Implementation

We now specify an implementation of the gas burner inspired by RRH’s “control model”. RRH also specify an “architecture”. However, a comparison of Figures 2 and 3 of [8] reveals that this architecture is just the same implementation expressed in a CSP-like language. A program in a toy language is no closer to a real program than the corresponding TLA^{+} or Duration Calculus formula is; it just has a syntax that can fool some people into thinking it is closer. So, we see no reason to introduce such a toy programming language.

The control model is described by the state-transition diagram of Figure 10. In the RRH specification, the states of the control model are abstract states that are only loosely coupled with states of the physical variables. For example, the specification of RRH asserts that the ignition and gas are turned on after the Ignite1 state is reached. The easiest way to duplicate the RRH specification would be to translate the state-machine into a simple TLA^{+} formula, and then translate the “phase requirements” of RRH into TLA^{+} using the operators

[figure: Idle; HeatOn; Ignite1; Out1a; Ignite2; Out1b; FlOn; Burn; HeatOff ,; FlOff; Purge; Out30]

Fig. 10. The control model, adapted from Figures 2 and 3 of [8].

from the HybridSystems module. However, we have already presented one level of specification and verification using the HybridSystems module’s operators, so this would be more of the same. Moreover, this is not the type of specification one would naturally write with TLA. In TLA, it is more natural to write lower level specifications purely in terms of states and transitions. One would draw a state-transition diagram for the gas and ignition variables—the transitions being enabled and disabled by changes to the control state—and write a TLA^{+} specification of the resulting system. This representation would be the first step in refining the control model to a realistic representation of an actual implementation. However, developing this specification would take more space than seems appropriate. Instead, we present a simplified version in which the physical variables gas and ignition that are under the implementer’s control change simultaneously with the control state.

The module BurnerControl of Figure 11 describes the time-independent behavior of the burner. It is a standard TLA specification; the next-state relation N is specified as the disjunction of individual actions corresponding to the transitions in Figure 10. Note that this module has a new parameter—the “internal” variable state. (Internal variables are ones that are existentially quantified.) The only surprising part of the specification is that the Out1b action can occur even if the flame is on. Timing requirements will prevent this action from occurring if the flame ignites quickly enough.

Next, module BurnerPhaseReqs of Figure 12 specifies the real-time requirements on the burner. It contains minimum and maximum delays on each of the transitions in Figure 10, which are expressed with the operators from the RealTime module. The constraints, and the new parameters ϵ_{1} and ϵ_{2}, are taken directly from the RRH specification. RRH’s condition Ignite2Req is split into two parts. The first, Ignite2aReq, asserts that an Out1b action cannot occur until it has been enabled (state = “Ignite2”) for at least 1 second, and it must occur if it has been enabled for 1 + ϵ_{1} seconds. (The formula Control asserts that the Out1b action remains enabled until an Out1b or FlOn step occurs.) The second part, Ignite2bReq, asserts that a FlOn action must be continuously enabled (state = “Ignite2” and flame on) for at least ϵ_{2} seconds before it can occur, and it must occur if it has been continuously enabled for ϵ_{1} seconds.

Next, module BurnerEnvironment in Figure 13 specifies the environment. The burner controls the gas and ignition variables; the environment controls the flame and heatReq variables. The specification of the initial condition and next-state relation are standard TLA. Condition ASM_{1} of RRH, that “no gas results in no flame within 0.1 seconds,” is expressed as usual with a timer. RRH’s condition ASM_{2}, that “gas does not ignite when the ignition transformer is not operating,” is a time-independent property that is encoded in the next-state relation N.

Finally, the pieces are put together in the ControlModel module of Figure 14. The assumptions about ϵ_{1} and ϵ_{2} are the same as RRH’s, except that our simpler specification is correct with a weaker upper bound on ϵ_{1}. The statement

include BurnerEnvironment as Env

module BurnerControl

import BurnerParameters

parameter state : variable

predicate w =^{Δ} ⟨gas, ignition, state⟩ Init =^{Δ} w = ⟨“off”, “off”, “Idle”⟩

actions HeatOn =^{Δ} ∧ HeatReq ∧ (state = “Idle”) ∧ (state′ = “Purge”) ∧ unchanged ⟨gas, ignition⟩

Out30 =^{Δ} ∧ (state = “Purge”) ∧ (state′ = “Ignite1”) ∧ unchanged ⟨gas, ignition⟩

Out1a =^{Δ} ∧ (state = “Ignite1”) ∧ (state′ = “Ignite2”) ∧ (ignition′ = “on”) ∧ (gas′ = “on”)

Out1b =^{Δ} ∧ (state = “Ignite2”) ∧ (state′ = “Idle”) ∧ (ignition′ = “off”) ∧ (gas′ = “off”)

FlOn =^{Δ} ∧ (state = “Ignite2”) ∧ Flame ∧ (state′ = “Burn”) ∧ (ignition′ = “off”) ∧ unchanged gas

GoIdle =^{Δ} ∧ (state = “Burn”) ∧ (¬Flame ∨ ¬HeatReq) ∧ (state′ = “Idle”) ∧ (gas′ = “off”) ∧ unchanged ignition

N =^{Δ} HeatOn ∨ Out30 ∨ Out1a ∨ Out1b ∨ FlOn ∨ GoIdle temporal

Control =^{Δ} Init ∧ □[N]_{w}

Fig. 11. The Control Actions.

is equivalent to inserting all the definitions from the BurnerEnvironment module, with the names of the defined symbols preceded by “Env.”.^{9} Similarly, the statement

include BurnerPhaseReqs as Burner(state)

is equivalent to including all the definitions of the BurnerPhaseReqs environment, with defined symbols renamed by prefacing them with “Burner(state).”. This makes state a free parameter of all those defined symbols, which must be instantiated when the symbol is used. (Note how it is instantiated with the bound variable s in the definition of Spec.) The complete specification is the conjunction of the burner’s complete specification and the environment specification,

9 In contrast to an imported module, whose parameters become parameters of the importing module, parameters of an included module are instantiated. In this case, there are no explicit instantiations, so the included module’s parameters are by default instantiated with parameters of the same name.

module BurnerPhaseReqs

import BurnerControl, RealTime

parameters ϵ_{1}, ϵ_{2} : R constants

temporal IdleReq =^{Δ} ∃ ∃ ∃ ∃ ∃ ∃x, y : ∧ VTimer(x, HeatOn, ϵ_{2}, w) ∧ MinTimer(x, HeatOn, w) ∧ VTimer(y, HeatOn, ϵ_{1}, w) ∧ MaxTimer(y)

PurgeReq =^{Δ} ∃ ∃ ∃ ∃ ∃ ∃x, y : ∧ VTimer(x, Out30 , 30, w) ∧ MinTimer(x, Out30 , w) ∧ VTimer(y, Out30 , 30 + ϵ_{1}, w) ∧ MaxTimer(y)

Ignite1Req =^{Δ} ∃ ∃ ∃ ∃ ∃ ∃x, y : ∧ VTimer(x, Out1a, 1, w) ∧ MinTimer(x, Out1a, w) ∧ VTimer(y, Out1a, 1 + ϵ_{1}, w) ∧ MaxTimer(y)

Ignite2aReq =^{Δ} ∃ ∃ ∃ ∃ ∃ ∃x, y : ∧ VTimer(x, Out1b, 1, w) ∧ MinTimer(x, Out1b, w) ∧ VTimer(y, Out1b, 1 + ϵ_{1}, w) ∧ MaxTimer(y)

Ignite2bReq =^{Δ} ∃ ∃ ∃ ∃ ∃ ∃x, y : ∧ VTimer(x, FlOn, ϵ_{2}, w) ∧ MinTimer(x, FlOn, w) ∧ VTimer(y, FlOn, ϵ_{1}, w) ∧ MaxTimer(y)

BurnReq =^{Δ} ∃ ∃ ∃ ∃ ∃ ∃x, y : ∧ VTimer(x, GoIdle, ϵ_{2}, w) ∧ MinTimer(x, GoIdle, w) ∧ VTimer(y, GoIdle, ϵ_{1}, w) ∧ MaxTimer(y)

PhaseReqs =^{Δ} IdleReq ∧ PurgeReq ∧ Ignite1Req ∧ Ignite2aReq ∧ Ignite2bReq ∧ BurnReq

Fig. 12. The control model’s timing requirements.

together with the formula RT (v) that describes how now changes and asserts that v does not change when now does. The burner’s specification is obtained by hiding the internal state variable in the conjunction of its time-independent specification, its timing requirements, and the RT -formula asserting that the internal state does not change when now does.^{10}

The next step is to prove that the Control Model satisfies requirements Req1 , Req2 , and Req3 . This means proving that formula Spec of module ControlModel implies Req1 ∧ Req2 ∧ Req3 . We very briefly sketch the proof that Spec implies Req1 ; the other proofs are similar.

We first reduce the problem to proving an assertion without quantification over flexible variables. Let Burner(s).VControl be the formula that is the same as Burner(s).Control except with the quantifiers ∃ ∃ ∃ ∃ ∃ ∃ x, y removed and each x and y replaced by a unique variable. For example, let xIgnite1 and yIgnite1 be substituted for x and y in Ignite1Req. Similarly, let Env.VSpec be the formula obtained by removing the quantifier from Env.Spec and substituting xEnv for x. Simple predicate logic shows that, to prove Spec ⇒ Req1 , it suffices to assume

10 Note that, since s does not appear in RT (v), the latter formula can be moved inside the quantifier; and RT (v) ∧ RT (s) is equivalent to RT (⟨v, s⟩).

module BurnerEnvironment

import BurnerParameters

predicate

Init =^{Δ} ⟨flame, heatReq⟩ = ⟨“off”, “off”⟩ actions

ChangeHeatReq =^{Δ} ∧ heatReq′ = if HeatReq then “off” else “on” ∧ unchanged flame

FlameOn =^{Δ} ∧ ¬Flame ∧ Gas ∧ Ignition ∧ (flame′ = “on”) ∧ unchanged heatReq

FlameOff =^{Δ} Flame ∧ (flame′ = “off”) ∧ unchanged heatReq

N =^{Δ} ChangeHeatReq ∨ FlameOn ∨ FlameOff temporal

Spec =^{Δ} ∧ Init ∧ □[N]_{⟨flame, heatReq⟩} ∧ ∃ ∃ ∃ ∃ ∃ ∃x : ∧ VTimer(x, FlameOff ∧ ¬Gas, 1/10, ⟨flame, heatReq⟩) ∧ MaxTimer(x)

Fig. 13. Timing assumptions on the environment.

module ControlModel

import BurnerParameters, RealTime

parameters ϵ_{1}, ϵ_{2} : R constants

assumption EpsilonAssumption =^{Δ} (0 < ϵ_{1}) ∧ (ϵ_{2} < ϵ_{1}) ∧ (ϵ_{1} ≤ 2/3)

include BurnerPhaseReqs as Burner(state) include BurnerEnvironment as Env temporal

Spec =^{Δ} ∧ ∃ ∃ ∃ ∃ ∃ ∃s : Burner(s).Control ∧ Burner(s).PhaseReqs ∧ RT (s) ∧ Env.Spec ∧ RT (v)

Fig. 14. The complete control model specification.

r ∈ R and prove Π ⇒ □(z ≤ 4), where

Π =^{Δ} ∧ [z =0+∫ G(r) | false, v] ∧ Burner(s).Control ∧ Burner(s).VPhaseReqs ∧ Env.VSpec ∧ RT (s) ∧ RT (v)

and G is defined by the let in the definition of Req1 .

The proof of Π ⇒ □(z ≤ 4) has the same form as the proof of step ⟨1⟩2 in the proof that RT (v) ∧ Req1 implies Req0 . We first prove Π ⇒ □T for a simple invariant T, which expresses the expected relations among the values of the variables. For example, one conjunct of T is

(s = “Ignite1”) ⇒ ∧ Gas ∧ Ignition ∧ (yIgnite1 ∈ R) ∧ (now ≤ yIgnite1 )

We then prove Π ∧ □T ⇒ □I for the following invariant I.

∧ z ≤ 4 ∧ (z > 0) ⇒ (z ≤ now − r) ∧ (now ∈ [[r, r + 30]]) ⇒ ∨ (s = “Idle”) ∨ (s = “Purge”) ∧ ((z > 0) ⇒ (xPurge ≥ r + 30)) ∨ (s = “Ignite1”) ∧ (z + (yIgnite1 − now) ≤ 1 + ϵ_{1}) ∨ (s = “Ignite2”) ∧ (z + yIgnite2a − now ≤ 2 + 2ϵ_{1}) ∨ ∧ (s = “Burn”) ∧ Gas ∧ ∨ Flame ∧ (z ≤ 2 + 2ϵ_{1}) ∨ ¬Flame ∧ (z + yBurn − now ≤ 2 + 3ϵ_{1})

The hard part of proving Π∧□T ⇒ □I is the analog of step ⟨3⟩2 in the proof that RT (v) ∧ Req1 implies Req0 . As usual, this step involves ordinary mathematics, with no temporal operators.

References

1. Martín Abadi and Leslie Lamport. An old-fashioned recipe for real time. Research Report 91, Digital Equipment Corporation Systems Research Center, 1992. An earlier version, without proofs, appeared in [3, pages 1–27].

2. K. Mani Chandy and Jayadev Misra. Parallel Program Design. Addison-Wesley, Reading, Massachusetts, 1988.

3. J. W. de Bakker, C. Huizing, W. P. de Roever, and G. Rozenberg, editors. Real-Time: Theory in Practice, volume 600 of Lecture Notes in Computer Science. Springer-Verlag, Berlin, 1992. Proceedings of a REX Real-Time Workshop, held in The Netherlands in June, 1991.

4. Urban Engberg, Peter Grønning, and Leslie Lamport. Mechanical verification of concurrent systems with tla. In Logics of Programs, Lecture Notes in Computer Science, Berlin, Heidelberg, New York, June 1992. Springer-Verlag.

5. Leslie Lamport. The temporal logic of actions. Research Report 79, Digital Equipment Corporation, Systems Research Center, December 1991.

6. A. C. Leisenring. Mathematical Logic and Hilbert’s ε-Symbol. Gordon and Breach, New York, 1969.

7. Zohar Manna and Amir Pnueli. The Temporal Logic of Concurrent Systems. Springer-Verlag, New York, 1991.

8. Anders P. Ravn, Hans Rischel, and Kirsten M. Hansen. Specifying and verifying requirements of real-time systems. IEEE Transactions on Software Engineering, January 1993. to appear.