![](bg2.png)
3 SEMANTICS FOR UML STATE
MACHINES
We give first the semantics for simple state machines
as used in (Lano, 2008a), and then extend this to the
full metamodel of Figure 1. The semantics of pro-
tocol and behavior state machines for a class C are
incorporated into theories representing the semantics
of C. This enables semantic checks of the consistency
of the state machine models compared to the class di-
agram model.
The semantics is expressed in terms of temporal
logic theories using the notation of Real-time Logic
(RTL) and Real-time Action Logic (RAL) (Lano,
1998). The reason for using this general framework
is that related notations of UML, such as interactions,
require explicit treatment of the times of events.
Each UML class and model is represented as a
temporal logic theory, which has semantic elements
(attributes and actions) representing structural and be-
havioral features of the class or model, and axioms
defining their properties. A generic instance of C is
represented as a theory I
C
, the class itself by a theory
Γ
C
, and models M by a theory Γ
M
composed from the
theories of the classes of M.
Refinement of model M1 by model M2 means that
the theory Γ
M2
proves each axiom of M 1, under some
interpretation of the elements of M1 in M2. This corre-
sponds to state-based concepts of refinement, such as
the weakening of preconditions and strengthening of
postconditions (Morgan, 1990), and to concepts based
on behavioural compatibility (Simons, 2005).
The following temporal logic notations are used to
define the semantics:
1. The times ←(≫p(p),i), →(≫p(p),i),
↑(≫p(p),i), ↓(≫p(p), i) of sending, request
arrival, activation and termination of an operation
execution (≫p(p),i). These have values in a
set TIME (normally N) and are enumerated by
the index i : N
1
in order of the reception times
→(≫p(p),i).
2. Formulae P}t, denoting that formula P holds at
time t, and expressions e~t denoting the value
of expression e at time t.
From these, other notations such as the RTL
event-occurrence operators ♣(ψ := true,i)
“the i-th time that ψ becomes true”, and
#active(≫p(x)), the number of currently
executing occurrences of ≫p(x), can also be
defined.
To define transition actions and other actions
within a state machine, we use a generic procedural
language with assignment, conditionals, loops, etc.
Composite statements in this notation correspond to
(structured) activities in UML 2.
The semantics of such statements is given by cor-
responding semantic actions v := e, α; β, etc, in
RAL. Each action has a write frame, which is the set
of attributes it may change.
We can express that one action always calls an-
other when it executes:
α ⊃ β ≡
∀i : N
1
· ∃j : N
1
·
↑(α,i) = ↑(β,j) ∧
↓(α,i) = ↓(β,j)
“α calls β”. This is also used to express that α is
defined by a (composite) action β.
Assignment t
1
:= t
2
can be defined as the action
α
t
1
:=t
2
where t
1
is an attribute symbol, the write
frame of this action is {t
1
}, and
∀i : N
1
· t
1
~↓(α
t
1
:=t
2
,i) = t
2
~↑(α
t
1
:=t
2
,i)
Similarly, sequential composition ; and parallel
composition || of actions can be expressed as derived
combinators.
The ; and || composite actions have write frames
the union of the write frames of their component ac-
tions.
Occurrences of if E the≪ S
1
else S
2
are
either occurrences of S
1
if E holds at commencement
of this action, or occurrences of S
2
, if ¬ E holds. This
action has write frame the union of those of S
1
and
S
2
.
Occurrences of while E d≫ S are a se-
quence of occurrences (S,i
1
),... ,(S,i
≪
) of S,
where E holds at the commencement of each of these
actions, and where E fails to hold at termination of
(S,i
≪
). The while action has the same write
frame as S.
Some important properties of ⊃ are that it is tran-
sitive:
(α ⊃ β) ∧ (β ⊃ γ) ⇒ (α ⊃ γ)
and that statement constructs such as ; and
if the≪ else are monotonic with respect to
it:
(α
1
⊃ α
2
) ∧ (β
1
⊃ β
2
) ⇒ (α
1
; β
1
⊃ α
2
; β
2
)
and
(α
1
⊃ α
2
) ∧ (β
1
⊃ β
2
) ⇒
if E the≪
α
1
else
β
1
⊃
if E the≪ α
2
else β
2
SEMANTICS AND REFINEMENT OF BEHAVIOR STATE MACHINES
43