Inductive Definition and Structural Induction Class Notes To - - PDF document

inductive definition and structural induction
SMART_READER_LITE
LIVE PREVIEW

Inductive Definition and Structural Induction Class Notes To - - PDF document

Inductive Definition and Structural Induction Class Notes To explain what are inductive definitions and structural induction, we start with, in section 1, a simple abstractionthe natural numbers. And then in section 2, we show how to deploy


slide-1
SLIDE 1

Inductive Definition and Structural Induction

Class Notes

To explain what are inductive definitions and structural induction, we start with, in section 1, a simple abstraction—the natural numbers. And then in section 2, we show how to deploy these techniques into data structure design and algorithm analysis, via one concrete example: linked list.

1 Natural Numbers

Given the informal definitions of a natural number: a natural number is either:

  • 1. zero; or
  • 2. a natural number following another natural number.

we can write it in an inductive definition form: n → Zero → Succ n Given this inductive definition, we write a mapping function f from a given natural number n to an integer: f(n) =

  • 0,

if n = Zero; 1 + f(m), if n = Succ m. note that function f is also inductively defined. Just like ordinary integers, we can also define operations on natural num-

  • bers. Here is the definition of addition:

n1 ⊕ n2 =

  • n2,

if n1 = Zero; Succ (m ⊕ n2), if n1 = Succ m. Given the inductive definitions for natural numbers and the addition op- erations, we can now prove the 1

slide-2
SLIDE 2

Thm 1: f(n1 ⊕ n2) = f(n1) + f(n2).

  • Proof. Induction on n1.

Case Zero left = f(Zero ⊕ n2) = f(n2). right = f(Zero) + f(n2) = 0 + f(n2) = f(n2). Case Succ m left = f(Succ m ⊕ n2) = f(Succ (m ⊕ n2)) = 1 + f(m ⊕ n2) = 1 + f(m) + f(n2). right = f(Succ m) + f(n2) = 1 + f(m) + f(n2). QED. By making use of addition, we can define multiplication on two natural numbers n1 and n2: n1 ⊗ n2 =

  • Zero,

if n1 = Zero; n2 ⊕ (m ⊗ n2), if n1 = Succ m. It is left an exercise to prove that Thm 2: f(n1 ⊗ n2) = f(n1) × f(n2). As a final example, we define an equality testing function on two natural numbers n1 and n2: n1 n2 =          Succ Zero, if n1 = Zero ∧ n2 = Zero; Zero, if n1 = Zero ∧ n2 = Succ m; Zero, if n1 = Succ m ∧ n2 = Zero; s t, if n1 = Succ s ∧ n2 = Succ t. It is also left as an exercise to prove Thm 3: f(n1 n2) = (f(n1) = f(n2)). 2

slide-3
SLIDE 3

2 Linked List

The real power of inductive definitions and structural induction is in that it can be used to define a rather large set of useful data structures, say, linked list, binary trees, red-black trees, and so on. In this section, we illustrate the main idea by studying an inductively defined linked list. Informal description: a linked list is either

  • 1. an empty list without any data; or
  • 2. a linked list with a head node, followed by another linked list.

And write into inductive definition form: list → Empty → Cons (T, list) We can define a function f on list l: f(l) =

  • 0,

if l = Empty; 1 + f(m), if l = Cons (x, m). intuitively, f counts the length of the list l. To concatenate two lists l1 and l2, we write another inductively defined function g: g(l1, l2) =

  • l2,

if l1 = Empty; Cons (x, g(m, l2)), if l1 = Cons (x, m). Intuitively, list concatenation does not change the list length, this fact is represented by Thm 4: f(g(l1, l2)) = f(l1) + f(l2).

  • Proof. By induction on l1.

Case Empty left = f(g(Empty, l2)) = f(l2). right = f(Empty) + f(l2) = f(l2). 3

slide-4
SLIDE 4

Case Cons (x, m) left = f(g(Cons (x, m), l2)) = f(Cons (x, g(m, l2))) = 1 + f(g(m, l2)) = 1 + f(m) + f(l2) right = f(Cons (x, m)) + f(l2) = 1 + f(m) + f(l2). QED. As a final example, if we reverse a linked list by function f: h(l) =

  • Empty,

if l = Empty; g(h(m), Cons (x, Empty)), if l = Cons (x, m). then we can prove Thm 5: f(h(l)) = f(l). Proof left to you. 4