Induction and Recursion

Transcription

1 Induction and Recursion Jan van Eijck June 3, 2003 Abstract A very important proof method that is not covered by the recipes from Chapter 3 is the method of proof by Mathematical Induction. Roughly speaking, mathematical induction is a method to prove things about objects that can be built from a finite number of ingredients in a finite number of steps. Such objects can be thought of as construed by means of recursive definitions. Thus, as we will see in this lecture, recursive definitions and inductive proofs are two sides of one coin.

2 module RCRH8 where import STAL (display)

3 Mathematical Induction Mathematical induction is a proof method that can be used to establish the truth of a statement for an infinite sequence of cases 0, 1, 2,.... Let P (n) be a property of natural numbers. To prove a goal of the form n N : P (n) one can proceed as follows: 1. Basis. Prove that 0 has the property P. 2. Induction step. Assume the induction hypothesis that n has property P. Prove on the basis of this that n + 1 has property P. The goal n N : P (n) follows from this by the principle of mathematical induction.

4 The Principle of Mathematical Induction By the principle of mathematical induction we mean the following fact: For every set X N, we have that: if 0 X and n N(n X n + 1 X), then X = N. This fact is obviously true.

5 Example: The Sum of the Angles of a Convex Polygon Suppose we want to prove that the sum of the angles of a convex polygon of n + 3 sides is (n + 1)π radians. We can show this by mathematical induction with respect to n, as follows:

6 Basis For n = 0, the statement runs: the sum of the angles of a convex polygon of 3 sides, i.e., of a triangle, is π radians. We know from elementary geometry that this is true. Induction step Assume that the sum of the angles of a convex polygon of n + 3 sides is (n + 1)π radians. Take a convex polygon P of n + 4 sides. Then, since P is convex, we can decompose P into a triangle T and a convex polygon P of n + 3 sides (just connect edges 1 and 3 of P ). The sum of the angles of P equals the sum of the angles of T, i.e. π radians, plus the sum of the angles of P, i.e., by the induction hypothesis, (n + 1)π radians. This shows that the sum of the angles of P is (n + 2)π radians. From 1. and 2. and the principle of mathematical induction the statement follows.

8 Why does Mathematical Induction Work? If one compares the proof strategy needed to establish a principle of the form n N : P (n) with that for an ordinary universal statement x A : P (x), where A is some domain of discourse, then the difference is that in the former case we can make use of what we know about the structure of N. In case we know nothing about A, and we have to prove P for an arbitrary element from A, we have to take our cue from P. In case we have to prove something about an arbitrary element n from N we know a lot more: we know that either n = 0 or n can be reached from 0 in a finite number of steps.

9 Induction and Wellfoundedness The key property of N that makes mathematical induction work is the fact that the relation < on N is well-founded: any sequence m 0 > m 1 > m 2 > terminates. This guarantees the existence of a starting point for the induction process. For any A that is well-founded by a relation the following principle holds. Let X A. If then X = A. a A( b a(b X) a X),

10 The Naturals as a Recursive Datatype We can think of any natural number n as the the result of starting from 0 and applying the successor operation +1 a finite number of times: data Natural = Z S Natural deriving (Eq, Show) Here Z is our representation of 0, while S n is a representation of n+1. The number 4 looks in our representation like S (S (S (S Z))).

11 We can define the operation of addition on the natural numbers recursively in terms of the successor operation +1 and addition for smaller numbers: m + 0 := m m + (n + 1) := (m + n) + 1 This definition of the operation of addition is called recursive because the operation + that is being defined is used in the defining clause, but for a smaller second argument. Recursive definitions always have a base case (in the example: the first line of the definition, where the second argument of the addition operation equals 0) and a recursive case (in the example: the second line of the definition, where the second argument of the addition operation is greater than 0, and the operation that is being defined appears in the righthand side of the definition).

12 In proving things about recursively defined objects the idea is to use mathematical induction with the basic step justified by the base case of the recursive definition, the induction step justified by the recursive case of the recursive definition. Here is the Haskell version of the definition of +, in prefix notation: plus m Z = m plus m (S n) = S (plus m n) Equivalent version of the definition with infix operators: m plus Z = m m plus (S n) = S (m plus n)

13 Now we can prove the following list of fundamental laws of addition from the definition. m + 0 = m (0 is identity element for +) m + n = n + m (commutativity of +) m + (n + k) = (m + n) + k (associativity of +) The first fact follows immediately from the definition of +. In proving things about a recursively defined operator it is convenient to be able to refer to clauses in the recursive definition, as follows:.1 refers to the first clause in the definition of,.2 to the second clause, and so on.

22 The Nature of Recursive Definitions Not any set of recursive equations over natural numbers can serve as a definition of an operation on natural numbers. Consider f(0) := 1 f(n + 1) := f(n + 2). This does not define unique values for f(1), f(2), f(3),..., for the equations only require that all these values should be the same, not what the value should be. The following format does guarantee a proper definition: f(0) := c f(n + 1) := h(f(n)). Here c is a description of a value (say of type A), and h is a function of type A A.

23 Structural Recursion A definition in this format is said to be a definition by structural recursion over the natural numbers. Definition by structural recursion of f from c and h works like this: take a natural number n, view it as 1 } + {{ + 1+ } 0, n times replace 0 by c, replace each successor step 1+ by h, and evaluate the result: h( (h(c)) ). }{{} n times

27 Induction and Recursion over Trees Here is a recursive definition of binary trees: A single leaf node is a binary tree. If t 1 and t 2 are binary trees, then the result of joining t 1 and t 2 under a single node (called the root node) is a binary tree. A notation for this is: ( t 1 t 2 ) Nothing else is a binary tree. The depth of a binary tree is given by: The depth of is 0. The depth of ( t 1 t 2 ) is 1+ the maximum of the depths of t 1 and t 2.

28 A binary tree is balanced if it either is a single leaf node, or it has the form ( t 1 t 2 ), with both t 1 and t 2 balanced, and having the same depth. We see the following: A balanced binary tree of depth 0 is just a single leaf node, so its number of nodes is 1. A balanced binary tree of depth 1 has one internal node and two leaves, so it has 3 nodes. A balanced binary tree of depth 2 has 3 internal nodes and 4 leaf nodes, so it has 7 nodes. A binary tree of depth 3 has 7 internal nodes plus 8 leaf nodes, so it has 15 nodes....

29 Recursion and induction over binary trees are based on two cases t = and t = ( t 1 t 2 ). Suppose we want to show in general that the number of nodes of a binary tree of depth n is 2 n+1 1. Then a proof by mathematical induction is in order.

30 Basis If n = 0, then 2 n+1 1 = = 1. This is indeed the number of nodes of a binary tree of depth 0. Induction step Assume the the number of nodes of a binary tree of depth n is 2 n+1 1. We have to show that the number of nodes of a binary tree of depth n + 1 equals 2 n+2 1. A binary tree of depth n + 1 can be viewed as a set of internal nodes constituting a binary tree of depth n, plus a set of leaf nodes, consisting of two new leaf nodes for every old leaf node from the tree of depth n. By induction hypothesis, we know that a tree of depth n has 2 n+1 1 nodes, so a tree of depth n + 1 has 2 n+1 1 internal nodes. It is easy to see that a tree of depth n + 1 has 2 n+1 leaf nodes. The total number of nodes of a tree of depth n + 2 is therefore 2 n n+1 = 2 2 n+1 1 = 2 n+2 1, and we have proved our induction step.

31 A Datastructure for Binary Trees We use L for a single leaf. The data declaration specifies that a BinTree either is an object L (a single leaf), or an object constructed by applying the constructor N to two BinTree objects (the result of constructing a new binary tree ( t 1 t 2 ) from two binary trees t 1 and t 2 ).

35 The Haskell programs allow us to check the relation between count (makebintree n) and 2^(n+1) - 1 for individual values of n: Main> count (makebintree 6) == 2^7-1 True What the proof by mathematical induction provides is an insight that the relation holds in general.

36 Mathematical induction does not give as clue as to how to find a formula for the number of nodes in a tree. It only serves as a method of proof once such a formula is found. So how does one find a formula for the number of nodes in a binary tree in the first place? By noticing how such trees grow. A binary tree of depth 0 has 1 node, and this node is a leaf node. This leaf grows two new nodes, so a binary tree of depth 1 has = 3 nodes. In the next step the 2 leaf nodes grow two new nodes each, so we get 2 2 = 4 new leaf nodes, and the number of nodes of a binary tree of depth 2 equals = 7.

37 In general, a tree of depth n 1 is transformed into one of depth n by growing 2 n new leaves, and the total number of leaves of the new tree is given by n. In other words, the number of nodes of a balanced binary tree of depth n is given by : n k=0 2k. To get a value for this, here is a simple trick: n n n 2 k = 2 2 k 2 k = (2 2 n + 2 n + 2) (2 n + + 1) = k=0 k=0 k=0 = 2 2 n 1 = 2 n+1 1.

38 Other Tree Formats Datatype for trees with integers at the internal nodes: data Tree = Lf Nd Int Tree Tree deriving Show A general datatype for binary trees with information at the internal nodes is given by: data Tr a = Nil T a (Tr a) (Tr a) deriving (Eq,Show)

73 0 Sequences and Series 6. Approximate e 0. using the first five terms of the series. Compare this approximation with your calculator evaluation of e 0.. 6. Approximate e 0.5 using the first five terms

Worksheet on induction MA113 Calculus I Fall 2006 First, let us explain the use of for summation. The notation f(k) means to evaluate the function f(k) at k = 1, 2,..., n and add up the results. In other

Basic Proof Techniques David Ferry dsf43@truman.edu September 13, 010 1 Four Fundamental Proof Techniques When one wishes to prove the statement P Q there are four fundamental approaches. This document

Continued Fractions and the Euclidean Algorithm Lecture notes prepared for MATH 326, Spring 997 Department of Mathematics and Statistics University at Albany William F Hammond Table of Contents Introduction

CHAPTER 3 Methods of Proofs 1. Logical Arguments and Formal Proofs 1.1. Basic Terminology. An axiom is a statement that is given to be true. A rule of inference is a logical rule that is used to deduce

Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about

Math 101 Rumbos Spring 2010 1 Handout #1: Mathematical Reasoning 1 Propositional Logic A proposition is a mathematical statement that it is either true or false; that is, a statement whose certainty or

Chapter 3 Sequences In this chapter, we discuss sequences. We say what it means for a sequence to converge, and define the limit of a convergent sequence. We begin with some preliminary results about the

Full and Complete Binary Trees Binary Tree Theorems 1 Here are two important types of binary trees. Note that the definitions, while similar, are logically independent. Definition: a binary tree T is full

2. METHODS OF PROOF 69 2. Methods of Proof 2.1. Types of Proofs. Suppose we wish to prove an implication p q. Here are some strategies we have available to try. Trivial Proof: If we know q is true then

APPLICATIONS OF THE ORDER FUNCTION LECTURE NOTES: MATH 432, CSUSM, SPRING 2009. PROF. WAYNE AITKEN In this lecture we will explore several applications of order functions including formulas for GCDs and

MODULAR ARITHMETIC 1 Working With Integers The usual arithmetic operations of addition, subtraction and multiplication can be performed on integers, and the result is always another integer Division, on

CHAPTER 3 Numbers and Numeral Systems Numbers play an important role in almost all areas of mathematics, not least in calculus. Virtually all calculus books contain a thorough description of the natural,

ENGG2012B Advanced Engineering Mathematics Notes on Determinant Lecturer: Kenneth Shum Lecture 9-18/02/2013 The determinant of a system of linear equations determines whether the solution is unique, without

Chapter 3 Cartesian Products and Relations The material in this chapter is the first real encounter with abstraction. Relations are very general thing they are a special type of subset. After introducing

16 Chapter P Prerequisites P.2 Properties of Real Numbers What you should learn: Identify and use the basic properties of real numbers Develop and use additional properties of real numbers Why you should

Real Numbers and Monotone Sequences. Introduction. Real numbers. Mathematical analysis depends on the properties of the set R of real numbers, so we should begin by saying something about it. There are

8 Primes and Modular Arithmetic 8.1 Primes and Factors Over two millennia ago already, people all over the world were considering the properties of numbers. One of the simplest concepts is prime numbers.

NYS COMMON CORE MATHEMATICS CURRICULUM Lesson 5 8 Student Outcomes Students know the definition of a number raised to a negative exponent. Students simplify and write equivalent expressions that contain

222 CHAPTER 6. PROBABILITY 6.3 Conditional Probability and Independence Conditional Probability Two cubical dice each have a triangle painted on one side, a circle painted on two sides and a square painted

Section 5.1 Radical Notation and Rational Exponents 1 5.1 Radical Notation and Rational Exponents We now review how exponents can be used to describe not only powers (such as 5 2 and 2 3 ), but also roots

Appendix F: Mathematical Induction Introduction In this appendix, you will study a form of mathematical proof called mathematical induction. To see the logical need for mathematical induction, take another

Regular Languages and Finite Automata 1 Introduction Hing Leung Department of Computer Science New Mexico State University Sep 16, 2010 In 1943, McCulloch and Pitts [4] published a pioneering work on a

1 Review of complex numbers 1.1 Complex numbers: algebra The set C of complex numbers is formed by adding a square root i of 1 to the set of real numbers: i = 1. Every complex number can be written uniquely

Chapter 1 LINEAR EQUATIONS 1.1 Introduction to linear equations A linear equation in n unknowns x 1, x,, x n is an equation of the form a 1 x 1 + a x + + a n x n = b, where a 1, a,..., a n, b are given

Mathematical Induction (Handout March 8, 01) The Principle of Mathematical Induction provides a means to prove infinitely many statements all at once The principle is logical rather than strictly mathematical,

Section 3 Sequences and Limits, Continued. Lemma 3.6 Let {a n } n N be a convergent sequence for which a n 0 for all n N and it α 0. Then there exists N N such that for all n N. α a n 3 α In particular

NUMBER SYSTEMS William Stallings The Decimal System... The Binary System...3 Converting between Binary and Decimal...3 Integers...4 Fractions...5 Hexadecimal Notation...6 This document available at WilliamStallings.com/StudentSupport.html

1 Sequences 11 Overview A (numerical) sequence is a list of real numbers in which each entry is a function of its position in the list The entries in the list are called terms For example, 1, 1, 1 3, 1

The Prime Numbers Before starting our study of primes, we record the following important lemma. Recall that integers a, b are said to be relatively prime if gcd(a, b) = 1. Lemma (Euclid s Lemma). If gcd(a,

Definition 1: GROUPS An operation on a set G is a function : G G G. Definition 2: A group is a set G which is equipped with an operation and a special element e G, called the identity, such that (i) the

Euclid s Algorithm for the Greatest Common Divisor Desh Ranjan Department of Computer Science New Mexico State University 1 Numbers, Division and Euclid People have been using numbers, and operations on

CHAPTER 5 Round-off errors In the two previous chapters we have seen how numbers can be represented in the binary numeral system and how this is the basis for representing numbers in computers. Since any

15-150 Lecture 11: Tail Recursion; Continuations Lecture by Dan Licata February 21, 2011 In this lecture we will discuss space usage: analyzing the memory it takes your program to run tail calls and tail

11.01 List the elements of Z 2 Z 4. Find the order of each of the elements is this group cyclic? Solution: The elements of Z 2 Z 4 are: (0, 0) : order 1; (0, 1) : order 4; (0, 2) : order 2; (0, 3) : order

1 Section 5.2 The Complete Ordered Field: Purpose of Section We present an axiomatic description of the real numbers as a complete ordered field. The axioms which describe the arithmetic of the real numbers

Arkansas Tech University MATH 4033: Elementary Modern Algebra Dr. Marcel B. Finan 3 Binary Operations We are used to addition and multiplication of real numbers. These operations combine two real numbers

In this session, we ll learn how to solve problems related to place value. This is one of the fundamental concepts in arithmetic, something every elementary and middle school mathematics teacher should

Section 1.5 Methods of Proof 1.5.1 1.5 METHODS OF PROOF Some forms of argument ( valid ) never lead from correct statements to an incorrect. Some other forms of argument ( fallacies ) can lead from true

MATH31: Number Theory Homework until Test # Philipp BRAUN Section 3.1 page 43, 1. It has been conjectured that there are infinitely many primes of the form n. Exhibit five such primes. Solution. Five such

Math Review for the Quantitative Reasoning Measure of the GRE revised General Test www.ets.org Overview This Math Review will familiarize you with the mathematical skills and concepts that are important

Induction Margaret M. Fleck 10 October 011 These notes cover mathematical induction and recursive definition 1 Introduction to induction At the start of the term, we saw the following formula for computing

Mathematics for Computer Science/Software Engineering Notes for the course MSM1F3 Dr. R. A. Wilson October 1996 Chapter 1 Logic Lecture no. 1. We introduce the concept of a proposition, which is a statement

Exercises 1 - number representations Questions 1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal: (a) 3012 (b) - 435 2. For each of

CHAPTER 4 Applications of Methods of Proof 1. Set Operations 1.1. Set Operations. The set-theoretic operations, intersection, union, and complementation, defined in Chapter 1.1 Introduction to Sets are

1.. SOLVING A SYSTEM OF LINEAR EQUATIONS 1. Solving a System of Linear Equations 1..1 Simple Systems - Basic De nitions As noticed above, the general form of a linear system of m equations in n variables

Chapter Pythagorean Triples The Pythagorean Theorem, that beloved formula of all high school geometry students, says that the sum of the squares of the sides of a right triangle equals the square of the

Lecture 5: Euclid s algorithm Introduction The fundamental arithmetic operations are addition, subtraction, multiplication and division. But there is a fifth operation which I would argue is just as fundamental

Chapter 2 Numbers God created the integers and the rest is the work of man. (Leopold Kronecker, in an after-dinner speech at a conference, Berlin, 1886) God created the integers and the rest is the work

Accelerated Mathematics 3 This is a course in precalculus and statistics, designed to prepare students to take AB or BC Advanced Placement Calculus. It includes rational, circular trigonometric, and inverse