Recursive Definitions & Structural Induction

Textbook
Rosen 8e, Section 5.3
Study day
Friday, Nov 6
Homework
Written HW 6: 1, 3, 7, 9–11, 13, 22–27, 31, 33–46, 50–57
Progress
Notes not read 0 / 38 problems graded

A recursive definition has two parts: a basis step (starting values or elements) and a recursive step (how to build new ones from old ones). Structural induction is how you prove things about objects defined this way.

Recursively defined functions

Recursive function on
  • Basis step: give (or the first few values).
  • Recursive step: give a rule for in terms of earlier values.
From class: for , expressed recursively

Basis: . Recursive rule: for .

Explicit formula → recursive definition

Ask: how do I get from ?

Explicit Recursive step Basis
(arithmetic)
(geometric)

Always state the basis. A recursive rule without a starting value defines nothing.

Computing values

Make a table and fill it in order: Each value only uses ones you have already written down. With two previous terms (like Fibonacci) you need two starting values.

Fibonacci numbers

, , and for .

0 1 2 3 4 5 6 7 8
0 1 1 2 3 5 8 13 21

Recursively defined sets

Recursive set
  • Basis step: list the initial elements.
  • Recursive step: rules that build new elements from elements already in the set.
  • Exclusion rule (implicit): nothing else is in the set.
From class: ; if then

Generate: , then , then , … so , the positive multiples of 5. (Proving this takes two inclusions. See Structural induction below.)

Writing a recursive definition for a set of integers

Find the period of the pattern. The basis lists one "block" of elements; the recursive step adds the period.

Set Basis Recursive step
Positive multiples of 5
Odd positive integers
Positive integers not divisible by 7
All even integers (incl. negatives)
Positive powers of 3

If the set includes negative numbers, you need a rule that goes down too.

Strings

Strings over an alphabet
  • is the empty string (no characters).
  • (the Kleene closure) is the set of all strings over , defined recursively: ; if and then .
  • Concatenation is " followed by ." It is not commutative: but . For every string, .

Convention: are symbols; are strings.

Recursive functions on strings (the pattern: say what gives, then what adding one symbol does)
Function Basis Recursive step (, )
length
number of 1s, bit strings , for
number of 0s, bit strings
reversal
power
Recursive sets of strings
Set Basis Recursive step
Palindromes (bit strings)

Well-formed formulae

Formulas are defined recursively too: the basis gives the atoms, the recursive step gives the operators with parentheses.

  • Propositional logic: Basis: , , and every propositional variable. Recursive: if are wffs, so are , , , , .
  • Arithmetic: Basis: every numeral and variable. Recursive: , , , , .
  • Sets: Basis: every set or set variable. Recursive: , , , .

Full binary trees

Full binary tree
  • Basis: a single vertex is a full binary tree.
  • Recursive: if are disjoint full binary trees, then (a new root with left subtree and right subtree ) is a full binary tree.
Tree functions to memorize
Basis (single root) Recursive ()
height
vertices
leaves
internal vertices

Facts (all proved by structural induction): , , .

Structural induction

Structural induction

To prove a property holds for every element of a recursively defined set:

  1. Basis step: show it holds for every element given in the basis.
  2. Recursive step: assume it holds for the elements used in a recursive rule (this is the IH). Show it holds for the new element built from them. Do this for every recursive rule.
Structural induction templates

Integers / sets: Basis: check the listed elements. Step: "Assume (and ) have the property; show (or , , …) does too."

Strings: Basis: prove . Step: assume , prove for every .

Full binary trees: Basis: prove it for the single-vertex tree. Step: assume it for and , prove it for using the recursive formulas for , , , .

Proving a recursive set equals a described set

To show , prove both inclusions.

From class: ; if then . Prove .
Proof

Part 1: (ordinary induction on ). Let : .

  • Basis: by the basis step.
  • Step: if , then since too, the recursive step gives .

Part 2: (structural induction).

  • Basis: .
  • Step: assume are in , so and . Then and , so .

By Parts 1 and 2, . ∎

From class (textbook Example 12): for all strings
Proof

Fix and use structural induction on . Let : .

Basis (): .

Recursive step. Assume . For any :
∎

Every element of has property (the "mod" pattern, 5.3 #26/#27 style)

: ; if then and . Show every satisfies .

Proof

Basis: .
Recursive step: Assume . Then and . Both new elements have the property. ∎

Showing the converse fails: , but , is not for an integer , and is not a perfect square. So .

Common mistakes
  • Only checking one of the recursive rules. Every rule needs its own case.
  • In the basis for strings, the case is , the empty string.
  • Using structural induction for the "" direction. That direction is usually ordinary induction (show each element of can be built).

Ackermann's function (this book's version)

Definition. Memorize the four cases exactly.

Useful facts: for , for , and (a tower of twos).

Evaluating Ackermann

Always expand the inner argument first. Example: .

Fixes to your class notes
  • "Clean closure" should be Kleene closure ().
  • The identity for the empty string is . Your notes wrote .
  • In the proof of , the basis case is , not .

Exam checklist

  • Compute values of a recursively defined function (including two-term recurrences and Ackermann).
  • Convert an explicit formula or a described set into a recursive definition.
  • Describe the set produced by a recursive definition.
  • Give recursive definitions on strings (length, ones, reversal, powers, palindromes).
  • Write a structural induction proof (sets, strings, full binary trees), handling every rule.
  • Prove via two inclusions.
Go to problems