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.
Using structural induction
Example proofs about recursively defined numbers, strings, and trees.
Prove that every $x\in S$ is divisible by 3
① Let $P(x)$ be $3 \vert x$.
We will show that $P(x)$ is true for every $x\in S$ by structural induction.
② Base cases ($x=6$, $x=15$):
$3 \vert 6$ so $P(6)$ holds, and $3 \vert 15$ so $P(15)$ holds.
③ Inductive hypothesis:
Assume that $P(x), P(y)$ are true for some arbitrary $x,y \in S$.
④ Inductive step:
We want to prove that $P(x+y)$ is true.
By the inductive hypothesis, $3\vert x$ and $3\vert y$, so $x = 3i$ and $y = 3j$ for some $i,j\in\Z$.
Therefore, $x + y = 3i + 3j = 3(i+j)$ so $3\vert (x+y)$.Hence, $P(x+y)$ is true.
⑤ The result follows for all $x\in S$ by structural induction.
Define $S$ by
Basis: $6\in S$, $15\in S$.
Recursive: if $x,y\in S$, then $x+y\in S$.
Prove $\op{len}(x\bullet y) = \op{len}(x) + \op{len}(y)$ for all $x,y\in\Sigma^* $
What object ($x$ or $y$) to do structural induction on?
① Let $P(y)$ be $\forall x\in\Sigma^* . \op{len}(x\bullet y) = \op{len}(x) + \op{len}(y)$.
We will show that $P(y)$ is true for every $y\in \Sigma^* $ by structural induction.
② Base case ($y=\varepsilon$):
For every $x\in \Sigma^* $, $\op{len}(x\bullet \varepsilon)$ $=$ $\op{len}(x)$ $=$ $\op{len}(x) + \op{len}(\varepsilon)$ since $\op{len}(\varepsilon) = 0$. So $P(\varepsilon)$ is true.
③ Inductive hypothesis:
Assume that $P(w)$ is true for some arbitrary $w \in \Sigma^* $.
④ Inductive step:
We want to prove that $P(wa)$ is true for every $a\in\Sigma$.
Let $a\in\Sigma$ and $x\in\Sigma^* $ be arbitrary. Then
So $\op{len}(x\bullet wa)=\op{len}(x) + \op{len}(wa)$ for all $x\in\Sigma^* $, and $P(wa)$ is true.
⑤ The result follows for all $y\in \Sigma^* $ by structural induction.
Define $\Sigma^* $ by
Basis: $\varepsilon \in \Sigma^* $.
Recursive:
if $w\in\Sigma^* $ and $a\in\Sigma$,
then $wa\in\Sigma^* $
Length
$\op{len}(\varepsilon) = 0$
$\op{len}(wa) = \op{len}(w) + 1$
Concatenation
$x\bullet \varepsilon = x$
$x\bullet (wa) = (x\bullet w)a$
Prove $\Size{t}\leq 2^{\Height{t}+1}-1$ for every rooted binary tree $t$
① Let $P(t)$ be $\Size{t}\leq 2^{\Height{t}+1}-1$.
We will show that $P(t)$ is true for every $t\in S $ by structural induction.
② Base case ($t=\Node$):
$\Size{\Node} = 1 = 2^1 - 1 = 2^{0+1}-1 = 2^{\Height{\Node}+1}-1$ so $P(\Node)$ is true.
③ Inductive hypothesis:
Assume that $P(L)$ and $P(R)$ are true for some arbitrary $L, R \in S$.
④ Inductive step:
We want to prove that $P(\Tree(\Node,L,R))$ is true.
⑤ The result follows for all $t\in S$ by structural induction.