Você está na página 1de 4

DISCRETE MATHEMATICS

RECURSIVE DEFINITIONS

A function f : Zm A is defined recursively as follows:


Basis Step: Let l Zm and let am , . . . al A. We define
f (m) = am
.
.
f (l) = al
Recursive Step:
Let n > l
f (n) = e(..n..f (i)..) mi<n
where e(..n..f (i)..) is an expression depending on n and f (m), . . . , f (n 1)

Different choices of the ai and of the expression e give rise to different functions.

Ex.1
Fibonacci function f : Z1 Z
(BS) f (1) = 1 f (2) = 1
(RS) n > 2 f (n) = f (n 1) + f (n 2)

Ex.2
Pn
i=1 ai where ai is an expression depending on i (e.g. ai = (2i 1) is a
recursive function.
(BS) f (1) = a1
Pn
(RS) n > 2 f (n) = i=1 ai = a1 + a2 + . . . + an1 + an = f (n 1) + an

Ex.3
Qn
i=1ai where ai is an expression depending on i (e.g. ai = 2i is a recursive
function.
(BS) f (1) = a1
Qn
(RS) n > 2 f (n) = i=1 ai = a1 a2 . . . an1 an = f (n 1) an
We assume
Pn Qn
i=m ai = 0 if m > n i=m ai = 0 if m > n

Ex.4
(BS) f (0) = 3
(RS) n > 0 f (n) = 2f (n 1) + 3

1
Find f (5)
There are two ways of finding the value of f (5)

By rewriting
f (5) = 2f (4) + 3 = 2(2f (3) + 3) + 3 = 4f (3) + 9 = 4(2f (2) + 3) + 9 =
8f (2) + 21 = 8(2f (1) + 3) + 21 = 16f (1) + 45 = 16(2f (0) + 3) + 45 =
32f (0) + 93 = 32 3 + 93 = 96 + 93 = 189
By iteration
We first find the values of f (0) . . . f (4) and we substitute, operating, in
the expression e of the definition.
f (0) = 3
f (1) = 2f (0) + 3 = 2 3 + 3 = 9
f (2) = 2f (1) + 3 = 2 9 + 3 = 21
f (3) = 2f (2) + 3 = 2 21 + 3 = 45
f (4) = 2f (3) + 3 = 2 45 + 3 = 93
f (5) = 2f (4) + 3 = 2 93 + 3 = 189

Recursion and induction are very closely related. Very often, we prove prop-
erties of recursive functions by induction.
For example, let f : Z1 Z be the Fibonacci function.
(BS) f (1) = 1 f (2) = 1
(RS) n > 2 f (n) = f (n 1) + f (n 2)
We are going to prove the following property by induction.
n Z3 f (1)2 + . . . + f (n)2 = f (n)f (n + 1)

Basis Step S(3) f (1)2 + f (2)2 + f (3)2 = 1 + 1 + 22 = 6 = 2 3 = f (3)f (4)


(f (4) = f (3) + f (2) = 2 + 1 = 3)
(IH) f (1)2 + . . . + f (k)2 = f (k)f (k + 1)
Inductive Step S(k + 1) (f (1)2 + . . . + f (k)2 ) + f (k + 1)2 = f (k)f (k + 1) +
f (k + 1)2 = f (k + 1)(f (k + 1) + f (k)) = f (k + 1)f (k + 2)

2
We extend this definition to functions with several arguments:

1. f : B Zm A is defined recvursively as follows:


Basis Step: Let l m, l Zm We define for all m n l
f (b, m) = em (..b..)
.
.
f (b, l) = el (..b..)

where ej (..b..) j = m . . . l are expressions depending on b.


Recursive Step:
Let n > l
f (b, n) = e(..b..n..f (c, i)..) m i < n (c may be b.)

Ex.1
+ : N N N
(B) +(m, 0) = m e0 (..b..) = b
(R) +(m, s(n)) = s(+(m, n)) e(..b..n..f (c, i)..) = s(f (b, n))

Ex.2
: N N N
(B) (m, 0) = 0 e0 (..b..) = 0
(R) (m, s(n)) = m + (m, n) e(..b..n..f (c, i)..) = b + f (b, n)

2. f : Zm C A is defined recursively as follows:


Basis Step: Let l m, l Zm We define for all m n l
f (m, c) = em (..c..)
.
.
f (l, c) = el (..c..)

where ej (..c..) j = m . . . l are expressions depending on c.


Recursive Step:
Let n > l
f (n, c) = e(..c..n..f (i, d)..) m i < n (d may be c.)

3
3. f : B Zm C A is defined recursively as follows:
Basis Step: Let l m, l Zm We define for all m n l
f (b, m, c) = em (..b..c..)
.
.
f (b, l, c) = el (..b..c..)

where ej (..b..c..) j = m . . . l are expressions depending on b and c.


Recursive Step:
Let n > l
f (b, n, c) = e(..b..n..c..f (d, i, g)..) m i < n (d, g may be
b, c.)

Você também pode gostar