A method for proving properties of recursive structures.
Advice for Homework 6
Start early, start early, start early, …
Homework 6 has fewer problems but …
You may find it to be more work than the previous assignments.
So please start early :)
Pay special attention to Problem 6.5.
Requires keeping careful track of
(1) what you know and
(2) what you need to prove.
You will have to be methodical and meticulous.
Details will make or break this proof.
Before starting to work on this problem, we strongly advise you to write out
the set $T_t$ for $t\in \{1, 2, 3, 4\}$. Then, calculate $\mathcal{P}(T_t)$ and
$S_t$ for each $T_t$. From this, you will be able to guess the answer for part
(a), which you can then prove. You will also convince yourself that the theorem
you need to prove for (b) is true!
When the recursive case refers only to $f(n)$, as in these examples,
we can prove properties of $f(n)$ easily using ordinary induction.
Recursively defined functions with multiple base cases
A recursive function can have more than one base case.
Base cases give the value of $f(0), \ldots, f(m)$ where $m\geq 0$.
Recursive case defines $f(n+1)$ in terms of $f(n-m), \ldots, f(n-1), f(n)$ for all $n\geq m+1$, or it defines $f(n)$ in terms of $f(n-1-m), \ldots, f(n-1)$.
Example: Fibonacci numbers
$f_0 = 0$
$f_1 = 1$
$f_n = f_{n-1} + f_{n-2} \text{ for all } n\geq 2$
When the recursive function has multiple base cases, we use strong induction
to prove its properties. And we also extend the strong induction
proof template to account for the additional base cases.
Strong inductive proofs with base cases $b, \ldots, b+m$
① Let $P(n)$ be [ definition of $P(n)$ ].
We will show that $P(n)$ is true for every integer $n\geq b$ by strong induction.
② Base cases ($n = b$$, \ldots, n=b+m$):
[ Proof of $P(b)$$, \ldots, P(b+m)$. ]
③ Inductive hypothesis:
Suppose that for some arbitrary integer $k\geq b+m$, $P(j)$ is true for every integer $b \leq j \leq k$.
④ Inductive step:
We want to prove that $P(k+1)$ is true.
[ Proof of $P(k+1)$. The proof must invoke the strong inductive hypothesis. ]
⑤ The result follows for all $n\geq b$ by strong induction.
Recursively defined sets
Recursive definitions of sets.
Giving a recursive definition of a set
A recursive definition of a set $S$ has the following parts:
Basis step specifies one or more initial members of $S$.
Recursive step specifies the rule(s) for constructing new elements of $S$ from the existing elements.
Exclusion (or closure) rule states that every element in $S$ follows from the basis step and a finite number of recursive steps.
The exclusion rule is assumed, so no need to state it explicitly.
Examples of recursively defined sets
Natural numbers
Basis: $0\in S$
Recursive: if $n\in S$, then $n+1\in S$
Even natural numbers
Basis: $0\in S$
Recursive: if $x\in S$, then $x + 2\in S$
Powers of 3
Basis: $1\in S$
Recursive: if $x\in S$, then $3x\in S$
Fibonacci numbers
Basis: $(0,0)\in S, (1,1)\in S$
Recursive: if $(n-1,x)\in S$ and $(n-2,y)\in S$, then $(n,x+y)\in S$
More examples of recursively defined sets
Strings
An alphabet $\Sigma$ is any finite set of characters.
The set $\Sigma^* $ of strings over the alphabet $\Sigma$ is defined as follows.
Basis: $\varepsilon \in \Sigma^* $, where $\varepsilon$ is the empty string.
Recursive: if $w\in\Sigma^* $ and $a\in\Sigma$, then $wa\in\Sigma^* $
Palindromes (strings that are the same forwards and backwards)
Basis: $\varepsilon\in S$ and $a\in S$ for every $a\in\Sigma$
Recursive: if $p\in S$, then $apa\in S$ for every $a\in\Sigma$
All binary strings with no 1’s before 0’s
Basis: $\varepsilon\in S$
Recursive: if $x\in S$, then $0x\in S$ and $x1\in S$
Functions on recursively defined sets
Length
$\op{len}(\varepsilon) = 0$
$\op{len}(wa) = \op{len}(w) + 1$ for $w\in\Sigma^* $, $a\in\Sigma$
Reversal
$\varepsilon^{\op{R}} = \varepsilon$
$(wa)^{\op{R}} = aw^{\op{R}}$ for $w\in\Sigma^* $, $a\in\Sigma$
Concatenation
$x\bullet \varepsilon = x$ for $x\in\Sigma^* $
$x\bullet (wa) = (x\bullet w)a$ for $x,w\in\Sigma^* $, $a\in\Sigma$
A method for proving properties of recursive structures.
How can we prove properties of recursive structures?
Suppose that $S$ is a recursively defined set.
And we want to prove that every element of $S$ satisfies a predicate $P$.
Can we use ordinary induction to prove $\forall x\in S. P(x)$?
Yes! Define $Q(n)$ to be “for all $x\in S$ that can be constructed in at most $n$ recursive steps, $P(x)$ is true.”
But this proof would be long and cumbersome to do!
So we use structural induction instead.
Follows from ordinary induction (on $Q$), while providing a more convenient proof template for reasoning about recursive structures.
As powerful as ordinary induction, which is just structural induction applied to the recursively defined set of natural numbers.
Proving $\forall x\in S. P(x)$ by structural induction
① Let $P(x)$ be [ definition of $P(x)$ ].
We will show that $P(x)$ is true for every $x\in S$ by structural induction.
② Base cases:
[ Proof of $P(s_0), \ldots, P(s_m)$. ]
③ Inductive hypothesis:
Assume that $P(y_0), \ldots, P(y_k)$ are true for some arbitrary $y_0, \ldots, y_k \in S$.
④ Inductive step:
We want to prove that $P(y)$ is true.
[ Proof of $P(y)$. The proof must invoke the structural inductive hypothesis. ]
⑤ The result follows for all $x\in S$ by structural induction.
Recursive definition of $S$
Basis step: $s_0\in S, \ldots, s_m\in S$.
Recursive step:
if $y_0, \ldots, y_k\in S$, then $y\in S$.
If the recursive step of $S$ includes multiple rules for constructing new elements from existing elements, then
③ assume $P$ for the existing elements in every rule, and
④ prove $P$ for the new element in every rule.
Summary
To define a function recursively, specify its base case(s) and recursive case.
Use (strong) induction to prove theorems about recursive functions.
To define a set recursively, specify its basis and recursive step.
Recursive set definitions assume the exclusion rule.
We use recursive functions to operate on elements of recursive sets.
Use structural induction to prove properties of recursive structures.
Structural induction follows from ordinary induction but is easier to use.