29
The Existence of Renement Mappings
Martn Abadi and Leslie Lamport
August 14, 1988
Systems Research Center
DEC's business and technology objectives require a strong research program.
The Systems Research Center (SRC) and three other research laboratories are committed to lling that need.
SRC began recruiting its rst research scientists in l984|their charter, to advance the state of knowledge in all aspects of computer systems research.
Our current work includes exploring high-performance personal computing, distributed computing, programming environments, system modelling tech- niques, specication technology, and tightly-coupled multiprocessors.
Our approach to both hardware and software research is to create and use real systems so that we can investigate their properties fully. Complex systems cannot be evaluated solely in the abstract. Based on this belief, our strategy is to demonstrate the technical and practical feasibility of our ideas by building prototypes and using them as daily tools. The experience we gain is useful in the short term in enabling us to rene our designs, and invaluable in the long term in helping us to advance the state of knowledge about those systems. Most of the major advances in information systems have come through this strategy, including time-sharing, the ArpaNet, and distributed personal computing.
SRC also performs work of a more mathematical avor which complements our systems research. Some of this work is in established elds of theoretical computer science, such as the analysis of algorithms, computational geome- try, and logics of programming. The rest of this work explores new ground motivated by problems that arise in our systems research.
DEC has a strong commitment to communicating the results and experience gained through pursuing these activities. The Company values the improved understanding that comes with exposing and testing our ideas within the research community. SRC will therefore report results in conferences, in professional journals, and in our research report series. We will seek users for our prototype systems among those with whom we have common research interests, and we will encourage collaboration with university researchers.
Robert W. Taylor, Director
The Existence of Renement Mappings
Martn Abadi and Leslie Lamport
August 14, 1988
c
Digital Equipment Corporation 1988
This work may not be copied or reproduced in whole or in part for any com- mercial purpose. Permission to copy in whole or in part without payment of fee is granted for nonprot educational and research purposes provided that all such whole or partial copies include the following: a notice that such copying is by permission of the Systems Research Center of Digital Equipment Corporation in Palo Alto, California; an acknowledgment of the authors and individual contributors to the work; and all applicable portions of the copyright notice. Copying, reproducing, or republishing for any other purpose shall require a license with payment of fee to the Systems Research Center. All rights reserved.
Author's Abstract
Renement mappings are used to prove that a lower-level specication cor- rectly implements a higher-level one. We consider specications consisting of a state machine (which may be innite-state) that species safety re- quirements, and an arbitrary supplementary property that species liveness requirements. A renement mapping from a lower-level specication
S
1 to a higher-level oneS
2is a mapping fromS
1's state space toS
2's state space.It maps steps of
S
1's state machine to steps ofS
2's state machine and maps behaviors allowed byS
1 to behaviors allowed byS
2. We show that, un- der reasonable assumptions about the specications, ifS
1 implementsS
2, then by adding auxiliary variables toS
1 we can guarantee the existence of a renement mapping. This provides a completeness result for a practical, hierarchical specication method.Capsule Review
This report deals with the problem of proving that implementations satisfy their specications. Suppose, for example, that a client asks a circuit fabri- cator to build a box with
S
inside and with certain external signals (inputs and outputs). The circuit fabricator returns later with an epoxy brick that has an appropriate number of wires sticking out for the external signals, but that actually contains notS
but some other ciruitI
. In order to guarantee that the client cannot detect the substitution without breaking open the brick (and thereby voiding the warranty), the fabricator must be sure that for any possible behavior ofI
there corresponds at least one behavior ofS
that produces identical external signals.In some cases, such a correspondence between behaviors can be proved using a renement mapping, a function that maps states of
I
to states ofS
and that satises certain conditions. The renment mapping technique reduces a problem of proving something about arbitrary behaviors to one of proving something about single state transitions. Unfortunately there are many cases in which a correct implementationI
cannot be related to its specicationS
by a renement mapping.This report shows that it is possible in a very large class of cases to augment a legal implementation with some extra state components (history and prophecy variables) in a way that places no constraints on the behavior of the implementation but that makes it possible to produce an appropriate renement mapping to the specication. This result broadens considerably the domain of applicability of the renement mapping technique.
Contents
1 Introduction 1
1.1 Specications
: : : : : : : : : : : : : : : : : : : : : : : : : : :
1 1.2 Proving That One Specication Implements Another: : : : :
32 Preliminaries 6
2.1 Sequences
: : : : : : : : : : : : : : : : : : : : : : : : : : : : :
6 2.2 Properties: : : : : : : : : : : : : : : : : : : : : : : : : : : : :
7 2.3 Specications: : : : : : : : : : : : : : : : : : : : : : : : : : :
8 2.4 Renement Mappings: : : : : : : : : : : : : : : : : : : : : :
113 Finite Invisible Nondeterminism 12
4 Safety Properties 16
5 Auxiliary Variables 20
5.1 History Variables
: : : : : : : : : : : : : : : : : : : : : : : : :
20 5.2 Simple Prophecy Variables: : : : : : : : : : : : : : : : : : : :
22 5.3 Prophecy Variables That Add Stuttering: : : : : : : : : : : :
256 Internal Continuity 28
7 The Completeness Theorem 30
8 Whence and Whither? 35
References 38
1 Introduction
1.1 Specications
A system may be specied at many levels of abstraction, from a description of its highest-level properties to a description of its implementation in terms of microcode and circuitry. We address the problem of proving that a lower- level specication is a correct implementation of a higher-level one.
Unlike simple programs, which can be specied by input/output rela- tions, complex systems can be adequately specied only by describing their behaviors|that is, their possible sequences of inputs and outputs. We con- sider specication methods in which a behavior is represented by a sequence of states and a system is specied by a set of permitted behaviors. Input and output are represented in the state|for example, by including a key- board state describing which keys are currently depressed and a screen state describing what is currently displayed.
A specication should describe only the externally visible components of a system's state. However, it is often helpful to describe its behavior in terms of unobservable internal components. For example, a natural way to specify a queue includes a description of the sequence of elements currently in the queue, and that sequence is not externally visible. Although internal components are mentioned, the specication prescribes the behavior of only the externally visible components. The system may exhibit the externally visible behavior
hh
e
0; e
1; e
2; :::
iiwhere
e
i is a state of the externally visible component, if there exist statesy
i of the internal component such that the complete behaviorhh(
e
0;y
0);
(e
1;y
1);
(e
2;y
2); :::
iiis permitted by the specication. (We use hhii to denote a sequence.) A specication may allow steps in which only the internal state compo- nent changes|for example, a sequence
(
e ;y
);
(e ;y
);
(e ;y
);
(e ;y
);
(e ;y
); :::
Such internal steps are not externally visible, so the sequence of external states hh
e
0;e
1;e
1;e
1;e
2;:::
ii should be equivalent to the sequence hhe
0;e
1; e
2;:::
ii obtained by removing the \stuttering" steps frome
1 toe
1. Lethh
e
0;e
1;:::
ii be the set of all sequences obtained from hhe
0;e
1;:::
ii by re- peating states and deleting repeated states|that is, by adding and remov- ing nite amounts of stuttering. We consider only specications in which a sequence hhe
0;e
1;:::
ii is allowed only if all sequences in hhe
0;e
1;:::
ii are allowed. Such specications are said to be invariant under stuttering.The behaviors permitted by a specication can be described as the set of sequences satisfying a safety and a liveness property [AS86, Lam77]. In- tuitively, a safety property asserts that something bad does not happen and a liveness property asserts that something good does eventually happen.
In specifying a queue, the safety property might assert that the sequence of elements removed from the queue is an initial prex of the sequence of elements added to the queue. The liveness property might assert that an operation of putting an element into the queue is eventually completed if the queue is not full, and an operation of removing an element from the queue is eventually completed if the queue is not empty. (What operations are in progress and what elements they are adding to or have removed from the queue would be described by the externally visible state.)
We are concerned with specications in which the safety property is de- scribed by an \abstract" nondeterministic program; a behavior satises the property if it can be generated by the program. Liveness properties are described either directly by writing axioms or indirectly by placing fairness constraints on the abstract program. In a specication of a queue, the pro- gram describes the sequence of actions by which an element is added to or removed from the sequence of queued elements, ensuring the safety property that the correct elements are removed from the queue. Additional fairness constraints assert that certain actions must eventually occur, ensuring the liveness property that operations that should complete eventually do com- plete.
Many proposed specication methods involve writing programs and fairness conditions in this way [LS84, Lam83, LT87]. (Some methods do not consider liveness at all and just specify safety properties with programs.)
To describe specications formally, we represent a program by a state machine (whose set of states may be innite) and we represent the fairness constraints by an arbitrary supplementary condition. For our results, it does not matter if the supplementary condition species a liveness property.
1.2 Proving That One Specication Implements Another
A specication
S
1 implements a specicationS
2 if every externally visible behavior allowed byS
1is also allowed byS
2. To prove thatS
1 implementsS
2, it suces to prove that ifS
1 allows the behaviorhh(
e
0;z
0);
(e
1;z
1);
(e
2;z
2); :::
iiwhere the
z
i are internal states, then there exist internal statesy
i such thatS
2 allowshh(
e
0;y
0);
(e
1;y
1);
(e
2;y
2); :::
iiIn general, each
y
i can depend upon the entire sequence hh(e
0;z
0);
(e
1;z
1);
(e
2;z
2);:::
ii, and proving the existence of they
i may be quite dicult. The proof is easier if eachy
i depends only upone
i andz
i, so there exists a functionf
such that (e
i;y
i) =f
(e
i;z
i). To verify that hhf
(e
0;z
0);f
(e
1;z
1); f
(e
2;z
2);:::
ii satises the safety property ofS
2, it suces to show thatf
preserves state machine behavior|that is, it maps executions ofS
1's state machine to executions (possibly with stuttering) ofS
2's state ma- chine. Proving thatf
preserves state machine behavior involves reasoning about states and pairs of states, not about sequences. Verifying thatf
preserves liveness|meaning thathhf
(e
0;z
0);f
(e
1;z
1);f
(e
2;z
2);:::
iisatises the liveness property ofS
2|usually also requires only local reasoning, with no explicit reasoning about sequences. A mappingf
that preserves state machine behavior and liveness is called a renement mapping.In the example of a queue, the internal state
y
i of specicationS
2might describe the sequence of elements currently in the queue, and the internal statez
i of specicationS
1 might describe the contents of an array that im- plements the queue. To prove thatS
1 implementsS
2, one would construct a renement mappingf
such thatf
(e
i;z
i) = (e
i;y
i), wherey
i describes the state of the queue that is represented by the contents of the array described by statez
i.Several methods for proving that one specication implements another are based upon nding a renement mapping [LS84, Lam83]. In practice, if
S
1 implementsS
2, then these methods usually can prove that the im- plementation is correct|usually, but not always. The methods fail if the renement mapping does not exist. Three reasons why the mapping might not exist are:
S
2 may specify an internal state with \historical information" not needed byS
. For example, supposeS
requires that the systemdisplay up to three of the least-signicant bits of a three-bit clock.
This specication is implemented by a lower-level specication
S
1that alternately displays zero and one, with no internal state. A renement mapping does not exist because there is no way to dene the internal state of a three-bit clock as a function of its low-order bit.
S
2 may specify that a nondeterministic choice is made before it has to be. For example, consider two specicationsS
1 andS
2 for a sys- tem that displays ten nondeterministically chosen values in sequence.Suppose
S
2 requires that all values be chosen before any is displayed, whileS
1 requires each value to be chosen as it is displayed. Both specications describe the same externally visible behaviors, so each implements the other. However,S
2 requires the internal state to con- tain all ten values before any is displayed, whileS
1 does not specify any internal state, so no renement mapping is possible.
S
2may \run slower" thanS
1. For example, letS
1andS
2both specify clocks in which hours and minutes are externally visible and seconds are internal. Suppose that inS
2 each step increments the clock by one second, while inS
1 each step increments the clock by ten seconds.Both specications allow the same externally visible behaviors. To show that
S
2 implementsS
1, we can use the renement mappingf
that rounds the time down to the nearest multiple of ten seconds. For any complete behavior hhs
0;s
1;s
2;:::
ii allowed byS
2, the behaviorhh
f
(s
0);f
(s
1);f
(s
2);:::
ii is a complete behavior allowed byS
1 that contains nine \stuttering" steps for every step that changes the state.On the other hand, a complete behavior hh
s
0;s
1;s
2;:::
ii specied byS
1 may produce an externally visible change every six steps. For any mappingf
, the sequence hhf
(s
0);f
(s
1);f
(s
2);:::
ii may also produce an externally visible change every six steps. This is not allowed byS
2, which requires fty-nine internal steps for every externally visible one.Hence, no renement mapping can prove that
S
1 implementsS
2. If a renement mapping does not exist, it can often be made to exist by adding auxiliary variables to the lower-level specication. An auxiliary variable is an internal state component that is added to a specication with- out aecting the externally visible behavior. The three situations described above in which renement mappings cannot be found are handled as follows:Historical information missing from the internal state specied by
S
can be provided by adding a history variable|a well-known form of auxiliary variable that merely records past actions [Owi75].
If
S
2 requires that a nondeterministic choice be made before it has to be, thenS
1 can be modied so the choice is made sooner by adding a prophecy variable. A prophecy variable is a new form of auxiliary variable that is the mirror image of a history variable|its formal def- inition is almost the same as the denition of a history variable with past and future interchanged, but there is an asymmetry due to be- haviors having a beginning but not necessarily an end.If
S
2 runs slower thanS
1, then an auxiliary variable must be added toS
1 to slow it down. We will dene prophecy variables in such a way that they can perform this slowing.Our main result is a completeness theorem. It states that, under three hypotheses about the specications, if
S
1 implementsS
2 then one can add auxiliary history and prophecy variables toS
1 to form an equivalent spec- icationS
hp1 and nd a renement mapping fromS
hp1 toS
2. The three hypotheses, and their intuitive meanings, are:S
1 is machine closed. Machine closure means that the supplementary prop- erty (the one normally used to specify liveness requirements) does not specify any safety property not already specied by the state machine.In other words, the state machine does as much of the specifying as possible.
S
2 has nite invisible nondeterminism. This denotes that, given any nite number of steps of an externally visible behavior allowed byS
2, there are only a nite number of possible choices for its internal state com- ponent.S
2 is internally continuous. A specication is internally continuous if, for any complete behavior that is not allowed, we can determine that it is not allowed by examining only its externally visible part (which may be innite) and some nite portion of the complete behavior.We will show by examples why these three hypotheses are needed.
We will prove that any safety property has a specication with nite invisible nondeterminism, any specication of a safety property is internally continuous, and any property has a machine-closed specication. Therefore,
our completeness theorem implies that if the specications are written in a suitable form and
S
2 species only a safety property then one can ensure that a renement mapping exists. We will also show that, even whenS
2is not internally continuous, a renement mapping exists to show that
S
1satises the safety property specied by
S
2. Therefore, by writing suitable specications, renement mappings can always be used to prove the safety property of a specication if not its liveness property. We do not know if anything can be said about proving arbitrary liveness properties.Throughout this report, proofs are written in a self-explanatory struc- tured format. The format permits very careful proofs that can be read to any desired level of detail by ignoring lower-level statements. Writing proofs in this format helped us to eliminate many errors and greatly increased our condence in the correctness of the results.
A glossary/index of notations and conventions appears at the end of this report, along with an index. We hope they will help the reader cope with the formalism.
2 Preliminaries
2.1 Sequences
We now dene some useful notations for sequences. In these denitions,
denotes the sequence hhs
0;s
1;s
2;:::
ii and denotes the sequence hht
0;t
1; t
2;:::
ii. These sequences may be nite or innite. If is nite, we letkk denote its length and last() denote its last element, sokhhs
0;:::;s
m 1iik=m
and last(hhs
0;:::;s
m 1ii) =s
m 1. An innite sequence is said to be terminating i (if and only if) it is of the formhhs
0;s
1;:::;s
n;s
n;s
n;:::
ii| in other words, if it reaches a nal state in which it stutters forever.As usual, a mapping on elements is extended to a mapping on sequences of elements by dening
g
() to equal hhg
(s
0);g
(s
1);:::
ii, and to a mapping on sets of elements by deningg
(S
) to equalfg
(s
) :s
2S
g.The sequence
is said to be stutter-free if, for eachi
, eithers
i 6=s
i+1or the sequence is innite and
s
i =s
j for allj
i
. Thus, a nonterminating sequence is stutter-free i it never stutters, and a terminating sequence is stutter-free i it stutters only after reaching its nal state. We dene\
to be the stutter-free form of|that is, the stutter-free sequence obtained by replacing every maximal nite subsequences
i;s
i+1;:::;s
j of identicalelements with the single element
s
i. For example,\
hh0;
1;
1;
2;
2;
2;
3;
3;
3;
3;
4:::
ii = hh0;
1;
2;
3;
4;:::
iiWe dene
' to mean that\
=\
, so ' i and are equivalent up to stuttering, and we dene to be the set f : 'g. IfS
is a set of sequences, (S
) is the set f :9 2S:
2 g. A set of sequencesS
is closed under stuttering ifS
= (S
). Thus,S
is closed under stuttering i for every pair of sequences, with ', if 2S
then 2S
.We use \" to denote concatenation of sequences|that is, if k
k =m
, then = hhs
0;:::;s
m 1;t
0;t
1;:::
ii. If kkm
, we let jm denotehh
s
0;s
1;:::;s
m 1ii, the prex of of lengthm
.For any set , let ! denote the set of all innite sequences of elements in . An innite sequence hh
0;
1;
2;:::
ii of sequences in ! is said to converge to the sequence in ! i for allm
0 there exists ann
0 such that ijm =jm for alli
n
. In this case, we dene limi to be . This denition of convergence gives rise to a topology on !. We now recall some other denitions.Let
be an element of ! and letS
be a subset of !. We say that is a limit point ofS
i there exist elements i inS
such that limi =. The setS
is closed iS
contains all its limit points. The closure ofS
, denotedS
, consists of all limit points ofS
; it is the smallest closed superset ofS
.2.2 Properties
We can only say that one specication implements another if we are given a correspondence between the externally visible states of the two specica- tions. For example, if
S
2asserts that the initial value of a particular register is the integer 3 andS
1 asserts that the register's initial value is the se- quence of bits 1111100, then we can't say whether or notS
1 implementsS
2 without knowing how to interpret a sequence of bits as an integer. In general, to decide ifS
1 implementsS
2, we must know how to interpret an externally visible state ofS
1 as an externally visible state ofS
2. Given such an interpretation, we can translateS
1 into a specication with the same set of externally visible states asS
2. Thus, there is no loss of generality in requiring thatS
1 andS
2 have the same set of externally visible states.We therefore assume that all specications under consideration have the same xed set E of externally visible states. A state space is a subset of E I for some set I of internal states. We let E be the obvious
projection mapping from EI onto E. The set E itself is considered to be a state space for which E is the identity mapping.
If is a state space, then a -behavior is an element of !. A E- behavior is called an externally visible behavior. A -property
P
is a set of -behaviors that is closed under stuttering. A E-property is called an externally visible property. IfP
is a -property, then E(P
) is a set of externally visible behaviors but is not necessarily an externally visible property because it need not be closed under stuttering. The externally visible property induced by a -propertyP
is dened to be the set (E(P
)).If is clear from context or is irrelevant, we use the terms behavior and property instead of -behavior and -property. We sometimes add the adjective \complete", as in \complete behavior", to distinguish behaviors and properties from externally visible behaviors and properties.
A property
P
that is closed (P
=P
) is called a safety property. In- tuitively, a safety property is one asserting that something bad does not happen. To see that our formal denition of a safety property as a closed set captures this intuitive meaning, observe that if something bad happens, then it must happen within some nite period of time. Thus,P
is a safety property i, for any sequence not inP
, one can tell that is not inP
by looking at some nite prexji of . In other words, 62P
i there exists ani
such that for all if ji =ji then 62P
. Hence, 2P
i for alli
there exists ai 2P
such thatiji =ji. But limi=, which implies that 2P
; thus, 2P
i 2P
. Therefore,P
satises the intuitive denition of a safety property only ifP
=P
.Even though we do not use the formal denition, it is interesting to note that a -property
L
can be dened to be a liveness property i it is dense in !|in other words, ifL
= !. This means thatL
is a liveness property i any nite sequence of elements in can be extended to a behavior inL
. In a topological space, every set can be written as the intersection of a closed set and a dense set, so any propertyP
can be written asM
\L
, whereM
is a safety property andL
is a liveness property. Moreover,M
can be taken to beP
.2.3 Specications
A state machine is a triple (
;F;N
) whereis a state space. (Recall that this means EI for some set I of internal states.)
F
, the set of initial states, is a subset of .
N
, the next-state relation, is a subset of . (Elements ofN
are denoted by pairs of states enclosed in angle brackets, like hs;t
i.) The (complete) property generated by a state machine (;F;N
) consists of all innite sequenceshhs
0;s
1;:::
ii such thats
0 2F
and, for alli
0, eitherh
s
i;s
i+1i 2N
ors
i =s
i+1. This set is closed under stuttering, so it is a -property. The externally visible property generated by a state machine is the externally visible property induced by its complete property.We now show that the complete property
P
generated by a state machine is a safety property. This requires proving that if limi =and eachi 2P
, then 2P
. For any behavior = hhs
0;s
1;:::
ii and anyj
0, let j be the terminating behavior hhs
0;s
1;:::;s
j;s
j;s
j;:::
ii. Then is inP
i each j is inP
. Since limi =, eachj equals (i)j for somei
. Since eachiis in
P
, each (i)j is inP
, which implies that is also inP
. Hence,P
is closed, so the complete property generated by a state machine is a safety property. However, we will show in Section 3 that the externally visible property generated by a state machine need not be a safety property.A state machine (
;F;N
) is a familiar type of nondeterministic automa- ton, whereF
is the set of starting states andN
describes the possible state transitions. (However, remember that may be an innite set.) The set of sequences generated (or accepted) by such an automaton is usually dened to be the setA
of all sequences starting with a state inF
and progressing by making transitions allowed byN
. However, we also allow stuttering transi- tions, so we have dened the property generated by the state machine to be (A
) together with all terminating sequences obtained from nite prexes of behaviors in (A
) by innite stuttering.A specication
S
is a four-tuple (;F;N;L
), where (;F;N
) is a state machine andL
is a -property, called the supplementary property of the specication. The propertyM
generated by the state machine (;F;N
) is called the machine property ofS
. The (complete) property dened byS
is dened to beM
\L
, and the externally visible property dened byS
is dened to be (E(
M
\L
)), the externally visible property induced byM
\L
.State machines are easier to work with than arbitrary sets of sequences, so one would like to specify a property purely in terms of state machines.
However, the complete property generated by a state machine is a safety property. The supplementary property of a specication is needed to in- troduce liveness requirements. However, if we were to place no additional
requirement on our specications, we could use the supplementary property to do all the specifying. To see why this leads to trouble, let
S
2 be a speci- cation consisting of any arbitrary state machine that generates an externally visible safety propertyO
together with the trivial supplementary property that contains all behaviors. DeneS
1to be the specication with state space E whose state machine is the trivial one that generates all E-behaviors and whose supplementary property isO
. ObviouslyS
1 implementsS
2. The existence of a renement mapping fromS
1 toS
2 implies thatS
1's state machine implementsS
2's state machine. However,S
1 has the trivial state machine and no internal state. As we will see, auxiliary variables are added to a specication's state machine without aecting or being aected by the supplementary property. (This is what makes the addition of aux- iliary variables practical.) No sound method of adding auxiliary variables can transform the trivial machine into one that implements an arbitrary state machine. Therefore, we need some constraint on the supplementary property.In practice, we specify a desired property
P
by writingP
as the inter- sectionM
\L
of a safety propertyM
and a liveness propertyL
. We try to constructL
so that it does not specify any safety property, meaning that it does not rule out any nite behavior. More precisely, we try to chooseL
to be a liveness property such that any nite sequence of states generated by the state machine is the prex of a behavior inP
. For our results, it is not necessary thatL
be a liveness property; we need only require thatL
does not specify any safety property not implied byM
. To express this requirement formally, we say that a specicationS
having machine propertyM
and supplementary propertyL
is machine closed iM
=M
\L
.The following lemma implies that, for a machine-closed specication, we can ignore the supplementary property and consider only the state machine when we are interested in nite portions of behaviors.
Lemma 1
IfM
=P
, then every prex of a behavior inM
is the prex of a behavior inP
.Proof of Lemma 1
Given: A1.
M
=P
. A2. 2M
. A3.m
0.Prove: C1. There exists
2P
such thatjm=jm. Pf: 1. Choose iP
such that limi =.Pf: A1, A2, and the denition of
P
.2. Choose
n
0 such that, for alli
n
,ijm=jm. Pf: Denition of convergence.3. C1 holds.
Pf: Let
be n.End Proof of Lemma 1
The converse of this lemma is also true when
M
is generated by a state machine, but we will not need it.2.4 Renement Mappings
A specication
S
1 implements a specicationS
2 i the externally visible property induced byS
1is a subset of the externally visible property induced byS
2. In other words,S
1implementsS
2i every externally visible behavior allowed byS
1 is also allowed byS
2.A renement mapping from a specication
S
1 = (1;F
1;N
1;L
1) to a specicationS
2 = (2;F
2;N
2;L
2) is a mappingf
: 1!2 such thatR1. For all
s
21: E(f
(s
)) = E(s
). (f
preserves the externally visible state component.)R2.
f
(F
1)F
2. (f
takes initial states into initial states.)R3. Ifh
s;t
i2N
1 thenhf
(s
);f
(t
)i2N
2orf
(s
) =f
(t
). (A state transition allowed byN
1 is mapped byf
into a [possibly stuttering] transition allowed byN
2.)R4.
f
(P
1)L
2, whereP
1 is the property dened byS
1. (f
maps be- haviors allowed byS
1 into behaviors that satisfyS
2's supplementary property.)Conditions R1{R3 are local, meaning that they can be checked by reasoning about states or pairs of states rather than about behaviors. Condition R4 is not local, but checking it is simplied by the fact that
f
is not an arbitrary mapping on sequences, but is obtained from a mapping on states. Thus, one can apply local methods like well-founded induction to prove R4.Proposition 1
If there exists a renement mapping fromS
1 toS
2, thenS
1 implementsS
2.Proof of Proposition 1
.Given: A1.
S
i= (i;F
i;N
i;L
i), fori
= 1;
2.A2.
M
i is the machine property ofS
i, fori
= 1;
2.A3.
f
is a renement mapping fromS
1 toS
2. A4. 2 (E(M
1\L
1))Prove: C1.
2 (E(M
2\L
2)).Pf: 1.
f
(M
1)M
2.Given: A1.1.
=hhs
0;s
1;:::
ii2M
1. Prove: C1.1.f
()2M
2.Pf: 1.1.
f
(s
0)2F
2.Pf: By A1.1, A2, the denition of machine property (which per- mits stuttering), A3, and property R2 in the denition of renement mapping.
1.2. For all
i
0: hf
(s
i);f
(s
i+1)i2N
2 orf
(s
i) =f
(s
i+1).Pf: By A1.1, A2, the denition of machine property, A3, and property R3.
1.3. C1.1 holds.
Pf: By 1.1, 1.2, the denition of
f
() (it equals hhf
(s
0); f
(s
1);:::
ii), A2, and the denition of machine property.2.
f
(M
1\L
1)M
2\L
2.Pf: By 1, A3, and R4, since
g
(S
\T
)g
(S
)\g
(T
) for any setsS
andT
and any mappingg
.3. Choose
=hhs
0;s
1;:::
ii2M
1\L
1 such that E()'. Pf: Such a exists by A4 and the denition of . 4. E(f
()) = E().Pf: By A3 and R1.
5. E(
f
())'. Pf: By 3 and 4.6. E(
f
())2E(M
2\L
2).Pf: By 3 and 2.
7. C1 holds.
Pf: By 5, 6, and the denition of .
End Proof of Proposition 1
.3 Finite Invisible Nondeterminism
The machine property
M
of a specication is a safety property. However, the property that is really being specied by the specication's state machineis the externally visible property (E(
M
)) induced byM
. The following example shows that this externally visible property is not necessarily a safety property.Let E be the set
N
of natural numbers, and dene the state machine (;F;N
) by:equals E
N
.
F
equalsf(0;
0)g.
N
is the union of the following two sets:{
fh(0;
0);
(1;n
)i:n
2N
g,{
fh(m;n
+ 1);
(m
+ 1;n
)i:m;n
2N
g.A stutter-free behavior of this machine starts in state (0
;
0), goes to state (1;n
) for some arbitraryn
0, then goes through the sequence of states (2;n
1), (3;n
2),:::
, (n i
+1;i
) for somei
0, and terminates (stutters forever) in the state (n i
+ 1;i
).The set of externally visible behaviors induced by this state machine consists of all sequences obtainable by stuttering from a sequence
n of the formhh0;
1;
2;:::;n;n;n;:::
ii. This set is not closed, because limn =hh0
;
1;
2;
3;:::
ii, and hh0;
1;
2;
3;:::
ii is not in the set. The externally visible property specied by this state machine is the conjunction of two properties:1. The set of all behaviors that start in state 0 and change state only by adding 1 to the previous state.
2. The set of terminating behaviors.
The rst property is a safety property, but the second is a liveness property;
their intersection is neither a safety nor a liveness property.
The purpose of a specication is to specify an externally visible property.
We feel that the externally visible property specied by a state machine should be a safety property, so we want to restrict the class of allowed state machines.
The reason the externally visible property dened by the state machine in our example is not a safety property can be traced to the existence of innitely many state transitions h(0
;
0);
(1;n
)ithat correspond to the same externally visible transitionh0;
1i. It is this type of innite invisible nonde- terminism that allows the introduction of liveness into the externally visibleproperty of a state machine. To ensure that a state machine species only safety properties, we must restrict it to having nite invisible nondetermin- ism.Instead of dening the concept of nite invisible nondeterminism for a state machine, it is more general to dene it for a property. A state machine is dened to have nite invisible nondeterminism i the property it generates does.
Denition 1
LetP
be a property andO
its induced externally visible prop- erty (E(P
)). We say thatP
isn (for nitely invisibly nondeterministic) i for all 2O
and alln
0, the setf
\
(jm) : (m >
0)^ ( 2P
) ^ (E(jm)'jn)gis nite. We say that a specication is n i the complete property of the specication is n.
In other words, property
P
is n i every nite prex jn of any exter- nally visible behavior is the projection of only nitely many inequivalent (under ') nite prexes jm of complete behaviors inP
.If a property
M
is n then every stronger propertyP
is also n. (Prop- ertyP
is stronger than propertyM
iP
M
.) In our main theorem, instead of requiring that the state machine ofS
2is n, we make the weaker assumption thatS
2 is n. This is strictly weaker only ifS
2 is not machine closed, since a machine-closed specication is n i its state machine is n.The following proposition asserts that the externally visible property of a n state machine is a safety property. It is a simple corollary of the subsequent lemma, which will be used later as well.
Proposition 2
If a safety propertyP
is n, then the externally visible prop- erty (E(P
)) that it induces is also a safety property.Lemma 2 (Closure and nondeterminism)
Let propertyP
be n and letO
be the externally visible property that it induces. If is a limit point ofO
then there is a limit pointofP
such that E()'.Proof of Lemma 2
Given: A1. P is n.
A2.
O
= (E(P
)).A3.
is a limit point ofO
.Prove: C1. There exists
such that:C1a.
is a limit point ofP
. C1b. E()'.Pf: 1. Let n equal f
\
(jm) : (m >
0)^ (2P
) ^ (E(jm)'jn)g. For alln
, the set n is nite. (n is the set of stutter-free prexes of behaviors inP
that are externally equivalent tojn.)Pf: By A3, we can choose
2O
such thatjn =jn. Statement 1 then follows from A1 and Denition 1.2. For all
n
, the set n is nonempty.Pf: 2.1. Choose
2O
such that jn=jn. Pf: A3 implies the existence of . 2.2. Choose 2P
such that E()'.Pf: A2 and denition of imply the existence of
. 2.3. There existsm
such that E(jm)'jn.Pf: 2.2 and the denition of'. 2.4.
\
(jm)2n, so n is nonempty.Pf:
2P
(by 2.2), and E(jm)'jn(by 2.3 and 2.1), so 2.4 follows from 1 (the denition of n).3. For nite sequences
and, let i there is a (possibly empty) sequence such that = . For alln
and all 2 n+1 there exists02n such that 0.Pf: By 1 (the denition of n), since if
jm ' jn+1, then there existsm
0m
such thatjm0 'jn.4. There is an innite sequence
123:::
with each i 2i. Pf: By 1, 2, 3 and Konig's Lemma [Knu73, pages 381{383].5. For all
i
, choose 0i such that:5a.
0i 'i. 5b. k0iki
.5c.
01 0203:::
.Pf: The existence of the
0i is proved by induction using 4, where the length of 0i is increased by stuttering the last element when necessary.6. Let
bi be an element ofP
such that0i is a prex of bi.Pf: Since
i 2 i (by 4), the denition of i (1) implies that there exists a stutter-free sequence i2P
such thatiis a prex of i. By 5a and the assumption thatP
(like all properties) is invariant under stuttering, bi can be obtained by adding stuttering to i. 7. Letequal limbi.Pf:
exists by 6 (i a prex of i), 5b, and 5c.8. C1a holds.
Pf: Follows immediately from 7, 6 (
bi 2P
), and the denition of limit point.9. For every
i
there exists anm
i
such that E(bijm)'ji. Pf: 5a, 5b, 6, 4 (i2i), and 1 (the denition of i).10. lim E(
bi)'.Pf: Follows immediately from 9.
11. C1b holds.
Pf: By 6 (
bi 2P
), 7, and 10, since limi = implies limE(i) = E() .End Proof of Lemma 2
For a state machine to be n, it may not make an innite nondetermin- istic choice unless all but a nite part of that choice is immediately revealed in the externally visible state. We can weaken our denition by requiring only that the choice eventually be revealed. Formally, this means dening a property
P
with induced externally visible propertyO
to be n i for every inO
andn
0 there exists ann
0n
such that the setf
\
(jm) : (m >
0) ^ (2P
) ^ (E(jm) 'jn)^ 9
m
0: (E(jm0)'jn0)gis nite. However, using this weaker denition of nite invisible nonde- terminism would require somewhat more powerful prophecy variables and would complicate our proofs, so we will stick with our original denition.
4 Safety Properties
Alpern and Schneider [AS87] and others have observed in the nite-state case that there is a correspondence between state machines and externally visible safety properties. We extend their results to the innite-state case for state machines with nite invisible nondeterminism. We also prove a result that allows us to apply our completeness theorem to safety properties even when the internal continuity hypothesis dened later is not satised.
Proposition 2 implies that the externally visible property generated by a n state machine is a safety property. We now prove the converse.