Lecture 28: Structural induction, languages

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.



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):

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 e1 and e2 in the e1 + e2 rule could be arbitrary elements of the set E, 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.


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.


Language of a Machine

Extended transition function (Note: because this doesn't render nicely in HTML, I will write δ^ for "delta-hat")

Language - A language is a set of strings

Language of a machine - L(M) stands for the "language of M". - contains all (and only) strings that M accepts - Informally, a string x is accepted by a machine M if, after processing x starting at the start state, the machine ends in a final state. - formal definition: L(M)={x ∈ Σ*  |  δ^(q0, x)∈F}, where M = (Q, Σ, δ, q0, F). - We say x is accepted by M if x ∈ L(M), x is rejected otherwise. - We say that M recognizes L if L = L(M). - A language L is DFA-recognizable if there is some machine M with L = L(M).

Proof of correctness of an automaton

Given a language L, we may wish to build a machine that recognizes L, and prove that it is correct.

In other words, we wish to prove that L = L(M).

In other words, we wish to prove that x ∈ Σ*, x ∈ L if and only if x ∈ L(M).

In other words, we wish to prove that x ∈ Σ*, x ∈ L if and only if δ^(q0, x)∈F.

A straightforward approach is induction on the structure of x; however the induction hypothesis usually needs to be strengthened to describe all of the states (and not just the final state); essentially you want to prove that each state "satisfies its specification".

For example: we may want to build a machine that recognizes strings that contain at least two ones. We might build a machine with three states: q0 represents strings with no 1's, q1 represents strings with one 1, and q2 represents strings with two or more 1's. automaton with 3 states

A proof of correctness for this machine might go as follows:

Let P(x) be the statement "δ^(q0, x)=q0 if and only if x has no 1s, and δ^(q0, x)=q1 if and only if x has exactly one 1, and δ^(q0, x)=q2 if and only if x has two or more 1's. I claim that x ∈ Σ*, P(x) holds.

We will prove this claim by induction on the structure of x. We must show P(ε) and, assuming P(x), P(xa).

To prove P(ε), note that δ^(q0, ε)=q0. Thus only the first part of P(x) makes any claim (it is vacuously true that if δ^(q0, ε)=q1, then ε contains one 1, because the statement says nothing).

Now, to prove P(xa), assume P(x). a can be either 0 or 1, and δ^(q0, x) could be any of q0, q1, and q2. We consider each case:

  1. If a = 0, then note that δ(qi, a)=qi. Moreover, note that xa has the same number of 1's as x. Thus in this case, P(xa) follows directly from P(x).

  2. If a = 1 and δ^(q0, x)=q0, then by P(x), x must have no 1's. Thus xa has exactly one 1. Moreover, δ^(q0, xa)=δ(δ^(q0, x),a)=δ(q0, 1)=q1, so $P(xa) holds in this case.

  3. If a = 1 and δ^(q0, x)=q1, then by $P(x), x must have one
  4. Thus xa has two ones. Moreover, δ^(q0, xa)=δ(δ^(q0, x),a)=δ(q1, 1)=q2, so $P(xa) holds in this case.

  5. If a = 1 and δ^(q0, x)=q2, then by $P(x), x must have two or more 1's. Thus xa has more than two ones. Moreover, δ^(q0, xa)=δ(δ^(q0, x),a)=δ(q2, 1)=q2, so $P(xa) holds in this case.

In all possible cases, we have shown P(xa). This concludes the inductive proof.

Note that the framework provided by the inductive proof forces you to write down a specification for each state, and then reason about each transition.