Recursion and Structural Induction. Andreas Klappenecker

Similar documents
Mathematical Induction. Lecture 10-11

Full and Complete Binary Trees

Cartesian Products and Relations

Math 55: Discrete Mathematics

Basic Proof Techniques

Lecture 1: Course overview, circuits, and formulas

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

Handout #1: Mathematical Reasoning

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

1 if 1 x 0 1 if 0 x 1

it is easy to see that α = a

Section IV.1: Recursive Algorithms and Recursion Trees

SECTION 10-2 Mathematical Induction

C H A P T E R Regular Expressions regular expression

3. Mathematical Induction

1. Prove that the empty set is a subset of every set.

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Mathematical Induction

8 Divisibility and prime numbers

Sample Induction Proofs

INTRODUCTORY SET THEORY

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics

MATH 4330/5330, Fourier Analysis Section 11, The Discrete Fourier Transform

MATH 289 PROBLEM SET 4: NUMBER THEORY

Examination paper for MA0301 Elementær diskret matematikk

Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Cardinality. The set of all finite strings over the alphabet of lowercase letters is countable. The set of real numbers R is an uncountable set.

Continued Fractions and the Euclidean Algorithm

Graph Theory Problems and Solutions

CS 103X: Discrete Structures Homework Assignment 3 Solutions

Page 331, 38.4 Suppose a is a positive integer and p is a prime. Prove that p a if and only if the prime factorization of a contains p.

CHAPTER 5. Number Theory. 1. Integers and Division. Discussion

k, then n = p2α 1 1 pα k

Fundamentele Informatica II

GRAPH THEORY LECTURE 4: TREES

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

MA651 Topology. Lecture 6. Separation Axioms.

Solutions for Practice problems on proofs

Regular Languages and Finite Automata

Math 319 Problem Set #3 Solution 21 February 2002

This asserts two sets are equal iff they have the same elements, that is, a set is determined by its elements.

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

Reading 13 : Finite State Automata and Regular Expressions

HOMEWORK 5 SOLUTIONS. n!f n (1) lim. ln x n! + xn x. 1 = G n 1 (x). (2) k + 1 n. (n 1)!

Solutions to Homework 6 Mathematics 503 Foundations of Mathematics Spring 2014

Algorithms and Data Structures

To define function and introduce operations on the set of functions. To investigate which of the field properties hold in the set of functions

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2

Collinear Points in Permutations

Math Abstract Algebra I Questions for Section 23: Factoring Polynomials over a Field

So let us begin our quest to find the holy grail of real analysis.

P. Jeyanthi and N. Angel Benseera

Student Outcomes. Lesson Notes. Classwork. Discussion (10 minutes)

Answer Key for California State Standards: Algebra I

Math 115 Spring 2011 Written Homework 5 Solutions

Lecture 13 - Basic Number Theory.

SUBGROUPS OF CYCLIC GROUPS. 1. Introduction In a group G, we denote the (cyclic) group of powers of some g G by

Introduction to Automata Theory. Reading: Chapter 1

8 Primes and Modular Arithmetic

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 4 Nancy Lynch

Mathematical Induction. Mary Barnes Sue Gordon

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

Applications of Fermat s Little Theorem and Congruences

Automata and Formal Languages

4.6 The Primitive Recursive Functions

Mathematical Induction

MATH10040 Chapter 2: Prime and relatively prime numbers

Connectivity and cuts

The last three chapters introduced three major proof techniques: direct,

LEARNING OBJECTIVES FOR THIS CHAPTER

Real Roots of Univariate Polynomials with Real Coefficients

6.3 Conditional Probability and Independence

No: Bilkent University. Monotonic Extension. Farhad Husseinov. Discussion Papers. Department of Economics

WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT?

Just the Factors, Ma am

I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

(0, 0) : order 1; (0, 1) : order 4; (0, 2) : order 2; (0, 3) : order 4; (1, 0) : order 2; (1, 1) : order 4; (1, 2) : order 2; (1, 3) : order 4.

The Mean Value Theorem

Proseminar on Semantic Theory Fall 2013 Ling 720. Problem Set on the Formal Preliminaries : Answers and Notes

Math 223 Abstract Algebra Lecture Notes

Introduction. Appendix D Mathematical Induction D1

COMPUTER SCIENCE. Paper 1 (THEORY)

CS154. Turing Machines. Turing Machine. Turing Machines versus DFAs FINITE STATE CONTROL AI N P U T INFINITE TAPE. read write move.

From Last Time: Remove (Delete) Operation

5.1 Radical Notation and Rational Exponents

CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

Public Key Cryptography: RSA and Lots of Number Theory

Automata on Infinite Words and Trees

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

A First Investigation of Sturmian Trees

3515ICT Theory of Computation Turing Machines

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

3. INNER PRODUCT SPACES

Elements of probability theory

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

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

11 Multivariate Polynomials

Approximation Algorithms

Automata and Computability. Solutions to Exercises

Transcription:

Recursion and Structural Induction Andreas Klappenecker

Inductively Defined Sets

Motivating Example Consider the set A = {3,5,7,...} There is a certain ambiguity about this definition of the set A. Likely, A is the set of odd integers >= 3. [However, A could be the set of odd primes... ]

Motivating Example In Computer Science, we prefer to avoid such ambiguities. You will often encounter sets that are inductively defined. We can specify the set as follows: 3 A and if n is in A, then n+2 is in A. In this definition, there is (a) an initial element in A, namely 3. (b) you construct additional elements by adding 2 to an element in A, (c) nothing else belongs to A. We will call this an inductive definition of A.

Inductively Defined Sets An inductive definition of a set S has the following form: (a) Basis: Specify one or more initial elements of S. (b) Induction: Give one or more rules for constructing new elements of S from old elements of S. (c) Closure: The set S consists of exactly the elements that can be obtained by starting with the initial elements of S and applying the rules for constructing new elements of S. The closure condition is usually omitted, since it is always assumed in inductive definitions.

Example 1: Natural Numbers Let S be the set defined as follows: Basis: 0 S Induction: If n S, then n+1 S Then S is the set of natural numbers (with 0). Closure? Implied!

Example 2 Let S be the set defined as follows: Basis: 0 S Induction: If n S, then 2n+1 S. Can you describe the set S? S = {0,1,3,7,15,31,... } = { 2 n -1 n a nonnegative integer } since 2 0-1=0 and 2 n+1-1 = 2(2 n -1)+1

Example 3: Well-Formed Formulas We can define the set of well-formed formulas consisting of variables, numerals, and operators from the set {+,-,*,/} as follows: Basis: x is a well-formed formula if x is a numeral or a variable. Induction: If F and G are well-formed formulas, then (F+G), (F-G), (F*G), and (F/G) are well-formed formulas. Examples: 42, x, (x+42), (x/y), (3/0), (x*(y+z))

Example 4: Lists We can define the set L of finite lists of integers as follows. Basis: The empty list () is contained in L Induction: If i is an integer, and l is a list in L, then (cons i l) is in L. [Note: This is the Lisp style of lists, where (cons i l) appends the data item i at the front of the list l] Example: (cons 1 (cons 2 (cons 3 () ))) is the list (1 2 3) in Lisp.

Example 5: Binary Trees We can define the set B of binary trees over an alphabet A as follows: Basis: B. Induction: If L, R B and x A, then L,x,R B. Example:,1, // tree with one node (1) Example:,1,, r,,2, // tree with root r and two children (1 and 2).

Applications of Inductively Defined Sets In Computer Science, we typically use inductively defined sets (a.k.a. recursively defined sets) when defining: - programming languages (via grammars) - logic (via well-formed logical formulas) - data structures (binary trees, rooted trees, lists). - fractals We also use them in connection with functional programming languages. Extremely popular in Computer Science!

Recursively Defined Functions

Recursively Defined Functions Suppose we have a function with the set of nonnegative integers as its domain. We can specify the function as follows: Basis step: Specify the value of the function at 0 Inductive step: Give a rule for finding its value at an integer from its values at smaller integers. This is called a recursive or inductive definition.

Example: Factorial Function We can define the factorial function n! as follows: Base step: 0! = 1 Inductive step: n! = n (n-1)!

Example: Fibonacci Numbers The Fibonacci numbers f n are defined as follows: Base step: f 0 =0 and f 1 =1 Inductive step: f n = f n-1 + f n-2 for n >=2 We can use the recursive definition of the Fibonacci numbers to prove many properties of these numbers. The recursive structure actually helps to formulate the proofs.

Recursively Defined Functions One can define recursively defined functions for domains other than the nonnegative integers. In general, a function f is called recursively defined if and only of at least one value f(x) is define in terms of another value f(y), where x and y are distinct elements. [However, we will typically consider recursively defined functions that have more structure than this definition suggests.]

Example: Ackermann Function A(m, n) = n +1 ifm =0, A(m 1, 1) if m>0 and n =0, A(m 1,A(m, n 1)) if m>0 and n>0 The Ackermann function has particular significance in computability theory. The values of A(m,n) grow very, very quickly.

Example: Ackermann Function # In Ruby, the Ackermann function can be defined as follows: def A(m,n) return n+1 if m==0 return A(m-1,1) if n==0 return A(m-1,A(m,n-1)) end # Now try calculating A(0,0), A(1,1), A(2,2), A(3,3), A(4,4)

Example: Ackermann Function A(m, n) = n +1 ifm =0, A(m 1, 1) if m>0 and n =0, A(m 1,A(m, n 1)) if m>0 and n>0 Why does the recursion terminate? Lexicographically order the pairs (m,n). So (m,n) < (m,n ) iff m<m or (m=m and n<n ). Note that arguments used in the RHS are lexicographically smaller than the arguments in the LHS. Thus, eventually we need to end up in case m=0, though it might take an extremely long time.

Structural Induction

Structural Induction Structural induction asserts a property about elements of an inductively defined set. The proof method directly exploits the inductive definition of the set. The method is more powerful than strong induction in the sense that one can prove statements that are difficult (or impossible) to prove with strong induction. Typically, though, it is simply used because it is more convenient than (strong) induction.

Structural Induction In structural induction, the proof of the assertion that every element of an inductively defined set S has a certain property P proceeds by showing that Basis: Every element in the basis of the definition of S satisfies the property P. Induction: Assuming that every argument of a constructor has property P, show that the constructed element has the property P.

Example: Binary Trees Recall that the set B of binary trees over an alphabet A is defined as follows: Basis: B. Induction: If L, R B and x A, then L,x,R B. We can now prove that every binary tree has a property P by arguing that Basis: P( ) is true. Induction: For all binary trees L and R and x in A, if P(L) and P(R), then P( L,x,R ).

Example: Binary Trees Let f: B -> N be the function defined by f() = 0 1 if L = R = f(l, x, R) = f(l)+f(r) otherwise Theorem: Let T in B be a binary tree. Then f(b) yields the number of leaves of T.

Example: Binary Trees Theorem: Let T in B be a binary tree. Then f(b) yields the number of leaves of T. Proof: By structural induction on T. Basis: The empty tree has no leaves, so f( ) = 0 is correct. Induction: Let L,R be trees in B, x in A. Suppose that f(l) and f(r) denotes the number of leaves of L and R, respectively. If L=R=, then L,x,R> =,x, has one leaf, namely x, so f (,x, )=1 is correct.

Example: Binary Trees If L and R are not both empty, then the number of leaves of the tree L,x,R is equal to the number of leaves of L plus the number of leaves of R. Hence, by induction hypothesis, we get as claimed. f( L,x,R ) = f(r)+f(l) This completes the proof.

Example: Full Binary Trees The set of full binary trees can be defined as follows: Basis: There is a full binary tree consisting of a single vertex r Induction: If T 1 and T 2 are disjoint full binary trees and r in A is a node, then <T 1, r, T 2 > is a full binary tree with root r and left subtree T 1 and right subtree T 2. The difference between binary trees and full binary trees is in the basis step. A binary tree is full if and only if each node is either a leaf or has precisely two children.

Small Full Binary Trees Level 0: Level 1: not full! Level 2:

Height of a Full Binary Tree Let T be a full binary tree over an alphabet A. We define the height h(t) of a full binary tree as follows: Basis: For r in A, we define h(r) = 0; that is, the height of a full binary tree with just a single node is 0. Induction: If L and R are full binary trees and r in A, then the tree <L,r,R> has height h( <L,r,R> ) = 1 + max( h(l), h(r) ).

Number of Nodes of a Full Binary Tree Let n(t) denote the number of nodes of a full binary tree over an alphabet A. Then Basis: For r in A, we have n(r)=1. Induction: If L and R are full binary trees and r in A, then the number of nodes of <L,r,R> is given by n(<l,r,r>) = 1+n(L)+n(R).

Example of Structural Induction Theorem: Let T be a full binary tree over an alphabet A. Then we have n(t) <= 2 h(t)+1-1. Proof: By structural induction. Basis step: For r in A, we have n(r)=1 and h(r)=0, therefore, we have n(r) = 1 <= 2 (0+1) -1 = 2 h(r)+1-1, as claimed. Inductive step: Suppose that L and R are full binary trees that satisfy n(l) <= 2 h(l)+1-1 and n(r) <= 2 h(r)+1-1. Then the tree T=<L,r,R> satisfies: n(t) = 1 + n(l) + n(r) <= 1 + 2 h(l)+1-1 + 2 h(r)+1-1 <= 2 max(2 h(l)+1, 2 h(r)+1 )-1, since a+b <= 2max(a,b) <= 2. 2 max(h(l),h(r))+1-1=2. 2 h(t) -1 = 2 h(t)+1-1