• 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!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. A. Poetzsch-Heffter Dipl.-Inf. P. Michel

Dipl.-Inf. C. Feller

University of Kaiserslautern

Department of Computer Science Software Technology Group

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

Date: 23.05.2012

Exercise 1 Case Study: Greatest Common Divisor

You have seen amodel,propertyandproof for the Euclidean algorithm in the lecture. We want to keep the model, but specify the property differently and prove it.

fun gcd :: " nat nat nat " w h e r e

" gcd m 0 = m "

| " gcd m n = gcd n ( m mod n ) "

a) Start a new theory file and prove that the functiongcdcomputes the greatest common divisor ofmandn: 1. The result of gcd divides both arguments, i.e., its a common divisor.

2. The result of gcd is greater than (or equal to) every common divisor, provided not both arguments are zero.

You can prove (1) directly, but for (2) it might be useful to define and prove the following two properties ofgcdfirst:

• Each common divisor divides the result ofgcd.

• The result ofgcdis not zero if at least one argument is not zero.

From this you can prove (2) by showing that a natural number dividing a non-zero natural number has to be less than (or equal to) that number.

Hint: In Isabelle/HOL, the property that a divides b is expressed by:a dvd b. b) Prove the following property ofgcd:k * gcd m n = gcd (k * m) (k * n).

c) Consider a slightly different implementation of the greatest common divisor function:

fun gcd :: " nat nat nat " w h e r e

" gcd m n = ( if n = 0 t h e n m e l s e gcd n ( m mod n )) "

• Prove that this implementation is equivalent to the first one.

• Prove the property of b) for this implementation.

d) Use the main property of a) to define the greatest common divisor directly (not recursively) with the Hilbert-Choice operator (SOME), in particular not using the Euclidean algorithm.

Prove the equivalence of this function to the originalgcd.

Referenzen

ÄHNLICHE DOKUMENTE

Formal syntax and semantics of the specification language..

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

Formal syntax and semantics of the specification language. Introduction 1.3 Specification and Verification

• Bertrand Russell found paradox in Frege’s system and proposed the Ramified Theory of Types.. • Wrote Principia Mathematica with Whitehead, an attempt at developing basic

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