Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software...

77
Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin Weiß Institut f¨ ur Theoretische Informatik Universit¨ at Karlsruhe 07. Januar 2009

Transcript of Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software...

Page 1: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Formale Entwicklung objektorientierter SoftwarePraktikum im Wintersemester 2008/2009

Prof. P. H. SchmittChristian Engel, Benjamin Weiß

Institut fur Theoretische InformatikUniversitat Karlsruhe

07. Januar 2009

Page 2: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Loop Invariants

Formale Entwicklung objektorientierter Software 07. Januar 2009 2 / 15

Page 3: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwind

Γ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations? Unwind 1×10 iterations? Unwind 11×10000 iterations? Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 4: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwindΓ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations? Unwind 1×10 iterations? Unwind 11×10000 iterations? Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 5: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwindΓ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations?

Unwind 1×10 iterations? Unwind 11×10000 iterations? Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 6: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwindΓ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations? Unwind 1×

10 iterations? Unwind 11×10000 iterations? Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 7: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwindΓ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations? Unwind 1×10 iterations?

Unwind 11×10000 iterations? Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 8: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwindΓ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations? Unwind 1×10 iterations? Unwind 11×

10000 iterations? Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 9: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwindΓ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations? Unwind 1×10 iterations? Unwind 11×10000 iterations?

Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 10: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwindΓ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations? Unwind 1×10 iterations? Unwind 11×10000 iterations? Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 11: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwindΓ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations? Unwind 1×10 iterations? Unwind 11×10000 iterations? Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 12: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Unwinding Loops

loopUnwindΓ ==> U〈π if(e){p; while(e) p} ω〉ψ, ∆

Γ ==> U〈π while(e) p ω〉φ, ∆

How to handle a loop with. . .

0 iterations? Unwind 1×10 iterations? Unwind 11×10000 iterations? Unwind 10001×(and don’t make any plans for the rest of the day)

an unknown number of iterations?

We need an invariant rule (or some other form of induction)

Formale Entwicklung objektorientierter Software 07. Januar 2009 3 / 15

Page 13: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

An Invariant Rule

Idea behind loop invariants

Find a formula Inv which. . .

holds at the beginning of the loop

is preserved by the loop body

Consequence:

Inv still holds after arbitrarily many loop iterationsIf the loop terminates at all, then Inv holds afterwards

Encode the desired postcondition after the loop into Inv

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 4 / 15

Page 14: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

An Invariant Rule

Idea behind loop invariants

Find a formula Inv which. . .

holds at the beginning of the loopis preserved by the loop body

Consequence:

Inv still holds after arbitrarily many loop iterationsIf the loop terminates at all, then Inv holds afterwards

Encode the desired postcondition after the loop into Inv

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 4 / 15

Page 15: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

An Invariant Rule

Idea behind loop invariants

Find a formula Inv which. . .

holds at the beginning of the loopis preserved by the loop body

Consequence:

Inv still holds after arbitrarily many loop iterations

If the loop terminates at all, then Inv holds afterwards

Encode the desired postcondition after the loop into Inv

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 4 / 15

Page 16: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

An Invariant Rule

Idea behind loop invariants

Find a formula Inv which. . .

holds at the beginning of the loopis preserved by the loop body

Consequence:

Inv still holds after arbitrarily many loop iterationsIf the loop terminates at all, then Inv holds afterwards

Encode the desired postcondition after the loop into Inv

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 4 / 15

Page 17: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

An Invariant Rule

Idea behind loop invariants

Find a formula Inv which. . .

holds at the beginning of the loopis preserved by the loop body

Consequence:

Inv still holds after arbitrarily many loop iterationsIf the loop terminates at all, then Inv holds afterwards

Encode the desired postcondition after the loop into Inv

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 4 / 15

Page 18: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

An Invariant Rule

Idea behind loop invariants

Find a formula Inv which. . .

holds at the beginning of the loopis preserved by the loop body

Consequence:

Inv still holds after arbitrarily many loop iterationsIf the loop terminates at all, then Inv holds afterwards

Encode the desired postcondition after the loop into Inv

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 4 / 15

Page 19: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

An Invariant Rule

Idea behind loop invariants

Find a formula Inv which. . .

holds at the beginning of the loopis preserved by the loop body

Consequence:

Inv still holds after arbitrarily many loop iterationsIf the loop terminates at all, then Inv holds afterwards

Encode the desired postcondition after the loop into Inv

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)

Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 4 / 15

Page 20: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

An Invariant Rule

Idea behind loop invariants

Find a formula Inv which. . .

holds at the beginning of the loopis preserved by the loop body

Consequence:

Inv still holds after arbitrarily many loop iterationsIf the loop terminates at all, then Inv holds afterwards

Encode the desired postcondition after the loop into Inv

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)

Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 4 / 15

Page 21: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

An Invariant Rule

Idea behind loop invariants

Find a formula Inv which. . .

holds at the beginning of the loopis preserved by the loop body

Consequence:

Inv still holds after arbitrarily many loop iterationsIf the loop terminates at all, then Inv holds afterwards

Encode the desired postcondition after the loop into Inv

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 4 / 15

Page 22: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Example

Precondition: a 6 .= null

& ClassInv

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

Postcondition: ∀x.(0 ≤ x < a.length→ a[x].= 0)

Loop invariant: 0 ≤ i & i ≤ a.length

& ∀x.(0 ≤ x < i→ a[x].= 0)

& a 6 .= null& ClassInv ′

Formale Entwicklung objektorientierter Software 07. Januar 2009 5 / 15

Page 23: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Example

Precondition: a 6 .= null

& ClassInv

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

Postcondition: ∀x.(0 ≤ x < a.length→ a[x].= 0)

Loop invariant: 0 ≤ i & i ≤ a.length

& ∀x.(0 ≤ x < i→ a[x].= 0)

& a 6 .= null& ClassInv ′

Formale Entwicklung objektorientierter Software 07. Januar 2009 5 / 15

Page 24: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Example

Precondition: a 6 .= null

& ClassInv

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

Postcondition: ∀x.(0 ≤ x < a.length→ a[x].= 0)

Loop invariant: 0 ≤ i & i ≤ a.length

& ∀x.(0 ≤ x < i→ a[x].= 0)

& a 6 .= null& ClassInv ′

Formale Entwicklung objektorientierter Software 07. Januar 2009 5 / 15

Page 25: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Example

Precondition: a 6 .= null

& ClassInv

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

Postcondition: ∀x.(0 ≤ x < a.length→ a[x].= 0)

Loop invariant: 0 ≤ i & i ≤ a.length

& ∀x.(0 ≤ x < i→ a[x].= 0)

& a 6 .= null& ClassInv ′

Formale Entwicklung objektorientierter Software 07. Januar 2009 5 / 15

Page 26: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Example

Precondition: a 6 .= null

& ClassInv

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

Postcondition: ∀x.(0 ≤ x < a.length→ a[x].= 0)

Loop invariant: 0 ≤ i & i ≤ a.length& ∀x.(0 ≤ x < i→ a[x]

.= 0)

& a 6 .= null& ClassInv ′

Formale Entwicklung objektorientierter Software 07. Januar 2009 5 / 15

Page 27: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Example

Precondition: a 6 .= null

& ClassInv

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

Postcondition: ∀x.(0 ≤ x < a.length→ a[x].= 0)

Loop invariant: 0 ≤ i & i ≤ a.length& ∀x.(0 ≤ x < i→ a[x]

.= 0)& a 6 .= null

& ClassInv ′

Formale Entwicklung objektorientierter Software 07. Januar 2009 5 / 15

Page 28: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Example

Precondition: a 6 .= null & ClassInv

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

Postcondition: ∀x.(0 ≤ x < a.length→ a[x].= 0)

Loop invariant: 0 ≤ i & i ≤ a.length& ∀x.(0 ≤ x < i→ a[x]

.= 0)& a 6 .= null& ClassInv ′

Formale Entwicklung objektorientierter Software 07. Januar 2009 5 / 15

Page 29: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Basic Invariant Rule: Problem

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context Γ, ∆, U must be omitted in 2nd and 3rd premiss

Context contains (parts of) precondition and class invariants

Required context information must be added to loop invariant Inv

Formale Entwicklung objektorientierter Software 07. Januar 2009 6 / 15

Page 30: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Basic Invariant Rule: Problem

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context Γ, ∆, U must be omitted in 2nd and 3rd premiss

Context contains (parts of) precondition and class invariants

Required context information must be added to loop invariant Inv

Formale Entwicklung objektorientierter Software 07. Januar 2009 6 / 15

Page 31: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Basic Invariant Rule: Problem

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context Γ, ∆, U must be omitted in 2nd and 3rd premiss

Context contains (parts of) precondition and class invariants

Required context information must be added to loop invariant Inv

Formale Entwicklung objektorientierter Software 07. Januar 2009 6 / 15

Page 32: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Basic Invariant Rule: Problem

Basic invariant rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Inv , e ==> [p]Inv (preserved)Inv ,¬e ==> [π ω]φ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context Γ, ∆, U must be omitted in 2nd and 3rd premiss

Context contains (parts of) precondition and class invariants

Required context information must be added to loop invariant Inv

Formale Entwicklung objektorientierter Software 07. Januar 2009 6 / 15

Page 33: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Keeping the Context

We would like to keep unmodified parts of the context

assignable clauses for loops can tell what may be modified

//@ assignable i, a[*];

But: determining unaffected formulas syntactically is impossiblebecause of aliasing

Solution: anonymising updates V delete information about modifiedlocations

V = {i := i0 | for x; a[x] := arr0(a, x)}

Formale Entwicklung objektorientierter Software 07. Januar 2009 7 / 15

Page 34: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Keeping the Context

We would like to keep unmodified parts of the context

assignable clauses for loops can tell what may be modified

//@ assignable i, a[*];

But: determining unaffected formulas syntactically is impossiblebecause of aliasing

Solution: anonymising updates V delete information about modifiedlocations

V = {i := i0 | for x; a[x] := arr0(a, x)}

Formale Entwicklung objektorientierter Software 07. Januar 2009 7 / 15

Page 35: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Keeping the Context

We would like to keep unmodified parts of the context

assignable clauses for loops can tell what may be modified

//@ assignable i, a[*];

But: determining unaffected formulas syntactically is impossiblebecause of aliasing

Solution: anonymising updates V delete information about modifiedlocations

V = {i := i0 | for x; a[x] := arr0(a, x)}

Formale Entwicklung objektorientierter Software 07. Januar 2009 7 / 15

Page 36: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Keeping the Context

We would like to keep unmodified parts of the context

assignable clauses for loops can tell what may be modified

//@ assignable i, a[*];

But: determining unaffected formulas syntactically is impossiblebecause of aliasing

Solution: anonymising updates V delete information about modifiedlocations

V = {i := i0 | for x; a[x] := arr0(a, x)}

Formale Entwicklung objektorientierter Software 07. Januar 2009 7 / 15

Page 37: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Improved Invariant Rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Γ ==> UV(Inv & e→ [p]Inv), ∆ (preserved)Γ ==> UV(Inv & !e→ [π ω]φ), ∆ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context is kept as far as possible

Invariant does not need to talk about unmodified locations

For assignable \everything (the default):

V = {∗ := ∗} wipes out all informationEquivalent to basic invariant ruleAvoid this! Always give a more narrow assignable clause.

Formale Entwicklung objektorientierter Software 07. Januar 2009 8 / 15

Page 38: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Improved Invariant Rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)

Γ ==> UV(Inv & e→ [p]Inv), ∆ (preserved)Γ ==> UV(Inv & !e→ [π ω]φ), ∆ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context is kept as far as possible

Invariant does not need to talk about unmodified locations

For assignable \everything (the default):

V = {∗ := ∗} wipes out all informationEquivalent to basic invariant ruleAvoid this! Always give a more narrow assignable clause.

Formale Entwicklung objektorientierter Software 07. Januar 2009 8 / 15

Page 39: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Improved Invariant Rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Γ ==> UV(Inv & e→ [p]Inv), ∆ (preserved)

Γ ==> UV(Inv & !e→ [π ω]φ), ∆ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context is kept as far as possible

Invariant does not need to talk about unmodified locations

For assignable \everything (the default):

V = {∗ := ∗} wipes out all informationEquivalent to basic invariant ruleAvoid this! Always give a more narrow assignable clause.

Formale Entwicklung objektorientierter Software 07. Januar 2009 8 / 15

Page 40: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Improved Invariant Rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Γ ==> UV(Inv & e→ [p]Inv), ∆ (preserved)Γ ==> UV(Inv & !e→ [π ω]φ), ∆ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context is kept as far as possible

Invariant does not need to talk about unmodified locations

For assignable \everything (the default):

V = {∗ := ∗} wipes out all informationEquivalent to basic invariant ruleAvoid this! Always give a more narrow assignable clause.

Formale Entwicklung objektorientierter Software 07. Januar 2009 8 / 15

Page 41: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Improved Invariant Rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Γ ==> UV(Inv & e→ [p]Inv), ∆ (preserved)Γ ==> UV(Inv & !e→ [π ω]φ), ∆ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context is kept as far as possible

Invariant does not need to talk about unmodified locations

For assignable \everything (the default):

V = {∗ := ∗} wipes out all informationEquivalent to basic invariant ruleAvoid this! Always give a more narrow assignable clause.

Formale Entwicklung objektorientierter Software 07. Januar 2009 8 / 15

Page 42: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Improved Invariant Rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Γ ==> UV(Inv & e→ [p]Inv), ∆ (preserved)Γ ==> UV(Inv & !e→ [π ω]φ), ∆ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context is kept as far as possible

Invariant does not need to talk about unmodified locations

For assignable \everything (the default):

V = {∗ := ∗} wipes out all informationEquivalent to basic invariant ruleAvoid this! Always give a more narrow assignable clause.

Formale Entwicklung objektorientierter Software 07. Januar 2009 8 / 15

Page 43: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Improved Invariant Rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Γ ==> UV(Inv & e→ [p]Inv), ∆ (preserved)Γ ==> UV(Inv & !e→ [π ω]φ), ∆ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context is kept as far as possible

Invariant does not need to talk about unmodified locations

For assignable \everything (the default):

V = {∗ := ∗} wipes out all information

Equivalent to basic invariant ruleAvoid this! Always give a more narrow assignable clause.

Formale Entwicklung objektorientierter Software 07. Januar 2009 8 / 15

Page 44: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Improved Invariant Rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Γ ==> UV(Inv & e→ [p]Inv), ∆ (preserved)Γ ==> UV(Inv & !e→ [π ω]φ), ∆ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context is kept as far as possible

Invariant does not need to talk about unmodified locations

For assignable \everything (the default):

V = {∗ := ∗} wipes out all informationEquivalent to basic invariant rule

Avoid this! Always give a more narrow assignable clause.

Formale Entwicklung objektorientierter Software 07. Januar 2009 8 / 15

Page 45: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Improved Invariant Rule

loopInvariant

Γ ==> UInv , ∆ (initially valid)Γ ==> UV(Inv & e→ [p]Inv), ∆ (preserved)Γ ==> UV(Inv & !e→ [π ω]φ), ∆ (use case)

Γ ==> U [π while(e) p; ω]φ, ∆

Context is kept as far as possible

Invariant does not need to talk about unmodified locations

For assignable \everything (the default):

V = {∗ := ∗} wipes out all informationEquivalent to basic invariant ruleAvoid this! Always give a more narrow assignable clause.

Formale Entwicklung objektorientierter Software 07. Januar 2009 8 / 15

Page 46: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially validv ≥ 0 is preserved by the loop bodyv is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 47: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially validv ≥ 0 is preserved by the loop bodyv is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 48: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially valid

v ≥ 0 is preserved by the loop bodyv is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 49: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially validv ≥ 0 is preserved by the loop body

v is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 50: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially validv ≥ 0 is preserved by the loop bodyv is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 51: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially validv ≥ 0 is preserved by the loop bodyv is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 52: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially validv ≥ 0 is preserved by the loop bodyv is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 53: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially validv ≥ 0 is preserved by the loop bodyv is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv

- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 54: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially validv ≥ 0 is preserved by the loop bodyv is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 55: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Proving Termination

The invariant rule only proves partial correctness

Solution: Find a decreasing integer term v (called variant)

v ≥ 0 is initially validv ≥ 0 is preserved by the loop bodyv is strictly decreased by the loop body

int i = 0;while(i < a.length) {

a[i] = 0;i++;

}

v = a.length-i

- Add v ≥ 0 to Inv- Add v < vold to right of “preserved” case

- Replace box with diamond

Formale Entwicklung objektorientierter Software 07. Januar 2009 9 / 15

Page 56: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Further Complications

Since Java is a real language. . .

the loop guard expression e may have side effects

both e and the loop body may throw an exception

the loop body may use break or continue

The invariant rule in KeY takes all this into account.

Formale Entwicklung objektorientierter Software 07. Januar 2009 10 / 15

Page 57: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Further Complications

Since Java is a real language. . .

the loop guard expression e may have side effects

both e and the loop body may throw an exception

the loop body may use break or continue

The invariant rule in KeY takes all this into account.

Formale Entwicklung objektorientierter Software 07. Januar 2009 10 / 15

Page 58: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Further Complications

Since Java is a real language. . .

the loop guard expression e may have side effects

both e and the loop body may throw an exception

the loop body may use break or continue

The invariant rule in KeY takes all this into account.

Formale Entwicklung objektorientierter Software 07. Januar 2009 10 / 15

Page 59: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Further Complications

Since Java is a real language. . .

the loop guard expression e may have side effects

both e and the loop body may throw an exception

the loop body may use break or continue

The invariant rule in KeY takes all this into account.

Formale Entwicklung objektorientierter Software 07. Januar 2009 10 / 15

Page 60: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Loop Specifications in JML

int i = 0;/*@@@@@@*/

while(i < a.length) {a[i] = 0;i++;

}

Formale Entwicklung objektorientierter Software 07. Januar 2009 11 / 15

Page 61: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Loop Specifications in JML

int i = 0;/*@ loop_invariant

@ 0<= i && i<=a.length@ && (\forall int x; 0<=x && x<a.length; a[x]==0);@@@*/

while(i < a.length) {a[i] = 0;i++;

}

Formale Entwicklung objektorientierter Software 07. Januar 2009 11 / 15

Page 62: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Loop Specifications in JML

int i = 0;/*@ loop_invariant

@ 0<= i && i<=a.length@ && (\forall int x; 0<=x && x<a.length; a[x]==0);@ assignable i, a[*];@@*/

while(i < a.length) {a[i] = 0;i++;

}

Formale Entwicklung objektorientierter Software 07. Januar 2009 11 / 15

Page 63: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Loop Specifications in JML

int i = 0;/*@ loop_invariant

@ 0<= i && i<=a.length@ && (\forall int x; 0<=x && x<a.length; a[x]==0);@ assignable i, a[*];@ decreases a.length-i;@*/

while(i < a.length) {a[i] = 0;i++;

}

Formale Entwicklung objektorientierter Software 07. Januar 2009 11 / 15

Page 64: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Using Method Contracts

Formale Entwicklung objektorientierter Software 07. Januar 2009 12 / 15

Page 65: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Expanding Method Bodies

methodBodyExpand

Γ ==> U〈π method-frame(C,o){b} ω〉φ, ∆

Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Disadvantages:

Non-modular

Duplication of effort

Can lead to huge proofs

Sometimes the method body is not available (e.g. native methods)

Formale Entwicklung objektorientierter Software 07. Januar 2009 13 / 15

Page 66: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Expanding Method Bodies

methodBodyExpandΓ ==> U〈π method-frame(C,o){b} ω〉φ, ∆Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Disadvantages:

Non-modular

Duplication of effort

Can lead to huge proofs

Sometimes the method body is not available (e.g. native methods)

Formale Entwicklung objektorientierter Software 07. Januar 2009 13 / 15

Page 67: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Expanding Method Bodies

methodBodyExpandΓ ==> U〈π method-frame(C,o){b} ω〉φ, ∆Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Disadvantages:

Non-modular

Duplication of effort

Can lead to huge proofs

Sometimes the method body is not available (e.g. native methods)

Formale Entwicklung objektorientierter Software 07. Januar 2009 13 / 15

Page 68: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Expanding Method Bodies

methodBodyExpandΓ ==> U〈π method-frame(C,o){b} ω〉φ, ∆Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Disadvantages:

Non-modular

Duplication of effort

Can lead to huge proofs

Sometimes the method body is not available (e.g. native methods)

Formale Entwicklung objektorientierter Software 07. Januar 2009 13 / 15

Page 69: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Expanding Method Bodies

methodBodyExpandΓ ==> U〈π method-frame(C,o){b} ω〉φ, ∆Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Disadvantages:

Non-modular

Duplication of effort

Can lead to huge proofs

Sometimes the method body is not available (e.g. native methods)

Formale Entwicklung objektorientierter Software 07. Januar 2009 13 / 15

Page 70: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Expanding Method Bodies

methodBodyExpandΓ ==> U〈π method-frame(C,o){b} ω〉φ, ∆Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Disadvantages:

Non-modular

Duplication of effort

Can lead to huge proofs

Sometimes the method body is not available (e.g. native methods)

Formale Entwicklung objektorientierter Software 07. Januar 2009 13 / 15

Page 71: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Use Method Contract Rule

Given a contract (Pre, Post , V):

Γ ==> UPre, ∆ (Pre)Γ ==> UV(exc .= null ∧ Post → 〈π ω〉φ), ∆ (Post)Γ ==> UV(exc 6 .= null ∧ Post → 〈π throw exc; ω〉φ), ∆ (Exc.)

Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 14 / 15

Page 72: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Use Method Contract Rule

Given a contract (Pre, Post , V):

Γ ==> UPre, ∆ (Pre)Γ ==> UV(exc .= null ∧ Post → 〈π ω〉φ), ∆ (Post)Γ ==> UV(exc 6 .= null ∧ Post → 〈π throw exc; ω〉φ), ∆ (Exc.)

Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 14 / 15

Page 73: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Use Method Contract Rule

Given a contract (Pre, Post , V):

Γ ==> UPre, ∆ (Pre)

Γ ==> UV(exc .= null ∧ Post → 〈π ω〉φ), ∆ (Post)Γ ==> UV(exc 6 .= null ∧ Post → 〈π throw exc; ω〉φ), ∆ (Exc.)

Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 14 / 15

Page 74: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Use Method Contract Rule

Given a contract (Pre, Post , V):

Γ ==> UPre, ∆ (Pre)Γ ==> UV(exc .= null ∧ Post → 〈π ω〉φ), ∆ (Post)

Γ ==> UV(exc 6 .= null ∧ Post → 〈π throw exc; ω〉φ), ∆ (Exc.)

Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 14 / 15

Page 75: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

Use Method Contract Rule

Given a contract (Pre, Post , V):

Γ ==> UPre, ∆ (Pre)Γ ==> UV(exc .= null ∧ Post → 〈π ω〉φ), ∆ (Post)Γ ==> UV(exc 6 .= null ∧ Post → 〈π throw exc; ω〉φ), ∆ (Exc.)

Γ ==> U〈π o.m(p1, ..., pn)@C; ω〉φ, ∆

Formale Entwicklung objektorientierter Software 07. Januar 2009 14 / 15

Page 76: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

THE

END

Formale Entwicklung objektorientierter Software 07. Januar 2009 15 / 15

Page 77: Formale Entwicklung objektorientierter Software · Formale Entwicklung objektorientierter Software Praktikum im Wintersemester 2008/2009 Prof. P. H. Schmitt Christian Engel, Benjamin

THEEND

Formale Entwicklung objektorientierter Software 07. Januar 2009 15 / 15