# Lecture 30: Structural induction

• Inductively defined sets
• BNF
• Inductively defined functions
• Proofs by structural induction

## Inductively defined sets

An inductively defined set is a set where the elements are constructed by a finite number of applications of a given set of rules.

Examples:

• the set N of natural numbers is the set of elements defined by the following rules:
1. 0 ∈ N
2. If n ∈ N then Sn ∈ N.

thus the elements of N are {0, S0, SS0, SSS0, …}. S stands for successor. You can then define 1 as S0, 2 as SS0, and so on.

• the set Σ  *  of strings with characters in Σ  is defined by
1. ε ∈ Σ  *
2. If a ∈ Σ  and x ∈ Σ  *  then xa ∈ Σ  * .

thus the elements of Σ  *

• the set RE of regular expressions with characters in Σ  is defined by
1. ε ∈ RE
2. ∅ ∈ RE
3. if a ∈ Σ  then a ∈ RE
4. if r1 ∈ RE and r2 ∈ RE then r1r2 ∈ RE
5. if r1 ∈ RE and r2 ∈ RE then r1 + r2 ∈ RE
6. if r ∈ RE then r *  ∈ RE

## BNF

Compact way of writing down inductively defined sets: BNF (Backus Naur Form)

Only the name of the set and the rules are written down; they are separated by a "::=", and the rules are separated by vertical bar ().

Examples (from above):

• n ∈ N: :  = 0∣Sn

• x ∈ Σ  * : :  = εxa
a ∈ Σ

• r ∈ RE: :  = ε∣∅∣ar1r2r1 + r2r *
a ∈ Σ

Here, the variables to the left of the  ∈  indicate metavariables. When the same characters appear in the rules on the right-hand side of the : :  = , they indicate an arbitrary element of the set being defined. For example, the r1 and r2 in the r1 + r2 rule could be arbitrary elements of the set RE, but  +  is just the symbol  + .

## Inductively defined functions

If X is an inductively defined set, you can define a function from X to Y by defining the function on each of the types of elements of X; i.e. for each of the rules. In the inductive rules (i.e. the ones containing the metavariable being defined), you can assume the function is already defined on the subterms.

Examples:

• plus: N × N→N given by plus: (0, n)↦n and plus: (Sn, nʹ)↦S(plus(n, nʹ)). Note that we don't need to use induction on both of the inputs.

• L: RE→2Σ  *
• δ̂: Q × Σ  * Q

## Proofs by structural induction

If X is an inductively defined set, then you can prove statements of the form ∀ x ∈ X, P(x) by giving a separate proof for each rule. For the inductive/recursive rules (i.e. the ones containing metavariables), you can assume that P holds on all subexpressions of x.

Examples:

• Proof that M is correct (see homework solutions) can be simplified using structural induction

• Proof that every regular expression has an equivalent NFA is a structural induction proof.

• A proof by structural induction on the natural numbers as defined above is the same thing as a proof by weak induction. You must prove P(0) and also prove P(Sn) assuming P(n).