fsv slide
fsv slide
Martin Kappes
Frankfurt University of Applied Sciences
1 Introduction 3
1.1 The Idea of Model Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Practical Examples for Model Checking . . . . . . . . . . . . . . . . . . . . . . 5
1.3 Formalisms for Model Checking . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3.1 System Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3.2 Requirements Specification . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3.3 Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4 Outline of this course . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5 Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
6 Spin 37
6.1 Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.2 Running Simulations in Spin . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.3 Simulation Options for Spin . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.4 Verifying a Model with Spin . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.5 Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
8 Transition Systems 59
8.1 Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2 Modeling Concurrent Processes as Transition Systems . . . . . . . . . . . . . . 60
8.3 Traces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
9 Finite Automata 61
9.1 Mathematical Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
9.1.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
9.1.2 Alphabets, Words, Languages . . . . . . . . . . . . . . . . . . . . . . . 62
9.2 Automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
9.3 Closure Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
9.4 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
9.5 Modeling Automata in Promela . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
9.6 Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
10 Büchi Automata 77
10.1 Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
10.2 ω-Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
10.3 Generalized Büchi-Automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
10.4 Safety Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
10.5 Liveness Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
10.6 Characterizing Safety and Liveness . . . . . . . . . . . . . . . . . . . . . . . . . 84
Contents III
10.7 Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Bibliography 97
Reading Instructions
These are the lecture notes for the course “Formal Specification and Verification”. Please note
that these notes do neither cover the complete material presented in lectures and/or exercises nor
are meant for self-study. Moreover, this class is based on textbooks. These notes are comple-
mentary to studying the literature and do not replace it.
1 Introduction
• no algorithm exists which can check two programs for equivalence and
• no algorithm exists to check whether a given program has any nontrivial property stated in
any form of specification.
Thus, the correctness of programs can, in general, not be algorithmically determined. Cor-
rectness of programs is of course one building block for establishing the reliability of software,
however, there is also no algorithm to compute, either precisely or approximately, the reliability
of an arbitrary software system, even if the reliabilities of the components in that system or the
reliabilities of the operations in the components are known [7].
While all nontrivial properties of software as represented by Turing-Machines, i.e., automata
with an infinite tape, are undecidable, it is well known that many relevant properties for the much
simpler class of Finite Automata can be determined by algorithms even with polynomial runtime.
Finite Automata are basically Turing Machines without a tape which can only process their input
in one direction. Thus, if it is possible to abstract relevant aspects of software into a finite state
model, many interesting properties of the model can be studied and determined algorithmically.
4 1 Introduction
Moreover, there are formalisms which allow to specify requirements for finite automata in a
manner such that these requirements can be algorithmically checked for a finite state model, in
particluar certain types of logic. It should be noted that these logics are not very expressive in
the sense that quite a few interesting properties for finite automata cannot be formulated within
such logic formalism. So, only certain properties can be checked. However, analogously to
Turing Machines, for more expressive logic formalisms nontrivial properties cannot be checked
algorithmically either. This is known as Gödel’s Incompleteness Theorem.
It has turned out that, while there are quite a few pitfalls an fallacies, using algorithmic meth-
ods based on simple formalisms can be still be quite useful in improving the correctness and
reliablilty of software (and especially also hardware). This is particularly the case for software
for which meaningful aspects can be abstracted into a finite automaton such as, e.g, communi-
cation protocols between multiple processes and other software which is not data-centric. Also,
relevant requirements for such systems can be formulated in simple logical formalisms and thus
automatically checked.
This overall process is called model checking. “Model checking is an automated technique
that, given a finite-state model of a system and a formal property, systematically checks whether
this property holds for (a given state in) that model” [1].
The overall workflow of model checking is shown in Figure 1.1: The system under consid-
eration is modeled in a formalism through which a system model is obtained. The model is an
abstraction from the actual system and includes the relevant aspects which are to be checked.
Also, the requirements for the system are specified in another formalism. Both the system ab-
straction and the properties are described in formalisms which then allow for automated model
checking of the properties against the system description. The model checking may have as out-
come that the properties hold in the model, i.e. the desired properties are satisfied. Also, it is
possible that model checking finds that the model violates the properties. In this case, a counter
1.2 Practical Examples for Model Checking 5
example is produced in which can be further examined through simulations of the system such
that the error can be found. However, there is a third possible outcome. Model checking essen-
tially works by exploring all possible outcomes of the model by an exhaustive search. If, during
this search, a counterexample is produced, the process will stop. However, the correctness of the
model is established by not finding any counterexample in any possible execution of the model.
In general, exhaustive search leads to exponential increases in runtime and memory use, so the
run of the model checker may yield an inconclusive result. In this case, the model needs to be
adapted.
As model checking checks any possible execution, it is not “biased towards the most probable
scenarios”, but will check any scenario. Hence, errors in very unlikely scenarios will also get
caught if a conclusive result is obtained. Clearly, one might also ask the question whether it
would not be better to focus on the very likely scenarios if an exhaustive check of the model is
impossible.
In summary, model checking has the following advantages:
• It is based on a formal foundation and the applied techniques are mathematically proven
to work.
• It allows for a partially automated verification which can be implemented in a tool.
• In case of property violations, it provides counterexamples which can be used to debug the
system model.
• It has relevant applications (protocols, hardware, control software).
However, there are quite a few disadvantages as well:
• The used formalisms have a very limited expressiveness and can only model certain as-
pects.
• The accuracy of the results depends on the quality of the used model and the formally
specified requirements which both may not be correct for the actual system under consid-
eration.
• Even for the limited formalisms, an automatic verification may fail due to exponential use
of time and space.
1.3.3 Checking
Thus, requirements R and system model M are specified as finite automata of sorts. Since
finite automata are closed under complementation and intersection and the constructions can
be done in an automated way, it is possible to check algorithmically whether the intersection
of the behavior of the model T (M) with the complement of the requirements T (R) is empty
or not, T (M) ∩ T (R) = 0.
/ If so, the model meets the requirements, if not, a counterexample
w ∈ T (M) ∩ T (R) is given - at least if the computational demands of the model and the require-
ments allow for it. The reason that the process may fail is that the system model can become
quite large (“state explosion”), and the negation of the requirements under consideration may
also lead to an exponential increase. Thus, model checking, even with such limited formalisms,
may fail.
1.4 Outline of this course 7
• Specifying safety and liveness properties of concurrent systems using temporal logic and/or
computational tree logic.
• Verifying that a concurrent system satisfies certain safety and liveness properties using
model checking algorithms.
1.5 Tasks
Task 1.1:
Describe the process of model checking.
Task 1.2:
Explain advantages and disadvantages of model checking.
Theorem 1.2 There is no algorithm solving the halting problem, i.e. the halting problem is
undecidable
Proof. Suppose, for the sake of contradiction, there was an algorithm HALT() solving the halting
problem:
bool result;
// we have no idea of halt’s inner workings but assume
// it will stop and output ’yes’ iff P halts on w and
// no otherwise.
// (...)
//
//
return result; // 0 == no, 1 == yes.
}
absurd() takes a program P as input and calls HALT(P,P). Therefore, HALT() computes
whether program P terminates when called with itself as input. If P terminates with itself as
input, then absurd() will get stuck in an infinite loop and will not terminate, if P does not
terminate with itself as input, then absurd() will terminate. Thus, absurd() always does the
opposite of P(P), we have
does not terminate if P terminates on P,
absurd(P) =
terminates fif P does not terminate on P.
Consider calling absurd() with itself as input. There are two possibilities. Either absurd()
terminates with itself as input or not.
Suppose absurd(absurd) terminates. We have HALT(absurd,absurd)=yes. In this case
absurd() will execute (*) and get stuck in an infinite loop and thus not terminate. On the
other hand, if absurd(absurd) does not terminate, we obtain HALT(absurd,absurd)=no and
absurd() will execute (**) and terminate. In summary, we have
does not terminate if absurd(absurd) does terminate,
absurd(absurd) =
terminates if absurd(absurd) does not terminate,
This is a contradiction. We conclude our assumption was wrong and that there is no algorithm
HALT(). □
1.5 Tasks 9
Theorem 1.3 (Rice’s Theorem for Recursive Sets) Let M be a program with output “yes” or
“no” when terminating and denote by T (M) the set of all inputs for which the program outputs
“yes”. Any nontrivial property ot T (M) is undecidable.
Proof. We prove that we could decide the Halting Problem if there was an an algorithm to decide
a nontrivial property.
Suppose there was a nontrivial property (i.e. a property which is not fulfilled or fulfilled for
any program) prop for which there was an algorithm which takes as input a program P and
outputs “yes” if P fulfills prop and “no” otherwise.:
Since the property is nontrivial, there is at least one program Q such that T (Q) fulfills the
property. Without loss of generality we also assume that 0/ (a program which never outputs “yes”
for any input) does not fulfil prop (otherwise we consider the complement of prop). For any
given program P and input w we construct the following program:
Clearly, we have
T (Q) if P terminates on w,
T(Q2) =
0/ if P does not terminate on w.
Thus,
1 if P terminates on w,
Prop(Q2) =
0 if P does not terminate on w.
Thus, we can construct an algorithm solving the halting problem as follows:
This is a contradiction. We conclude our assumption was wrong and that there is no algorithm
deciding the property. □
Thus, is is clear that we cannot algorithmically verify general programs and must restrict
ourselves to much simpler finite automata models.
2 Installing and Running Spin
To run iSpin, execute the file Spin/optional gui/ispin.tcl. More detailed instructions
and a Getting Started guide can be found at https://spinroot.com/spin/Man/3_SpinGUI.
html.
2.4 Tasks
Task 2.1:
Install Spin on a Machine and run it.
Task 2.2:
Install the required packages to run iSpin on a Machine and start it.
Task 2.3:
What are advantages and disadvantages of installing Spin in a Virtual Machine as opposed to
directly on a system?
3 Promela Language Basics
• [4]
• [12]
3.1 Fundamentals
In this course, we will use the modeling language Promela (PROcess MEta LAnguage) [11] in
conjunction with Spin, a tool for randomly or interactively simulating and analyzing systems, in
particular concurrent systems. Spin uses three types of objects: processes, variables and message
channels. It also allows for the checking of the defined models using assertions, logical formula
and so-called never claims. We will deal with these features in a later chapter. Here, we focus on
the basic language constructs and features.
Promela is intended for modeling a system with a finite number of processes (256 max). A
run of a Promela model does not require any input. The processes may run synchronous or
asynchronous and may communicate via channels or (shared) global variables. As processes run
interleaved in any arbitrary possible order, the system may be nondeterministic, i.e. two different
runs of the system may yield different results. Also, Promela allows for nondeterminism within
a single process. Its semantics are intended for using the model for verification through Model
Checking.
Promela is quite restricted in the sense that it does not have any libraries, pointers, ability to
define functions and floating-point variables. All structures are finite and bound.
1 int shared = 0
2
4 init {
5
6 if
7 :: (myvar < 10) -> assigned = 1
8 :: (myvar < 20) -> assigned = 2
9 :: (myvar == 10) -> assigned = 3
10 :: true -> break
11 fi
12 }
10 atomic {
11 printf("z:␣"); printm(z); printf("\n");
12 printf("y:␣"); printm(y); printf("\n");
13 }
14 q?a,b,c,_
15 atomic {
16 printm(a) printm(b) printm(c) printf("\n")
17 }
18 q?c,a,b,_ // flagged as type error
19 atomic {
20 printm(a) printm(b) printm(c) printf("\n")
21 }
22 }
23
24 init
25 { mtype numbers, nn;
26 mtype:fruit snack, ss;
27 mtype:sizes package, pp;
28 run recipient(pear, two)
29 //run recipient(small, two) // type error
30 //package = pear // type error
31 numbers = one
32 snack = pear
33 package = large
34 printm(numbers)
35 printm(snack)
36 printm(package)
37 printf("\n")
38 q!numbers,snack,large,9
39 //q!large,ss,pp,3 // type error
40 }
Table 3.1 shows the operators and precedence rules from the Promela Reference Pages [12].
Variables need to be declared and are strictly typed. They may be global or local to a process
depending on where they are declared (globally or in the process). The declaration of (one-
dimensional) arrays is possible. User-defined data types can be created with typedef. Listing
3.2 shows examples of the declaration and the use of variables.
Listing 3.2: Examples for Variable Declarations
1 #define N 5 // definition of a constant as preprocessor option
2 // declaration of global variables:
3 unsigned h : 4 // declaration of an unsigned with 4 bit
4 // initial value 0 if not specified
5 unsigned i : 5 = 8 // unsigned with 5 bit, initial value 8
6 byte z[N] // declaration of array of N bytes
7 // indices from 0 to N-1
8
The syntax of Promela is c-like. A complete grammar specification can be found in [10].
Statements in Promela may either be executable or not. The statement a==b is only executable
if a == b, otherwise execution blocks until it holds. Thus, executablilty of statements is one of
the main means for synchronization.
5 proctype A()
6 { atomic {turn == 1;
7 turn = 0; // Necessary for B to not block on turn==0
8 stateA == 1; // B must first execute stateA=1
9 stateB = 1;
10 }
11 }
3.5 Control Flow 19
12
13 proctype B()
14 { atomic {turn == 0; // If B is executed first, it will block here
15 stateB == 0; // A must first execute stateB=1
16 stateA = 1;
17 }
18 }
19 init
20 { atomic{run A();run B()};
21 }
Promela also features case selection, repetition and uncondituonal jumps. A case selection is
enclosed by the keywords if and fi.
if
:: (a != b) -> option1
:: (a == b) -> option2
fi
Moreover, each possible selection starts with ::, followed by a guard statement, -> and a se-
quence of statements (named option1 and option 2 in the example) which can get executed if the
guard statement is true. Please note that the guard statements may not me mutually exclusive.
In this case, the execution of the case selection is nondeterministc and any options for which the
guard-statement is true may get selected. If none of the guards of the possible selections is true,
the statement will block until one or more become available. It is also possible to use else as
guard. The option following else is executed if all other guards are false.
Note that using -> above is optional, the statement separator ; may also be used and is seman-
tically identical. The use of -> soley may simplify reading the code. Moreover, guard statements
need not be followed by any options.
Repetition is an extension to case selection and enclosed by the keywords do and od. The
syntax of the repetition structure is more or less identical to the selection structure. The repetition
may be ended by the break statement. The following shows a conter that is nondeterministically
increased or decreased. If its value is 3, the repetition may be stopped or the counter may be
increased or decreased. do will also block if none of the guards is true.
do
:: counter++
:: counter--
:: (counter == 3) -> break
od
Unconditional jumps can be facilitated by defining a label. The label is defined and placed in
the code with a colon and may be the target of a jump sttement. Labels must be unique and may
be used only within the same process. Label are not allowed in front of guards. The following
code shows a process fragment where counter is increased from 0 in increments of 1 to 10.
20 3 Promela Language Basics
counter = 0
label1:
if
:: counter < 10 -> counter ++; goto label1
:: else -> skip
fi
byte cc
select(cc: 5 .. 22)
will assign cc a value between 5 and 22. The boundaries may also be given by expressions.
16 init
3.7 Message Channels and Message Passing 21
17 {
18 run A()
19 run C(2,55)
20 }
Processes run concurrently, so the order of execution may be nondeterministic and a process
may not immediately start after creation.
Each process carries a specific pid which is stored in the predefined global variable pid.
The number of active processes is stored in nr pr. At most 255 processes can be running
simultaneously. Another useful predefined variable particularly for verification is lastand
holds the instantiation number of the process that performed the last step in the current execution
sequence.
declares a channel which may hold up to 8 messages of type byte. The names of channels may
be passed as parameters in the process instantiaton or through channels as well.
Messages in a channel may consist of more than a single field and elements of different types.
declares a channel which may hold up to 16 messages each of which contains a byte, a short and
a channel.
The statement mychannel!expr sends the value of expression expr to mychannel. Receiving
a message from the channel can be facilitated via mychannel?myvar and stores the value in
myvar. Also, the message is deleted from the channel. Reading without deletion is possible with
mychannel?<myvar>. Channels operate first-in-first-out. Statements to read from or write to a
channel which is empty or full respectively are blocking until one message is written to or read
from the channel. Writing to and reading from channels with more than a single field is done via
a comma-separated list, e.g., mysecondchannel!expr1,expr2,expr3.
8 {int x;
9 qforb?x;
10 printf("x␣=␣%d\n", x)
11 }
12
13 init {
14 chan qname = [1] of { chan };
15 chan qforb = [1] of { int };
16 run A(qname);
17 run B(qforb);
18 qname!qforb
19 }
Listing 3.6 presents an example from [11] which shows the passing of channel names. The
value printed will be 123.
For every channel, the predefined function len(mychannel) gives the number of messages
stored in the channel. This function may also be used as statement in which case it blocks if the
number of messages is zero.
Also, there are the functions full(mychannel), nfull(mychannel), empty(mychannel)
and nempty(mychannel) which return true or false and can be seen as special cases of len.
Channels of size 0 are so-called rendez-vous channels as communication is synchronous (send-
ing process blocks until message is read by a process and vice-versa).
Also, it is possible on the receiving side to use a constant as parameter when receiving a mes-
sage. In this case, the message will only be read if the constant matches the value in the message.
Similarly, eval(var) will only retrieve the message in the channel if the value of var matches
the respective message field. Functionally equivalent to mysecondchannel?eval(arg1),arg2
is the command mysecondchannel?arg1(arg2).
Furthermore, mysecondchannel?? arguments will retrieve (and delete) the first message
in the channel that matches constants specified in the arguments. For example, mysecondchannel??
1, ... will retrieve the first message where the first argument is 1. The non-deleting variant
mysecondchannel?? <1, ...> also exists.
Writing to a channel may also be done via mychannel!!expr. In this case, the message will
be lexicographically sorted into the channel, i.e. no first in. first out.
A simple example for the use of a channel is given in Listing 3.6.
8 }
3.8 Tasks 23
Three processes are created which randomly take messages out of the channel. If line 5 is
changed from channel?ignored,what to channel?eval(num),what, processes will only
take messages with their value of num in the first position. Consequently, changing the select
(where 1..3) statement in line 16 to select (where:1..4) will eventually lead to a timeout
as no messages with value 4 are being processed.
3.8 Tasks
Task 3.1:
Use len to implement the functions full, nfull, empty and nempty
Task 3.2:
Promela also features the expression channel?[variable]. Find out what this expression is
doing and give an example how it might be used.
Task 3.3:
In Listing 3.1, the variable is used. Explain what this variable is doing and where it is defined.
Task 3.4:
In the Promela Manual, it is stated that
is functionally equivalent to
#define ack 5
#define nak 4
#define err 3
#define next 2
#define accept 1
24 3 Promela Language Basics
Task 3.5:
Consider the following Promela code snippet:
#define LOW 0
#define HIGH 15
byte range = LOW;
do
:: range < HIGH -> range++
:: break
od
Assuming that the probability of choosing a guard which is true is uniformly distributed, what is
the probability of generating value i?
Does this behavour matter in simulations and verification or not?
4 Simple Promela Model Tasks
In this chapter, we will present some simple examples for models in promela by different authors
in order to also show various programming styles. They are formulated as task for the reader to
program themselves.
Task 4.2:
Write a revisited hello world program which starts another process that adds “revisited” behind
hello world.
Task 4.3:
Consider the following Promela code fragment;
1 active proctype P(){
2 int value;
3 do
4 /* code to be added here */
5 printf("value␣is:␣%d\n", value)
6 od
7 }
1. Add code such that value is set to either 0, 1 or 2 using the select-statement. Simulate
your model with Spin using random mode and interactive mode.
26 4 Simple Promela Model Tasks
Task 4.4:
Consider the following Promela code fragment:
1 #define N 10
2 active proctype P() {
3 int value[N];
4 int product = 1;
5
6 /* to be added */
7
8 }
1. Add code such that all elements of the array are initialized with the values 1 or 2.
2. Add code to calculate the product of all elements of the array and print it out.
3. Simulate your model with Spin in random and interactive mode and present example runs.
4. Determine and prove which values product can have. Valitate your assumptions by using
Spin in interactive mode.
5. Assuming an equal probability for all values to be 1 or 2, give a formula for the likelihood
of value to be x.
Task 4.5:
Write a Promela model which prints the first 20 natural numbers in random order. “Random” is
synonymous to any permutation of the numbers in the output is possible, likeliness disregarded.
10 proctype Q(){
11 int counter = 0
12 do
13 :: counter<N -> printf("Q␣"); counter++
14 :: else -> break
15 od
16 }
17
18 init {
19 atomic{run P();
20 run Q();}
21 }
1. Run the model in random and interactive mode. How many interleaving possibilities does
the program have and which?
2. How many possibilities are there for arbitrary values of N?
Task 4.7:
Consider the following Promela model:
1 int x = 8;
2 int y = 6;
3 int z = 0;
4
1. Complete the code such that process P writes all natural numbers up to N in ascending
order into the channel while process Q reads the numbers and prints them out. Both pro-
cesses shall terminate once the number N is sent/received.
3. Change M to 10 and run simulations of the model. Which changes can be observed?
1. Name all possible values for myvalue after executing the following Promela code:
byte myvalue=50
if
:: myvalue = 100
:: myvalue = 200
fi
4.5 Further Tasks 29
2. Name all possible values for myvalue after executing the following Promela code:
byte myvalue=50
int a = 5
if
:: a<5 -> myvalue = 100
:: else -> myvalue = 200
fi
3. Name all possible values for myvalue after executing the following Promela code:
byte myvalue=50
int a = 5
if
:: a<5 -> myvalue = 100
:: a<3 -> myvalue = 200
fi
4. Name all possible values for myvalue after executing the following Promela code:
byte myvalue=50
int a = 5
if
:: a<5 -> a=2
:: a=2 -> myvalue = 200
fi
5. Name all possible values for mybyte after executing the following Promela code:
byte mybyte=10
6. Name all possible values for mybyte after executing the following Promela code:
byte mybyte=10
7. Name all possible values for value after executing the following Promela code:
Task 5.2:
The Fibonacci Numbers are defined as follows: F(0) = 0, F(1) = 1 and F(n) = F(n − 1) +
F(n − 2) for all natural numbers n ≥ 2.
2. What is the maximum Fibonacci Number which can be computed and why?
3. Improve your program to calculate the highest Fibonacci number possible in Promela.
with the number of years he is supposed to spend in detention, using the same channel from
which he received the initial message.”
• Each ControlPillar waits for input commands sent through their input channel ctl. When-
ever a pillar receives a command, it atomically changes its own state –and the state of its
immediate left and right neighbours– to the opposite value. To this extent, pillars 0 and 4
must be considered neighbours of each other.
4 select(a: 0..1)
5 select(b: 0..1)
6 select(c: 0..1)
7
6 byte distance[N*N];
7 byte city, dest, tour, seen;
8 byte visited[N]; // shortest tour so far
9
12 // (0) -- (1)
13 // | \__/ |
14 // | / \ |
15 // (2) -- (3)
16
17 inline travel2(dest) {
18
34 5 Advanced Promela Model Tasks
33 init {
34 Dist(0,1) = 20; Dist(1,0) = 20
35 Dist(0,2) = 42; Dist(1,2) = 30
36 Dist(0,3) = 35; Dist(1,3) = 34
37
47 }
48
51 // exercises:
52 // 1. change it so that the distance going from a higher
53 // city number to a lower number is half that of going
54 // the other way (downhill/uphill)
55 // 2. change it to find the longest iso shortest tour
cally. One of these problems is the discovery of dead code, i.e., code that will never be executed
in any run of the program.
6.1 Fundamentals
The tool for simulating and analyzing Promela models is called Spin. It is particilarly suitable
for asynchronous distributed software systems and communication protocols, nevertheless it can
also be used for single processes. For the analysis of the models, correctness properties can be
specified in multiple ways.
For a Promela model, Spin can perform random, interactive or guided simulations of the
model. For analysis, Spin creates c-code from the model (pan.c) which can be compiled and
then be used to analyze it.
of the model will continue. If it is false (i.e. 0), the assertion violation will be reported and the
execution of the model will also continue. As we will see, assertions are mainly useful when
analyzing the model.
For now, we first start with a random simulation of the model which can be performed by
running Spin without options. We either obtain
or
as output. For now, we can ignore the details of the assertion. Clearly, the result of the sim-
ulation depends on the nondeterministic choice in the respective simulation which is randomly
performed by Spin.
We can also use interactive mode. By using the option -i, the user is prompted every time
a nondeterministic choice can be made and can select which of the alternatives to choose. For
example, we take choice 1 and obtain
It is also possible to run a simulation where the nondeterministic choices are selected according
to a recorded execution trail specified in simple.pml.trail. This option can be invoked by
using the option -t, i.e. spin -t simple.pml. It is particularly useful when examining an
error trail obtained from the analysis of a promela model. We will discuss this feature later.
• “-p: Shows the state changes of the Promela processes at every time step.
• -g: Shows the current value of global variables at every time step.
• -l: Shows the current value of local variables, after the process that owns them has
changed state.
• -r: Shows all message receive events. It shows the process performing the receive, its
name and number, the source line number, the message parameter number (there is one
line for each parameter), the message type and the message channel number and name.
Spin also offers quite a few more run-time options which can be foind in [15].
6.5 Tasks
Task 6.1:
Consider the Promela-model created in Section 4.2 for computing the product of N random
numbers with values either 1 or 2. For N = 10, Use an assert-statement and find a run where
the product is 1024 using verification.
Task 6.2:
Consider the following Promela model “Double”:
Listing 6.2: Promela Model “Double”
1 byte a,b,x
2
11
12 init
13 { x = 1
14 run proc(1)
15 run proc(2)
16 printf ("x␣=␣%d␣\n",x);
17 }
2. Use Spin to find all potential values which can be printed for x.
Task 6.3:
Consider the following Promela model:
For each property, state and explain whether the property is true or false. Present LTL-formulae
in Promela to automatically verify these claims and present the automatic verification.
7 Modeling Mutual Exclusion of Processes
7.1 Fundamentals
A general problem in interprocess communication are race conditions between processes (see
[16], pp. 119–148). This term refers to situatios in which processes access shared data and the
outcome depends on which process exactly runs when. Race conditions are in general unwanted
and need to be avoided.
Listing 7.1 shows an example for race conditions from [2]. If both processes (let us call them
A and B) are executed sequentially, the final value of n will be 20. However, if both processes
store the value of n in temp before the respective other process has saved its increment back,
3 proctype P() {
4 byte temp, i;
5 for (i : 1..10)
6 {
7 temp = n;
8 n = temp + 1
9 }
10 }
11
12 init {
13 atomic {
14 run P();
15 run P()
16 }
17 (_nr_pr == 1);
18 printf("The␣value␣is␣%d\n", n);
19 }
44 7 Modeling Mutual Exclusion of Processes
the increment is lost resulting in a final value of n lower than 20.The minimal value for n after a
competion of the two processes may even be as low as 2 if, e.g., processes A stores 0 in temp,
then process B runs uninterrupted until n is set to 9. At this point process A runs once setting
n back to 1. Then, process B stores 1 in temp after which A runs uninterrupted until it finishes.
Then B finally sets n to 2.
With the Promela model at hand, we can use Spin to find this particular execution of the model.
We append an assertion before the printf-statement assert(n>2) and run the commands
spin -a filename.pml
gcc pan.c -o pan
pan
and obtain a trail of a run violating the condition. We now look into this trail by running spin
-t -p -l -g filename.pml. The behavior outlined above can also clearlz be found in the
trail (boring parts are omitted):
3 proctype P() {
4 byte temp, i;
5 for (i : 1..10)
6 { atomic{
7 temp = n;
8 n = temp + 1
9 }}
10 }
11
12 init {
13 atomic {
14 run P();
15 run P()
16 }
17 (_nr_pr == 1);
18 printf("The␣value␣is␣%d\n", n);
19 }
Select a statement
choice 1: proc 1 (Q:1) notmutex.pml:15 (state 8) [printf(’Q noncritical \\n’)]
choice 2: proc 0 (P:1) notmutex.pml:4 (state 8) [printf(’P noncritical \\n’)]
Select [1-2]: 1
Q noncritical
Select a statement
choice 1: proc 1 (Q:1) notmutex.pml:17 (state 6) [((critical==0))]
choice 2: proc 0 (P:1) notmutex.pml:4 (state 8) [printf(’P noncritical \\n’)]
Select [1-2]: 2
P noncritical
Select a statement
choice 1: proc 1 (Q:1) notmutex.pml:17 (state 6) [((critical==0))]
choice 2: proc 0 (P:1) notmutex.pml:6 (state 6) [((critical==0))]
7.2 A Failed Attempt for Mutual Exclusion 47
13 }
14 active proctype Q(){
15 do
16 :: printf("Q␣noncritical␣\n");
17 if
18 :: critical == 0 -> critical=1;
19 printf("Q␣critical␣\n");
20 critical=0;
21 fi
22 od
23
24 }
Select [1-2]: 1
Select a statement
choice 1: proc 1 (Q:1) notmutex.pml:18 (state 3) [critical = 1]
choice 2: proc 0 (P:1) notmutex.pml:6 (state 6) [((critical==0))]
Select [1-2]: 2
Select a statement
choice 1: proc 1 (Q:1) notmutex.pml:18 (state 3) [critical = 1]
choice 2: proc 0 (P:1) notmutex.pml:7 (state 3) [critical = 1]
Select [1-2]: 1
Select a statement
choice 1: proc 1 (Q:1) notmutex.pml:19 (state 4) [printf(’Q critical \\n’)]
choice 2: proc 0 (P:1) notmutex.pml:7 (state 3) [critical = 1]
Select [1-2]: 2
Select a statement
choice 1: proc 1 (Q:1) notmutex.pml:19 (state 4) [printf(’Q critical \\n’)]
48 7 Modeling Mutual Exclusion of Processes
However, let us try to find this error using Spin’s verification features. The first possibility is
to introduce a variable which is not part of the model, but only used for verification purposes.
Such a variable is called ghost variable. We introduce a ghost variable which starts with value 0
is increased by one of a processe is in the critical section, and then decreased. If only one process
at a time is in the critical section, this variable should never reach the value 2. We then check this
with a corresponding assertion. The modified listing is shown in 7.4.
When verifying this model, a violation of the assertion is found and the respectve trail can be
studied. Clearly, this is a more systematic approach.
Another means of checking for the same property is the use of linear temporal logic. While
we will discuss this formalism in more detail in Chapter 11. The modified listing is shown in
Listing 7.5.
We have introduced two boolean ghost variables pcrit and qcrit which indicate whether the
respective processes are in their critical section. Clearly, in order to have mutual exclusion, both
variables should never be true at the same point in time at any point in time. In LTL, at any point
in time (or “always”) can be expressed by the □-operator, and the formula for not both variables
true is of course ¬(pcrit ∧ qcrit), which yields us the LTL-formula
In Promela, an LTL-foumla can be specified by providing the lexem ltl, a name for the for-
mula (here mutex) and the formula enclosed in curly brackets. The operators are translated into
Promelas syntax straightforward and leaves us with []!(pcrit && qcrit).
The usual steps and running pan give us again a trail of an execution where both processes are
in the critical region at the same time.
17 }
18 active proctype Q(){
19 do
20 :: printf("Q␣noncritical␣\n");
21 if
22 :: critical == 0 -> critical=1;
23 printf("Q␣critical␣\n");
24 ghostcounter++;
25 ghostcounter--;
26 critical=0;
27 fi
28 od
29
30 }
that process Q is in the critical region and the process blocks and will get unblocked once Q leaves
the critica region and sets qwant to 0.
The code shown in the listing still contains our code for verifying mutual exclusion, and we
now use Spin to check whether mutual exclusion holds. And, indeed, pan does not come back
with an error trial, so this model indeed guarantees mutual exclusion.
However, it contains another glitch which may lead to a deadlock. A deadlock in general refers
to a set of processes which are blocked waiting for an event which would also be triggered by
a process in the same set. As all processes are blocked, no process will trigger an event and all
processes will not resume forever.
50 7 Modeling Mutual Exclusion of Processes
Listing 7.5: Failed Attempt for Mutual Exclusion for Verification with LTL.
1 byte critical = 0
2 bool pcrit = 0;
3 bool qcrit = 0;
4 ltl mutex{[]!(pcrit && qcrit)}
5
19 }
20 active proctype Q(){
21 do
22 :: printf("Q␣noncritical␣\n");
23 if
24 :: critical == 0 -> critical=1;
25 printf("Q␣critical␣\n");
26 qcrit=1;
27 qcrit=0;
28 critical=0;
29 fi
30 od
31
32 }
In our case, a deadlock will occur if P and Q set their flags immediately after one another before
then checking the flag of the other process. Spin in interactive mode can reach this situation as
follows:
Select a statement
choice 1: proc 1 (Q:1) notmutexver.pml:22 (state 10) [printf(’Q noncritical \\n’)]
choice 2: proc 0 (P:1) notmutexver.pml:9 (state 10) [printf(’P noncritical \\n’)]
Select [1-2]: 1
7.3 Mutual Exclusion with Deadlock 51
20 }
21 active proctype Q(){
22 do
23 :: printf("Q␣noncritical␣\n");
24 qwant=true;
25 if :: pwant==false ->
26 printf("Q␣critical␣\n");
27 qcrit=1;
28 qcrit=0;
29 qwant=false;
30 fi
31 od
32
33 }
Q noncritical
Select a statement
choice 1: proc 1 (Q:1) notmutexver.pml:24 (state 2) [qwant = 1]
choice 2: proc 0 (P:1) notmutexver.pml:9 (state 10) [printf(’P noncritical \\n’)]
Select [1-2]: 2
P noncritical
52 7 Modeling Mutual Exclusion of Processes
Select a statement
choice 1: proc 1 (Q:1) notmutexver.pml:24 (state 2) [qwant = 1]
choice 2: proc 0 (P:1) notmutexver.pml:11 (state 2) [pwant = 1]
Select [1-2]: 1
Select a statement
choice 1: proc 1 (Q:1) notmutexver.pml:25 (state 8) [((pwant==0))]
choice 2: proc 0 (P:1) notmutexver.pml:11 (state 2) [pwant = 1]
Select [1-2]: 2
Select a statement
no executable choices
Let us now also use Spin’s verification feature to detect the deadlock. What we want is that
always at some time Q or P enter their critical section. However, there may be a time when none
of the processes is in the critical section, but eventually one of them enters. Something which
eventually happens can be specified in LTL using the ♢-operator. So, for “always eventually qcrit
or pcrit” we obtain
□♢(pcrit ∨ qcrit),
or in Promela’s syntax []<>(pcrit || qcrit).
We replace our original LTL-formula with this formula (named deadlock and again run our
verifier (pan -a). We obtain a trail of a violation of the condition as follows:
spin -t -p -l -g notmutexver.pml
ltl deadlock: [] (<> ((pcrit) || (qcrit)))
starting claim 2
Never claim moves to line 3 [(!((pcrit||qcrit)))]
Q noncritical
2: proc 1 (Q:1) notmutexver.pml:22 (state 1) [printf(’Q noncritical \\n’)]
Never claim moves to line 8 [(!((pcrit||qcrit)))]
P noncritical
4: proc 0 (P:1) notmutexver.pml:9 (state 1) [printf(’P noncritical \\n’)]
6: proc 1 (Q:1) notmutexver.pml:23 (state 2) [qwant = 1]
qwant = 1
8: proc 0 (P:1) notmutexver.pml:10 (state 2) [pwant = 1]
pwant = 1
<<<<<START OF CYCLE>>>>>
spin: trail ends after 10 steps
#processes: 2
pcrit = 0
qcrit = 0
pwant = 1
qwant = 1
10: proc 1 (Q:1) notmutexver.pml:24 (state 8)
10: proc 0 (P:1) notmutexver.pml:11 (state 8)
10: proc - (deadlock:1) _spin_nvr.tmp:7 (state 10)
2 processes created
7.4 A Probabilistic Solution 53
20 }
21 active proctype Q(){
22 do
23 :: printf("Q␣noncritical␣\n");
24 qwant=true;
25 if :: pwant==false ->
26 printf("Q␣critical␣\n");
27 qcrit=1;
28 qcrit=0;
29 qwant=false;
30 :: else -> qwant=false;
31 fi
32 od
33
34 }
exclusion is achieved while, also, no deadlock seems to occur. If we run a simulation of the
model, we can clearly observe this behavior:
spin deadlockprob.pml
ltl deadlock: [] (<> ((pcrit) || (qcrit)))
Q noncritical
P noncritical
P noncritical
Q critical
P noncritical
Q noncritical
Q critical
P critical
Q noncritical
P noncritical
P noncritical
Q critical
P noncritical
P noncritical
Q noncritical
P critical
Q noncritical
P noncritical
P noncritical
Q noncritical
Q critical
P noncritical
P critical
Q noncritical
Q critical
(...)
However, if we run pan -a on the analysis code, we obtain an error with the following trail
of the violation:
spin -t -p -l -g deadlockprob.pml
ltl deadlock: [] (<> ((pcrit) || (qcrit)))
starting claim 2
Never claim moves to line 3 [(!((pcrit||qcrit)))]
Q noncritical
2: proc 1 (Q:1) deadlockprob.pml:23 (state 1) [printf(’Q noncritical \\n’)]
Never claim moves to line 8 [(!((pcrit||qcrit)))]
P noncritical
4: proc 0 (P:1) deadlockprob.pml:9 (state 1) [printf(’P noncritical \\n’)]
6: proc 1 (Q:1) deadlockprob.pml:24 (state 2) [qwant = 1]
7.4 A Probabilistic Solution 55
qwant = 1
8: proc 1 (Q:1) deadlockprob.pml:25 (state 3) [((pwant==0))]
Q critical
10: proc 1 (Q:1) deadlockprob.pml:26 (state 4) [printf(’Q critical \\n’)]
<<<<<START OF CYCLE>>>>>
12: proc 0 (P:1) deadlockprob.pml:10 (state 2) [pwant = 1]
pwant = 1
14: proc 0 (P:1) deadlockprob.pml:16 (state 8) [else]
16: proc 0 (P:1) deadlockprob.pml:16 (state 9) [pwant = 0]
pwant = 0
P noncritical
18: proc 0 (P:1) deadlockprob.pml:9 (state 1) [printf(’P noncritical \\n’)]
spin: trail ends after 18 steps
#processes: 2
pcrit = 0
qcrit = 0
pwant = 0
qwant = 1
18: proc 1 (Q:1) deadlockprob.pml:27 (state 5)
18: proc 0 (P:1) deadlockprob.pml:10 (state 2)
18: proc - (deadlock:1) _spin_nvr.tmp:7 (state 10)
2 processes created
As can be seen, the trail shows an execution of the model violating our LTL-statement where
process P keeps looping while Q remains in the critical section and is not further executed!
While such an execution cannot be ruled out, it is on one hand practically arbitrarily unlikely as,
assuming a constant distribution of probalilities that p that P runs and (1 − p) that Q runs, the
probability for this behavior is pn after n executions of the model and converges to 0 for n → ∞.
The non-execution of a process which is reaty to run is also called starvation.
Spin also offers a feature to only consider executions of the model which are (weakly) fair.
This can be achieved by using the option -f (please note that spin is somewhat experimental and
the feature not well-documented, thus different behaviour may also be observed, caution should
be used). However, by running pan -a -f we still obtain a violation with the following trail:
spin -t -p -l -g deadlockprob.pml
ltl deadlock: [] (<> ((pcrit) || (qcrit)))
starting claim 2
Never claim moves to line 3 [(!((pcrit||qcrit)))]
Q noncritical
2: proc 1 (Q:1) deadlockprob.pml:23 (state 1) [printf(’Q noncritical \\n’)]
Never claim moves to line 8 [(!((pcrit||qcrit)))]
P noncritical
4: proc 0 (P:1) deadlockprob.pml:9 (state 1) [printf(’P noncritical \\n’)]
6: proc 1 (Q:1) deadlockprob.pml:24 (state 2) [qwant = 1]
qwant = 1
56 7 Modeling Mutual Exclusion of Processes
qcrit = 0
pwant = 0
qwant = 1
52: proc 1 (Q:1) deadlockprob.pml:25 (state 10)
52: proc 0 (P:1) deadlockprob.pml:8 (state 12)
52: proc - (deadlock:1) _spin_nvr.tmp:7 (state 10)
2 processes created
Here, the unproductive cycle is due to the fact that neither P or Q enter the critical section, but
both defer access indefinetely. Regarding the likelihood for this behaviour, similar considerations
as above yield the result that it is arbitrarily unlikely. However, there are no built-in options to
only consider practically really relevant scenarios for this case.
7.6 Tasks
Task 7.1:
Assume we modify Listing 7.1 to run P three times. What would be the possible value range for
n?
Task 7.2:
Verify for Listing 7.2 that the final value of n is always 20 using Spin.
Task 7.3:
Create a Promela model for Peterson’s algorithm. Verify mutual exclusion and deadlock-freeness
with Spin.
Task 7.4:
Create a Promela model using Peterson’s algorithm instead of atomicity to resolve the race con-
dition from Listing 7.1
8 Transition Systems
8.1 Fundamentals
A powerful modeling tool for modeling processes in Computer Science are Transition Systems:
T = (Q, Σ, δ , Q0 , AP, L)
where
Q is a set of states
Σ is a set of actions
Q0 ⊆ Q is the set of initial states
Q
δ : Q×Σ → 2 the transition relation
AP is a set of labels
L : Q → 2AP ⊆ Q is the labelling function.
8.3 Traces
Definition 8.3 Let T = (Q, Σ, δ , Q0 , AP, L) be a transition system without terminal states. The
trace of an execution ρ = q0 σ1 q1 σ2 q2 . . . is given by
Furthermore,
trace(T ) = {trace(ρ) | ρ is an execution of T }
Theorem 8.4 Let T = T = (Q, Σ, δ , Q0 , AP, L) be a transition system without terminal states with
a finite number of states over a finite set of actions. Then there is a Büchi-Automaton M with
Tω (M) = trace(T ).
Proof. Without loss of generality, we assume T has only one initial state, {q0 } = Q0 . We define
the B"uchi-Automaton M = (Q, 2AP , δ ′ , q0 , Q) where for all σ ∈ 2AP
Example 9.1 Consider the set A = {p, q, r}. We have |A| = 3 and
2A = {0,
/ {p}, {q}, {r}, {p, q}, {p, r}, {q, r}, {p, q, r}}.
Definition 9.2 Let A and B be two sets. The product between A and B, A × B, is the set
A × B = {(a, b) |a ∈ A, b ∈ B}.
Definition 9.3 A binary relation R on a set A is a subset of the product of A with itself, R ⊆ A ×A.
For such a relation we put R0 := {(a, a) ∈ A × A | a ∈ A} and Rk := {(a, c) ∈ A × A | there is a b ∈
A, such that (a, b) ∈ R and (b, c) ∈ Rk−1 }. The transitive closure of R is R+ := ∪i≥1 Ri , the reflex-
ive transitive closure R∗ := ∪i≥0 Ri .
For binary relations we use aRb synomynously for (a, b) ∈ R.
A relation R ⊆ A × A is called
• transitive, if for all a, b, c ∈ A we have: If aRb and bRc, then aRc holds,
Example 9.4 Consider the latin alphabet A = {a, b, c, . . . , z} and the binary alphabet B = {0, 1}.
Words over an alphabet are constructed by concatenating symbols of the alphabet. For an
alphabet Σ, Σ∗ denotes the set of all words over the alphabet including the empty word ε. The set
of all non-empty words is Σ+ := Σ∗ − {ε}. The length |w| of a word w is the number of symbols
it constructed of, |ε| = 0. The set of all non-empty words of length k is Σk := {w ∈ Σ+ | |w| = k},
Accordingly, Σ⋄k := {w ∈ Σ+ | |w| ⋄ k} for ⋄ ∈ {<, ≤, >, ≥}. A word v ∈ Σ∗ is called (proper)
substring of x ∈ Σ∗ if there is a partitioning x = uvw such that u, w ∈ Σ∗ (and |uw| > 0). If |u| = 0
(|w| = 0), v is called prefix (suffix) of x. For two words x = σ1 . . . σm and y = τ1 . . . τn ∈ Σ∗ ,
σi ∈ Σ, 1 ≤ i ≤ m, τi ∈ Σ, 1 ≤ i ≤ n the concatenation xy of x and y, i.e. the word consistin of the
m + n symbols xy = σ1 . . . σm τ1 . . . τn .
Example 9.5 For the alphabets A and B as above, we have 01101 ∈ B∗ and test ∈ A∗ . Also,
|01101| = 5 and |test| = 4. Furthermore,
B∗ = {ε, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101, 110, 111, 0000, . . .}
and
A∗ = {ε, a, b, . . . , z, aa, . . . , az, ba, . . .}.
The set of all words of length 3 over B is
B3 = {000, 001, 010, 011, 100, 101, 110, 111}.
For x = 01001 and y = 10010110 we have xy = 0100110010110.
Formal languages consist of a (not necessarily empty) set of words over an alphabet Σ. Any
subset L ⊆ Σ∗ is called formal language.
Example 9.6 Again, consider B as above. Examples for formal languages over B are
L1 = {ε, 0, 00, 000, 0000, 00000, 000000, . . .}
L2 = {w ∈ B∗ | the number of ones in w is even}
L3 = 0/
L4n = {x1y ∈ B∗ | x ∈ B∗ , y ∈ Bn−1 }.
L1 ist the set of all words over B which do not contain a one. L4 is the set of all worfs over B
where the nth position from the end is a one.
If not explicitly stated, w denotes a (possibly empty) word w ∈ Σ∗ and σ an input symbol
σ ∈ Σ.
Let L ⊆ Σ∗ . The complement of L is definde as L = Σ∗ − L. Hence, for every w ∈ Σ∗ we have
eitherL or L; L is partitioning Σ∗ in two parts.
For a subset Γ ⊆ Σ |w|Γ is the number of occurences of symbols from Γ in w. for singleton
sets, we use the notation |w|a instead of |w|{a} .
9.2 Automata 63
9.2 Automata
Definition 9.7 (NFA) A Nondeterministic Finite Automaton (NFA) M is a tuple
M = (Q, Σ, δ , q0 , F)
where
Q is a non-empty finite set of states
Σ is a non-empty finite set of symbols
q0 ∈ Q is the initial state
F ⊆Q is a set of final states
δ : Q × Σ → 2Q the transition function.
Σ∗ denotes the set of all inputs for M including the empty word ε. The set of all non-empty inputs
is denoted by Σ+ := Σ∗ − {ε}. The length of an input |w| is the number of symbols it consists of,
we have |ε| = 0. If not mentioned differently, w denotes a (potentially empty) input w ∈ Σ∗ and
σ denotes a symbol σ ∈ Σ. Furthermore i, j, k, m and n denote natural numbers (including 0). We
also use the notation a ≤ i ≤ b for i ∈ {a, a + 1, . . . , b}. For a set A, |A| denotes the cardinality
of the set and the set of all subsets is given by 2A . Sometimes, the alphabet symbols for the
automata under consideration are sets over a finite set of atomic propositions of a propositional
logic AP, i.e. Σ = 2AP .. In this case, we also use the symbolic notation for transitions of the
automata, particular in depictions. For a formula φ over AP, φ refers to the set of sets of atomic
propistions which satisfy φ = {A ∈ 2AP | A |= φ }.
Definition 9.8 (Extended δ -function) Let M = (Q, Σ, δ , q0 , F) an NFA with δ : Q × Σ → 2Q . We
define
δ̂ : 2Q × Σ∗ → 2Q
as follows:
δ̂ (A, ε) := A for all A ∈ 2Q
for all A ∈ 2Q , w ∈ Σ∗ , σ ∈ Σ.
S
δ̂ (A, wσ ) := δ (q, σ )
q∈δ̂ (A,w)
For subsets of Q consisting of a single element, we also may drop the brackets in the notation.
Also, we will refer to δ̂ simply by δ .
Definition 9.9 The language T (M) accepted by an NFA M = (Q, Σ, δ , q0 , F) is defined as
T (M) := {w ∈ Σ∗ | δ (q0 , w) ∩ F ̸= 0}.
/
Two automata M and M ′ are called equivalent if T (M) = T (M ′ ). The set of all languages
which can be accepted by an NFA is called regular languages. The set of regular languages is
closed under concatenation, intersection, union, Kleene-∗, homomorphims and inverse homo-
morphisms. We will look into some of these operations in detail later.
Automata are often specified using a table for the specification of the δ -function. Moreover,
they can be represented by a transition diagram (see Tasks).
64 9 Finite Automata
a,b
Figure 9.1: NFA with n + 1 states for which each equivalent DFA has at least 2n states.
Definition 9.10 (DFA) A finite automaton M = (Q, Σ, δ , q0 , F) is called Deterministic Finite Au-
tomaton (DFA) if
For a DFA, we have |δ (q, w)| = 1 for all q ∈ Q and w ∈ Σ∗ . Consequently, we can use an extended
δ -function δ̌ : Q × Σ∗ → Q which we also refer to as δ .
Theorem 9.11 For every NFA M with n states there is a DFA M ′ with 2n states and T (M ′ ) =
T (M).
Proof. Let M = (Q, Σ, δ , q0 , F) be an NFA with |Q| = n. We construct a DFA M ′ := (Q′ , Σ, δ ′ , [q0 ], F ′ )
via the so-called power set construction:
Q′ := {[A] | A ∈ 2Q }
F′ := {[A] ∈ Q′ | A ∩ F ̸= 0}
/
δ ′ ([A], σ ) := [δ (A, σ )] for all A ∈ 2Q , σ ∈ Σ.
States in M ′ are all sets of states from M. We can prove by induction: For all w ∈ Σ∗ we have:
Thus we have
w ∈ T (M) ⇔ δ (q0 , w) = A ∧ A ∩ F ̸= 0/
⇔ δ ([q0 ], w) = [A] ∧ [A] ∈ F ′
′
⇔ w ∈ T (M ′ ).
In the above construction, each NFA with n states is converted into a DFA with 2n states, i.e.
there is an exponential blow-up in the number of states. While this construction may sometimes
yield an DFA for which equivalent smaller DFA exist, there are cases in which the construction
yields a minimal DFA:
Fact 9.12 There exists an infinite sequence of languages Li , i ≥ 1 such that there is an NFA Mi
for Li with n states but every equivalent DFA needs at least 2n states.
9.3 Closure Properties 65
While we will just state this as fact, we will now consider an example for which we almost
achieve such an exponential blow-up in the number of states.
Example 9.13 Consider the NFA with n states in Figure 9.1 which operates over Σ = {a, b}.
It operates as follows: In the initial state q0 , the automaton has the choice to remain in q0 for
arbitrary symbols or -in case the input symbol is an a, to proceed to q1 . From qi , 1 ≤ i < n the
automaton proceeds to qi+1 for any input symbol. qn is accepting and has no transition to other
states. In other words, the automaton accepts an input if the n-th position from the end of the
input is an a,
The NFA ”guesses” if an a it sees is at the nth position before the end or not. If not, it remains
in q0 , if yes, it moves to q1 .
Every DFA for T (M) need at least 2n states. Suppose for the sake of contradiction that there
was a DFA M = (Q, Σ, δ , q0 , F) with less than 2n states. Then, there are two x, y ∈ Σn , x ̸= y.
where δ (q0 , x) = δ (q0 , y) (since there are 2n such words). Since x and y are different, they dif-
fer in at least one position. W.l.o.g. we may assume that x = x1 az and y = y1 bz, |x1 | = |y1 | =
n − 1 − |z|. As xan−1−|z| is in L, we have δ (q0 , xan−1−|z| ) ∈ F. However, δ (q0 , xan−1−|z| ) =
δ (δ (q0 , x), an−1−|z| ) = δ (δ (q0 , y), an−1−|z| ) = δ (q0 , yan−1−|z| ). Therefore, yan−1−|z| will be ac-
cepted by M. However, yan−1−|z| ) ∈ / L, contradiction.
L∗ :=
[
Li .
0≤i≤∞
Proof. Let L1 ⊆ Σ∗ and L2 ⊆ Σ∗ be two regular languages. Then, there are two NFA M1 =
(Q1 , Σ, δ1 , q10 , F1 ) and M2 = (Q2 , Σ, δ2 , q20 , F2 ) with T (M1 ) = L1 and T (M2 ) = L2 . Without loss of
generality we assume Q1 ∩ Q2 = 0. / We construct M = (Q1 ∪ Q2 , Σ, δ , q10 , F) where
δ1 (q, σ ) if q ∈ Q1 − F1
δ (q, σ ) := δ1 (q, σ ) ∪ δ (q20 , σ ) if q ∈ F1
δ2 (q, σ ) if q ∈ Q2
66 9 Finite Automata
Proof. Let L1 ⊆ Σ∗ and L2 ⊆ Σ∗ be two regular languages. Then, there are two NFA M1 =
(Q1 , Σ, δ1 , q10 , F1 ) and M2 = (Q2 , Σ, δ2 , q20 , F2 ) with T (M1 ) = L1 und T (M2 ) = L2 . Without loss of
generality we assume Q1 ∩ Q2 = 0/ and q0 ∈ / Q1 ∪ Q2 a new state. We construct M = (Q1 ∪ Q2 ∪
{q0 }, Σ, δ , q0 , F) with
δ1 (q, σ ) if q ∈ Q1
δ (q, σ ) := δ2 (q, σ ) if q ∈ Q2
δ1 (q10 , σ , ) ∪ δ2 (q20 , σ ) if q = q0
for all q ∈ Q, σ ∈ Σ.
9.4 Regular Expressions 67
Regular expressions are for reasons of distinction often printed in bold. The language associated
with a regular expression is uniquely defined due to the bracketing. The following precedeces
are used to simplify regular expressions: ∗ before concatenation and concatenation before +.
Hence, the regular expression ((((ab)b)∗ ) + (b(a∗ ))) can be simplified to (abb)∗ + ba∗ . For a
regular expression αα ∗ , we also use the simplification α + . We also use a regular expression γ
synonymously for L(γ).
Lemma 9.22 Let L be a regular language. Then, there is a regular expression γ with L = L(γ).
Proof. Let L be regular. Then, there is a DFA M = (Q, Σ, δ , q1 , F) mit T (M) = L. Without loss
of generality we assume the states in M to be numbered from 1 to n: Q = {q1 , . . . , qn }. We define
(k)
Ri, j := {w ∈ Σ∗ | δ (qi , w) = q j and for all ql ∈ Q and w1 , w2 ∈ Σ+
with w = w1 w2 and δ (qi , w1 ) = ql
we have l ≤ k}.
9.4 Regular Expressions 69
(k)
Intuitively, Ri, j consists of the set of all words over Σ, with which one in M gets from state qi to
state q j without going over intermediate states with an index number higher than k.
S (n)
It is not difficult to show T (M) = qr ∈F R1,r .
(k) (k)
We now prove by induction over k: There is a regular expression ri, j with L(ri, j ) = Rki, j .
Basis for Induction k = 0. For k = 0 no intermediate states at all can be present. Thus, we have
(0)
Ri, j = {a ∈ Σ | δ (qi , a) = q j } ∪ {ε | i = j}.
(0)
It is easy to construct a regular expression for Ri, j .
(k+1)
Suppose the inductive hypothesis is valid for k < n. We consider Ri, j . We have
(k+1) (k)
as every w ∈ Ri, j either does not pass through stateqk+1 and is already contained inRi, j or state
(k) (k) (k)
k + 1 is passed once or multiple times, in which case w is contained in Ri,k+1 (Rk+1,k+1 )∗ Rk+1, j .
(k) (k) (k) (k)
Due to the inductive hypothesis, there are regular expressions ri, j , ri,k+1 , rk+1,k+1 and rk+1, j with
(k) (k) (k) (k) (k) (k) (k) (k)
L(ri, j ) = Ri, j , L(ri,k+1 ) = Ri,k+1 , L(rk+1,k+1 ) = Rk+1,k+1 and L(rk+1, j ) = Rk+1, j .
Thus, we have for the regular expression
(k+1) (k+1)
L(ri, j = Ri, j .
(n)
A regular expression for T (M) can be constructed by building the union over r1, j for all q j ∈ F
(plus-operator). □
Start q a q a q
1 2 3
b
a,b
70 9 Finite Automata
We have
(0)
r1,1 = ε +b
(0)
r1,2 = a
(0)
r1,3 = 0/
(0)
r2,1 = b
(0)
r2,2 = ε
(0)
r2,3 = a
(0)
r3,1 = a+b
(0)
r3,2 = 0/
(0)
r3,3 = ε
(3) (3)
For ri, j we only calulate r1,3 , as q3 is the only accepting state.
9.5 Modeling Automata in Promela 71
Example 9.24 Consider the DFA from 9.23. An example for a Promela model for the automaton
is as follows (we use 0 for a and 1 for b for simplification):
Listing 9.1: NFA from Figure 9.23 in Promela.
1 # define N 10
2 byte input[N+1] = { 0, 1, 1, 0, 1, 0, 1, 0, 1, 2 }
3 byte state = 1
4 active proctype automaton() {
5 int ctr = 0
6 byte what
7 do
8 :: atomic { what = input[ctr]-> ctr++;
9 if ::(what == 0 && state == 1) -> state = 2; printf("|q1|␣-a->")
10 ::(what == 1 && state == 1) -> state = 1; printf("|q1|␣-b->")
11 ::(what == 0 && state == 2) -> state = 3; printf("|q2|␣-a->")
12 ::(what == 1 && state == 2) -> state = 1; printf("|q2|␣-b->")
13 ::(what == 0 && state == 3) -> state = 1; printf("|q3|␣-a->")
14 ::(what == 1 && state == 3) -> state = 1; printf("|q3|␣-b->")
15 ::(what == 2 && state != 3) -> printf("|q3|.");goto reject
16 ::(what == 2 && state == 3) -> printf("|q%d.",what);goto accept
17 fi
18 }
19 od
20
21 accept:
22 printf("Input␣accepted.\n")
23 assert(false)
24 goto end
25
26 reject:
72 9 Finite Automata
27 printf("Input␣rejected.\n")
28
29 end:
30 printf("The␣End\n")
31 }
Thus, finite automata can be used in Promela to specify program features for verification. In
most cases however, the automata for checking properties are created automatically, not manu-
ally.
9.6 Tasks
Task 9.1:
Consider the following automaton:
b b
start q0 q1
a
a a
q3 a q2
b b
4. What would change if F = {q1 } or F = {q0 , q2 }? Also give formal definitions for the
languages.
Task 9.2:
Consider L = {0, 10, 110}.
1. Write down L0 , L1 , L2 and L3 .
2. Write down L∗ .
• ε
• 0000100001100000
• 11011010010
• 00111010010010110
• 00000000001110010
• 00000000101100000110
Task 9.3:
Consider L = {ε, ab, baa, aabaa}.
1. Calculate L0 , L1 and L2 .
2. Calculate L∗ and L+ .
Task 9.4:
2. Using the construction from Lemma 9.15, construct an automaton M ′ with T (M ′ ) = T (M1 )T (M2 ).
Give a formal definition for the automata and draw its transition diagram.
Task 9.5:
Let L ⊆ Σ∗ be language. When does L∗ = L+ ? hold? Prove your solution.
Task 9.6:
Give Regular Expressions for the following languages:
74 9 Finite Automata
1. The set of all words over the alphabet {a, b, c}, in which there is at least one a and at least
one b.
2. The set of all words over the alphabet {a, b, c}, in which there is at most one c.
3. The set of all words over the alphabet {0, 1}, in which at least two consecutive 1s occur.
4. The set of all words over the alphabet {0, 1}, in which exactly two consecutive 1s occur.
5. The set of all words over the alphabet {0, 1}, in which the number of 0 is even.
Task 9.7:
Construct a DFA M for
Task 9.8:
Consider an NFA M = (Q, 2AP , δ , q0 , F) with AP = {a, b, c}. For the following propositional
formulae, specify the set of input symbols which are represented by the following propositional
formulae:
1. true
2. f alse
3. ¬a
4. a ∧ ¬b
5. ¬a ∧ b ∧ ¬c
6. ¬a ∧ ¬b ∧ ¬c
7. ¬a ∧ b ∧ ¬c if AP = {a, b, c, d}
Task 9.9:
Prove or disprove the following for two regular expressions: r and s.
1. r + s = s + r
2. (r + s)∗ = r∗ + s∗
3. 0/ ∗ = ε
5. (r∗ s∗ )∗ = (r + s)∗
Task 9.10:
Consider the NFA from Figure 9.1. Implement the FA as Promela model for n = 50 in the
following template
1 # define N 50
2 byte state = 0 // holds state number
3 byte input[N+1] // holds input symbols from 0 to N-1 and end delimiter at N
4
7 /* code to be added */
8
9 }
Task 9.11:
In the following, we consider Σ = {a, b}.
10.1 Fundamentals
For ω-languages, various finite state automata models have been proposed (see e.g., [22, 24,
26]). Here, we focus on “Büchi-Automata” [20] as they are the most elementary automaton
model for infinite languages. Büchi Automata resemble Finite Automata but use a different
acceptance condition. “Büchi-Automata” resemble “regular” (deterministic or nondeterministic)
FAs as defined in the previous with an altered acceptance criterion. Throughout this paper, we
refer to NFAs used to accept infinite languages as NBA (or DBA if |δ (q, σ )| ≤ 1 for all states
and input symbols). Let Σω denote the set of all words over Σ having infinite length.
Definition 10.1 A run of an NBA M = (Q, Σ, δ , q0 , F) on an ω-word x = x0 x1 · · · ∈ Σω is a se-
quence of states of M ρ(x) = ρ0 ρ1 . . . such that ρ0 = q0 and ρi+1 ∈ δ (ρi , xi ) for i ≥ 0. We define
Inf (ρ(x)) = {q ∈ Q | there exist infinitely many i such that ρi = q} as the set of states that occur
infinitely often in the computation ρ(x) of M on x. We call ρ(x) successful if Inf (ρ(x)) ∩ F ̸= 0, /
i.e., if there is at least one state q ∈ F that appears infinitely often in ρ(x). A string x ∈ Σω is
accepted by M if there is a successful run of M on x. The ω-language recognized by M is defined
by Tω (M) = {x ∈ Σω | M accepts x}.
Two BA M and M ′ are considered equivalent iff Tω (M) = Tω (M ′ ).
A Büchi-Automaton is called reduced if from every state there is a path to an accepting state
(i.e. no trap states). For any Büchi-Automaton M it is possible to construct an equivalent reduced
Büchi-Automaton M ′ accepting the same languate by simply deleting every state from which no
accepting state is reachable.
The set of languages which are recognizable by an NBA is the set of regular ω-languages. An
NBA M is called deterministic (DBA) if |δ (q, σ )| ≤ 1 for all states and input symbols. Since for
Σ = {a} the language accepted by an NBA is either empty or aω , we assume that all automata
operate over an at least binary alphabet, |Σ| ≥ 2.
Let L ⊆ Σ∗ be a language. The Eilenberg-limit of L is defined by lim(L) = {w ∈ Σω | there
exist infinitely many prefixes x of w, such that x ∈ L} [21].
It is known that the language Tω (M) of an ω-DFA M is exactly the Eilenberg-limit of the
regular language that is accepted by M when it is interpreted as a traditional DFA, i.e., Tω (M) =
lim(T (M)). Thus, for two DFA M,M ′ with T (M) = T (M ′ ) we have Tω (M) = Tω (M ′ ).
However, we need to be careful when considering eqiivalence of automata as, in general,
equivalence in the case of infinite languagages does not imply equivalence for regular languages
78 10 Büchi Automata
a,b b
start q0 q1
b
and vice-versa: There are nondeterministic automata M and M ′ such that T (M) = T (M ′ ) but
Tω (M) ̸= Tω (M ′ ) (even already over a unary alphabet). Consider, e.g., the following Automata
M on the left and M ′ on the right hand side:
a a
start q0 q1 start q0 q1
a a
a a
start q0 q1 start q0 q1
a a
Theorem 10.2 There is a language L which can be accepted by an NBA while there is no DBA
accepting L.
δ (q0 , w0 w1 . . . wi ) = pi = p j = δ (q0 , w0 w1 . . . w j ).
10.2 ω-Regular Expressions 79
The following theorem states that Büchi-Automata are closed under intersection:
Theorem 10.3 Let M1 = (Q1 , Σ, δ1 , q10 , F1 ) and M2 = (Q2 , Σ, δ2 , q20 , F2 be two Büchi-Automata.
Then, there is a Büchi-Automaton M with Tω (M) = Tω (M1 ) ∩ Tω (M2 ).
Q = Q1 × Q2 × {1, 2}
F = Q1 × F2 × {2}
We can prove by induction: Let w ∈ Σω be an infinite word. If ρ = (q10 , q20 , i0 )(q11 , q21 , i1 )(q12 , q22 , i2 ) . . .
is a run on w in M, then ρ1 := q10 , q11 , q12 . . . is a run on w in M1 and ρ2 := q20 , q21 , q22 . . . is a run on w
in M2 . Moreover, ρ1 and ρ2 are successful if ρ is successful. Thus, Tω (M) ⊆ Tω (M1 ) ∩ Tω (M2 ).
Also we can prove by induction: If ρ1 and ρ2 are successful runs on w in M1 and M2 respec-
tively, then there is an accepting run ρ on w in M, hence we have Tω (M1 ) ∩ Tω (M2 ) ⊆ Tω (M),
and Tω (M1 ) ∩ Tω (M2 ) = Tω (M) follows. □
Lω := {w1 w2 w3 . . . |, wi ∈ L, i ≥ i}
The language associated with an ω-regular expresssion is L(A)L(B)ω or L(C) ∪ L(D), respec-
tively.
80 10 Büchi Automata
A1 Bω ω ω
1 + A2 B2 + . . . + An Bn
Fact 10.6 For every ω-regular expression there is a Büchi-automaton accepting the same lan-
guage and vice-versa.
M = (Q, Σ, δ , q0 , F )
where
Theorem 10.8 For every GNBA M = (Q, Σ, δ , q0 , F ) there is a NBA M ′ = (Q′ , Σ, δ ′ , q′0 , F) such
that Tω (M) = Tω (M ′ )
where
Definition 10.9 (Property) A property P is a set of infinite sequences of program states. For an
infinite sequence σ , write σ |= P if σ is in property P.
Now we will define safety properies. Informally, a safety property is a property which stipu-
lates that something “bad” does not happen. The safety propery is fulfilled as long as this bad
thing does not happen. If it happens, it must happen after some finite prefix and once this “bad
thing” occurs, the property can no longer be fulfilled. In other words, if an infinite word fulfills
the property, something “bad” never happens. Formally, this means that for any finite prefix of
this infinite word it must be possible to cconcatenate this prefix with an infinite word such that
the resulting word also fulfills the property.
Definition 10.10 (Safety Property) A property is a called a safety property if for all σ ∈ Σω we
have σ |= P if and only if for all i ≥ 1 there is a β ∈ Σω such that σ [..i]β |= P. σ [..i] denotes the
prefix of length i from σ .
or, equivalently
Definition 10.11 (Safety Property Alt) A property is a called a safety property if for all σ ∈ Σω
we have σ ̸|= P if and only if there is an i ≥ 1 such that for all β ∈ Σω we have σ [..i]β ̸|= P.
Consider
Example 10.12 The language (a + b)∗ bω can be accepted by a NBA as depicted in Figure 10.1.
Consider aω ∈/ (a + b)∗ bω . However, for every n ≥ 1 we have an bω ∈ (a + b)∗ bω , thus (a + b)∗ bω
does not specify a safety property.
Definition 10.13 For every reduced Büchi-Automaton M = (Q, Σ, δ , q0 , F), we define the closure
of M as cl(M) = (Q, Σ, δ , q0 , Q), i.e., every state is turned into an accepting state.
Theorem 10.14 A reduced Büchi-Automaton specifies a safety property if and only if Tω (M) =
Tω (cl(M))
82 10 Büchi Automata
Thus, the Büchi-Automaton only has accepting states. In other words, inputs which do not
have any accepting run and this violate the safety property, will, at some point, not have any con-
tinuation in the reduced Büchi-Automaton. If we apply the powerset construction to this reduced
Büchi-Automaton, this corresponds with all inputs which eventually reach the state representing
0.
/ Since all states are accepting, this automaton is a deterministic B"uchi-Automaton accepting
the same language. As all states of a Büchi-Automaton specifying a safety property can be made
accepting, the following follows:
Fact 10.15 Let P be a safety property over Σω which can be represented by a Büchi-Automaton
M, Tω (M) = P. Then, there is an equivalent DBA M ′ such that Tω (M) = Tω (M ′ ).
This automaton can be obtained by applying the power set construction to the reduced version of
the NBA. See, e.g., [29] for proof.
If we complement this DBA, making only the state representing 0/ accepting and all other states
non-accepting, we get a finite automaton which accepts the set of all bad prefixes of the property
the original Büchi-Automaton. Please note that these DFA have a special structure in that they
only have one accepting state which is never left for any input symbol. Intuitively, this state is
reached once the “bad thing” has happened.
This is also quite important for our model checking approaches: If a safety property is violated,
a finite counterexample of a run of the model may be given which clearly shows the violation of
the safety property.
We will summarize this now:
Definition 10.16 Let P be a safety property over Σω . The set of all bad prefixes of P, BadPre f (P) ⊆
Σ∗ is given by
BadPre f (P) = {α ∈ Σ∗ | ασ ̸∈ P for any σ ∈ Σω }.
Fact 10.17 Let P be a safety property over Σω which can be represented by a Büchi-Automaton
M, Tω (M) = P. Then, there is a DFA M ′ such that T (M ′ ) = BadPre f (Tω (M)).
Consider
Example 10.18 Let us for example consider the specification on mutual exclusion of two pro-
cesses A and B. We specify the properties csa and csb specifying that a and be are in their critical
section, respectively, and specify a Büchi-Automaton over the Alphabet Σ = {0, / {csA }, {csB }, {csA , csB }}
as depicted in Figure 10.2.
The Büchi-Automaton accepts the language {0, / {csA }, {csB }}ω . As DFA for BadPre f (Tω (M))
when applying the outlined construction from above, we obtain the DFA shown in Figure 10.3
which accepts the language {0, / {csA }, {csB }}∗ {csA , csB }{0,
/ {csA }, {csB }, {csA , csB }}∗ .
¬(csa ∧ csb )
start q0
¬(csa ∧ csb )
true
Figure 10.3: DFA for BadPre f for Mutual Exclusion of two processes A and B.
An invariant can be accepted by a reduced DBA with a single state as depicted in Figure 10.4.
The DBA loops in this state for all symbols σ ∈ ∆ and has no subsequent state for all σ ∈ Σ − ∆.
Clearly, the language accepted by this automaton is a safety property due to Theorem 10.14
as M = cl(M) and Tω (M) = Tω (cl(M)) holds. The example presented in 10.18 is, in fact, an
invariant.
Invariants are a special simple case of safety properties. There are also safety properties which
are not invariants and more complex. An example is the safety property (aaa∗ + b)ω in which
the “bad event” happens if less than two as occur . This property cannot be determined by just
looking at every single input symbol.
start q0
true P
start q0 q1
P
Definition 10.21 A property P is a called a liveness property if for all α ∈ Σ∗ there exists a β ∈
Σω such that αβ |= P.
Theorem 10.22 A reduced Büchi-Automaton specifies a liveness property if and only if Tω (cl(M)) =
Σω
From the definition of liveness, important aspects for verification also follow. If a liveness
property is specified by a Büchi-automaton and violated by a program, there is no counterex-
ample in the sense of a single input which violates it. A counterexample is rather given by the
fact that there is an (infinite) run of the program which does not have any accepting run in the
automaton. Equivalently, there is an infinite run for a run of the program which does get accepted
by a Büchi-automaton accepting the complement of the liveness-property.
Example 10.23 Let us for example consider a Büchi-automaton assuring that a property P will
eventually hold forever (which is in fact the Automaton from Figure 10.1 with different labels)
in Figure 10.5. Clearly, it specifies a liveness property.
Also, we have
10.7 Tasks 85
Safety
Invariants Liveness
Σω
Fact 10.25 The only property over Σ which is a safety and a liveness property is Σω .
Tω (M) = Tω (cl(M)) = Σω
A general proof would require an extended definition of the closure operation but is otherwise
identical.
Summarizing these results, we obtain the Venn diagram in Figure 10.6 of the linear time
properties discussed here.
10.7 Tasks
Task 10.1:
1. Give a definition for a Büchi-Automaton accepting all inputs with an infinite number of as
immediately followed by a b.
3. Present a definition for a Büchi-Automaton accepting all inputs over a, b with an infinite
number of six consecutive as.
86 10 Büchi Automata
Task 10.2:
Let Σ = {a, b, c}. Provide ω-regular expressions and a Büchi-Automaton for the following lan-
guages:
Task 10.3:
Specify the language the following Büchi-automaton acccepts:
a b
start q0 q1
b
a
a
q2
Task 10.4:
Prove that for every Büchi-Automaton there is a reduced Büchi-Automaton accepting the same
language.
11 Linear Temporal Logic
11.1 Fundamentals
Definition 11.1 (LTL) Let AP be atomic propositions (symbols). A linear temporal logic for-
mula φ over AP is definded by:
• if φ is an LTL-formula, ⃝φ is an LTL-formula
• φ = φ1 ∧ φ1 and σ |= φ1 and σ |= φ2
• φ = ⃝φ1 and σ1 |= φ1
Words(φ ) = {σ ∈ (2AP )ω } | σ |= φ }.
Two formula φ and ψ are called eqivalent, notation φ = ψ, if Words(φ ) = Words(ψ). For a
set α ⊆ (2AP )ω we define α |= φ if and only if α ⊆ Words(φ ).
88 11 Linear Temporal Logic
φ has to hold until ψ holds at a future position or the current one. Moreover, while σ |= φ ψ
S
implies that there is a minimal i ≥ 0 such that σi |= psi, the -operator does not necessarily refer
S
to the first position. For example, for AP = {a, b}, {a}{a}{b}(2AP )ω ∈ Words(true a ⃝ b).
S
Definition 11.2 (Derived Operators) Let φ and ψ be two LTL-formulae. For shortening LTL-
formulae, we use the following derived operators:
φ ∨ψ := ¬(¬φ ∧ ¬ψ) or
φ ⇒ψ := ¬φ ∨ ψ implication
φ ⇔ψ := (φ ⇒ ψ) ∧ (ψ ⇒ φ ) equivalence
φ ⊕ψ := (φ ∧ =
̸ ψ) ∨ (¬φ ∧ ψ) xor
true := φ ∨ ¬φ
f alse := ¬true
♢φ := true ∪ φ some time in the future
□φ := ¬♢¬φ from now on always
The operators ⃝, , ♢, □ are called temporal operators. A formula which does not use any
S
temporal operators is also called propositonal formula as definition and semantics coincide with
to so-called propositional logic.
Intuitively, the semantics of the temporal aspects can be depicted as follows:
• Atomic proposition a:
···
• ⃝φ :
···
• φ ∪ ψ:
φ ∧ ¬ψ φ ∧ ¬ψ φ ∧ ¬ψ ψ arbitrary
···
also:
11.1 Fundamentals 89
···
• ♢φ :
¬φ ¬φ ¬φ φ arbitrary
···
also:
···
• □φ :
φ φ φ φ φ
···
• Idempotence: φ ∨ φ = φ = φ ∧ φ
• Commutativity: φ ∨ ψ = ψ ∨ φ and φ ∧ ψ = ψ ∧ φ
• Associativity: φ ∨ (ψ ∨ χ) = (φ ∨ ψ) ∨ χ and φ ∧ (ψ ∧ χ) = (φ ∧ ψ) ∧ χ
• Distributivity: φ ∧ (ψ ∨ χ) = (φ ∧ ψ) ∨ (φ ∧ χ) and φ ∨ (ψ ∧ χ) = (φ ∨ ψ) ∧ (φ ∨ χ)
• Absorption: φ ∨ (φ ∧ ψ) = φ and φ ∧ (φ ∨ ψ) = φ
• Negation: ¬¬φ = φ
Tω (M) |= φ
does not hold.
Consider a Büchi-Automaton accepting aω + bω (the construction is left to the reader) and con-
sider the LTL formula ♢a. Clearly, aω + bω ̸|= ♢a as bω does not fulfill the formula. However,
aω + bω ̸|= ¬♢a as aω does not fulfill it.
Trivially stated, just because some set A1 ⊆ A is not a subset of a set A2 ⊆ A it does not imply
that A1 ⊆ A − A2 as A1 . This is wrong if A1 contains at least one element of A2 .
11.3 Fairness 91
11.3 Fairness
Definition 11.10 Let φ and ψ be propositional formulae over AP.
□♢φ
□♢ψ ⇒ □♢φ
♢□ψ ⇒ □♢φ
Intuitively, ψ stands for is enabled and φ stands for is taken. So, an unconditional fairness
constraint specifies that φ holds infinitely often. A strong fairness constraint specifies that φ
holds infinitely often if ψ holds infinitely often. A weak constraint stands for the situation that if
ψ eventually holds forever, then φ holds infinetely often.
Clearly, unconditionally fairness implies strong fairness implies weak fairness.
Definition 11.11 An LTL fairness assumption f air is the conjunction of fairness constraints.
For set α of infinite words over 2AP , we define α α |= f air φ if and only if α |= ( f air ⇒ φ ), i.e φ
holds in case the fairness condition is satisfied. Please note that words which violate the fairness
constraints are not considered.
Fact 11.13 There is a Büchi automaton M such that there is no LTL formula φ with Words(φ ) =
Tω (M).
a
start q0 q1
true
92 11 Linear Temporal Logic
11.5 Tasks
Task 11.1:
Let φ ,be an LTL-formula. Prove the following properties:
1. ¬♢φ = □¬φ
2. ¬□φ = ♢¬φ .
Task 11.2:
Let φ , ψ and χ be LTL-formulae. Prove the following properties:
1. χ ∪ (φ ∨ ψ) = (χ ∪ φ ) ∨ (χ ∪ ψ)
2. ♢(φ ∨ ψ) = ♢φ ∨ ♢ψ
3. □(φ ∧ ψ) = □φ ∧ □ψ.
Task 11.3:
Prove or disprove:
•
Words(♢(φ ∪ ψ)) ⊂ Words((♢φ ) ∪ (♢ψ))
•
Words(□(φ ∧ ψ) ⊃ Words(♢φ ) ∨ (♢ψ)
Task 11.4:
Give equivalent Büchi-Automata for the following LTL-Formulae:
1. □P
2. ♢P
S
3. Q P
Task 11.5:
Give eqivalent LTL-Formulae for the following Büchi-Automata:
true P
start q0 q1
P
2. Automaton
¬P P
start q0 q1
P
3. Automaton
¬P P
P
start q0 q1
¬P
4. Automaton
true P
P
start q0 q1
¬P
5. Automaton
true P
P
start q0 q1
true
6. Automaton
b, c a, c
a
start q0 q1
b
94 11 Linear Temporal Logic
b a,b
start q0 q1 q2 qF
a a,b a,b
q p∧q
start q0 q1 q2 qF
p p∧q p∨q
¬p ∨ q p ∧ ¬q ¬q
start q0 q1
Task 11.6:
Let AP = {a, b} and Σ = 2AP . Give LTL formulae defining the following languages:
1. {a, b}0Σ
/ ω
2. Σ∗ {a}ω
4. {a}∗ {b}∗ 0/ ω
Task 11.7:
Provide a Büchi-Automaton equivalent to the following LTL-Formula over the atomic proposi-
tions a and b:
1. □(a ⇔ b)
2. ♢a
11.5 Tasks 95
Task 11.8:
Consider the Dining Philosopher’s Problem as presented in Section 5.9 and the atomic proposi-
tons hi : Philospher i is hungry, ei : Philosopher i is eating. Express the following properties as
LTL formulae:
1. An eating philosopher prevents his/her neighbours from eating.
2. An eating philosopher eats until he/she is no longer hungry.
3. Every hungry philosopher eats eventually.
4. An eating philosopher eventually loses his/her appetite.
Task 11.9:
3. Simplify the LTL-formula φ ∨ ((¬φ ) ⃝ (♢true)) as much as possible, present your calcu-
lation.
Task 11.10:
Consider the LTL-formula
φ = (♢x) ⇒ ♢(y ∧ z) over {x, y, z}.
Which of the following words satisfies φ ? Explain your calculation and answer.
1. 0/ ω
2. {x, y, z}ω
3. {x}ω
4. {y, z}, {x}{z}ω
5. ({x}{y}{z})ω
6. {y}ω
7. {y}{x}{y}ω
Bibliography
[1] C. Baier, J.-P. Katoen, Principles of Model Checking, MIT Press, London, UK, 2007.
[2] M. Ben-Ari, Principles of the Spin Model Checker, Springer London, UK, 2008.
[3] E.W. Dijkstra, Solution to a problem in concurrent programming control, CACM 8, 9
(1965), 569.
[4] R. Garth, Concise Promela Reference, available online at https://spinroot.com/
spin/Man/Quick.html
[5] M.R. Garey, D.S. Johnson, Computers and Intractability - A Guide to the Theory of
NP-Completeness, W.H. Freeman and Company, New York NY, 1978.
[6] J.E. Hopcroft, J.D. Ullman, Introduction to Automata Theory, Languages and Com-
putation, Addison-Wesley, Reading MA, 1979.
[7] M. Kappes, R. P. Klemm, C. M. R. Kintala, Formal Limits on Determining Reliabil-
ities of Component-Based Software Systems, Proceedings 11th International Sympo-
sium on Software Reliability Engineering (ISSRE), 2000.
[8] C.H. Papadimitriou, Computational Complexity, Addison-Wesley, Reading MA,
1994.
[9] Pan Verification Options Overview available online at https://spinroot.com/
spin/Man/Pan.html
[10] Spin Version 6 - Promela Grammar, available online at https://spinroot.com/
spin/Man/grammar.html
[11] Promela Reference Manual, available online at https://spinroot.com/spin/
Man/Intro.html
[12] Promela Reference Pages, available online at https://spinroot.com/spin/Man/
promela.html
[13] C.H. Papadimitriou, K. Steiglitz, Combinatorial Optimization : Algorithms and Com-
plexity, Prentice Hall, Englewood Cliffs NJ, 1982.
[14] Basic Spin Manual, available online at https://spinroot.com/spin/Man/
Manual.html
[15] Spin Run-Time Options Overview, available online at https://spinroot.com/
spin/Man/Spin.html
98 Bibliography
[16] A.S. Tanenbaum, H. Bos, Modern Operating Systems, Fourth Edition, Pearson, Essex,
UK, 2015.
[18] B. Alpern and F.B. Schneider, Defining Liveness, Information Processing Letters,
21(4), pp 181-185, 1985.
[19] B. Alpern and F.B. Schneider, Recognizing Safety and Liveness, Distributed Comput-
ing, 2, pp 117-126, 1987.
[20] J.R. Büchi, On a Decision Method in Restricted Second Order Arithmetic. In E. Nagel
et al., editors, Proceedings of the International Congress on Logic, Methodology and
Philosophy of Science 1960, pp 1-11. Stanford University Press, 1962.
[21] S. Eilenberg, Automata, Languages and Machines, volume A, Academic Press, New
York, 1974.
[22] L.H. Landweber, Decision problems for ω-automata, Mathematical System Theory 4,
pp 376-384, 1969
[24] D.E. Muller, Infinite Sequences and Finite Machines, in Proceedings of the 4th IEEE
Symposium on Switching Circuit Theory and Logical Design, pp 3-16, 1963.
[26] W. Thomas, Languages, Automata and Logic, Handbook of Formal Language Theory,
volume III, Springer-Verlag 1997, pp 389-455.
[27] M.Y. Vardi and P. Wolper, Automata-theoretic Techniques for Modal Logics of Pro-
grams, Journal of Computer and System Sciences, 32, pp 182-211, 1986.
[28] M.Y. Vardi and P. Wolper, Reasoning About Infinite Computations, Information and
Computation, 115, pp 1-37, 1994.
[29] Z. Manna, A. Pnueli, A hierarchy of temporal properties, in: Proceedings of the 9th
Annual ACM Symposium on Principles of Distributed Computing, ACM Press, 1990,
pp. 377–408.