• Keine Ergebnisse gefunden

University of Kaiserslautern Department of Computer Science AG Grundlagen der Informatik

N/A
N/A
Protected

Academic year: 2021

Aktie "University of Kaiserslautern Department of Computer Science AG Grundlagen der Informatik"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. K. Madlener Dipl.-Inf. P. Michel Dipl.-Inf. C. Feller

University of Kaiserslautern

Department of Computer Science AG Grundlagen der Informatik

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

Date: 26.05.2011

Exercise 1 Inductive Definitions, Lattices and Fixpoints

a) (Prepare!) Define the reflexive, transitive closure of a relationras inductive set.

b) (Prepare!) Define a function whose least fixpoint is the aforementioned set.

c) (Prepare!) LetL be a complete lattice,a, b ∈ Landa ≤ b. Prove that the closed interval[a, b]is a complete lattice.

Reminder:[a, b] :={x. a≤x≤b}

It is not required that you solve this exercise in Isabelle/HOL.

Exercise 2 Case Study: Inductive Sets and Fixpoint Induction

In the lecture we have seen the inductive definition of the set of even numbers:

inductive_set evens :: "nat set" where

"0 evens"

| "n evens = n + 2 evens"

Using the generated theoremevens.induct, we can then prove that all members of the set are indeed even:

theorem evens_are_even:

"∀x evens. x mod 2 = 0"

a) Prove the theorem using the given induction rule.

b) Define a function evenf whose fixpoint is the inductive set evens, by deriving it from the inductive definition ofevens:

definition evenf :: "??" where

"evenf M ??"

c) Formulate an analogous theorem for the least fixpoint ofevenf(i.e.lfp evenf), stating that all elements in the set are even.

d) Prove the theorem using fixpoint induction, specifically the theoremlfp_ordinal_induct. Do not use automated methods to prove the theorem and make yourself familiar with theFind Theoremsfunction of Isabelle/HOL.

(2)

Exercise 3 Case Study: Greatest Common Divisor

a) Consider the following implementation of the greatest common divisor function:

fun gcd :: "nat => nat => nat" where

"gcd m 0 = m" |

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

Prove that the function really computes the greatest common divisor ofmandn.

It might be useful to define and prove the following properties ofgcdfirst:

• The result ofgcddivides both arguments.

• Each common divisor divides the result ofgcd.

• Each divisor of the result ofgcdis a common divisor.

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

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" where

"gcd m n = (if n = 0 then m else 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 non-recursively with the Hilbert- Choice operator (SOME), i.e. not using the Euclidean algorithm.

Prove the equivalence of this function to the originalgcd.

Referenzen

ÄHNLICHE DOKUMENTE

Archaeological field work is a sensual experience: it engages our senses in the moment of the creation of data, and it requires a sensual imagination to create an

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

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