# Old Flow Plug in page

## Flows plugin

An extension of the Flow Plugin is in the development. It will provide step-wise flow transformation rules.

Event-B, being an event systems formalism does not have a mechanism for explicitly defining event ordering. Although event guards may express any desired event ordering, the ability to have a summary of possible event flows in a concise and compact form is useful for many tasks, for example, code generation and connecting with other formalisms. The flows plugin addresses one aspect of event ordering: it allows a modeller to specify and prove that a given sequence of events does not contradict a given machine specification. More precisely, if we were to execute a machine step-by-step following our prescribed sequence of events we would not discover divergencies and deadlocks not already present in the original machine. In other words, the constraining of event ordering must be such that the overall specification is an Event-B refinement of the original model. Importantly, this means that all the desired model properties proved before are preserved.

Sequential composition of events may be expressed in a number of ways:

- event immediately follows another event; no other events may take place between the composed events.
- event eventually follows an event; thus, although there is an interference from other events, it is guaranteed that the second is eventually enabled.
- event may follow an event; this is the weakest form of connection when we only say that it may be the case that the second event follows the first event; it may happen, however, that some other event interferes and the second event is delayed or is even not enabled ever.

### The Flows Approach

Although the last case may seem the least appealing, it is the one that forms the basis of the flows approach. The primary reason for offering such a weak guarantee is proof effort required for stronger types of connectives. Let us see what it means to provide a formal proof for the various cases of sequential event composition.

"immediately after" requires, among others, the demonstration of a condition that no event other than is enabled in the after-state of . This leads to proof obligations where is the number of machine events. This number of proof obligations is comparable to the effort of demonstrating machine consistency. For a flow expression mentioning "immediately after" times there would be proof obligations. Even if only a small fraction of these result in interactive proofs, it would still be impractical for any realistic model.

For the second case, where "eventually follows" , one has to prove that an overall effect of any possible interference between the occurrence of and is such that the resultant state is a sub-state of states where is enabled. Seeing all other events as relations on machine state and assuming they are already proved convergent, the effect of event interference is represented by a transitive closure of a disjunction of all interference relations. The result is a rather expensive proof obligation that, almost certainly, would require a manual proof.

Contrastingly, the last case - "may follow" - requires one simple proof obligation that, in most cases, would be discharged without a user assistance: the after-state of should imply the guard of . We denote this condition as . This style of sequential composition used in the flows method and the following shortcut notation is offered: (note the events order).

One generalisation of is having a vector of events on the right-hand side: . It is easy to see how to scale up the proof obligation for this case. Then, .

The meaning of this extended construct is quite straightforward: there is a choice of possible continuation events after some current event . Further, we use the following notation for : where reads as "a choice of and ". Note that expression is not well-formed on its own. Choice of events has a meaning only in a combination with operator .

A flow expression is a list of statements about event ordering.

The semantics of each such statement is already given above: it is a theorem expressing requirements to the events mentioned in a statement. More precisely, it is an additional proof obligation for machine for which the flow statements are defined. Note that there is no obligation to mention all the machine events in a flow expression.

How expressive is the language of flows? There is, effectively, just one construct but it already covers a form of sequential composition, choice and loop. A loop is expressed by adding a statement to pass control back the beginning of the loop body:

The above is a loop made of a sequential composition of three events .

#### Concurrency

One important notion missing in the flows language is event concurrency. And here again, the concept of passing control from one event to another (operator ) plays the central role. First, we note that concurrency is linked to the idea of a thread of a control. In other words, to define events as executing concurrently there must be at least threads of control. Another observation is that there should be a way to start (or unblock) and terminate (block) a thread. In this case, by starting a thread we understanding passing a control to a continuation that has one additional thread of control (an alternative is having all threads started by an initialisation and then being unblocked and blocked when necessary). Correspondingly, termination of thread is a continuation that has one less thread of control. Terminating the last thread is the termination of the whole system.

To construct a new thread, some current tread is split into two threads. In Event-B terms, this corresponds to passing the control from an event to a pair of events such that they may execute in any order, that is, hey are both enabled and do not assign to the same model variables. We call such events independent. Let and be some distinct independent events. Then notation states that after both and are enabled. reads as " concurrently with ". The semantics of this construct is quite simple: .

Thread termination is a symmetric case of thread creation. Concurrent events appear on the left-hand side of a sequential composition with an event: . The meaning of this construct is that once and stopped, is enabled. Since and are independent, it is enough to separately demonstrate that enables and enables : .

The way we have defined thread construction does not make it clear how to define a thread that starts with a choice of events, for example . This limitation, however, is easy to overcome by noticing that the skip event may be used to reduce the case of a thread starting with a choice to thread that has a single initial event: . Since does no alter state, the overall behaviour is the same. This way, we are able to treat a general case:

The semantics of the construct is defined as follows:

The same thinking is applied to thread termination case. For a more readable notation, the sequential composition operation may be generalised to an associative version:

The above simply stands for . It is also easy to see how to scale this up to for the case of choice construct. However, loop would be defined as - using a new operator * - rather than . The is due to the fact that we want to be able to make a distinction between an event of a model and an event of a flow expression. Such a generalisation makes it possible to include the same event more than once in a flow expression and define event parameters in flows.

To account for event parameter, the basic PO rule is now extended to accept two parameters: . Here, and are predicates defined on model variables and also on the parameters of their respective events. and are, essentially, additional event guards and that is also how they appear in a proof obligation.

#### Event Compositionality PO

Finally, we give a formal definition of . Remember, that was defined as *an event may follow another event*. A way to formally demonstrate this is to show that an after-state of the first event always enables the guard of the next event.

where and are the parameters of the first and the second event, correspondingly. and are the guard and before-after predicate of the first event whereas is the guard of the second event. is the model invariant and and are the parameter constraining predicates from a flow expression.

#### Update site

http://iliasov.org/flowplugin/1.2/