31
How to Explain Mistakes Stefan Hallerstede and Michael Leuschel Universit¨ at D¨ usseldorf Teaching Formal Methods 2009 6 November 2009

How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

How to Explain Mistakes

Stefan Hallerstede and Michael Leuschel

Universitat Dusseldorf

Teaching Formal Methods 20096 November 2009

Page 2: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Contents

Event-BEvent-B in General TermsEvent-B by Example

Tool Support

Making Mistakes

Explaining Mistakes

On-going Work and Conclusion

Page 3: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Contents

Event-BEvent-B in General TermsEvent-B by Example

Tool Support

Making Mistakes

Explaining Mistakes

On-going Work and Conclusion

Page 4: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Contents

Event-BEvent-B in General TermsEvent-B by Example

Tool Support

Making Mistakes

Explaining Mistakes

On-going Work and Conclusion

Page 5: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Modelling and Proving in Event-B

I Main purpose of modelling is reasoning

I Models determine what is to be formally proved

I Proof obligations are automatically generated

I Tool support is essential

I Refinement is a proof technique

I Models and proof obligations correspond closely

ProofObligationsModelling Proving

Page 6: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Contents

Event-BEvent-B in General TermsEvent-B by Example

Tool Support

Making Mistakes

Explaining Mistakes

On-going Work and Conclusion

Page 7: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

A Simple Example of an Event-B Model

I Invariants

inv1 : auth ∈ Person↔RoomA person is authorised to be in certain rooms

inv2 : in ∈ Person 7→RoomA person can be at most in one room

inv3 : in ⊆ authA person can only be in rooms where he is authorised to be

I Events

enterany

p rwhen

grd1 : p 6∈ dom(in) Person is not in buildinggrd2 : p 7→ r ∈ auth Person is authorised to enter room

thenact1 : in := in ∪ {p 7→ r}

end

Page 8: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Proof Obligations of the Event-B Model

I Preservation of invariant inv3 by event enter

I Name of proof obligation

“enter/inv3/INV”

I Sequent

auth ∈ Person↔Room invariant inv1in ∈ Person 7→Room invariant inv2in ⊆ auth invariant inv3p /∈ dom(in) guard grd1p 7→ r ∈ auth guard grd2

`in ∪ { p 7→ r} ⊆ auth modified (act1) invariant inv3

I Simple correspondence between proof obligations and model

Page 9: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Contents

Event-BEvent-B in General TermsEvent-B by Example

Tool Support

Making Mistakes

Explaining Mistakes

On-going Work and Conclusion

Page 10: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

The Rodin Tool — Modelling

Error: 'x' is not a variable

event searchwhen f(i) = v then

k := iend

event incwhen f(i) < v then

p := i + 1i := (i + 1 + q)÷ 2

endevent dec

when v < f(i) thenq := i! 1i := (p + i! 1)÷ 2

Messages

Model Editor

☑ search/i1/INV☑ search/i2/INV☑ inc/i1/INV☒inc/i2/INV☒dec/i1/INV☑dec/i2/INV

ProofObligations

Page 11: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

The Rodin Tool — Proving

p ! 1..Ni < Nf(i) < v

i + 1 ! 1..N

Conclusion

Premises

☑ search/i1/INV☑ search/i2/INV☑ inc/i1/INV☒inc/i2/INV☒dec/i1/INV☑dec/i2/INV

ProofObligations

Page 12: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

The Rodin Tool — Animation (ProB)

Event1Event2

INITIALISATIONx=2

S3

S2

S1

S4

CurrentState of

the ModelEnabledEvents History

Graphical View of the State(space)

Page 13: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Screen Shot of the Rodin Tool — Modelling

Page 14: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Contents

Event-BEvent-B in General TermsEvent-B by Example

Tool Support

Making Mistakes

Explaining Mistakes

On-going Work and Conclusion

Page 15: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Starting From a Perfect Solutions

I Usually we present (perfect) solutions to selected problems

I This does not show how the solution was obtained

I It creates the illusion there would be a perfect solution

I This fails to demonstrate a major strength of formal methods

I Support towards finding a good solution

I It is not just about correctness

Page 16: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Finding a Good Solution

Problem solving (Polya, Lakatos)

I Think about how to approach the problem

I Start with a model that appears reasonable

I Make mistakes

I Analyse the model

I Think again

I Improve the model

I Make mistakes

Page 17: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Contents

Event-BEvent-B in General TermsEvent-B by Example

Tool Support

Making Mistakes

Explaining Mistakes

On-going Work and Conclusion

Page 18: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Analysing and Explaining Mistakes

I Proof is a good tool for analysing inconsistent models

I It points to the place where the inconsistency occurs

I It does not serve well for explaining inconsistencies

I Useful tools for explanation:

I Model checking: counter examples

I Animation: see “how it happens”

I ProB can also be used for this

Page 19: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Example of requirements

P1 : The system consists of persons and one building.

P2 : The building consists of rooms and doors.

P3 : Each person can be at most in one room.

P4 : Each person is authorised to be in certain rooms (but not others).

P5 : Each person is authorised to use certain doors (but not others).

P6 : Each person can only be in a room where the person is authorised to be.

P7 : Each person must be able to leave the building from any room where the person is authorised to be.

P8 : Each person can pass from one room to another if there is a door connecting the two rooms and theperson has the proper authorisation.

P9 : Authorisations can be granted and revoked.

I Example provides room for misunderstanding

I Unlike a sequential program, for instance

I Model is much simplifiedfrom “Event Driven System Construction” by Abrial

Page 20: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Getting Started

I the abstract machine models room authorisations

I the concrete machine models room and door authorisations

Abstract invariants

inv1 : arm ∈ Person ↔ Room Property P4

inv2 : Person × {O} ⊆ arm

inv3 : loc ∈ Person → Room Property P3

inv4 : loc ⊆ arm Property P6

Page 21: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Revoking an Authorisation

P9 Authorisations can be granted and revoked.

revokeany p r when

grd1 : p ∈ Persongrd2 : p 7→ r /∈ loc

thenact1 : arm := arm \ {p 7→ r}

end

Page 22: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

How the model looks in Rodin

Page 23: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

What have to prove:

Event revoke preserves invariant inv2:

Person × {O} ⊆ arm Invariant inv2p ∈ Person Guard grd1p 7→ r /∈ loc Guard grd2`Person × {O} ⊆ arm \ {p 7→ r} Modified invariant inv2

Page 24: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

How the proof obligation looks in Rodin

Page 25: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

What have to prove:

Event revoke preserves invariant inv2:

Person × {O} ⊆ arm Invariant inv2p ∈ Person Guard grd1p 7→ r /∈ loc Guard grd2`Person × {O} ⊆ arm \ {p 7→ r} Modified invariant inv2

I Is it (not) provable?

I Why?

I Our aim is to improve the model

I Not to make the proof obligation “pass”

Page 26: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Change of perspective

I Look at a problematic state trace(leading to an inconsistent state)

I ProB alerts us that it violates invariant inv2:Person × {O} ⊆ arm

Page 27: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

How the counter example looks in ProB

Page 28: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Contents

Event-BEvent-B in General TermsEvent-B by Example

Tool Support

Making Mistakes

Explaining Mistakes

On-going Work and Conclusion

Page 29: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Refinement Animation

We work on refinement animation similar to Brama

Page 30: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Refinement Animation

CoffeeR2 CoffeeR1 CoffeeMINITIALSATIONfill_mugdrinkinsert_coin

INITIALSATIONfill_mugdrinkinsert_coin

INITIALSATIONfill_mugdrink

Inv Inv

⟲↓↓ →

↓⟲

↓⟲

Sketch of non-graphical display of state of refinement animation

Page 31: How to Explain Mistakes - Universidade do Minho - Hallerstede/method.pdf · Example of requirements P1 :The system consists of persons and one building. P2 :The building consists

Conclusion

I Teach formal modelling how it is done

I Teach incremental modelling

I Teach how to improve a model in small increments

I Teach making mistakes (how to profit from making mistakes)

I Teach how to explain mistakes and to justify improvements

I Use a software tool like Rodin/ProB in class and in exercises

I Getting a model right is not easy