building and reasoning about DFAs
When building a DFA, it is helpful to write down a condition associated with each state. For example, suppose we wanted to build a machine that recognizes strings starting with "11". We might build the machine to the right (click for LaTeX source):
How does this machine work? Well, we know that if processing x ends in state q1, then x must be the empty string. Similarly, the only string that gets to q2 is "1". Similarly, any string that starts with "0" or "10" ends in q4; so in order to get to state q3, the string must start with "11".
When building an automaton, associate a fact with each state. You can then check that each transition is correct by assuming that the string without the last character satisfies the property correspoinding to the start of the transition, and then proving that the string with the last character satisfies the property of the target of the transition.
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:
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.
thus the elements of Σ * are {ε, ε0, ε1, ε00, ε01, …, ε1010101, …}. we usually leave off the ε at the beginning of strings of length 1 or more.
thus the elements of T are things like the picture to the right (click for tex), which might be written textually as node(3, node(0, nil, nil), node(1, node(2, nil, nil), nil))
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 ∈ Σ
t ∈ T: : = nil ∣ node(a, t1, t2)
a ∈ Z
(basic mathematical expresssions)
e ∈ E: : = n ∣ e1 + e2 ∣ e1 * e2 ∣ − e ∣ e1 / e2
n ∈ Z
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 + .
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:
add2: N→N is given by add2: 0↦SS0 and add2: Sn↦S(add2(n)).
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.
δ̂: Q × Σ * →Q
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
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).