HOL: Well-founded and Primitive Recursion

Similar documents
Miscellaneous HOL Examples

Gerwin Klein, June Andronick, Ramana Kumar S2/2016

Red-black Trees of smlnj Studienarbeit. Angelika Kimmig

Beyond First-Order Logic

Automated Reasoning Lecture 17: Inductive Proof (in Isabelle)

CS411 Notes 3 Induction and Recursion

7. The Recursion Theorem

Free Groups. Joachim Breitner. April 17, 2016

Lattices and Orders in Isabelle/HOL

Inductive Theorem Proving

A New Look At Generalized Rewriting in Type Theory

7. The Recursion Theorem

7. The Recursion Theorem

Inductive Definitions and Fixed Points

CS261: Problem Set #3

Algebraic View of Computation. Primitive Recursive Functions. We can assign a term to each partial recursive function. E.g.

Well Founded Relations and Recursion

2.2 Some Consequences of the Completeness Axiom

CSCE 222 Discrete Structures for Computing. Review for Exam 2. Dr. Hyunyoung Lee !!!

Landau Symbols. Manuel Eberl. November 28, 2018

5. The Primitive Recursive Function

The Hahn-Banach Theorem for Real Vector Spaces

MAGIC Set theory. lecture 6

Fall Lecture 5

Homework #2 Solutions Due: September 5, for all n N n 3 = n2 (n + 1) 2 4

Miscellaneous Isabelle/Isar examples

Examples for program extraction in Higher-Order Logic

Axioms of Kleene Algebra

A New Look at Generalized Rewriting in Type Theory

A Certified Denotational Abstract Interpreter (Proof Pearl)

Knowledge Bases in Description Logics

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

Context Free Grammars

Fundamental Properties of Lambda-calculus

Imperative Insertion Sort

Depending on equations

The syntactic guard condition of Coq

Functional Data Structures

Gödel s Incompleteness Theorems. Lawrence C. Paulson

The Divergence of the Prime Harmonic Series

Imperative Insertion Sort

Ramsey s Theorem in ProofPower (Draft)

Fuzzy Description Logics

FORMAL METHODS LECTURE V: CTL MODEL CHECKING

Discrete Mathematics

Consequences of the Completeness Property

The Tortoise and the Hare Algorithm

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

S ) is wf as well. (Exercise) The main example for a wf Relation is the membership Relation = {( x, y) : x y}

NAME: Mathematics 205A, Fall 2008, Final Examination. Answer Key

SEMANTICS OF PROGRAMMING LANGUAGES Course Notes MC 308

CMSC 631 Program Analysis and Understanding Fall Type Systems

Program Composition in Isabelle/UNITY

Structural Induction

Subresultants. Sebastiaan Joosten, René Thiemann and Akihisa Yamada. October 10, 2017

7 RC Simulates RA. Lemma: For every RA expression E(A 1... A k ) there exists a DRC formula F with F V (F ) = {A 1,..., A k } and

Syntax and semantics of a GPU kernel programming language

Model Checking for the -calculus. Paolo Zuliani , Spring 2011

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

An Isabelle/HOL Formalization of the Textbook Proof of Huffman s Algorithm

An axiom free Coq proof of Kruskal s tree theorem

III.2 (b) Higher level programming concepts for URMs Anton Setzer

Programming with Dependent Types in Coq

Lecture 4 October 18th

c i r i i=1 r 1 = [1, 2] r 2 = [0, 1] r 3 = [3, 4].

A Formal Proof of Sylow s Theorem

Amortized Complexity Verified

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions

Remnants from the Bookshelf

Linear Classification: Linear Programming

Total (Co)Programming with Guarded Recursion

Compiling Techniques

ALGEBRAIC GEOMETRY COURSE NOTES, LECTURE 2: HILBERT S NULLSTELLENSATZ.

INTRODUCTORY ANALYSIS I Homework #13 (The lucky one)

µ (X) := inf l(i k ) where X k=1 I k, I k an open interval Notice that is a map from subsets of R to non-negative number together with infinity

Operationally-Based Theories of Program Equivalence

Computer-supported. Modeling and Reasoning. Computer-supported. Exercises and Solutions (Isabelle 2004)

Part III. 10 Topological Space Basics. Topological Spaces

CSE 505, Fall 2008, Midterm Examination 29 October Please do not turn the page until everyone is ready.

Code Generation for a Simple First-Order Prover

Technische Universität Dresden. Fakultät Informatik EMCL Master s Thesis on. Hybrid Unification in the Description Logic EL

Administrivia. COMP9020 Lecture 7 Session 2, 2017 Induction and Recursion. Lecture 6 recap. Lecture 6 recap

CSCI 490 problem set 6

Math.3336: Discrete Mathematics. Advanced Counting Techniques

Copatterns Programming Infinite Objects by Observations

Important Properties of R

More on Finite Automata and Regular Languages. (NTU EE) Regular Languages Fall / 41

We are going to discuss what it means for a sequence to converge in three stages: First, we define what it means for a sequence to converge to zero

MS 3011 Exercises. December 11, 2013

Finite Universes. L is a fixed-length language if it has length n for some

CS294-9 September 14, 2006 Adam Chlipala UC Berkeley

The Reflection Theorem

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

CMPSCI 250: Introduction to Computation. Lecture #15: The Fundamental Theorem of Arithmetic David Mix Barrington 24 February 2014

Fast Growing Functions and Arithmetical Independence Results

The Tortoise and the Hare Algorithm

Finite State Automata

Generating Functions

4th Preparation Sheet - Solutions

Analyse et Conception Formelle. Lesson 4. Proofs with a proof assistant

Transcription:

Dipl.-Inf. Achim D. Brucker Dr. Burkhart Wolff Computer-supported Modeling and Reasoning http://www.infsec.ethz.ch/ education/permanent/csmr/ (rev. 16814) Submission date: HOL: Well-founded and Primitive Recursion In this exercise, we will deepen our knowledge on well-founded orderings and induction as well as its applications in form of recursive definitions. 1 Recursive Definitions 1.1 Primitive recursion Isabelle provides a syntactic front-end for defining an important subclass of well-founded recursions, namely primitive recursive functions, e.g.: add 0: 0 + n = n add Suc: Suc m + n = Suc (m + n) primitive recursive diff 0 : m 0 = m diff Suc : m Suc n = (case m n of 0 => 0 Suc k => k) 1

where rule are reduction rules (as usual, the names name 1... name n are op- tional). The reduction rules specify one or more equations of the form reduction rules The general form of a primitive recursive definitions in Isabelle is: name 1 : rule. name n : rule f x 1... x n (C y 1... y n ) z 1... z n = r such that C is a constructor of the datatype (e.g. Suc in our first example), r contains only free variables on the left-hand side, and all recursive calls in r are of the form f... y i... for some i. 1.2 General Recursive Definitions recdef Isabelle also offers a way for declaring functions using general well-founded recursion: recdef. Using recdef, you can declare functions involving nested recursion and pattern-matching, e.g. we can define the Fibonacci function: consts fib :: nat nat recdef fib less than fib 0 = 0 fib 1 = 1 fib (Suc(Suc x)) = (fib x + fib (Suc x)) where les than is the less than on the natural numbers. The general form of a recursive definitions in Isabelle is: function rule congs rules simpset rules name 1 : rule. name n : rule where function is the functions name and rule a hol expression for the wellfounded termination relation (Isabelle provides several built-in relations such as less than or measure). With the to optional arguments congs and simpset one can influence the set of congurences rules and the simpset used during the termination proof. Finally, the rule s are specifing the computational recursive equations. 2

2 Exercises 2.1 Exercise 40 Prove the following consequences of well-founded orderings: 1. a well-founded ordering is not symmetric: lemma wf not sym: wf(r) = a x. (a,x) r (x,a) / r 2. a well-founded ordering contains minimal elements: lemma wf minimal: wf r = x. y. (y,x) / rˆ+ 3. a subrelation of a well-founded ordering is well-founded: lemma wf subrel: wf(p) = r. r p ( x. y. (y,x) / rˆ+) 4. a well-founded ordering satisfies characterization (1): lemma wf eq minimal2: wf(p) = ( r. (r {} r p) ( x Domain r. ( y. (y,x) / r ))) Hint: Look up the various theorems about wellfounded orderings that Isabelle provides (wf induct, wf empty, wf subset, wf not sym, wf not refl, wf trancl, wf acyclic, and wfrec def) and use them as you like. 2.2 Exercise 41 1. Define a the recursor iter f n in terms of the well-founded recursor wfrec and the theory of the natural numbers. Derive from your definition the properties: lemma iter 0 : iter 0 g = (λ x. x) lemma iter Suc : iter (Suc n) g = g ( iter n g) 2. Define the addition add, the multiplication mult, the exponentiation exp and the sumup operation sumup ( sumup 3 = 1 + 2 + 3) on natural numbers. Use in at least two definitions the iter -recursor and derive the usual computational equations; in the other cases, you may use a construct. 3

2.3 Exercise 42 The approximation theorem of lfp In lecture hol: Fixpoints we have seen the theorem: ( S. f( S) = (f S)) = n N f n ( ) = lfp f i.e. under a certain condition, a fix-point can be seen as a limit of an approximation process. This condition is also called continuity of f. Under an obvious alternative constraint, namely that the fix-point must be reachable after finitely many steps, this principle is of practical importance, for example in data-flow analysis algorithms (such as the Java Byte-code Verifier). Prove one of the following versions of the approximation theorem: 1. lemma lfp approximable if finite : [mono f; m. f ( iter m f {}) = ( iter m f {})] = (UN n:univ. (iter n f {})) = lfp f 2. lemma lfp approximable if cont : [( S. f (Union S) = Union (f S)) ] = (UN n:univ. (iter n f {})) = lfp f For the first option, we suggest the following intermediate lemmas: 1. mono f = (UN n:univ. (iter n f {})) lfp f 2. [mono f; m. f ( iter m f {}) = ( iter m f {})] = lfp f (UN n:univ. (iter n f {})) For the second option, we suggest the following milestones: 1. mono f = (UN n:univ. (iter n f {})) lfp f 2. ( S. f (Union S) = Union (f S)) = mono f 3. (UN n:univ. iter (Suc n) f {}) = (UN n:{m. 0 < m}. (iter n f {})) 4. (UN n:univ. g (n::nat)) = (UN n:{m. 0 < m}. (g n))un (g 0) 5. ( S. f ( S)= f S) = f ( n iter n f {}) = ( niter n f {}) 6. ( S. f (Union S) = Union (f S)) = f (UN n:univ. (iter n f {})) = (UN n:univ. f (iter n f {})) 4

7. S. f (Union S) = Union (f S))= lfp f (UN n:univ. (iter n f {}) ) Hint: Look up the various theorems about the inclusion operation that Isabelle provides (rev subsetd, lfp unfold, monod, Un upper1, Un absorb1, image Collect) and use them as you like. 5