Section 19.2.10

Bisimulation and why equivalence is stronger than one-way refinement

Definition

A bisimulation is a relation between the states of two systems such that related states match each other’s steps in both directions: when either takes a step showing some event, the other can take a step showing the same event, and the new states are again related. Two systems are bisimilar when a bisimulation relates their initial states; being bisimilar is a two-way equivalence. One-way refinement asks only that the specification allow every behavior of the implementation, so an implementation may drop choices the specification offers.

The idea

A specification often leaves choices open on purpose: a lookup may return any one of several matching entries, and a scheduler may run any ready task. Each choice is a permission, not an obligation, so an implementation that always returns the first matching entry is correct although it never shows the others. Refinement answers the question “is this implementation correct?” A two-way equivalence answers another: “can one system replace the other without any observer noticing?” That question arises when an optimizer rewrites a program or a new implementation replaces an old one behind the same interface.

Two-way notions also differ from each other. Trace equivalence requires the same set of event sequences; bisimulation also compares when choices are made. Machine PP takes a coin and then lets the customer choose tea or coffee. Machine QQ, on taking a coin, decides by itself to offer only tea or only coffee. Both produce the same sequences: nothing, coin, coin then tea, coin then coffee. Yet a customer who wants coffee always gets it from PP and may be stuck at QQ. Bisimulation notices because it compares the states reached after each step. The customer is only a picture: bisimulation compares which steps states can take, not anyone’s wishes.

How it works

Bisimulation is defined on a labeled transition system: a set of states, one initial state, and steps between states, each marked with a label that names the event it shows, such as coin. The label τ\tau (the Greek letter tau) marks a silent step, an internal step that no observer sees.

Two systems are shown bisimilar in four steps.

  1. Propose a relation RR: a set of pairs, each made of a state of the first system and a state of the second.

  2. Check that RR contains the pair of initial states.

  3. For every pair (p,q)(p, q) in RR and every step from pp with some label aa to a state p′p', find a step from qq with label aa to some state q′q' such that (p′,q′)(p', q') is in RR.

  4. Check the other direction the same way, with the roles of pp and qq exchanged.

To show that no bisimulation exists, start from the initial pair and follow the pairs that every bisimulation would be forced to contain until a step has no match.

A simulation is the one-direction version: steps 1 to 3 alone. A simulation in which the specification matches every implementation step proves that the implementation refines the specification. Step 4 adds exactly the obligation to show every specification choice.

Silent steps give rise to variants. Strong bisimulation treats τ\tau as an ordinary label. Weak bisimulation lets a visible step be matched by the same step with any number of silent steps around it, and a silent step by zero or more silent steps. Branching bisimulation, stricter than weak, also requires every state passed through on the matching silent steps to stay related to the state being matched. For finite systems, the partition refinement algorithm §14.1 of Paige and Tarjan (1987) [438] decides strong bisimilarity in time proportional to mlognm \log n for nn states and mm steps; for trace equivalence of nondeterministic systems, no algorithm polynomial in the number of states is known.

Worked example

Output choice. Specification SS has two steps, s0s_0 to s1s_1 with label out0 and s0s_0 to s2s_2 with label out1: it may output 0 or 1. Implementation II has one step, i0i_0 to i1i_1 with label out0: it always outputs 0. Refinement holds. The relation {(i0,s0),(i1,s1)}\{(i_0, s_0), (i_1, s_1)\} is a simulation: it contains the initial pair, the step i0i_0 to i1i_1 is matched by s0s_0 to s1s_1, which lands on (i1,s1)(i_1, s_1), and i1i_1 has no steps. Bisimilarity fails. Every bisimulation would contain (i0,s0)(i_0, s_0), and the step s0s_0 to s2s_2 with label out1 has no match from i0i_0.

Choice timing. Machine PP has the steps p0p_0 to p1p_1 (coin), p1p_1 to p2p_2 (tea) and p1p_1 to p3p_3 (coffee). Machine QQ has the steps q0q_0 to q1q_1 (coin), q0q_0 to q2q_2 (coin), q1q_1 to q3q_3 (tea) and q2q_2 to q4q_4 (coffee). Both have the same 4 traces, the event sequences from the initial state: the empty sequence, coin, coin tea and coin coffee. A bisimulation would contain (p0,q0)(p_0, q_0). The step p0p_0 to p1p_1 is matched only by q0q_0 to q1q_1 or by q0q_0 to q2q_2, so the bisimulation would contain (p1,q1)(p_1, q_1) or (p1,q2)(p_1, q_2). In (p1,q1)(p_1, q_1), the coffee step of p1p_1 has no match; in (p1,q2)(p_1, q_2), its tea step has none. No bisimulation exists: the machines are trace equivalent but not bisimilar.

The same machines show what one-way refinement permits. The relation {(q0,p0),(q1,p1),(q2,p1),(q3,p2),(q4,p3)}\{(q_0, p_0), (q_1, p_1), (q_2, p_1), (q_3, p_2), (q_4, p_3)\} is a simulation in which PP matches every step of QQ, so QQ refines PP: the machine that can strand a coffee drinker is a correct implementation of the one that never does.

Stated precisely

Write s→as′s \xrightarrow{a} s' when state ss of a labeled transition system can take a step with label aa to state s′s'. For systems PP and QQ, a relation RR that pairs states of PP with states of QQ is a strong bisimulation when, for every pair (p,q)∈R(p, q) \in R and every label aa, p→ap′⟹there is a q′ with q→aq′ and (p′,q′)∈R,q→aq′⟹there is a p′ with p→ap′ and (p′,q′)∈R.\begin{aligned} p \xrightarrow{a} p' &\implies \text{there is a } q' \text{ with } q \xrightarrow{a} q' \text{ and } (p', q') \in R, \\ q \xrightarrow{a} q' &\implies \text{there is a } p' \text{ with } p \xrightarrow{a} p' \text{ and } (p', q') \in R. \end{aligned} PP and QQ are bisimilar, written P∼QP \sim Q, when some bisimulation contains the pair of their initial states. A relation that meets only the first condition is a simulation, and QQ then simulates PP.

Write Tr(P)\mathrm{Tr}(P) for the set of traces of PP, the label sequences along runs from its initial state. An implementation II trace-refines a specification SS when Tr(I)⊆Tr(S)\mathrm{Tr}(I) \subseteq \mathrm{Tr}(S), and PP and QQ are trace equivalent when Tr(P)=Tr(Q)\mathrm{Tr}(P) = \mathrm{Tr}(Q). Then P∼Q⟹Tr(P)=Tr(Q)⟹Tr(P)⊆Tr(Q).P \sim Q \implies \mathrm{Tr}(P) = \mathrm{Tr}(Q) \implies \mathrm{Tr}(P) \subseteq \mathrm{Tr}(Q). Neither converse holds in general: the drink machines refute the first and the output example refutes the second. The first converse holds for deterministic systems, in which no state has two steps with the same label and no step is silent.

For weak bisimulation, write q⇒aq′q \overset{a}{\Longrightarrow} q' when qq can reach q′q' by zero or more τ\tau steps, one step labeled aa, then zero or more τ\tau steps; for a=τa = \tau it means zero or more τ\tau steps. A weak bisimulation meets both conditions with ⇒a\overset{a}{\Longrightarrow} in place of →a\xrightarrow{a} after “there is”. Every guarantee concerns the labels only: time, energy and faults are compared only if they are made into labels.

Limits and common mistakes

Demanding bisimulation, or trace equivalence, with a specification that leaves choices open rejects correct implementations. For correctness, demand refinement; for interchangeability, name the equivalence and the events the observer sees.

Trace refinement is met by doing too little: a system whose only trace is the empty sequence refines every specification, and QQ refines PP. Trace refinement guarantees only safety properties §1.11: that nothing forbidden is ever shown. When a choice must stay available, state a liveness property §1.12, a requirement that something good eventually happens, or use a refinement that also records the events a system can refuse after each trace. Failures refinement in CSP (Communicating Sequential Processes), Hoare’s notation for describing and reasoning about communicating processes, does this and rejects QQ as an implementation of PP, because after coin, QQ can refuse coffee.

Simulations in both directions do not make a bisimulation. System UU has two a steps: one to a state that then does b, and one to a state that does nothing more. System VV has one a step, to a state that then does b. Each simulates the other, but they are not bisimilar: after a, UU may be unable to do b.

Trace equivalence and bisimilarity are different claims; showing one does not show the other. Name the variant, and say whether divergence, an endless run of silent steps, is observable: weak bisimilarity does not separate a system that can loop forever on silent steps from one that cannot.

Questions answered

Why not require every implementation to exhibit every specification choice?

Implementations need not exhibit every specification choice, because a choice in a specification is normally a permission, not an obligation: if the specification allows output 0 or output 1, an implementation that always outputs 0 does nothing forbidden and is correct. Correctness means one-way refinement: every behavior of the implementation must be one the specification allows. Requiring every choice would demand a two-way equivalence such as bisimulation, in which each system must match every step of the other, and would reject correct implementations that are simpler, deterministic or faster.

Demand a two-way equivalence only when one system must replace another without any observer telling them apart, as when an optimizer rewrites code, and then name it, since trace equivalence and bisimulation differ. When one particular choice must stay available, such as a drink the customer selects, state that as its own obligation, for example a liveness property, instead of demanding equivalence with the whole specification.

Related entries: Refinement (§3.32), Assumption versus guarantee (§1.36), Forward simulation and observable refinement (§19.2.9), Liveness property (§1.12). Further reading: [438].