# Difference between revisions of "Structured Types"

imported>WikiSysop |
imported>WikiSysop |
||

Line 40: | Line 40: | ||

==Constructing Structured Values== | ==Constructing Structured Values== | ||

+ | |||

+ | Suppose we have a variable ''v'' in a machine whose type is the structure ''C'' defined above: | ||

+ | <center> | ||

+ | <math>\textit{VARIABLE}~~ v\in C</math> | ||

+ | </center> | ||

+ | We wish to assign a structured value to ''v'' whose ''e'' field has some value ''e1'' and whose ''f'' field has some value ''f1''. | ||

+ | This can be achieved by specifying the choice of an event parameter ''c'' whose fields are constrained by appropriate guards | ||

+ | and assigning parameter ''c'' to the machine variable ''v''. This is shown in the following event: | ||

+ | |||

+ | <center><math> | ||

+ | \begin{array}{l} | ||

+ | \textit{ANY}~~ c ~~\textit{WHERE} \\ | ||

+ | ~~~~ c \in C \\ | ||

+ | ~~~~ e( c ) = e1 \\ | ||

+ | ~~~~ f( c ) = f1 \\ | ||

+ | \textit{THEN} \\ | ||

+ | ~~~~ v := c \\ | ||

+ | \textit{END} | ||

+ | \end{array} | ||

+ | </math></center> | ||

+ | |||

+ | If we only wish to update some fields and leave others changed, this needs to be done by specifying explicitly that some fields | ||

+ | remain unchanged. This is shown in the following example where only the ''e'' field is modified: | ||

+ | |||

+ | <center><math> | ||

+ | \begin{array}{l} | ||

+ | \textit{ANY}~~ c ~~\textit{WHERE} \\ | ||

+ | ~~~~ c \in C \\ | ||

+ | ~~~~ e( c ) = e1 \\ | ||

+ | ~~~~ f( c ) = f(v) \\ | ||

+ | \textit{THEN} \\ | ||

+ | ~~~~ v := c \\ | ||

+ | \textit{END} | ||

+ | \end{array} | ||

+ | </math></center> | ||

+ | |||

+ | If we don't care about the value of some field (e.g., ''f''), we simply omit any guard on that field as follows: | ||

+ | |||

+ | <center><math> | ||

+ | \begin{array}{l} | ||

+ | \textit{ANY}~~ c ~~\textit{WHERE} \\ | ||

+ | ~~~~ c \in C \\ | ||

+ | ~~~~ e( c ) = e1 \\ | ||

+ | \textit{THEN} \\ | ||

+ | ~~~~ v := c \\ | ||

+ | \textit{END} | ||

+ | \end{array} | ||

+ | </math></center> | ||

+ | |||

+ | |||

+ | Sometimes we will wish to model a set of structured elements as a machine variable, e.g., | ||

+ | <center> | ||

+ | <math>\textit{VARIABLE}~~ vs\subseteq C</math> | ||

+ | </center> | ||

+ | |||

+ | We can add a structured element to this set using the following event: | ||

+ | <center><math> | ||

+ | \begin{array}{l} | ||

+ | \textit{ANY}~~ c ~~\textit{WHERE} \\ | ||

+ | ~~~~ c \in C \\ | ||

+ | ~~~~ e( c ) = e1 \\ | ||

+ | ~~~~ f( c ) = f1 \\ | ||

+ | \textit{THEN} \\ | ||

+ | ~~~~ vs := vs \cup \{c\} \\ | ||

+ | \textit{END} | ||

+ | \end{array} | ||

+ | </math></center> | ||

==Extending Structured Types== | ==Extending Structured Types== |

## Revision as of 15:59, 5 May 2009

## Contents

## Modelling Structured Types

The Event-B mathematical language currently does not support a syntax for the direct definition of structured types such as records or class structures.
Nevertheless it is possible to model structured types using projection functions to represent the fields/attributes. For example,
suppose we wish to model a record structure *C* with fields *e* and *f* (with type *E* and *F* respectively).
Let us use the following syntax for this (not part of Event-B syntax):

We can model this structure in Event-B by introducing (in a context) a carrier set *C* and two
functions *e* and *f* as constants as follows:

Now, given an element representing a record structure, we write for the *e* component of *c* and for the *f* component of *c*.

*E* and *F* can be any type definable in Event-B, including a type representing a record structure.

## Constructing Structured Values

Suppose we have a variable *v* in a machine whose type is the structure *C* defined above:

We wish to assign a structured value to *v* whose *e* field has some value *e1* and whose *f* field has some value *f1*.
This can be achieved by specifying the choice of an event parameter *c* whose fields are constrained by appropriate guards
and assigning parameter *c* to the machine variable *v*. This is shown in the following event:

If we only wish to update some fields and leave others changed, this needs to be done by specifying explicitly that some fields
remain unchanged. This is shown in the following example where only the *e* field is modified:

If we don't care about the value of some field (e.g., *f*), we simply omit any guard on that field as follows:

Sometimes we will wish to model a set of structured elements as a machine variable, e.g.,

We can add a structured element to this set using the following event: