Cs7120 (Prasad)L9-RECUR-IND1 Recursion and Induction.

Slides:



Advertisements
Similar presentations
Functional Programming Lecture 13 - induction on lists.
Advertisements

Introduction to Proofs
Chapter Three: Closure Properties for Regular Languages
Λλ Fernando Magno Quintão Pereira P ROGRAMMING L ANGUAGES L ABORATORY Universidade Federal de Minas Gerais - Department of Computer Science P ROGRAM A.
Determinacy Inference for Logic Programs Lunjin Oakland University In collaboration with Andy Kent University, UK.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
© M. Winter COSC 4P41 – Functional Programming Testing vs Proving Testing –uses a set of “typical” examples, –symbolic testing, –may find errors,
Chapter 11 Proof by Induction. Induction and Recursion Two sides of the same coin.  Induction usually starts with small things, and then generalizes.
Chapter 3. Mathematical Reasoning 3.1 Methods of proof A theorem is a statement that can be shown to be true. A proof is to demonstrate that a theorem.
Functional Design and Programming Lecture 11: Functional reasoning.
Induction and recursion
CS466 (Prasad)L1Sets1 Introduction Language: Set of Strings.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Fall 2007CS 2251 Proof by Induction. Fall 2007CS 2252 Proof by Induction There are two forms of induction Standard Induction –Prove the theorem is true.
CSE115/ENGR160 Discrete Mathematics 04/03/12 Ming-Hsuan Yang UC Merced 1.
0 PROGRAMMING IN HASKELL Chapter 7 - Higher-Order Functions.
Discussion #131/18 Discussion #13 Induction (the process of deriving generalities from particulars) Mathematical Induction (deductive reasoning over the.
Inductive Definitions COS 510 David Walker. Inductive Definitions Inductive definitions play a central role in the study of programming languages They.
Cse536 Functional Programming Lecture #14, Nov. 10, 2004 Programming with Streams –Infinite lists v.s. Streams –Normal order evaluation –Recursive streams.
Computing Fundamentals 1 Lecture 1 Lecturer: Patrick Browne Room K308 Based on Chapter 1. A Logical approach to Discrete.
CSE115/ENGR160 Discrete Mathematics 03/31/11
The ACL2 Proof Assistant Formal Methods Jeremy Johnson.
Inductive Proof (the process of deriving generalities from particulars) Mathematical Induction (reasoning over the natural numbers)
Induction Schemes Math Foundations of Computer Science.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
Copyright © Peter Cappello Mathematical Induction Goals Explain & illustrate construction of proofs of a variety of theorems using mathematical induction.
March 3, 2015Applied Discrete Mathematics Week 5: Mathematical Reasoning 1Arguments Just like a rule of inference, an argument consists of one or more.
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
CS 363 Comparative Programming Languages Semantics.
Type Safety Kangwon National University 임현승 Programming Languages.
1.1 Introduction to Inductive and Deductive Reasoning
CS 611: Lecture 6 Rule Induction September 8, 1999 Cornell University Computer Science Department Andrew Myers.
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Chapter 3 Part II Describing Syntax and Semantics.
Ceg860 (Prasad)LADT1 Specification and Implementation of Abstract Data Types Algebraic Techniques.
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
INM175 Topic 8 1 Module INM175 Discrete Mathematics Topic 8 Algebraic Theories.
Incompleteness. System Relativity Soundness and completeness are properties of particular logical systems. There’s no sense to be made of the claim that.
Lecture 1 Overview Topics 1. Proof techniques: induction, contradiction Proof techniques June 1, 2015 CSCE 355 Foundations of Computation.
Kyung-Goo Doh Hanyang University - ERICAComputer Science & Engineering Functional Programming / Imperative Programming CSE215 Fundamentals of Program Design.
Discrete Mathematics ? Transparency No. 2-0 Chapter 3 Induction and Recursion Transparency No. 3-1 formal logic mathematical preliminaries.
Classifications LanguageGrammarAutomaton Regular, right- linear Right-linear, left-linear DFA, NFA Context-free PDA Context- sensitive LBA Recursively.
Chapter 5. Section 5.1 Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
June 21, Reasoning about explicit strictness in a lazy language using mixed lazy/strict semantics Marko van Eekelen Maarten de Mol Nijmegen University,
Mathematical Induction 1. 2 Suppose we have a sequence of propositions which we would like to prove: P (0), P (1), P (2), P (3), P (4), … P (n), … We.
Mathematical Induction
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
CSCE 355 Foundations of Computation
Chapter 3 The Real Numbers.
Induction and recursion
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
CSCE 355 Foundations of Computation
Proving Properties of Recursive List Functions
Recursion and Induction
Induction and recursion
Lecture 11 CS 1813 – Discrete Mathematics
MA/CSSE 474 More Math Review Theory of Computation
Applied Discrete Mathematics Week 9: Integer Properties
Predicate Transformers
Testing vs Proving Testing uses a set of “typical” examples,
Chapter 11: Further Topics in Algebra
PROGRAMMING IN HASKELL
1.1 Introduction to Inductive and Deductive Reasoning
Agenda Proofs (Konsep Pembuktian) Direct Proofs & Counterexamples
Recursion.
Presentation transcript:

cs7120 (Prasad)L9-RECUR-IND1 Recursion and Induction

cs7120 (Prasad)L9-RECUR-IND2 inductionDefine sets by induction zero  N n  N  succ( n )  N recursionDefine functions on sets by recursion  n  N : plus(zero, n ) = n  m, n  N : plus(succ( m ), n ) = succ(plus( m, n )) principle of structural inductionProve properties about the defined functions using principle of structural induction.

cs7120 (Prasad)L9-RECUR-IND3 Example 0 + n = n (obvious) n + 0 = n (not so obvious!) Prove that the two rules for “+” are adequate to rewrite (n+0) to n. (Induction on the structure of the first argument) Show that “+” is commutative, that is, (x + y) = (y + x). Motivation To ensure that sufficient relevant information has been encoded for automated reasoning.

cs7120 (Prasad)L9-RECUR-IND4 Induction Proof Definition of “+” 0 + m = m s(n) + m = s(n+m) Proof that 0 is the identity w.r.t. + 0+m = m+0 = m Basis: = 0 Induction Hypothesis:  k >= 0: k + 0 = k Induction Step: Show s(k) + 0 = s(k) s(k) + 0 = s(k + 0) (*rule 2*) = s(k) (*ind hyp*) Conclusion: By principle of mathematical induction  m  N: m + 0 = m

cs7120 (Prasad)L9-RECUR-IND5 Basis:  n : n + 0 = n  n : 0 + n = n  n: n + 0 = n + 0 Induction Hypothesis:  k >= 0,  n : k + n = n + k Induction Step: s(k)+n = n+s(k) s(k)+n = (*rule2*) s(k+n) = (*ind. hyp.*) s(n+k) = (*rule2*) s(n)+k (* STUCK!!! our goal: n+s(k) *) So prove the auxiliary result. s(k)+n = k+s(n) n m Proof proceeds row by row

cs7120 (Prasad)L9-RECUR-IND6 Auxiliary result s(i)+ m = i+s(m) Basis: s(0) + m = (*rule2*) s(0 + m) = (*rule1*) s(m) = (*rule1*) 0 + s(m) Induction step: s(s(j)) + m = (*rule2*) s(s(j)+m) = (*ind.hyp.*) s(j+s(m)) = (*rule2*) s(j)+s(m) Overall result s(k) + n = (*auxiliary result*) k + s(n) = (*induction hyp.*) s(n) + k = (*auxiliary result*) n + s(k) (* End of proof of commutativity *)

cs7120 (Prasad)L9-RECUR-IND7 Motivation for formal proofs In mathematics, proving theorems enhances our understanding of the domain of discourse and our faith in the formalization. In automated theorem proving, these results demonstrate the adequacy of the formal description and the symbol manipulation system. These properties also guide the design of canonical forms for (optimal) representation of expressions and for proving equivalence.

cs7120 (Prasad)L9-RECUR-IND8 Semantic Equivalence vs Syntactic Identity Machines can directly test only syntactic identity. Several distinct expressions can have the same meaning (value) in the domain of discourse. To formally establish their equivalence, the domain is first axiomatized, by providing axioms (equations) that characterize (are satisfied by) the operations. In practice, an equational specification is transformed into a set of rewrite rules, to normalize expressions (into a canonical form). (Cf. Arithmetic Expression Evaluation)

cs7120 (Prasad)L9-RECUR-IND9 Induction Principle for Lists P(xs) holds for any finite list xs if: – P([]) holds, and – Whenever P(xs) holds, it implies that for every x, P(x::xs) also holds. Prove: filter p (map f xs) = map f (filter (p o f) xs)

cs7120 (Prasad)L9-RECUR-IND10 Basis: filter p (map f []) = filter p [] = [] map f(filter (p o f) []) = map f []= [] Induction Step: map f (filter (p o f) (x::xs)) = map f (if ((p o f) x) then x:: (filter (p o f) xs) else filter (p o f) xs ) case 1: (p o f) x = true case 2: (p o f) x = false

cs7120 (Prasad)L9-RECUR-IND11 case 1: map f ( x:: (filter (p o f) xs) ) = f x :: map f (filter (p o f) xs) = f x :: filter p (map f xs) (* induction hypothesis *) = filter p (f x :: map f xs) (* p (f x) holds *) = filter p (map f (x::xs)) case 2: filter p (map f (x::xs)) = filter p (f x :: map f xs) (* p (f x) does not hold *) = filter p (map f xs) = map f ( filter (p o f) xs ) (* induction hypothesis *)

cs7120 (Prasad)L9-RECUR-IND12 Tailoring Induction Principle fun interval m n = if m > n then [] else m:: interval (m+1) n (* Quantity (n-m) reduces at each recursive call. *) Basis: P(m,n) holds for m > n Induction step: P(m,n) holds for m <= n, given that P(m+1,n) holds.

cs7120 (Prasad)L9-RECUR-IND13 Induction Proof with Auxiliaries fun xs = xs | xs = y:: fun rev [] = [] | rev (x::xs) = (rev [x]; Prove : rev (rev xs) = xs Basis : rev (rev []) = rev [] = [] Induction step: rev(rev (y::ys)) = rev ( (rev [y] ) = (* via auxiliary result *) y :: ( rev (rev ys) ) = y :: ys (* ind. hyp. *)

cs7120 (Prasad)L9-RECUR-IND14 Auxiliary result rev ( [z] ) = z:: rev zs Induction Step: rev [z]) = rev ( u :: [z])) def *) = (rev [u] (* rev def*) = (z :: (rev [u] (* ind hyp *) = z :: ((rev [u]) def *) = z :: rev (u::us) (* rev def*) (*Creativity required in guessing a suitable auxiliary result.*)

cs7120 (Prasad)L9-RECUR-IND15 Weak Induction vs Strong Induction datatype exp = VarOp Var of string | Op of exp * exp; VarOpProve that the number of occurrences of the constructors in a legal exp are related thus: #Var(e) = #Op(e) + 1 To show this result, we need the result on all smaller exp s, not just the exp s whose “node count” or “height” is one less. –Motivates Strong/Complete Induction Principle.

cs7120 (Prasad)L9-RECUR-IND16 McCarthy’s 91-function fun f x = if x > 100 then x - 10 else f(f(x+11)) fun f x = if x > 100 then x - 10 else 91

cs7120 (Prasad)L9-RECUR-IND17 Is f total? fun f x = if (x mod 2) = 0 then x div 2 else f(f(3*x+1)) View int x as (2i + 1) 2^k - 1