• Keine Ergebnisse gefunden

Exercise 2 Sets as Functions in Isabelle/HOL

N/A
N/A
Protected

Academic year: 2022

Aktie "Exercise 2 Sets as Functions in Isabelle/HOL"

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

Date: 25.04.2012

Exercise 1 Datatypes and Properties in Isabelle/HOL

a) (Prepare!) Define a datatype ’a treeto represent binary trees. Leaves should be Emptyand internal nodes should store a value of type’a.

b) (Prepare!) Define the functions root, leftmostandrightmoston trees, which return the respective values for non-empty trees and areundefinedotherwise.

c) Define the functionspreOrder,postOrderandinOrderthat traverse and convert a binary tree to a list in the respective order.

d) Define a functionmirrorthat returns the mirror image of a binary tree.

e) Prove or disprove the following theorems:

• t 6= Empty −→ last (inOrder t) = rightmost t

• t 6= Empty −→ hd (inOrder t) = leftmost t

• t 6= Empty −→ hd (preOrder t) = last (postOrder t)

• t 6= Empty −→ hd (preOrder t) = root t

• t 6= Empty −→ hd (inOrder t) = root t

• t 6= Empty −→ last (postOrder t) = root t

f) Suppose that xOrder andyOrder are tree traversal functions chosen frompreOrder, postOrder, and inOrder. Examine for which traversal functions the following formula holds:

xOrder (mirror xt) = rev (yOrder xt)

Exercise 2 Sets as Functions in Isabelle/HOL

Consider the following type synonym: type_synonym ’a myset = "’a bool"

The idea behind this definition is that sets can be represented by their characteristic function, i.e., the function which decides for each element if it is in the set or not.

(Prepare!) Define the following constants for our new type:

1. Theemptyset.

2. Theinsertanddeletefunction on sets.

3. Theunionandintersectionon sets.

4. The set of allevenintegers.

(2)

Exercise 3 Using and Extending the Simple Theorem Prover

You can find the SimpleTheoremProver2.thyused in the lecture on our website. We want to use this simple prover to prove the theorem from Exercise 1a on Sheet 1.

a) (Prepare!) Download the file and run it through Isabelle/HOL. Think about the existing proof in the file and how it is done.

b) (Prepare!) Extend the data type for formulas to support the logical operatorsAndandOr. Remember to also adjust the functions which are using the data type!

c) (Prepare!) The theory so far has only four rules. Add further rule definitions from the natural deduction calculus, such that you can do the proof of the sequent from Exercise 1a.

d) (Prepare!) Proof the sequent:`(a∨(b∧c))→((a∨b)∧(a∨c))

Tips and Tricks to make your life easier

• You can define abbreviations in Isabelle/HOL, which will be used for both input and output. For example, you might want to define abbreviations for normal and schematic variables like this:

a b b r e v i a t i o n a w h e r e " a Var ’ ’a ’ ’ "

a b b r e v i a t i o n b w h e r e " b Var ’ ’b ’ ’ "

a b b r e v i a t i o n c w h e r e " c Var ’ ’c ’ ’ "

a b b r e v i a t i o n A w h e r e " A S V a r ’ ’A ’ ’ "

a b b r e v i a t i o n B w h e r e " B S V a r ’ ’B ’ ’ "

a b b r e v i a t i o n C w h e r e " C S V a r ’ ’C ’ ’ "

You can then use the abbreviations in the theory but internally they will still be applications ofVar andSVar, respectively, without the need to unfold a definition!

Isabelle/HOL will also use them for its output, so that’s nicer as well!

• You probably will use “copy & paste” a lot in this exercise. You can replace a string with something else in a marked block (or starting from the cursor if nothing is marked), using META % (press ESC once, then press %).

Emacs will prompt you for the string to search, then for the string to replace it by. He will then highlight the first appearence and ask what to do. You can get a help window within Emacs itself at this point, but we just print it here for your convenience:

T y p e S p a c e or ‘y ’ to r e p l a c e one match , D e l e t e or ‘n ’ to s k i p to next , RET or ‘q ’ to exit , P e r i o d to r e p l a c e one m a t c h and exit ,

C o m m a to r e p l a c e but not m o v e p o i n t i m m e d i a t e l y , C - r to e n t e r r e c u r s i v e e d i t ( C - M - c to get out a g a i n ) , C - w to d e l e t e m a t c h and r e c u r s i v e edit ,

C - l to c l e a r the screen , r e d i s p l a y , and o f f e r s a m e r e p l a c e m e n t again ,

! to r e p l a c e all r e m a i n i n g m a t c h e s w i t h no m o r e q u e s t i o n s ,

^ to m o v e p o i n t b a c k to p r e v i o u s match , E to e d i t the r e p l a c e m e n t s t r i n g

The most commonly used keys are ’y’ and ’n’ to replace or not replace an occurence, ’q’ to quit and

’!” to replacealloccurrences in the file.

Referenzen

ÄHNLICHE DOKUMENTE

3) Click in cell C5. This means that Calc interprets the formula in B5, applies it to the cells in the B column, and puts the result in the cell holding the formula. When you

The calculus has only one axiom, which states that every formula can be derived from itself: A ` A, for all formulas A. The name of the corresponding Isabel- le/HOL rules are

• (λx. J interprets all constants as defined in the lecture and + as the usual addition on natural numbers.. Exercises 2 and 4 will only be discussed in the exercise meeting, if

Käesolevas töös uuritakse eeliseid ja probleeme, mis sülearvuti igapäevase kasutamisega õppetöös kaasnevad, seda nii uurimuses osalenud õpilaste kui õpetajate poolt

Using the KHB method to further decompose the education effects, we find that the effect of education on disaster preparedness is mainly mediated through social capital and disaster

The idea is to build strong incentives for all euro-area member states (as well as willing EU member states outside the euro area) to implement structural reforms and

Only after completing these 12 trips (lid she begin to perform strong waggle dances and so produce numerous waggle runs. After the next 10 visits to the feeder, trips

Author contributions BB has led overall research activities from proposal development to data compilation, data entry and processing, data analysis, and interpretation of the result