• Keine Ergebnisse gefunden

University of Kaiserslautern Department of Computer Science Software Technology Group

N/A
N/A
Protected

Academic year: 2022

Aktie "University of Kaiserslautern Department of Computer Science Software Technology Group"

Copied!
2
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 7: Specification and Verification with Higher-Order Logic (Summer Term 2014)

Please prepare the marked tasks for the exercise on Wednesday, June 18, 2014

Exercise 1 Big Step Semantics

Please download the fileSheet7_bigstep.thyfrom the homepage. It includes a definition of the syntax and semantics of a simple imperative while-language.

Consider the following program:

vi := 1;

vsum := 0;

WHILE vi <= vn DO

vsum := vsum + vi;

vi := vi + 1 END

You can find the abstract syntax tree of this program as the definitionprogin the given theory file.

a) (Prepare!) Use the given big step semantics to show that the program terminates in a state wherevsum is6, when in the initial statevnwas3.

Use the given elimination rules likestepSemiandstepAsgnfor this proof.

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

c) As the next step, prove that the while-loop will add the sum of the numbers betweenviandvntovsum.

d) Now prove that the complete program calculates the sum of the numbers from0tovn.

(2)

Exercise 2 Extending the Big Step Semantics

In this exercise you should extend the language and the big step semantics from the Exercise 1 with some new language constructs. The file Sheet7_bigstep_ext.thycontains definitions for the programs below. Use those examples to check if your language extensions work as desired.

a) Write down the semantics rules required for exercises b) and c) on paper.

b) Extend the language with a construct for local variables. The scope of the local variables should already be part of the abstract syntax. For example the following program should result in a state wherex = 2 andy= 4.

x := 1; y := 2;

VAR x := y + 2 IN y := x END;

x := x + 1

c) Extend the language with a LOOPconstruct. It should take an expression and a command as the loop body. If the expression evaluates ton, the body should be executedntimes. For example this program will result in a state wherex= 9:

x := 3;

LOOP x BEGIN

x := x + 2 END

d) (optional) Add procedures and procedure calls to the language. A program then consists of a list of procedures and one main block. Procedures should have a list of parameters, but no return value.

Here is an example of a program using procedures and local variables:

MAIN

CALL fib [4]

END

PROCEDURE fib [x] BEGIN IF x<=1 THEN

r := 1 ELSE

CALL fib [x + −2];

VAR a := r IN

CALL FIB [x + −1];

r := r + a END

END END

Referenzen

ÄHNLICHE DOKUMENTE

The goal of this project is to write a compiler that translates a program of the toy language Mini to an intermediate representation (a CFG with IR instructions), performs

b) Download the theory “RQSort.thy” – which stands for refined quicksort – in which you prove the correctness of the efficient quicksort. prove that the efficient version of

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

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 is

h) Write a function forall : (’a -&gt; bool) -&gt; ’a list -&gt; bool, which calculates wether all ele- ments of a list satisfy the given predicate.. i) Write a function exists :

Prove the equivalence of this function to the

For mergesort you will of course need a different lemma capturing the basic idea of