... Finite Automata ∗. Peter Cappello ... ∗Based on An Introduction to Formal
Languages and Automata, 3rd Ed., Peter Linz, Jones and Bartlett. Publishers, Inc.
1 ...
Chapter 2: Finite Automata ∗ Peter Cappello Department of Computer Science University of California, Santa Barbara Santa Barbara, CA 93106
[email protected]
• Please read the corresponding chapter before attending this lecture. • These notes are not intended to be complete. They are supplemented with figures, and material that arises during the lecture period in response to questions. Based on An Introduction to Formal Languages and Automata, 3rd Ed., Peter Linz, Jones and Bartlett Publishers, Inc. ∗
1
2.1 Deterministic Finite Acceptors Deterministic Acceptors & Transition Graphs
Defn. 2.1 A deterministic finite acceptor (DFA) is defined by a 5-tuple M = (Q, Σ, δ, q0, F ), where Q is a finite set of states, Σ is a finite alphabet, δ : Q × Σ 7→ Q is a total function called the state transition function, q0 ∈ Q is the initial state, F ⊆ Q is a set of final states.
2
(Illustrate the operation of a DFA; see Java code for generic DFA.) A transition graph (TG) is an alternate specification of a DFA: • For each q ∈ Q, construct a node in the transition graph labelled q. • For each δ(q, a) = q 0, construct an arc from the node labelled q to the node labelled q 0, labelled a. • Distinguish the initial state with in incoming arc. • Signify final states with a double circle. Draw the transition graph that corresponds to the following DFA specification: M = ({q0 , q1, q2}, {0, 1}, δ, q0 , {q0}), where δ is given by Table 1: Notation: λ is the string of 0 symbols.
3
δ 0 q0 q0 q1 q1 q2 q2
1 q1 q2 q2
Table 1: Specification for a simple DFA.
Σ∗ = {all finite strings over Σ, including λ}. Σ+ = Σ∗ − {λ}. We introduce the extended transition function, δ ∗ : Q × Σ∗ 7→ Q : δ ∗(q, λ) = q, δ ∗(q, wa) = δ(δ ∗(q, w), a) for all q ∈ Q, w ∈ Σ∗, a ∈ Σ.
4
(1) (2)
Heuristic: If an object is defined recursively, prove its properties by induction. (Illustrate δ ∗ using the transition graph corresponding to Table 1.) Languages & Dfa’s
Defn. 2.2 The language accepted by a DFA M = (Q, Σ, δ, q0, F ), denoted L(M ), is {w ∈ Σ∗ : δ(q0, w) ∈ F }. Observe that L(M ) = Σ∗ − L = {w ∈ Σ∗ : δ(q0, w) ∈ / F }. (Illustrate notation for labelling 1 arc in a TG with multiple symbols in Σ.) (Give a simple DFA; ask what language it accepts.) (Illustrate a dead state aka trap state.)
5
Custom: When an arc from a TG node is missing (for 1 or more symbols) from a node, it is implicit that such transitions are to an implicit dead state.) Give a transition graph for {01n : n ≥ 0}. Thm. 2.1 Let M = (Q, Σ, δ, q0, F ) be a DFA, and let GM be its associated TG. Then, ∀q, q 0 ∈ Q and w ∈ Σ+, δ ∗(q, w) = q 0 ⇔ ∃ a [q, q 0] path in GM labelled w. Proof We prove this by induction on |w|. Basis: If w ∈ Σ, then, by the construction of GM , δ ∗(q, w) = δ(q, w) = q 0 ⇔ the TG has an arc labelled w from the node labelled q to the node labelled q 0. Induction hypothesis: Assume, when |w| = n that ∀q, q 0 ∈ Q and w ∈ Σ+, δ ∗(q, w) = q 0 ⇔ ∃ a [q, q 0] path in GM labelled w.
6
Induction step: We now show, when |w| = n + 1 that ∀q, q 0 ∈ Q and w ∈ Σ+, δ ∗(q, w) = q 0 ⇔ ∃ a [q, q 0] path in GM labelled w. Let w = va, where |v| = n and a ∈ Σ. By the induction hypothesis, ∀q, q 00 ∈ Q, δ ∗(q, v) = q 00 ⇔ ∃ a [q, q 00] path in GM labelled v. Let p = δ ∗(q, v). Then, by the induction hypothesis, the TG has an arc labelled v from the node labelled q to the node labelled p. Case δ(p, a) = q 0: δ ∗(q, w) = δ(δ ∗(q, v), a) = δ(p, a) = q 0 and the TG has an arc labelled v from the node labelled q to the node labelled p, and, by construction of the GM , there is an arc labelled a from the node labelled p to the node labelled q 0.
7
Case δ(p, a) 6= q 0: δ ∗(q, w) = δ(δ ∗(q, v), a) = δ(p, a) 6= q 0 and the TG has an arc labelled v from the node labelled q to the node labelled p, and, by construction of the GM , there is no arc labelled a from the node labelled p to the node labelled q 0. This completes the proof by induction on |w|. Problem: Give a TG for: 1. {w ∈ {0, 1, 2}∗ : w.#(0) ≡ 1 mod 2}. 2. {w ∈ {0, 1, 2}∗ : w.#(0) ≡ 1 mod 2 and w.#(1) ≡ 0 mod 2}. 3. {w ∈ {0, 1, 2}∗ : w.#(0) ≡ 1 mod 2 and w.#(1) ≡ 0 mod 2 and w.#(2) ≡ 1 mod 3}.
8