• Keine Ergebnisse gefunden

University of Kaiserslautern

N/A
N/A
Protected

Academic year: 2022

Aktie "University of Kaiserslautern"

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

Exercise 1 Hoare Logics

Please download the fileSheet9_hoare.thy.

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. In addition to the semantics, the file also contains a notion for Hoare triples and a Hoare logic calculus in the “WP-form” as presented in the lecture on slide 476.

a) Consider the following specification of the programprogA:

` {λs. vxs = VX ∧ vys = VY} progA {λs. vxs = VY ∧ vys = VX }

Herevxsdenotes the state of variablevxin states.

Write down a definition ofprogAwhich satisfies this specification. Then use the Hoare logic to prove the correctness of your program with respect to this specification. Before you do the proof in Isabelle, write it down on paper by putting assertions between each code line.

b) Show that the specification in a) does not specify the program completely. To show this, define a different programprogBwhich has a different behavior thanprogAbut also satisfies the specification.

c) (optional) Give a specification ofprogAwhich specifies the program completely (except for terminati- on). More precisely, your specificationswapSpecshould satisfy the following property:

JswapSpec pa; swapSpec pb; V

s. ∃s'. hpa, si→s'; V

s. ∃s'. hpb, si→s'K

=⇒ hpa, si→s' ←→ hpb, si→s'

d) Consider the following program:

IF vx ≤ vy THEN SKIP

ELSE

vx ::= vx + vy;

vy ::= vx − vy;

vx ::= vx − vy END

Give pre- and post-conditions which specify that this program sorts the two variablesvxandvy, so that after executing the program,vxcontains the smaller number. Then proof that your specification actually holds for the given program.

(2)

e) Prove the following Hoare Triple on paper by adding assertions to the program:

{n ≥ 0}

i := 1;

sum := 0;

WHILE i <= n DO

sum := sum + i;

i := i + 1 END

{sum = Σ{0..n}}

Make sure that the assertion steps precisely match the rules of the Hoare Logic.

f) Transfer your proof from e) to Isabelle.

g) Write a program which swaps two elements in the array ar1. The two positions are given by the va- riablesvxandvy. Specify the programs with a pre- and post-condition and proof that your program satisfies the specification.

h) (optional) Prove that the following program swaps the values ofxandy.

z := x − y;

WHILE 1 ≤ z DO x := x − 1;

y := y + 1;

z := z − 1 END

i) (optional) Prove that the following program calculates the nth Fibonacci number:

x := 0;

y := 1;

i := 0;

WHILE i < n DO y := x + y;

x := y − x;

i := i + 1 END;

r = x

j) (optional) Prove that the following program calculates the result of dividingxbyy. At the end of the programicontains the result of the division.

r := x;

i := 0;

WHILE y ≤ r DO r := r − y;

i := i + 1 END

k) (optional) Implement a program which calculates the sum of all numbers in the array ar1. Proof that your implementation works correctly.

l) (optional) Implement a program which uses binary search to check if the number given byvxis contai- ned in the sorted arrayar1. Proof that your implementation works correctly.

Referenzen

ÄHNLICHE DOKUMENTE

If my doctor asks me these questions, it may help to improve the quality of my care. The questions asked in the questionnaire are usually dealt with during the

Statistics Finland Official Statistics of Finland (OSF):

We propose to extract type and identifier information of interacting artifact types and to make these information visible to developers, so developers are enabled to apply

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

[r]

1 — Gerhard J¨ ager (Semantics of color terms) December 14, 2016.?. The psychological

11:30-13:00 Meeting with survivors Yehudit Yerushalmi and Vera Dotan Anna Stocker, European Department, ISHS, Yad Vashem 13:00-14:00 Lunch Break. 14:00-14:30 Reflections on

Appendix A.3], briefly recall the notions of a strict monoidal category and their functors [EGNO15, Section 2.8] or [Kock04, Section 3.2], of a symmetric monoidal category, and