2009: j paul gibsont&msp-csc 4504 : langages formels et applications event-b/refinement.1 csc...

36
2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B) J Paul Gibson, A207 [email protected] ://www-public.it-sudparis.eu/~gibson/Teaching/Event Refinement /www-public.it-sudparis.eu/~gibson/Teaching/Event-B/Refineme

Upload: hannah-hopkins

Post on 26-Mar-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1

CSC 4504 : Langages formels et applications

(La méthode Event-B)

J Paul Gibson, A207

[email protected]

http://www-public.it-sudparis.eu/~gibson/Teaching/Event-B/

Refinement

http://www-public.it-sudparis.eu/~gibson/Teaching/Event-B/Refinement.pdf

Page 2: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.2

OBJECTIF: Construire des programmes corrects.

Il existe deux techniques :

• a posteriori

– preuves de programmes: triplet de Hoare {P}S{Q}– interprétation abstraite et model checking, eg: Vol 502 (Ariane)

• a priori

construction incrémentale (raffinement) de programme correct en utilisant une méthode formelle. Preuves à chaque étape + preuve du raffinement.

Langages formels et applications

Page 3: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.3

RAFFINEMENT

• nous pouvons ajouter de nouveaux détails (variables),

• nous pouvons ajouter de nouveaux événements (nous pourrons

observer plus de transformations),

• nous devons prouver que les comportements concrets sont des

comportements abstraits; le raffinement préservera donc l’invariant

abstrait.

• chaque nouvel événement raffine skip

• pas plus de blocage que dans l’abstraction,

• les événement abstraits devront se produire.

Page 4: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.4

RAFFINEMENT

But du raffinement

• comprendre de plus en plus le système,

• distribuer la complexité du système,

• distribuer la difficulté de la preuve,

• faciliter l’explication,

• validation (pas par pas)

• raffinement de système (invariance & comportement)

Page 5: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.5

RAFFINEMENT

Obligations de preuve (chaque machine)

Page 6: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.6

RAFFINEMENT

Techniques de raffinement

• Chaque événement abstrait est raffiné par l’événement concret de même nom

-> un événement concret ne contredit pas son abstraction

• x sont les variables de l’abstraction,

• y sont les variables du raffinement,

-> x et y sont distinctes (pas de variable commune ou renommage)

• I(x) est l’invariant abstrait et J(x, y) est l’invariant concret qui explique la

relation entre les deux mondes.

Page 7: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.7

RAFFINEMENT

Les preuves du raffinement

On doit prouver que

• l’invariant J(x, y) est préservé,• les comportements concrets sont des comportements abstraits,• les événements abstraits doivent se produire,• pas plus de blocage dans le raffinement.

Page 8: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.8

RAFFINEMENT

Étapes de construction d’un programme

On construit une abstraction MAGIQUE qui simule l’execution du programmeen un seul coup.

• On construit des raffinements par ajout de variables et de nouveaux événementsavec les contraintes suivantes :

– le système que l’on construit ne doit jamais se bloquer (absence de dealock)– les nouveaux événements ne doivent jamais prendre indéfiniment la main

• à la fin on obtient (à l’aide de rêgles) un programme concret et en prime nousavons la correction.

Page 9: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.9

RAFFINEMENT

Refinement Based Program Development

The client provides a non executable program (the specification)

The developer's job is to transform it into an executable program

It will pass through a series of stages in which some parts are executable, but others are not

Specifications give lots of freedom about how a result is obtained •executable code has no freedom •mixed programs have some freedom

• Monotonicity is key: to show that a component of the model (like a command) can be refined by refining one or more of its component parts

Refinement doesn’t stop one making stupid design decisions, but it does stop you from producing incorrect executable code.

Page 10: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.10

Refinement Problems\Examples: modelling non-reactive systems

1. Calculate square root

2. Multiply 2 numbers

3. Find the celebrity

4. Find the minimum

In next class we look at modelling reactive systems

Page 11: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.11

RAFFINEMENT

Abstract Operation(in B notation) for finding square root of a natural

We see the difference between B operations and Event-B events, in later lectures (on theory)

Find square root

Page 12: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.12

RAFFINEMENT

Concrete Operationfor finding square root of a natural … it is a refinement of the abstract operation

Find square root

Page 13: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.13

RAFFINEMENT

Déterministe:Trop concrete pour une specification?

Nondéterministe:Pourqui pas la remplacer par une specification plus abstraite?

Find square root

Page 14: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.14

RAFFINEMENT Find square root

Déterministe:Trop concrete pour une specification?

Nondéterministe:Pourquoi pas la remplacer par une specification plus abstraite?

QUESTION: ??

Page 15: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.15

RAFFINEMENT Multiply 2 numbers: using multiplication

Multiplier x et y, ou x = 49 et y = 82

result := x*y

But, what if our implementation machine/enviroment does not have a « magic » multiply operator?

We refine towards the core operators/functions of the machine chosen to implement our system.

Page 16: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.16

RAFFINEMENT Multiply 2 numbers: using addition

Multiplier x et y, ou x = 49 et y = 82

Result = 82 + (48 * 82)= 82+82 + (47*82)

= 82+82 +82 + (46*82) = …

= 82 + …+ 82

48 +s

Page 17: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.17

RAFFINEMENT Multiply 2 numbers: using addition in Event-B

Some useful context specification

Page 18: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.18

RAFFINEMENT

Multiply 2 numbers: using addition in Event-B

A first (abstract) machineM0

« magic » mul finds result in 1 step

Page 19: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.19

RAFFINEMENT

Multiply 2 numbers: using addition in Event-B – 1st refinement

Page 20: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.20

RAFFINEMENT

Multiply 2 numbers: using addition in Event-B – 1st refinement (proof obligations)

Page 21: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.21

RAFFINEMENT

Multiply 2 numbers: using addition in Event-B – 2nd refinement

Need more context definitions for the 2nd refinement.

Page 22: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.22

RAFFINEMENT

Multiply 2 numbers: using addition in Event-B – 2nd refinement

Page 23: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.23

RAFFINEMENT

Multiply 2 numbers: using addition in Event-B – 2nd refinement

Deadlock freeness

Page 24: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.24

RAFFINEMENT Multiply 2 numbers: using addition in Event-B – 2nd refinement

Page 25: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.25

RAFFINEMENT Multiply 2 numbers: Russian algorithmuses impair, /2 *2 and addition

Multiplier x et y, ou x = 49 et x = 82

49/2 =24/2 =12/2 =6/2 = 3/2 =

If Impair(x)Then result = result+ y

result

QUESTION:Modeliser l’algorithm en event-B

Page 26: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.26

Find the celebrity

There are 2 types of people:

1. A unique celebrity who is known by all other people, but who knows nobody

2. All non-celebrities who can know anybody except themselves, and who must know the celebrity

Problem: given a set of people (represented as integers) and a knows relationship then build a machine that finds the celebrity (integer)

Page 27: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.27

Find the celebrity

Step 1: the context for the static rules (axioms)

Page 28: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.28

Find the celebrity

Step 2: the 1-step (« magic ») machine specifying dynamic requirements – what not how

Result – r – is initially set to be a randomly chosen person. After the find_celebrity event, r now identifies the celebrity c

Page 29: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.29

Find the celebrityStep 3: A first refinement towards a solution

Page 30: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.30

Find the celebrityStep 3: A first refinement towards a solution

QUESTION: Is this a correct refinement (of skip)?

Page 31: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.31

Find the celebrityStep 3: A first refinement towards a solution

QUESTION: Is this a correct refinement (of skip)?

Page 32: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.32

Find the celebrityStep 4: A second refinement towards a solution

Our machine is still too abstract (use of ANY with 2 parameters) …

We should remove the nondeterminism

Can do it incrementally – parameter by parameter

Page 33: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.33

Find the celebrityStep 4: A second refinement towards a solution (e.g. refine the remove_2 event)

Instantiateparameter

Question: can you do the same for remove_1?

Page 34: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.34

Find the minimum

Step1: the context

Page 35: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.35

Find the minimum

Step2: the abstract machine

Let’s try to do this together

Page 36: 2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

2009: J Paul Gibson T&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.36

Find the minimum

Step3: a first refinement

QUESTION: Specify a refinement and prove the obligations generated by Rodin