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

Please prepare the marked tasks for the exercise on Wednesday, May 28, 2014 Submit your solutions to the hand-in tasks before Monday, June 9, 2014

Exercise 1 Quicksort

In the lecture we have seen a definition of a quicksort functionqsortin Isabelle and proven its termination.

In this exercise we want to prove its correctness. Download the fileSheet4_qsort.thyto obtain the theory used in the lecture.

a) (Prepare!) Explain informally why theqsortfunction is a correct sorting function.

b) Define a property isPermutation :: 'a list ⇒ 'a list ⇒ bool that indicates if two lists are permutations of each other. For this it might be helpful to define a function that counts the elements in a list (count :: 'a list ⇒ 'a ⇒ nat).

c) Show that the result of theqsortfunction is a permution of its input.

d) Define a propertysorted :: ('a::linorder) list ⇒ boolthat indicates if a list is sorted in ascending order.

e) Show that the result of theqsortfunction is sorted.

Exercise 2 Verifying Haskell (Hand in!)

Download the fileSheet4_exprsimp.hsfrom the website. This Haskell program parses expressions given by the user and simplifies them. Expressions consist of numbers, variables, parenthesis and additions.

You can run the program with the following command:

runhaskell Sheet4_exprsimp.hs

Enter expression to simplify (q to quit):

1+2+−4+(3+−3+x)+y+z+3

expr = ((((((1 + 2) + −4) + ((3 + −3) + x)) + y) + z) + 3) simp = ((((−1 + x) + y) + z) + 3)

In this exercise you should verify that the simplify function works correctly. You do not have to understand the other parts of the Haskell code. If you find any bugs during your verification work, please fix them.

a) Rewrite the datatype definitionExpand the functionsimplifyin Isabelle. Keep the Isabelle code as close to the original code as possible.

b) Define the semantics of an expression by writing a functionsem :: "(string ⇒ int) ⇒ exp ⇒ int", which calculates the value of an expression for a given variable assignment.

c) Show that using thesimplifyfunction does not change the semantics of an expression.

d) Formulate the following property:simplifyalways returns an expression which is as small as possi- ble.

(2)

e) Disprove the above property by showing that there is an expression for which the result ofsimplify is not optimal.

f) Generate Haskell code from your Isabelle theory using the following steps:

1. Create a folder named “hs” next to your theory file.

2. Adjust the header of your theory file as follows:

theory Sheet4_Haskell imports

Main

"~~/src/HOL/Library/Code_Target_Int"

"~~/src/HOL/Library/Code_Char"

begin

3. Use the following line in your theory file to export the code:

export_code simplify in Haskell module_name Simplify file "hs/"

g) (optional) Adjust the original Haskell code, so that the generated code is used for the simplification instead.

h) (optional) Define a functionsimplify2which computes a minimal simplified expression.

Referenzen

ÄHNLICHE DOKUMENTE

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

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

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 -> bool) -> ’a list -> 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