System Modelling and Design Introduction to the B Method and B - - PowerPoint PPT Presentation

system modelling and design
SMART_READER_LITE
LIVE PREVIEW

System Modelling and Design Introduction to the B Method and B - - PowerPoint PPT Presentation

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity System Modelling and Design Introduction to the B Method and B


slide-1
SLIDE 1

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

System Modelling and Design

Introduction to the B Method and B Toolkit

Revision: 1.1, February 22, 2006

Ken Robinson

School of Computer Science & Engineering The University of New South Wales, Sydney Australia

March 10, 2006

c Ken Robinson 2005

mailto::k.robinson@unsw.edu.au

slide-2
SLIDE 2

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

Outline I

1

B Mathematical Toolkit

2

Set Theory Relations Functions

3

Predicate Calculus Some Terminology

4

Notation Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine Notation

slide-3
SLIDE 3

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

Outline II

5

The B-Toolkit The B-Toolkit interface Introducing a new machine

6

A Simple Model Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and Preconditions Trivial preconditions Problem with the PiggyBank Machine

slide-4
SLIDE 4

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

Outline III

Proof obligation generation and proof Viewing the proof obligations Adding a non-trivial precondition Towards understanding preconditions Total and Partial operations: preconditions

7

Modelling a Coffee Club A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying and fixing the problems

8

Specifying a Robust machine

slide-5
SLIDE 5

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

Outline IV

9

A Question of Identity

slide-6
SLIDE 6

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

B Mathematical Toolkit

The mathematical toolkit of B Method (B) is based on set theory simple set theory, consisting of aggregates having no

  • rdering and no multiplicity. The only property

possessed by a value and a set is membership of the set. logic first-order predicate calculus. A predicate is a function from variables to Boolean. The first-order calculus allows quantification only over variables, not predicates for example. Numbers Although B allows opaque types, essentially all numbers in a B development are eventually natural numbers, because real computers consist of binary

  • numerals. B does not contain infinity and all

implementable sets are finite. The set of natural numbers (N) is infinite and hence is not implementable. N1 is N − { 0 }

slide-7
SLIDE 7

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

B Mathematical Toolkit

The mathematical toolkit of B is based on set theory simple set theory, consisting of aggregates having no

  • rdering and no multiplicity. The only property

possessed by a value and a set is membership of the set. logic first-order predicate calculus. A predicate is a function from variables to Boolean. The first-order calculus allows quantification only over variables, not predicates for example. Numbers Although B allows opaque types, essentially all numbers in a B development are eventually natural numbers, because real computers consist of binary

  • numerals. B does not contain infinity and all

implementable sets are finite. The set of natural numbers (N) is infinite and hence is not implementable. N1 is N − { 0 }

slide-8
SLIDE 8

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

B Mathematical Toolkit

The mathematical toolkit of B is based on set theory simple set theory, consisting of aggregates having no

  • rdering and no multiplicity. The only property

possessed by a value and a set is membership of the set. logic first-order predicate calculus. A predicate is a function from variables to Boolean. The first-order calculus allows quantification only over variables, not predicates for example. Numbers Although B allows opaque types, essentially all numbers in a B development are eventually natural numbers, because real computers consist of binary

  • numerals. B does not contain infinity and all

implementable sets are finite. The set of natural numbers (N) is infinite and hence is not implementable. N1 is N − { 0 }

slide-9
SLIDE 9

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

B Mathematical Toolkit

The mathematical toolkit of B is based on set theory simple set theory, consisting of aggregates having no

  • rdering and no multiplicity. The only property

possessed by a value and a set is membership of the set. logic first-order predicate calculus. A predicate is a function from variables to Boolean. The first-order calculus allows quantification only over variables, not predicates for example. Numbers Although B allows opaque types, essentially all numbers in a B development are eventually natural numbers, because real computers consist of binary

  • numerals. B does not contain infinity and all

implementable sets are finite. The set of natural numbers (N) is infinite and hence is not implementable. N1 is N − { 0 }

slide-10
SLIDE 10

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Relations Functions

Set Theory

B uses sets to model other mathematical constructs such as: relations, functions, sequences. The base for modelling with sets are powerset P(S), the powerset of the set S, is the set of all subsets

  • f S. P(S) always contains the empty set.

P1(S) is the set of all non-empty subsets of S. product X × Y, the product of X and Y, is the set of ordered pairs with the first element from X and the second from Y, X × Y = { x, y | x ∈ X ∧ y ∈ Y }.

slide-11
SLIDE 11

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Relations Functions

Set Theory

B uses sets to model other mathematical constructs such as: relations, functions, sequences. The base for modelling with sets are powerset P(S), the powerset of the set S, is the set of all subsets

  • f S. P(S) always contains the empty set.

P1(S) is the set of all non-empty subsets of S. product X × Y, the product of X and Y, is the set of ordered pairs with the first element from X and the second from Y, X × Y = { x, y | x ∈ X ∧ y ∈ Y }.

slide-12
SLIDE 12

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Relations Functions

Set Theory

B uses sets to model other mathematical constructs such as: relations, functions, sequences. The base for modelling with sets are powerset P(S), the powerset of the set S, is the set of all subsets

  • f S. P(S) always contains the empty set.

P1(S) is the set of all non-empty subsets of S. product X × Y, the product of X and Y, is the set of ordered pairs with the first element from X and the second from Y, X × Y = { x, y | x ∈ X ∧ y ∈ Y }.

slide-13
SLIDE 13

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Relations Functions

Set Theory

B uses sets to model other mathematical constructs such as: relations, functions, sequences. The base for modelling with sets are powerset P(S), the powerset of the set S, is the set of all subsets

  • f S. P(S) always contains the empty set.

P1(S) is the set of all non-empty subsets of S. product X × Y, the product of X and Y, is the set of ordered pairs with the first element from X and the second from Y, X × Y = { x, y | x ∈ X ∧ y ∈ Y }.

slide-14
SLIDE 14

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Relations Functions

Relations

A relation is a set of ordered pairs between the members of two sets. X ↔ Y is the set of all many-to-many relations between X and Y. X ↔ Y = P X × Y

slide-15
SLIDE 15

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Relations Functions

Relations

A relation is a set of ordered pairs between the members of two sets. X ↔ Y is the set of all many-to-many relations between X and Y. X ↔ Y = P X × Y

slide-16
SLIDE 16

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Relations Functions

Relations

A relation is a set of ordered pairs between the members of two sets. X ↔ Y is the set of all many-to-many relations between X and Y. X ↔ Y = P X × Y

slide-17
SLIDE 17

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Relations Functions

Functions

X

  • ֌

֌

→ → → ֌ → Y set of partial functions set of total functions set of partial injection (one-to-one) set of total injection set of partial surjection (onto) set of total surjection set of total bijection (one-to-one and onto)

slide-18
SLIDE 18

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Some Terminology

Some Terminology

The following terms will be used frequently: predicate a predicate is a partial function from variables (state) to

  • Boolean. The predicate is usually expressed as a

closed expression, e.g. amount < balance(customer). satisfies we talk of some variables satisfying a predicate. This means that substituting the values of the variables into the predicate will make the predicate true. stronger and weaker if P ⇒ Q we frequently say that, “P is stronger than Q”, although strictly we should say, “P is at least as strong as Q”. Similarly, we might say “Q is weaker than P”. In the same vein we will talk of strengthening or weakening a

  • predicate. Strengthening a predicate subsets the set of values that

satisfy the predicate. Weakening a predicate supersets the set of values that satisfy the predicate.

slide-19
SLIDE 19

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Some Terminology

Some Terminology

The following terms will be used frequently: predicate a predicate is a partial function from variables (state) to

  • Boolean. The predicate is usually expressed as a

closed expression, e.g. amount < balance(customer). satisfies we talk of some variables satisfying a predicate. This means that substituting the values of the variables into the predicate will make the predicate true. stronger and weaker if P ⇒ Q we frequently say that, “P is stronger than Q”, although strictly we should say, “P is at least as strong as Q”. Similarly, we might say “Q is weaker than P”. In the same vein we will talk of strengthening or weakening a

  • predicate. Strengthening a predicate subsets the set of values that

satisfy the predicate. Weakening a predicate supersets the set of values that satisfy the predicate.

slide-20
SLIDE 20

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Some Terminology

Some Terminology

The following terms will be used frequently: predicate a predicate is a partial function from variables (state) to

  • Boolean. The predicate is usually expressed as a

closed expression, e.g. amount < balance(customer). satisfies we talk of some variables satisfying a predicate. This means that substituting the values of the variables into the predicate will make the predicate true. stronger and weaker if P ⇒ Q we frequently say that, “P is stronger than Q”, although strictly we should say, “P is at least as strong as Q”. Similarly, we might say “Q is weaker than P”. In the same vein we will talk of strengthening or weakening a

  • predicate. Strengthening a predicate subsets the set of values that

satisfy the predicate. Weakening a predicate supersets the set of values that satisfy the predicate.

slide-21
SLIDE 21

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Some Terminology

Some Terminology

The following terms will be used frequently: predicate a predicate is a partial function from variables (state) to

  • Boolean. The predicate is usually expressed as a

closed expression, e.g. amount < balance(customer). satisfies we talk of some variables satisfying a predicate. This means that substituting the values of the variables into the predicate will make the predicate true. stronger and weaker if P ⇒ Q we frequently say that, “P is stronger than Q”, although strictly we should say, “P is at least as strong as Q”. Similarly, we might say “Q is weaker than P”. In the same vein we will talk of strengthening or weakening a

  • predicate. Strengthening a predicate subsets the set of values that

satisfy the predicate. Weakening a predicate supersets the set of values that satisfy the predicate.

slide-22
SLIDE 22

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Notation

All components of a B development will have a source form, used to specify machines and other input to the B-Toolkit, and a publication form used in documentation. The notation for the source form will be ASCII. For example, account : ACCOUNT means the variable account is an element of the set ACCOUNT. The notation for publication will is marked up high quality

  • mathematics. For example,

account ∈ ACCOUNT, which has the same meaning as the ASCII example.

slide-23
SLIDE 23

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Notation

All components of a B development will have a source form, used to specify machines and other input to the B-Toolkit, and a publication form used in documentation. The notation for the source form will be ASCII. For example, account : ACCOUNT means the variable account is an element of the set ACCOUNT. The notation for publication will is marked up high quality

  • mathematics. For example,

account ∈ ACCOUNT, which has the same meaning as the ASCII example.

slide-24
SLIDE 24

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Notation

All components of a B development will have a source form, used to specify machines and other input to the B-Toolkit, and a publication form used in documentation. The notation for the source form will be ASCII. For example, account : ACCOUNT means the variable account is an element of the set ACCOUNT. The notation for publication will is marked up high quality

  • mathematics. For example,

account ∈ ACCOUNT, which has the same meaning as the ASCII example.

slide-25
SLIDE 25

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Notation

All components of a B development will have a source form, used to specify machines and other input to the B-Toolkit, and a publication form used in documentation. The notation for the source form will be ASCII. For example, account : ACCOUNT means the variable account is an element of the set ACCOUNT. The notation for publication will is marked up high quality

  • mathematics. For example,

account ∈ ACCOUNT, which has the same meaning as the ASCII example.

slide-26
SLIDE 26

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Abstract Machines

B uses Abstract Machines, which are machines that encapsulate: state consisting of a set of variables constrained by an invariant

  • perations operations may change the state, while maintaining the

invariant, and may return a sequence of results.

slide-27
SLIDE 27

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Abstract Machines

B uses Abstract Machines, which are machines that encapsulate: state consisting of a set of variables constrained by an invariant

  • perations operations may change the state, while maintaining the

invariant, and may return a sequence of results.

slide-28
SLIDE 28

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Abstract Machines

B uses Abstract Machines, which are machines that encapsulate: state consisting of a set of variables constrained by an invariant

  • perations operations may change the state, while maintaining the

invariant, and may return a sequence of results.

slide-29
SLIDE 29

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Machine Variables in B

For technical reasons that will not be explained now, machine variables in B must have at least two characters. Thus xx is a valid variable, while x is not. Warning: this is likely to cause many mysterious problems in your first attempts to write B machines. The error messages of the B-Toolkit will not clearly identify the problem! Where single letters are used in describing the notation, those letters represent context dependent expressions, which include proper variables.

slide-30
SLIDE 30

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Machine Variables in B

For technical reasons that will not be explained now, machine variables in B must have at least two characters. Thus xx is a valid variable, while x is not. Warning: this is likely to cause many mysterious problems in your first attempts to write B machines. The error messages of the B-Toolkit will not clearly identify the problem! Where single letters are used in describing the notation, those letters represent context dependent expressions, which include proper variables.

slide-31
SLIDE 31

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Machine Variables in B

For technical reasons that will not be explained now, machine variables in B must have at least two characters. Thus xx is a valid variable, while x is not. Warning: this is likely to cause many mysterious problems in your first attempts to write B machines. The error messages of the B-Toolkit will not clearly identify the problem! Where single letters are used in describing the notation, those letters represent context dependent expressions, which include proper variables.

slide-32
SLIDE 32

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Machine Variables in B

For technical reasons that will not be explained now, machine variables in B must have at least two characters. Thus xx is a valid variable, while x is not. Warning: this is likely to cause many mysterious problems in your first attempts to write B machines. The error messages of the B-Toolkit will not clearly identify the problem! Where single letters are used in describing the notation, those letters represent context dependent expressions, which include proper variables.

slide-33
SLIDE 33

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Object based

Abstract machines are sometimes described as object-based, rather than object-oriented. You will notice that a machine can be compared with an object, that is, an instance of a class. Importantly, a machine does not behave as a class, although it is possible to model a class.

slide-34
SLIDE 34

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Object based

Abstract machines are sometimes described as object-based, rather than object-oriented. You will notice that a machine can be compared with an object, that is, an instance of a class. Importantly, a machine does not behave as a class, although it is possible to model a class.

slide-35
SLIDE 35

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Object based

Abstract machines are sometimes described as object-based, rather than object-oriented. You will notice that a machine can be compared with an object, that is, an instance of a class. Importantly, a machine does not behave as a class, although it is possible to model a class.

slide-36
SLIDE 36

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Object based

Abstract machines are sometimes described as object-based, rather than object-oriented. You will notice that a machine can be compared with an object, that is, an instance of a class. Importantly, a machine does not behave as a class, although it is possible to model a class.

slide-37
SLIDE 37

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Substitutions

The foundation of B operations is a language called the Generalised Substitution Language or GSL. The GSL notation will not be described in this lecture. The elements of GSL are called substitutions, which have a role similar to statements or commands in a conventional programming language. A substitution is a construct that, in some way, changes the state by substituting values into variables of the state. The concept of the substitution is founded on the basic notion that the

  • nly way a state machine makes progress is by changing the value of

the state. We won’t describe the GSL at this stage, but we will note that there are only 11 basis substitutions in the GSL. Substitutions are given a formal semantics that in turn is expressed in in terms of substitution of values; thus the word “substitution” is a pun.

slide-38
SLIDE 38

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Substitutions

The foundation of B operations is a language called the Generalised Substitution Language or GSL. The GSL notation will not be described in this lecture. The elements of GSL are called substitutions, which have a role similar to statements or commands in a conventional programming language. A substitution is a construct that, in some way, changes the state by substituting values into variables of the state. The concept of the substitution is founded on the basic notion that the

  • nly way a state machine makes progress is by changing the value of

the state. We won’t describe the GSL at this stage, but we will note that there are only 11 basis substitutions in the GSL. Substitutions are given a formal semantics that in turn is expressed in in terms of substitution of values; thus the word “substitution” is a pun.

slide-39
SLIDE 39

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Substitutions

The foundation of B operations is a language called the Generalised Substitution Language or GSL. The GSL notation will not be described in this lecture. The elements of GSL are called substitutions, which have a role similar to statements or commands in a conventional programming language. A substitution is a construct that, in some way, changes the state by substituting values into variables of the state. The concept of the substitution is founded on the basic notion that the

  • nly way a state machine makes progress is by changing the value of

the state. We won’t describe the GSL at this stage, but we will note that there are only 11 basis substitutions in the GSL. Substitutions are given a formal semantics that in turn is expressed in in terms of substitution of values; thus the word “substitution” is a pun.

slide-40
SLIDE 40

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Substitutions

The foundation of B operations is a language called the Generalised Substitution Language or GSL. The GSL notation will not be described in this lecture. The elements of GSL are called substitutions, which have a role similar to statements or commands in a conventional programming language. A substitution is a construct that, in some way, changes the state by substituting values into variables of the state. The concept of the substitution is founded on the basic notion that the

  • nly way a state machine makes progress is by changing the value of

the state. We won’t describe the GSL at this stage, but we will note that there are only 11 basis substitutions in the GSL. Substitutions are given a formal semantics that in turn is expressed in in terms of substitution of values; thus the word “substitution” is a pun.

slide-41
SLIDE 41

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Substitutions

The foundation of B operations is a language called the Generalised Substitution Language or GSL. The GSL notation will not be described in this lecture. The elements of GSL are called substitutions, which have a role similar to statements or commands in a conventional programming language. A substitution is a construct that, in some way, changes the state by substituting values into variables of the state. The concept of the substitution is founded on the basic notion that the

  • nly way a state machine makes progress is by changing the value of

the state. We won’t describe the GSL at this stage, but we will note that there are only 11 basis substitutions in the GSL. Substitutions are given a formal semantics that in turn is expressed in in terms of substitution of values; thus the word “substitution” is a pun.

slide-42
SLIDE 42

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Abstract Machine Notation

Abstract Machine Notation (AMN) is the notation used to describe Abstract Machines. AMN also incorporates a syntactic dressing up of the basic generalized substitution language (GSL). AMN gives B an appearance and a feel of a programming language, although the level of abstraction is not changed by this syntactic sugaring. We will use only a few AMN constructs here.

slide-43
SLIDE 43

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Abstract Machine Notation

Abstract Machine Notation (AMN) is the notation used to describe Abstract Machines. AMN also incorporates a syntactic dressing up of the basic generalized substitution language (GSL). AMN gives B an appearance and a feel of a programming language, although the level of abstraction is not changed by this syntactic sugaring. We will use only a few AMN constructs here.

slide-44
SLIDE 44

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Abstract Machine Notation

Abstract Machine Notation (AMN) is the notation used to describe Abstract Machines. AMN also incorporates a syntactic dressing up of the basic generalized substitution language (GSL). AMN gives B an appearance and a feel of a programming language, although the level of abstraction is not changed by this syntactic sugaring. We will use only a few AMN constructs here.

slide-45
SLIDE 45

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Abstract Machine Notation

Abstract Machine Notation (AMN) is the notation used to describe Abstract Machines. AMN also incorporates a syntactic dressing up of the basic generalized substitution language (GSL). AMN gives B an appearance and a feel of a programming language, although the level of abstraction is not changed by this syntactic sugaring. We will use only a few AMN constructs here.

slide-46
SLIDE 46

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Abstract Machines Machine Variables in B Object based Substitutions Abstract Machine

Abstract Machine Notation

Abstract Machine Notation (AMN) is the notation used to describe Abstract Machines. AMN also incorporates a syntactic dressing up of the basic generalized substitution language (GSL). AMN gives B an appearance and a feel of a programming language, although the level of abstraction is not changed by this syntactic sugaring. We will use only a few AMN constructs here.

slide-47
SLIDE 47

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-48
SLIDE 48

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-49
SLIDE 49

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-50
SLIDE 50

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-51
SLIDE 51

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-52
SLIDE 52

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-53
SLIDE 53

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-54
SLIDE 54

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-55
SLIDE 55

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-56
SLIDE 56

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-57
SLIDE 57

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-58
SLIDE 58

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-59
SLIDE 59

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-60
SLIDE 60

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-61
SLIDE 61

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-62
SLIDE 62

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit

The B-Toolkit is a configuration management tool that provides the following facilities: introduction of new machines syntax and type analysis animation of specifications generation of proof obligations automatic & interactive proof introduction of user theories markup of machines maintenance of documents generation of code generation of interfaces execution of generated code generation of base machines automatic remakes browsing of designs & specifications hypertext displays of machines

  • nline help
slide-63
SLIDE 63

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit interface

The interface of the B-Toolkit is very compact, but has a large number

  • f configurations.

Menu bar the top line contains menus that control the functions of the toolkit. Environments Below the menu bar is a set of environments: Main, Provers, etc that present different views on the development process. Machine panel below the Environments is a panel that contains the names of machines or other constructs. This panel contains colour coded buttons that provide access to

  • ne of the functions of the toolkit.

Log panel at the bottom is another panel that contains a log of the interactions for the current session.

slide-64
SLIDE 64

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit interface

The interface of the B-Toolkit is very compact, but has a large number

  • f configurations.

Menu bar the top line contains menus that control the functions of the toolkit. Environments Below the menu bar is a set of environments: Main, Provers, etc that present different views on the development process. Machine panel below the Environments is a panel that contains the names of machines or other constructs. This panel contains colour coded buttons that provide access to

  • ne of the functions of the toolkit.

Log panel at the bottom is another panel that contains a log of the interactions for the current session.

slide-65
SLIDE 65

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit interface

The interface of the B-Toolkit is very compact, but has a large number

  • f configurations.

Menu bar the top line contains menus that control the functions of the toolkit. Environments Below the menu bar is a set of environments: Main, Provers, etc that present different views on the development process. Machine panel below the Environments is a panel that contains the names of machines or other constructs. This panel contains colour coded buttons that provide access to

  • ne of the functions of the toolkit.

Log panel at the bottom is another panel that contains a log of the interactions for the current session.

slide-66
SLIDE 66

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit interface

The interface of the B-Toolkit is very compact, but has a large number

  • f configurations.

Menu bar the top line contains menus that control the functions of the toolkit. Environments Below the menu bar is a set of environments: Main, Provers, etc that present different views on the development process. Machine panel below the Environments is a panel that contains the names of machines or other constructs. This panel contains colour coded buttons that provide access to

  • ne of the functions of the toolkit.

Log panel at the bottom is another panel that contains a log of the interactions for the current session.

slide-67
SLIDE 67

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit interface

The interface of the B-Toolkit is very compact, but has a large number

  • f configurations.

Menu bar the top line contains menus that control the functions of the toolkit. Environments Below the menu bar is a set of environments: Main, Provers, etc that present different views on the development process. Machine panel below the Environments is a panel that contains the names of machines or other constructs. This panel contains colour coded buttons that provide access to

  • ne of the functions of the toolkit.

Log panel at the bottom is another panel that contains a log of the interactions for the current session.

slide-68
SLIDE 68

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

The B-Toolkit interface

The interface of the B-Toolkit is very compact, but has a large number

  • f configurations.

Menu bar the top line contains menus that control the functions of the toolkit. Environments Below the menu bar is a set of environments: Main, Provers, etc that present different views on the development process. Machine panel below the Environments is a panel that contains the names of machines or other constructs. This panel contains colour coded buttons that provide access to

  • ne of the functions of the toolkit.

Log panel at the bottom is another panel that contains a log of the interactions for the current session.

slide-69
SLIDE 69

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

Introducing a new machine

To introduce a new machine you would select Introduce/New/Machine in the Main environment of the B-Toolkit. Having introduced the machine, a template will appear in your editor. The machine should be “filled in” and saved. Then the machine should be committed and analyzed, by selecting the cmt (commit) and anl (analyze) buttons in the Main environment.

slide-70
SLIDE 70

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

Introducing a new machine

To introduce a new machine you would select Introduce/New/Machine in the Main environment of the B-Toolkit. Having introduced the machine, a template will appear in your editor. The machine should be “filled in” and saved. Then the machine should be committed and analyzed, by selecting the cmt (commit) and anl (analyze) buttons in the Main environment.

slide-71
SLIDE 71

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity The B-Toolkit interface Introducing a new machine

Introducing a new machine

To introduce a new machine you would select Introduce/New/Machine in the Main environment of the B-Toolkit. Having introduced the machine, a template will appear in your editor. The machine should be “filled in” and saved. Then the machine should be committed and analyzed, by selecting the cmt (commit) and anl (analyze) buttons in the Main environment.

slide-72
SLIDE 72

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

A Simple Model I

As a first simple model we will take a simple coffee club, but we will do it in two steps. First we will model a “piggy bank” into which we can feed money and also take money out using the following operations: Feedbank(amount) feed amount cents to the piggybank. RobBank(amount) Rob the piggybank of amount cents. money ← − CashLeft Query the piggybank to obtain the amount of money left in the piggybank.

slide-73
SLIDE 73

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

A Simple Model I

As a first simple model we will take a simple coffee club, but we will do it in two steps. First we will model a “piggy bank” into which we can feed money and also take money out using the following operations: Feedbank(amount) feed amount cents to the piggybank. RobBank(amount) Rob the piggybank of amount cents. money ← − CashLeft Query the piggybank to obtain the amount of money left in the piggybank.

slide-74
SLIDE 74

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

A Simple Model II

In order to model the operations we will use a variable piggybank whose value is a natural number, representing the contents of the piggybank in cents. Let’s step through the specification of a machine that “owns” and manages the piggy bank.

slide-75
SLIDE 75

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

A Simple Model II

In order to model the operations we will use a variable piggybank whose value is a natural number, representing the contents of the piggybank in cents. Let’s step through the specification of a machine that “owns” and manages the piggy bank.

slide-76
SLIDE 76

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

PiggyBank0.mch I

MACHINE PiggyBank0 VARIABLES piggybank INVARIANT piggybank ∈ N INITIALISATION piggybank := 0 OPERATIONS

slide-77
SLIDE 77

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

PiggyBank0.mch II

FeedBank ( amount ) b = PRE amount ∈ N THEN piggybank := piggybank + amount END ; RobBank ( amount ) b = PRE amount ∈ N THEN piggybank := piggybank − amount END ; money ← − CashLeft b = BEGIN money := piggybank END END

slide-78
SLIDE 78

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-79
SLIDE 79

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-80
SLIDE 80

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-81
SLIDE 81

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-82
SLIDE 82

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-83
SLIDE 83

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-84
SLIDE 84

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-85
SLIDE 85

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-86
SLIDE 86

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-87
SLIDE 87

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-88
SLIDE 88

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-89
SLIDE 89

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Structure

MACHINE name set and numeric parameters CONSTRAINTS predicate INCLUDES/SEES/USES machine parameters SETS names CONSTANTS names PROPERTIES predicate VARIABLES names INVARIANT predicate INITIALISATION substitution OPERATIONS

  • perations

END In general, the clauses of a machine can appear in any order, although machines are stored and marked up according to a canonic structure.

slide-90
SLIDE 90

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

. . . Machine Structure

Note the hierarchy of constraints (clauses consisting of a predicate in the machine structure) constraints constrains the machine parameters properties constrains the sets and constants invariant constrains the variables Notice that constants and variables are not typed at the point of declaration, but their type must be constrained by the corresponding constraining predicate.

slide-91
SLIDE 91

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

. . . Machine Structure

Note the hierarchy of constraints (clauses consisting of a predicate in the machine structure) constraints constrains the machine parameters properties constrains the sets and constants invariant constrains the variables Notice that constants and variables are not typed at the point of declaration, but their type must be constrained by the corresponding constraining predicate.

slide-92
SLIDE 92

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

. . . Machine Structure

Note the hierarchy of constraints (clauses consisting of a predicate in the machine structure) constraints constrains the machine parameters properties constrains the sets and constants invariant constrains the variables Notice that constants and variables are not typed at the point of declaration, but their type must be constrained by the corresponding constraining predicate.

slide-93
SLIDE 93

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

. . . Machine Structure

Note the hierarchy of constraints (clauses consisting of a predicate in the machine structure) constraints constrains the machine parameters properties constrains the sets and constants invariant constrains the variables Notice that constants and variables are not typed at the point of declaration, but their type must be constrained by the corresponding constraining predicate.

slide-94
SLIDE 94

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

. . . Machine Structure

Note the hierarchy of constraints (clauses consisting of a predicate in the machine structure) constraints constrains the machine parameters properties constrains the sets and constants invariant constrains the variables Notice that constants and variables are not typed at the point of declaration, but their type must be constrained by the corresponding constraining predicate.

slide-95
SLIDE 95

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

. . . Machine Structure

Note the hierarchy of constraints (clauses consisting of a predicate in the machine structure) constraints constrains the machine parameters properties constrains the sets and constants invariant constrains the variables Notice that constants and variables are not typed at the point of declaration, but their type must be constrained by the corresponding constraining predicate.

slide-96
SLIDE 96

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Parameters

Machine parameters enable the specification of generic machines. The parameters are either: sets upper case identifiers; denote finite non-empty sets numeric natural number constants

slide-97
SLIDE 97

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Parameters

Machine parameters enable the specification of generic machines. The parameters are either: sets upper case identifiers; denote finite non-empty sets numeric natural number constants

slide-98
SLIDE 98

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Parameters

Machine parameters enable the specification of generic machines. The parameters are either: sets upper case identifiers; denote finite non-empty sets numeric natural number constants

slide-99
SLIDE 99

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Parameters

Machine parameters enable the specification of generic machines. The parameters are either: sets upper case identifiers; denote finite non-empty sets numeric natural number constants

slide-100
SLIDE 100

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Machine Parameters

Machine parameters enable the specification of generic machines. The parameters are either: sets upper case identifiers; denote finite non-empty sets numeric natural number constants

slide-101
SLIDE 101

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Operations

The form of an operation is

  • peration-signature

= substitution An operation-signature has the form name(args) for an operation that only makes a state substitution, or results ← − name(args) , where results is a list of identifiers that represent result values. In both cases the operation may have no arguments.

slide-102
SLIDE 102

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Operations

The form of an operation is

  • peration-signature

= substitution An operation-signature has the form name(args) for an operation that only makes a state substitution, or results ← − name(args) , where results is a list of identifiers that represent result values. In both cases the operation may have no arguments.

slide-103
SLIDE 103

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Operations

The form of an operation is

  • peration-signature

= substitution An operation-signature has the form name(args) for an operation that only makes a state substitution, or results ← − name(args) , where results is a list of identifiers that represent result values. In both cases the operation may have no arguments.

slide-104
SLIDE 104

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Invariant and Preconditions

The invariant of a machine is an expression of the properties that the state has to satisfy for the operations to correctly model the required behaviour. The invariant expresses what might be called safety or integrity conditions. The initial state must satisfy the invariant, and it is an obligation that each operation maintains the invariant: it is guaranteed that the invariant is true before an operation is invoked and it is the duty of the

  • peration to ensure that the invariant is true after the operation.

The precondition of an operation should capture all combinations of state and operation arguments before an operation that are required to ensure that the invariant is satisfied after the operation. It is important that the invariant is as strong as necessary, and the precondition is as weak as possible, but no weaker than necessary.

slide-105
SLIDE 105

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Invariant and Preconditions

The invariant of a machine is an expression of the properties that the state has to satisfy for the operations to correctly model the required behaviour. The invariant expresses what might be called safety or integrity conditions. The initial state must satisfy the invariant, and it is an obligation that each operation maintains the invariant: it is guaranteed that the invariant is true before an operation is invoked and it is the duty of the

  • peration to ensure that the invariant is true after the operation.

The precondition of an operation should capture all combinations of state and operation arguments before an operation that are required to ensure that the invariant is satisfied after the operation. It is important that the invariant is as strong as necessary, and the precondition is as weak as possible, but no weaker than necessary.

slide-106
SLIDE 106

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Invariant and Preconditions

The invariant of a machine is an expression of the properties that the state has to satisfy for the operations to correctly model the required behaviour. The invariant expresses what might be called safety or integrity conditions. The initial state must satisfy the invariant, and it is an obligation that each operation maintains the invariant: it is guaranteed that the invariant is true before an operation is invoked and it is the duty of the

  • peration to ensure that the invariant is true after the operation.

The precondition of an operation should capture all combinations of state and operation arguments before an operation that are required to ensure that the invariant is satisfied after the operation. It is important that the invariant is as strong as necessary, and the precondition is as weak as possible, but no weaker than necessary.

slide-107
SLIDE 107

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Invariant and Preconditions

The invariant of a machine is an expression of the properties that the state has to satisfy for the operations to correctly model the required behaviour. The invariant expresses what might be called safety or integrity conditions. The initial state must satisfy the invariant, and it is an obligation that each operation maintains the invariant: it is guaranteed that the invariant is true before an operation is invoked and it is the duty of the

  • peration to ensure that the invariant is true after the operation.

The precondition of an operation should capture all combinations of state and operation arguments before an operation that are required to ensure that the invariant is satisfied after the operation. It is important that the invariant is as strong as necessary, and the precondition is as weak as possible, but no weaker than necessary.

slide-108
SLIDE 108

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Invariant and Preconditions

The invariant of a machine is an expression of the properties that the state has to satisfy for the operations to correctly model the required behaviour. The invariant expresses what might be called safety or integrity conditions. The initial state must satisfy the invariant, and it is an obligation that each operation maintains the invariant: it is guaranteed that the invariant is true before an operation is invoked and it is the duty of the

  • peration to ensure that the invariant is true after the operation.

The precondition of an operation should capture all combinations of state and operation arguments before an operation that are required to ensure that the invariant is satisfied after the operation. It is important that the invariant is as strong as necessary, and the precondition is as weak as possible, but no weaker than necessary.

slide-109
SLIDE 109

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Trivial preconditions

Although the specification of FeedBank and RobBank use a preconditioned substitution the precondition is used only to carry the type of the parameter to the operation. This is a trivial precondition.

slide-110
SLIDE 110

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Trivial preconditions

Although the specification of FeedBank and RobBank use a preconditioned substitution the precondition is used only to carry the type of the parameter to the operation. This is a trivial precondition.

slide-111
SLIDE 111

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Problem with the PiggyBank Machine

There is a problem with the PiggyBank machine. See if you can spot it. Alternatively, generate the proof obligations and try to discharge them.

slide-112
SLIDE 112

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Problem with the PiggyBank Machine

There is a problem with the PiggyBank machine. See if you can spot it. Alternatively, generate the proof obligations and try to discharge them.

slide-113
SLIDE 113

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Problem with the PiggyBank Machine

There is a problem with the PiggyBank machine. See if you can spot it. Alternatively, generate the proof obligations and try to discharge them.

slide-114
SLIDE 114

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Proof obligation generation and proof

Having analyzed a machine, you should routinely generate the proof

  • bligations by selecting the pog (proof obligation generator) button in

the Main environment. Then move to the Provers environment, select the prv (provers) button for the machine, and select AutoProver. If there are unproved

  • bligations then you should either try to discharge the proof obligation

using the BToolProver, or at least inspect the obligation to see if it is true. This should be a routine validation step.

slide-115
SLIDE 115

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Proof obligation generation and proof

Having analyzed a machine, you should routinely generate the proof

  • bligations by selecting the pog (proof obligation generator) button in

the Main environment. Then move to the Provers environment, select the prv (provers) button for the machine, and select AutoProver. If there are unproved

  • bligations then you should either try to discharge the proof obligation

using the BToolProver, or at least inspect the obligation to see if it is true. This should be a routine validation step.

slide-116
SLIDE 116

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Proof obligation generation and proof

Having analyzed a machine, you should routinely generate the proof

  • bligations by selecting the pog (proof obligation generator) button in

the Main environment. Then move to the Provers environment, select the prv (provers) button for the machine, and select AutoProver. If there are unproved

  • bligations then you should either try to discharge the proof obligation

using the BToolProver, or at least inspect the obligation to see if it is true. This should be a routine validation step.

slide-117
SLIDE 117

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Viewing the proof obligations

Select the Provers environment and select the ppf (prettyprint proof) button for the machine of interest. Select the proof obligations from the list. Select the Documents environment, and notice that there is a green .prf construct for the chosen machine. Mark-up the proof obligations by selecting the dmu (document markup) button; the view by selecting the shw (show) button.

slide-118
SLIDE 118

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Viewing the proof obligations

Select the Provers environment and select the ppf (prettyprint proof) button for the machine of interest. Select the proof obligations from the list. Select the Documents environment, and notice that there is a green .prf construct for the chosen machine. Mark-up the proof obligations by selecting the dmu (document markup) button; the view by selecting the shw (show) button.

slide-119
SLIDE 119

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Viewing the proof obligations

Select the Provers environment and select the ppf (prettyprint proof) button for the machine of interest. Select the proof obligations from the list. Select the Documents environment, and notice that there is a green .prf construct for the chosen machine. Mark-up the proof obligations by selecting the dmu (document markup) button; the view by selecting the shw (show) button.

slide-120
SLIDE 120

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Viewing the proof obligations

Select the Provers environment and select the ppf (prettyprint proof) button for the machine of interest. Select the proof obligations from the list. Select the Documents environment, and notice that there is a green .prf construct for the chosen machine. Mark-up the proof obligations by selecting the dmu (document markup) button; the view by selecting the shw (show) button.

slide-121
SLIDE 121

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Adding a non-trivial precondition

An attempt to discharge the outstanding proof obligation for the

  • peration RobBank will leave amount ≤ piggybank unprovable.

This occurs because the machine invariant says that piggybank ∈ N, that is 0 ≤ piggybank both before and after an operation. Thus we need to add the conjunct amount ≤ piggybank to the precondition of RobBank.

slide-122
SLIDE 122

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Adding a non-trivial precondition

An attempt to discharge the outstanding proof obligation for the

  • peration RobBank will leave amount ≤ piggybank unprovable.

This occurs because the machine invariant says that piggybank ∈ N, that is 0 ≤ piggybank both before and after an operation. Thus we need to add the conjunct amount ≤ piggybank to the precondition of RobBank.

slide-123
SLIDE 123

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Adding a non-trivial precondition

An attempt to discharge the outstanding proof obligation for the

  • peration RobBank will leave amount ≤ piggybank unprovable.

This occurs because the machine invariant says that piggybank ∈ N, that is 0 ≤ piggybank both before and after an operation. Thus we need to add the conjunct amount ≤ piggybank to the precondition of RobBank.

slide-124
SLIDE 124

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-125
SLIDE 125

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-126
SLIDE 126

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-127
SLIDE 127

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-128
SLIDE 128

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-129
SLIDE 129

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-130
SLIDE 130

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-131
SLIDE 131

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-132
SLIDE 132

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-133
SLIDE 133

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Towards understanding preconditions

Run the following experiment:

1

run the animator on PiggyBank with RobBank having a trivial precondition;

2

run the animator on PiggyBank with RobBank having the non-trivial precondition. In each case:

1

enable display invariant —the default is not display;

2

run:

1

FeedBank(5)

2

RobBank(10)

3

FeedBank(5)

Describe the results. Notice very carefully that failure of the precondition does not stop the operation from going ahead.

slide-134
SLIDE 134

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Total and Partial operations: preconditions

Operations without non-trivial preconditions are total operations: that is the operation may be invoked in any state of the machine, and for any value of the arguments of the operation. Such operations are also called robust. Operations with non-trivial preconditions are partial operations: that is the operation may not be defined outside of the precondition. Such

  • perations are also called fragile.

A precondition is an assumption, it is not a condition that is going to be tested by the implementer of the operation. It is the obligation of the invoker of the operation to ensure that the precondition holds. The precondition is the part of the contract that applies to the client of the operation.

slide-135
SLIDE 135

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Total and Partial operations: preconditions

Operations without non-trivial preconditions are total operations: that is the operation may be invoked in any state of the machine, and for any value of the arguments of the operation. Such operations are also called robust. Operations with non-trivial preconditions are partial operations: that is the operation may not be defined outside of the precondition. Such

  • perations are also called fragile.

A precondition is an assumption, it is not a condition that is going to be tested by the implementer of the operation. It is the obligation of the invoker of the operation to ensure that the precondition holds. The precondition is the part of the contract that applies to the client of the operation.

slide-136
SLIDE 136

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Total and Partial operations: preconditions

Operations without non-trivial preconditions are total operations: that is the operation may be invoked in any state of the machine, and for any value of the arguments of the operation. Such operations are also called robust. Operations with non-trivial preconditions are partial operations: that is the operation may not be defined outside of the precondition. Such

  • perations are also called fragile.

A precondition is an assumption, it is not a condition that is going to be tested by the implementer of the operation. It is the obligation of the invoker of the operation to ensure that the precondition holds. The precondition is the part of the contract that applies to the client of the operation.

slide-137
SLIDE 137

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity Machine Structure . . . Machine Structure Machine Parameters Operations Invariant and

Total and Partial operations: preconditions

Operations without non-trivial preconditions are total operations: that is the operation may be invoked in any state of the machine, and for any value of the arguments of the operation. Such operations are also called robust. Operations with non-trivial preconditions are partial operations: that is the operation may not be defined outside of the precondition. Such

  • perations are also called fragile.

A precondition is an assumption, it is not a condition that is going to be tested by the implementer of the operation. It is the obligation of the invoker of the operation to ensure that the precondition holds. The precondition is the part of the contract that applies to the client of the operation.

slide-138
SLIDE 138

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Modelling a Coffee Club

We will now model a coffee club with the following facilities for members: Joining a person can join the club. For the purpose of this simple exercise we identify each member by an element of the set NAME. Of course we want all members to be distinct. Contributing members can contribute money to the club. This is used to increase the credit of the member, which in turn is used to pay for cups of coffee. Buy coffee a member can buy a cup of coffee. The price of a cup

  • f coffee is deducted from the members credit.

Credit a member can obtain their current credit balance. The above behaviour is modelled by the machine CoffeeClub, initially named CoffeeClub0.

slide-139
SLIDE 139

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Modelling a Coffee Club

We will now model a coffee club with the following facilities for members: Joining a person can join the club. For the purpose of this simple exercise we identify each member by an element of the set NAME. Of course we want all members to be distinct. Contributing members can contribute money to the club. This is used to increase the credit of the member, which in turn is used to pay for cups of coffee. Buy coffee a member can buy a cup of coffee. The price of a cup

  • f coffee is deducted from the members credit.

Credit a member can obtain their current credit balance. The above behaviour is modelled by the machine CoffeeClub, initially named CoffeeClub0.

slide-140
SLIDE 140

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Modelling a Coffee Club

We will now model a coffee club with the following facilities for members: Joining a person can join the club. For the purpose of this simple exercise we identify each member by an element of the set NAME. Of course we want all members to be distinct. Contributing members can contribute money to the club. This is used to increase the credit of the member, which in turn is used to pay for cups of coffee. Buy coffee a member can buy a cup of coffee. The price of a cup

  • f coffee is deducted from the members credit.

Credit a member can obtain their current credit balance. The above behaviour is modelled by the machine CoffeeClub, initially named CoffeeClub0.

slide-141
SLIDE 141

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Modelling a Coffee Club

We will now model a coffee club with the following facilities for members: Joining a person can join the club. For the purpose of this simple exercise we identify each member by an element of the set NAME. Of course we want all members to be distinct. Contributing members can contribute money to the club. This is used to increase the credit of the member, which in turn is used to pay for cups of coffee. Buy coffee a member can buy a cup of coffee. The price of a cup

  • f coffee is deducted from the members credit.

Credit a member can obtain their current credit balance. The above behaviour is modelled by the machine CoffeeClub, initially named CoffeeClub0.

slide-142
SLIDE 142

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Modelling a Coffee Club

We will now model a coffee club with the following facilities for members: Joining a person can join the club. For the purpose of this simple exercise we identify each member by an element of the set NAME. Of course we want all members to be distinct. Contributing members can contribute money to the club. This is used to increase the credit of the member, which in turn is used to pay for cups of coffee. Buy coffee a member can buy a cup of coffee. The price of a cup

  • f coffee is deducted from the members credit.

Credit a member can obtain their current credit balance. The above behaviour is modelled by the machine CoffeeClub, initially named CoffeeClub0.

slide-143
SLIDE 143

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Modelling a Coffee Club

We will now model a coffee club with the following facilities for members: Joining a person can join the club. For the purpose of this simple exercise we identify each member by an element of the set NAME. Of course we want all members to be distinct. Contributing members can contribute money to the club. This is used to increase the credit of the member, which in turn is used to pay for cups of coffee. Buy coffee a member can buy a cup of coffee. The price of a cup

  • f coffee is deducted from the members credit.

Credit a member can obtain their current credit balance. The above behaviour is modelled by the machine CoffeeClub, initially named CoffeeClub0.

slide-144
SLIDE 144

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

A CoffeeClub machine I

MACHINE CoffeeClub0 ( NAME ) INCLUDES PiggyBank PROMOTES RobBank , CashLeft CONSTANTS coffee PROPERTIES coffee = 120 VARIABLES finances INVARIANT finances ∈ NAME → N INITIALISATION finances := {} OPERATIONS

slide-145
SLIDE 145

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

A CoffeeClub machine II

NewMember ( member ) = PRE member ∈ NAME THEN finances ( member ) := 0 END ; Contribute ( member , amount ) = PRE member ∈ NAME ∧ amount ∈ N THEN finances ( member ) := finances ( member ) + amount FeedBank ( amount ) END ;

slide-146
SLIDE 146

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

A CoffeeClub machine III

BuyCoffee ( member ) = PRE member ∈ NAME THEN finances ( member ) := finances ( member ) − coffee END ; credit ← − Credit ( member ) = PRE member ∈ NAME THEN credit := finances ( member ) END END

slide-147
SLIDE 147

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Aspects of CoffeeClub0

Aspects of this machine are: The NAME set is represented by a machine parameter. The PiggyBank machine is included into this machine. This embeds the state of PiggyBank into this machine, and gives CoffeeClub access to the operations of PiggyBank. The operations RobBank and CashLeft are promoted to the interface of CoffeeClub. A constant coffee is used for the cost of a cup of coffee. The state of the machine consists of a variable finances, which is a partial function from NAME to N. Three operations NewMember, Contribute, BuyCoffee and Credit are used to model the required behaviour.

slide-148
SLIDE 148

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Aspects of CoffeeClub0

Aspects of this machine are: The NAME set is represented by a machine parameter. The PiggyBank machine is included into this machine. This embeds the state of PiggyBank into this machine, and gives CoffeeClub access to the operations of PiggyBank. The operations RobBank and CashLeft are promoted to the interface of CoffeeClub. A constant coffee is used for the cost of a cup of coffee. The state of the machine consists of a variable finances, which is a partial function from NAME to N. Three operations NewMember, Contribute, BuyCoffee and Credit are used to model the required behaviour.

slide-149
SLIDE 149

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Aspects of CoffeeClub0

Aspects of this machine are: The NAME set is represented by a machine parameter. The PiggyBank machine is included into this machine. This embeds the state of PiggyBank into this machine, and gives CoffeeClub access to the operations of PiggyBank. The operations RobBank and CashLeft are promoted to the interface of CoffeeClub. A constant coffee is used for the cost of a cup of coffee. The state of the machine consists of a variable finances, which is a partial function from NAME to N. Three operations NewMember, Contribute, BuyCoffee and Credit are used to model the required behaviour.

slide-150
SLIDE 150

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Aspects of CoffeeClub0

Aspects of this machine are: The NAME set is represented by a machine parameter. The PiggyBank machine is included into this machine. This embeds the state of PiggyBank into this machine, and gives CoffeeClub access to the operations of PiggyBank. The operations RobBank and CashLeft are promoted to the interface of CoffeeClub. A constant coffee is used for the cost of a cup of coffee. The state of the machine consists of a variable finances, which is a partial function from NAME to N. Three operations NewMember, Contribute, BuyCoffee and Credit are used to model the required behaviour.

slide-151
SLIDE 151

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Aspects of CoffeeClub0

Aspects of this machine are: The NAME set is represented by a machine parameter. The PiggyBank machine is included into this machine. This embeds the state of PiggyBank into this machine, and gives CoffeeClub access to the operations of PiggyBank. The operations RobBank and CashLeft are promoted to the interface of CoffeeClub. A constant coffee is used for the cost of a cup of coffee. The state of the machine consists of a variable finances, which is a partial function from NAME to N. Three operations NewMember, Contribute, BuyCoffee and Credit are used to model the required behaviour.

slide-152
SLIDE 152

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Aspects of CoffeeClub0

Aspects of this machine are: The NAME set is represented by a machine parameter. The PiggyBank machine is included into this machine. This embeds the state of PiggyBank into this machine, and gives CoffeeClub access to the operations of PiggyBank. The operations RobBank and CashLeft are promoted to the interface of CoffeeClub. A constant coffee is used for the cost of a cup of coffee. The state of the machine consists of a variable finances, which is a partial function from NAME to N. Three operations NewMember, Contribute, BuyCoffee and Credit are used to model the required behaviour.

slide-153
SLIDE 153

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Aspects of CoffeeClub0

Aspects of this machine are: The NAME set is represented by a machine parameter. The PiggyBank machine is included into this machine. This embeds the state of PiggyBank into this machine, and gives CoffeeClub access to the operations of PiggyBank. The operations RobBank and CashLeft are promoted to the interface of CoffeeClub. A constant coffee is used for the cost of a cup of coffee. The state of the machine consists of a variable finances, which is a partial function from NAME to N. Three operations NewMember, Contribute, BuyCoffee and Credit are used to model the required behaviour.

slide-154
SLIDE 154

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Aspects of CoffeeClub0

Aspects of this machine are: The NAME set is represented by a machine parameter. The PiggyBank machine is included into this machine. This embeds the state of PiggyBank into this machine, and gives CoffeeClub access to the operations of PiggyBank. The operations RobBank and CashLeft are promoted to the interface of CoffeeClub. A constant coffee is used for the cost of a cup of coffee. The state of the machine consists of a variable finances, which is a partial function from NAME to N. Three operations NewMember, Contribute, BuyCoffee and Credit are used to model the required behaviour.

slide-155
SLIDE 155

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Some notes on machine inclusion

Included machine state: the included machine’s state is “added” to the state of the including machine. Referencing included state: the variables in the state of the included machine may be referenced by the including machine. Modifying the variables of included state: variables of the included machine may be modified by the included machine, but

  • nly by invoking operations of the included machine.

Export of operations: While operations of the included machine may be used by the including machines, they do not becomes operations of the including machine unless promoted by including machine. Included machine parameters: if the included machine has parameters they must be instantiated by the including machine.

slide-156
SLIDE 156

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Some notes on machine inclusion

Included machine state: the included machine’s state is “added” to the state of the including machine. Referencing included state: the variables in the state of the included machine may be referenced by the including machine. Modifying the variables of included state: variables of the included machine may be modified by the included machine, but

  • nly by invoking operations of the included machine.

Export of operations: While operations of the included machine may be used by the including machines, they do not becomes operations of the including machine unless promoted by including machine. Included machine parameters: if the included machine has parameters they must be instantiated by the including machine.

slide-157
SLIDE 157

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Some notes on machine inclusion

Included machine state: the included machine’s state is “added” to the state of the including machine. Referencing included state: the variables in the state of the included machine may be referenced by the including machine. Modifying the variables of included state: variables of the included machine may be modified by the included machine, but

  • nly by invoking operations of the included machine.

Export of operations: While operations of the included machine may be used by the including machines, they do not becomes operations of the including machine unless promoted by including machine. Included machine parameters: if the included machine has parameters they must be instantiated by the including machine.

slide-158
SLIDE 158

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Some notes on machine inclusion

Included machine state: the included machine’s state is “added” to the state of the including machine. Referencing included state: the variables in the state of the included machine may be referenced by the including machine. Modifying the variables of included state: variables of the included machine may be modified by the included machine, but

  • nly by invoking operations of the included machine.

Export of operations: While operations of the included machine may be used by the including machines, they do not becomes operations of the including machine unless promoted by including machine. Included machine parameters: if the included machine has parameters they must be instantiated by the including machine.

slide-159
SLIDE 159

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Some notes on machine inclusion

Included machine state: the included machine’s state is “added” to the state of the including machine. Referencing included state: the variables in the state of the included machine may be referenced by the including machine. Modifying the variables of included state: variables of the included machine may be modified by the included machine, but

  • nly by invoking operations of the included machine.

Export of operations: While operations of the included machine may be used by the including machines, they do not becomes operations of the including machine unless promoted by including machine. Included machine parameters: if the included machine has parameters they must be instantiated by the including machine.

slide-160
SLIDE 160

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Problems with CoffeeClub

The specification given by this machine is not adequate. It is easy to show that the operations can break the invariant. Generating the proof obligations and attempting to discharge them will illustrate some of the problems. Run the AutoProver on the proof

  • bligations and examine any undischarged proof obligations.

Animation may help to illustrate where the problems lie.

slide-161
SLIDE 161

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Problems with CoffeeClub

The specification given by this machine is not adequate. It is easy to show that the operations can break the invariant. Generating the proof obligations and attempting to discharge them will illustrate some of the problems. Run the AutoProver on the proof

  • bligations and examine any undischarged proof obligations.

Animation may help to illustrate where the problems lie.

slide-162
SLIDE 162

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Problems with CoffeeClub

The specification given by this machine is not adequate. It is easy to show that the operations can break the invariant. Generating the proof obligations and attempting to discharge them will illustrate some of the problems. Run the AutoProver on the proof

  • bligations and examine any undischarged proof obligations.

Animation may help to illustrate where the problems lie.

slide-163
SLIDE 163

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems I

The problems are enumerated below: NewMember this operation has an undesirable functional property: if an existing member —or a new member with the same name as an existing member— with credit runs this

  • peration then their finances are set to 0! The

specification alerts the user to this undesirable effect by adding a precondition member ∈ dom(finances), that is, the prospective member is not an existing member. Contribute the function finances is partial, so the expression used to update the member’s finances: finances(member) := finances(member) + amount will be undefined when member ∈ dom(finances). A precondition that member ∈ dom(finances) is required.

slide-164
SLIDE 164

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems I

The problems are enumerated below: NewMember this operation has an undesirable functional property: if an existing member —or a new member with the same name as an existing member— with credit runs this

  • peration then their finances are set to 0! The

specification alerts the user to this undesirable effect by adding a precondition member ∈ dom(finances), that is, the prospective member is not an existing member. Contribute the function finances is partial, so the expression used to update the member’s finances: finances(member) := finances(member) + amount will be undefined when member ∈ dom(finances). A precondition that member ∈ dom(finances) is required.

slide-165
SLIDE 165

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems I

The problems are enumerated below: NewMember this operation has an undesirable functional property: if an existing member —or a new member with the same name as an existing member— with credit runs this

  • peration then their finances are set to 0! The

specification alerts the user to this undesirable effect by adding a precondition member ∈ dom(finances), that is, the prospective member is not an existing member. Contribute the function finances is partial, so the expression used to update the member’s finances: finances(member) := finances(member) + amount will be undefined when member ∈ dom(finances). A precondition that member ∈ dom(finances) is required.

slide-166
SLIDE 166

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems I

The problems are enumerated below: NewMember this operation has an undesirable functional property: if an existing member —or a new member with the same name as an existing member— with credit runs this

  • peration then their finances are set to 0! The

specification alerts the user to this undesirable effect by adding a precondition member ∈ dom(finances), that is, the prospective member is not an existing member. Contribute the function finances is partial, so the expression used to update the member’s finances: finances(member) := finances(member) + amount will be undefined when member ∈ dom(finances). A precondition that member ∈ dom(finances) is required.

slide-167
SLIDE 167

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems II

BuyCoffee In order to buy a coffee, two things are required

1

the person must be a member, otherwise finances(member) will be undefined;

2

a member must have enough finance to cover the price of a cup of coffee. If this is not the case then finances(member) − coffee will not be a natural number, breaking the invariant. So a precondition of: member ∈ dom(finances) ∧ finances(member) ≥ coffee is required. Credit finances(member) assumes member ∈ dom(finances), so this needs to be added to the precondition. The following versions of PiggyBank and CoffeeClub have appropriately strengthened preconditions.

slide-168
SLIDE 168

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems II

BuyCoffee In order to buy a coffee, two things are required

1

the person must be a member, otherwise finances(member) will be undefined;

2

a member must have enough finance to cover the price of a cup of coffee. If this is not the case then finances(member) − coffee will not be a natural number, breaking the invariant. So a precondition of: member ∈ dom(finances) ∧ finances(member) ≥ coffee is required. Credit finances(member) assumes member ∈ dom(finances), so this needs to be added to the precondition. The following versions of PiggyBank and CoffeeClub have appropriately strengthened preconditions.

slide-169
SLIDE 169

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems II

BuyCoffee In order to buy a coffee, two things are required

1

the person must be a member, otherwise finances(member) will be undefined;

2

a member must have enough finance to cover the price of a cup of coffee. If this is not the case then finances(member) − coffee will not be a natural number, breaking the invariant. So a precondition of: member ∈ dom(finances) ∧ finances(member) ≥ coffee is required. Credit finances(member) assumes member ∈ dom(finances), so this needs to be added to the precondition. The following versions of PiggyBank and CoffeeClub have appropriately strengthened preconditions.

slide-170
SLIDE 170

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems II

BuyCoffee In order to buy a coffee, two things are required

1

the person must be a member, otherwise finances(member) will be undefined;

2

a member must have enough finance to cover the price of a cup of coffee. If this is not the case then finances(member) − coffee will not be a natural number, breaking the invariant. So a precondition of: member ∈ dom(finances) ∧ finances(member) ≥ coffee is required. Credit finances(member) assumes member ∈ dom(finances), so this needs to be added to the precondition. The following versions of PiggyBank and CoffeeClub have appropriately strengthened preconditions.

slide-171
SLIDE 171

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems II

BuyCoffee In order to buy a coffee, two things are required

1

the person must be a member, otherwise finances(member) will be undefined;

2

a member must have enough finance to cover the price of a cup of coffee. If this is not the case then finances(member) − coffee will not be a natural number, breaking the invariant. So a precondition of: member ∈ dom(finances) ∧ finances(member) ≥ coffee is required. Credit finances(member) assumes member ∈ dom(finances), so this needs to be added to the precondition. The following versions of PiggyBank and CoffeeClub have appropriately strengthened preconditions.

slide-172
SLIDE 172

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

Identifying and fixing the problems II

BuyCoffee In order to buy a coffee, two things are required

1

the person must be a member, otherwise finances(member) will be undefined;

2

a member must have enough finance to cover the price of a cup of coffee. If this is not the case then finances(member) − coffee will not be a natural number, breaking the invariant. So a precondition of: member ∈ dom(finances) ∧ finances(member) ≥ coffee is required. Credit finances(member) assumes member ∈ dom(finances), so this needs to be added to the precondition. The following versions of PiggyBank and CoffeeClub have appropriately strengthened preconditions.

slide-173
SLIDE 173

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

PiggyBank.mch I

MACHINE PiggyBank VARIABLES piggybank INVARIANT piggybank ∈ N INITIALISATION piggybank := 0 OPERATIONS

slide-174
SLIDE 174

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

PiggyBank.mch II

FeedBank ( amount ) b = PRE amount ∈ N THEN piggybank := piggybank + amount END ; RobBank ( amount ) b = PRE amount ∈ N ∧ amount ≤ piggybank THEN piggybank := piggybank − amount END ; money ← − CashLeft b = BEGIN money := piggybank END END

slide-175
SLIDE 175

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

CoffeeClub.mch I

MACHINE CoffeeClub ( NAME ) INCLUDES PiggyBank PROMOTES RobBank , CashLeft CONSTANTS coffee PROPERTIES coffee = 120 VARIABLES finances INVARIANT finances ∈ NAME → N INITIALISATION finances := {} OPERATIONS

slide-176
SLIDE 176

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

CoffeeClub.mch II

NewMember ( member ) b = PRE member ∈ NAME ∧ member ∈ dom ( finances ) THEN finances ( member ) := 0 END ; Contribute ( member , amount ) b = PRE member ∈ NAME ∧ member ∈ dom ( finances ) ∧ amount ∈ N THEN finances ( member ) := finances ( member ) + amount FeedBank ( amount ) END ;

slide-177
SLIDE 177

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity A CoffeeClub machine Some notes on machine inclusion Problems with CoffeeClub Identifying

CoffeeClub.mch III

BuyCoffee ( member ) b = PRE member ∈ NAME ∧ member ∈ dom ( finances ) ∧ finances ( member ) ≥ coffee THEN finances ( member ) := finances ( member ) − coffee END ; credit ← − Credit ( member ) b = PRE member ∈ NAME ∧ member ∈ dom ( finances ) THEN credit := finances ( member ) END END

slide-178
SLIDE 178

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

Specifying a Robust machine

Most of the operations of the CoffeeClub machine are fragile, that is the operations have non-trivial preconditions. This means that there are combinations of state and operations arguments for which the

  • peration will fail.

Such operations are not safe to use in an application programmer interface (API) or user interface (UI). We will build an API machine, CoffeeClubAPI, with robust versions of the operations of CoffeeClub. These operations will use guards that discharge the precondition of the fragile operation ensuring that it is safe to invoke the fragile operation. Each operation returns a response that reports whether the operation was successful, or why the precondition failed.

slide-179
SLIDE 179

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

Specifying a Robust machine

Most of the operations of the CoffeeClub machine are fragile, that is the operations have non-trivial preconditions. This means that there are combinations of state and operations arguments for which the

  • peration will fail.

Such operations are not safe to use in an application programmer interface (API) or user interface (UI). We will build an API machine, CoffeeClubAPI, with robust versions of the operations of CoffeeClub. These operations will use guards that discharge the precondition of the fragile operation ensuring that it is safe to invoke the fragile operation. Each operation returns a response that reports whether the operation was successful, or why the precondition failed.

slide-180
SLIDE 180

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

Specifying a Robust machine

Most of the operations of the CoffeeClub machine are fragile, that is the operations have non-trivial preconditions. This means that there are combinations of state and operations arguments for which the

  • peration will fail.

Such operations are not safe to use in an application programmer interface (API) or user interface (UI). We will build an API machine, CoffeeClubAPI, with robust versions of the operations of CoffeeClub. These operations will use guards that discharge the precondition of the fragile operation ensuring that it is safe to invoke the fragile operation. Each operation returns a response that reports whether the operation was successful, or why the precondition failed.

slide-181
SLIDE 181

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

Specifying a Robust machine

Most of the operations of the CoffeeClub machine are fragile, that is the operations have non-trivial preconditions. This means that there are combinations of state and operations arguments for which the

  • peration will fail.

Such operations are not safe to use in an application programmer interface (API) or user interface (UI). We will build an API machine, CoffeeClubAPI, with robust versions of the operations of CoffeeClub. These operations will use guards that discharge the precondition of the fragile operation ensuring that it is safe to invoke the fragile operation. Each operation returns a response that reports whether the operation was successful, or why the precondition failed.

slide-182
SLIDE 182

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

CoffeeClubAPI.mch I

MACHINE CoffeeClubAPI ( NAME ) INCLUDES CoffeeClub ( NAME ) SETS RESPONSE = { OK , existing member , not a member , not enough finance , not enough in bank } OPERATIONS

slide-183
SLIDE 183

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

CoffeeClubAPI.mch II

response ← − NewMemberAPI ( member ) b = PRE member ∈ NAME THEN IF member ∈ dom ( finances ) THEN response := existing member ELSE response := OK NewMember ( member ) END END ; response ← − ContributeAPI ( member , amount ) b = PRE member ∈ NAME ∧ amount ∈ N THEN IF member ∈ dom ( finances ) THEN response := not a member ELSE response := OK Contribute ( member , amount ) END END ;

slide-184
SLIDE 184

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

CoffeeClubAPI.mch III

response ← − BuyCoffeeAPI ( member ) b = PRE member ∈ NAME THEN SELECT member ∈ dom ( finances ) THEN response := not a member WHEN finances ( member ) < coffee THEN response := not enough finance ELSE response := OK BuyCoffee ( member ) END END ; response , credit ← − CreditAPI ( member ) b = PRE member ∈ NAME THEN IF member ∈ dom ( finances ) THEN response := not a member credit :∈ N ELSE response := OK credit ← − Credit ( member ) END END ;

slide-185
SLIDE 185

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

CoffeeClubAPI.mch IV

response ← − RobBankAPI ( amount ) b = PRE amount ∈ N THEN IF piggybank < amount THEN response := not enough in bank ELSE response := OK RobBank ( amount ) END END ; money ← − CashLeftAPI b = money ← − CashLeft END

slide-186
SLIDE 186

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

A Question of Identity

The CoffeeClub, in addition to being a very simple model, also exhibits a serious deficiency: It uses names for the identity of members. This is clearly inadequate. For example we have a restriction that two people with the same name cannot belong to the club. In all real systems we need to allocate unique identifiers for each member of —for each component of— a system. Subsequent system models will demonstrate this.

slide-187
SLIDE 187

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

A Question of Identity

The CoffeeClub, in addition to being a very simple model, also exhibits a serious deficiency: It uses names for the identity of members. This is clearly inadequate. For example we have a restriction that two people with the same name cannot belong to the club. In all real systems we need to allocate unique identifiers for each member of —for each component of— a system. Subsequent system models will demonstrate this.

slide-188
SLIDE 188

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

A Question of Identity

The CoffeeClub, in addition to being a very simple model, also exhibits a serious deficiency: It uses names for the identity of members. This is clearly inadequate. For example we have a restriction that two people with the same name cannot belong to the club. In all real systems we need to allocate unique identifiers for each member of —for each component of— a system. Subsequent system models will demonstrate this.

slide-189
SLIDE 189

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

A Question of Identity

The CoffeeClub, in addition to being a very simple model, also exhibits a serious deficiency: It uses names for the identity of members. This is clearly inadequate. For example we have a restriction that two people with the same name cannot belong to the club. In all real systems we need to allocate unique identifiers for each member of —for each component of— a system. Subsequent system models will demonstrate this.

slide-190
SLIDE 190

Outline B Mathematical Toolkit Set Theory Predicate Calculus Notation The B-Toolkit A Simple Model Modelling a Coffee Club Specifying a Robust machine A Question of Identity

A Question of Identity

The CoffeeClub, in addition to being a very simple model, also exhibits a serious deficiency: It uses names for the identity of members. This is clearly inadequate. For example we have a restriction that two people with the same name cannot belong to the club. In all real systems we need to allocate unique identifiers for each member of —for each component of— a system. Subsequent system models will demonstrate this.