Discrete Structures

Lecture Notes, 15 Nov 2010

Last Update: 17 November 2010

Note: NEW or UPDATED material is highlighted


Note: A username and password may be required to access certain documents. Please contact Bill Rapaport.


Index to all lecture notes
…Previous lecture


§4.3: Recursive Definitions


  1. Consider f:NN s.t. f(n) = 5n+1

    1. "5n+1" characterizes f's O/P in terms of its I/P n

    2. But the sequence of its O/Ps exhibits another, related pattern:

      • Consider the differences between f(n) & f(n+1):

          f(1) = f(0)+5
          f(2) = f(1)+5

    3. In general, f(n) = f(n–1) + 5


  2. Defined this way, f is defined in terms of (an earlier version of) itself!


  3. But now we have 2 ways to describe the function:

    Is f(n), which = f(n–1)+5, also = 5n+1?

    1. i.e.) is f(current I/P) = f(previous O/P)+5 = 5(current I/P)+1?

    2. i.e.) we seem to have two algorithms for computing f(n):

      • compute f(previous O/P); then add 5
      • multiply current I/P by 5; then add 1

      Do these algorithms have the same I/O behavior?

    3. Let's prove that:

        the function f defined non-recursively (or "explicitly")
          =
        the function f defined recursively, for all n

    4. To avoid confusion,

        let's call the non-recursive function "f"
        & the recursive function "h".

      • i.e.) f,h:NN s.t.:

          f(n) = 5n+1
          h(n) = h(n–1)+5

    5. So: f=h?


  4. Let's check a few cases first:


  5. Have we proved ∀n[h(n) = f(n)]?


  6. Another e.g. of the ugly but explicit/non-recursive definition vs. the simple recursive definition:

    is most easily described not by giving a formula for each term:

    e.g.) Fib(n) = (φ1n – φ2n)/√5, where φ1 = (1+√5)/2 and φ2 = (1–√5)/2 (!!)

    Rather, it is most easily described by showing you the first 2 terms

    & then giving you a formula for computing the next term
    based on the 2 previous terms:


  7. This last kind of definition is called a recursive (or inductive) definition

    1. It consists of "initial conditions" = "base case"
      & a "general rule" = "recurrence relation"

    2. Advantages:

      1. Gives an ∞ definition in a finite way
      2. Can be understood by a computer
      3. Easier for humans :-)

    3. E.g.) n! = n * (n–1) * (n–2) * … * 3 * 2 * 1

      • We need a way to eliminate the "…",
        in order to make it more precise
        i.e.) more algorithmic

        • Is 3! = 3*2*1*…*3*2*1 ;???? No!

      Could try:

                i=n
        n! = Π i
                i=1

      • Now ∃ no "…",
        but no longer algorithmic:
        & what about n=0?
        n! = # ways you can arrange n terms;
        ∴ 0! = # ways you can arrange 0 terms, namely, 1 way (?!)

    4. Better:

      • base case:
          0! =def 1 (special case; if 0!=0, this rec def wouldn't work!)
        recursive case:
          (n+1)! =def (n+1)*n!

      • i.e.) S(n)! = S(n)*n!

      • 1! = (0+1)*0! = 1*1 = 1
        2! = (1+1)*1! = 2*1! = 2*1 = 2
        3! = (2+1)*2! = 3*2! = 3*2*1 = 6
        4! = (3+1)*3! = 4*3! = 4*3*2*1 = 24, etc.

      • Alternative recursive case (same thing, different notation):

        • n! =def n*(n–1)!

    5. E.g.) "+" defined recursively, in terms of the successor function:

      • base case:
          m + 0 =def m
        recursive case:
          m + S(n) =def S(m+n)
        i.e.)
          m + (n+1) = (m+n) + 1

        • Importantly, "+" must be defined in terms of the successor function S
          (which is a "recursive" definition),
          not in terms of "+1",
          which would be a circular definition!

        • And S is "defined" in terms of Peano's axioms!

          • S(n) is the "next" integer after n

      • e.g.)

          UPDATED
          6+4 = 6+S(3), by def of 4 as S(3)
                 = S(6+3), by rec def of 6+S(3)
                 = S(6+S(2)), by def of 3 as S(2)
                 = S(S(6+2)), by rec def of 6+S(2)
                 = S(S(6+S(1))), by def of 2 as S(1)
                 = S(S(S(6+1))), by rec def of 6+S(1)
                 = S(S(S(6+S(0)))), by def of 1 as S(0)
                 = S(S(S(S(6+0)))), by rec def of 6+S(0)
                 = S(S(S(S(6)))), by rec def of 6+0, base case
                 = S(S(S(7))), by def of S(6)
                 = S(S(8)), by def of S(7)
                 = S(9), by def of S(8)
                 = 10, by def of S(9)


Next lecture…


Text copyright © 2010 by William J. Rapaport (rapaport@buffalo.edu)
Cartoon links and screen-captures appear here for your enjoyment. They are not meant to infringe on any copyrights held by the creators. For more information on any cartoon, click on it, or contact me.
http://www.cse.buffalo.edu/~rapaport/191/F10/lecturenotes-20101115.html-20101117