(La méthode Event-B) Refinement CSC 4504 : Langages formels et applications

Download Report

Transcript (La méthode Event-B) Refinement CSC 4504 : Langages formels et applications

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
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.1
Langages formels et applications
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.
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.2
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.
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.3
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)
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.4
RAFFINEMENT
Obligations de preuve (chaque machine)
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.5
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.
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.6
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.
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.7
RAFFINEMENT
Étapes de construction d’un programme
On construit une abstraction MAGIQUE qui simule l’execution du programme
en un seul coup.
• On construit des raffinements par ajout de variables et de nouveaux événements
avec 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 nous
avons la correction.
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.8
RAFFINEMENT
RefinementBased Program Development
The client provides a nonexecutable 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.
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.9
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
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.10
RAFFINEMENT
Find square root
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)
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.11
RAFFINEMENT
Find square root
Concrete Operation
for finding square
root of a natural …
it is a refinement of
the abstract
operation
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.12
RAFFINEMENT
Find square root
Déterministe:
Trop concrete pour une
specification?
Nondéterministe:
Pourqui pas la remplacer
par une specification
plus abstraite?
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.13
Find square root
RAFFINEMENT
Déterministe:
Trop concrete pour une
specification?
QUESTION: ??
2009: J Paul Gibson
Nondéterministe:
Pourquoi pas la
remplacer par une
specification plus
abstraite?
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.14
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.
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.15
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
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.16
RAFFINEMENT
Multiply 2 numbers: using addition in Event-B
Some useful context specification
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
A first (abstract) machine
M0
« magic » mul finds result in 1 step
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
– 1st refinement
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 (proof obligations)
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
– 2nd refinement
Need more context
definitions for the 2nd
refinement.
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
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
Deadlock freeness
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.23
RAFFINEMENT
2009: J Paul Gibson
Multiply 2 numbers: using addition in Event-B – 2nd
refinement
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.24
RAFFINEMENT Multiply 2 numbers: Russian algorithm
uses 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
QUESTION:
Modeliser l’algorithm en
event-B
result
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.25
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)
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.26
Find the celebrity
Step 1: the context for the static rules (axioms)
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.27
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
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.28
Find the celebrity
Step 3: A first refinement towards a solution
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.29
Find the celebrity
Step 3: A first refinement towards a solution
QUESTION: Is this a correct refinement (of skip)?
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.30
Find the celebrity
Step 3: A first refinement towards a solution
QUESTION: Is this a correct refinement (of skip)?
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.31
Find the celebrity
Step 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
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.32
Find the celebrity
Step 4: A second refinement towards a
solution (e.g. refine the remove_2 event)
Instantiate
parameter
Question: can you do the same for remove_1?
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.33
Find the minimum
Step1: the context
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.34
Find the minimum
Step2: the abstract machine
Let’s try to do this together
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.35
Find the minimum
Step3: a first refinement
QUESTION: Specify a refinement and prove the
obligations generated by Rodin
2009: J Paul Gibson
T&MSP-CSC 4504 : Langages formels et applications
Event-B/Refinement.36