Recursive Definitions: Functions and Sets - Prof. Margaret M. Fleck, Study notes of Discrete Structures and Graph Theory

Recursive definitions, a mathematical technique used to define functions and sets recursively. The concept of recursive definitions, their relationship with computer programs, and examples of recursive definitions for sums, factorials, and fibonacci numbers. It also explains how recursive definitions are used in inductive proofs.

Typology: Study notes

Pre 2010

Uploaded on 03/11/2009

koofers-user-gop
koofers-user-gop 🇺🇸

5

(1)

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Recursive definition
Margaret M. Fleck
10 October 2008
In this lecture, we see how to define functions recursively, a mathematical
technique that closely parallels recursive function calls in computer programs.
1 Announcements
Notice the handout on proof techniques posted with the notes from Wednes-
day’s lecture. You may find it useful.
Status of exam grading: all graded, not quite totalled and entered. Grades
should be on compass later today, exams available at lecture Monday.
2 Recursive definitions
When we introduce the notation for a sum like Σn
i=1, we did it fairly infor-
mally, as
Σn
i=1 = 1 + 2 + 3 + ...+n
This often works well for human readers, but it isn’t very precise because
we’ve left you to fill in what’s meant by the ....
To define this notation more formally, we can use a fact that all been
assuming was obvious:
1
pf3
pf4
pf5

Partial preview of the text

Download Recursive Definitions: Functions and Sets - Prof. Margaret M. Fleck and more Study notes Discrete Structures and Graph Theory in PDF only on Docsity!

Recursive definition

Margaret M. Fleck

10 October 2008

In this lecture, we see how to define functions recursively, a mathematical technique that closely parallels recursive function calls in computer programs.

1 Announcements

Notice the handout on proof techniques posted with the notes from Wednes- day’s lecture. You may find it useful.

Status of exam grading: all graded, not quite totalled and entered. Grades should be on compass later today, exams available at lecture Monday.

2 Recursive definitions

When we introduce the notation for a sum like Σni=1, we did it fairly infor- mally, as

Σni=1 = 1 + 2 + 3 +... + n

This often works well for human readers, but it isn’t very precise because we’ve left you to fill in what’s meant by the.. ..

To define this notation more formally, we can use a fact that all been assuming was obvious:

Σn i=1+1 = Σni=1 + (n + 1)

That is, we’ve expressed the formula for larger values of n in terms of the formula for smaller values. We also need to explicitly define values for the formula for the smallest input value or values. So our full definition might look like:

  • Base: Σ^1 i=1 = 1
  • Induction: Σn i=1+1 = Σni=1 + (n + 1)

This is called a recursive definition. Or sometimes an inductive defini- tion. The inductive part of such a definition is sometimes called a recurrence relation.

The extra precision provided by the recursive definition is helpful when writing proofs.

Similarly, we can define the factorial function n! recursively:

  • n! = n · (n − 1)!

(The base and inductive parts of these definitions are quite often not labelled as such.)

3 Recursive definitions and programs

In real life, mathematicians alternate between the... and recursive definitions of objects, depending on which is more clear and convenient. For many problems, both methods work and this is a matter of personal taste.

When writing computer programs, you also face the need to be precise, but this time the audience is a computer. Again, you frequently have the

4 More interesting sorts of recursion

A recursive approach becomes critical when the result for n depends on the results for more than one smaller value, as in the strong induction examples we saw on Wednesday. For example, the famous Fibonacci numbers are defined by:

• F 0 = 0, F 1 = 1

  • ∀i ∈ N, i ≥ 2 , Fi = Fi− 1 + Fi− 2

So F 2 = 1, F 3 = 2, F 4 = 3, F 5 = 5, F 6 = 8, F 7 = 13, F 8 = 21, F 9 = 34.

Recursion is also often the best approach when the value for n depends on the value for n − 1 in a way that’s more complicated than simple sums or products. For example, we could define a function f by:

  • f (0) = 3
  • f (n) = 2f (n − 1) + 3

That is, f (0) = 3, f (1) = 9, f (2) = 21, f (3) = 45, etc. It’s not instantly obvious how to rewrite this definition using a sum with.. ..

5 Proofs with recursive definitions

Recursive definitions are ideally suited to inductive proofs. The main outline of the proof often mirrors the structure of the definition.

For example, let’s prove the following claim about the Fibonacci numbers:

Claim 1 For any n ≥ 0 , F 3 n is even.

Let’s check some concrete values: F 0 = 0, F 3 = 2, F 6 = 8, F 9 = 34. All are even. Claim looks good. So, let’s build an inductive proof:

Proof: by induction on n. Base: F 0 = 0, which is even. Induction; Suppose that F 3 k is even. We need to show that that F3(k+1) is even. F3(k+1) = F 3 k+3 = F 3 k+2 + F 3 k+ But F 3 k+2 = F 3 k+1+F 3 k. So, substituting into the above equation, we get: F3(k+1) = (F 3 k+1 + F 3 k) + F 3 k+1 = 2F 3 k+1 + F 3 k By the inductive hypothesis F 3 k is even. 2F 3 k+1 is even because it’s 2 times an integer. So their sum must be even. So F3(k+1) is even, which is what we needed to show.

Another example, again with the Fibonacci numbers:

Claim 2 For any n ≥ 1 , Σni=1 (Fi)^2 = (Fn)(Fn+1).

For example Σ^4 i=1 (Fi)^2 = 1 + 1 + 4 + 9 = 15 = 3 · 5 = F 4 F 5.

I have no intuitions about such equations. So let’s hope induction will work in a simple way and give it a try:

Proof: by induction on n. Base: If n = 1, then we have Σ^1 i=1 (Fi)^2 = (F 1 )^2 = 1 = 1 · 1 = F 1 F 2. So this checks out. Induction: Suppose that Σki=1 (Fi)^2 = (Fk)(Fk+1). Σk i=1+1 (Fi)^2 = (Σki=1 (Fi)^2 ) + (Fk+1)^2. By the inductive hypothesis, this is FkFk+1 + (Fk+1)^2. But FkFk+1 + (Fk+1)^2 = FkFk+1 + Fk+1Fk+1 = Fk+1(Fk + Fk+1) = Fk+1Fk+2. (The last step is using the definition of the Fibonacci numbers.) So Σk i=1+1 (Fi)^2 = Fk+1Fk+2, which is what we needed to show.