• Keine Ergebnisse gefunden

University of Kaiserslautern

N/A
N/A
Protected

Academic year: 2022

Aktie "University of Kaiserslautern"

Copied!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. A. Poetzsch-Heffter M.Sc. Peter Zeller

Dipl.-Inf. C. Feller

University of Kaiserslautern

Department of Computer Science Software Technology Group

Exercise Sheet 12: Specification and Verification with Higher-Order Logic (Summer Term 2014)

Exercise 1 Heap-manipulating OO programs

In this exercise we will use the calculus from the lecture to do some pen- and paper exercises about the following JavaKE program:

1 interface Cell {

2 int set(int val);

3 int get();

4 } 5 6

7 class StandardCell implements Cell {

8 int x;

9 int set(int par) {

10 x = par;

11 }

12 int get() {

13 res = x;

14 }

15 } 16 17 18 19 20

21 class PrevCell implements Cell { 22 boolean f;

23 int x1;

24 int x2;

25 int set(int par) {

26 boolean t;

27 t = f;

28 f = !t;

29 if (!t) x1 = par;

30 else x2 = par;

31 }

32 int get(){

33 if (f) res = x1;

34 else res = x2;

35 }

36 int getPrev(){

37 if (f) res = x2;

38 else res = x1;

39 }

40 }

a) Give a weak precondition P so that the following triple is valid in the context of the above program:

{ P }

c1.set(4);

c2.set(2);

intx = c1.get();

inty = c2.get();

res = x*10 + y;

{ res = 42 }

b) Define a heap abstraction cell(e,x) which states that reference “e” points to a cell object with a current value of “x”.

c) Prove the following statement on paper, using the rules from the lecture:

{c6=null} r = c.set( x ) {cell(c,x)}

You can assume that the static type ofcin this program part isCell.

For every step in the proof, write down the name of the used rule.

Try to get to the following intermediate goal first:

{c6=nullc = Cx = X} r = c.set( x ) {cell(C,X)}

Referenzen

ÄHNLICHE DOKUMENTE

The difference to the usual induction over natural numbers is, that one can assume, that the hypothesis holds for all numbers smaller than n, whereas in the usual induction rule it

Download the file Sheet4_exprsimp.hs from the website. This Haskell program parses expressions given by the user and simplifies them. You do not have to understand the other parts

b) We now want to proof a more general property of this program which is not fixed to vn being 3. As the first step towards this goal, prove that the execution of the loop body adds

This file contains the Imp language with additional constructs for working with Arrays. The program se- mantics is defined in terms of a Big Step Semantics, similar to Sheet 7.

e) Define simple generic properties of the newly defined functions and prove them (e.g. the empty list does not contain any elements, formulated on the two constants empty

Exercise Sheet 6: Specification and Verification with Higher-Order Logic (Summer Term 2012)..

c) Optimize your proof by using the custom wphoare method, like done in the splitcorrect lemmas... d) The splitcorrect lemma does not prove that split does not change the content of

In a software project, the classes Person, AgePerson und AgeManager were implemented; their source is given in Figure 1... a) For testing purposes, the following code