Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1
9/8/10
Example Example
2
9/8/10
Example
Different Kinds of Automata
temporary memory
x=2
CPU
f(x) = 8
Compute x*x
Compute x2*x
10
X
temporary memory Stack!
3
9/8/10
Power of Automata
Turing Machine
Random
access
memory!
input memory
CPU Less power More power
output memory
Solve more computational problems
Program memory
14
4
9/8/10
Transition Diagram
Operation
• FA is always is one of the n states, which we name 0
through n-1 • Represent visually by a graph:
– Each state is labeled true (“yes”) or false (“no”) – nodes = states
• Begins in the start state – arc from q to p is labeled by the set of input
• As the input characters are read in one at a time, symbols a such that δ(q, a) = p
changes from one state to another in a pre-specified – No arc if no such a
way
– new state is completely determined by the current state and the
– Start state indicated by word "start" and an
character just read in arrow
• When input is exhausted, outputs true (yes, the string is – Accepting states get double circles
in the language) or false (no, the string is not in the
language) according to the label of the state it is
currently in
5
9/8/10
quarter!
dime! dime! dime,!
dime! quarter!
start!
quarter!
6
9/8/10
Conventions
Model as an FA
HH: Flip first coin
a HH: Flip second coin
• It helps if we can avoid mentioning the
start
HH
TH
TH: Flip first coin
type of every name by following some
a
TH: Flip second coin rules:
b b b b – Input symbols are a, b, etc., or digits.
HT: Flip first coin
HT: Flip second coin – Strings of input symbols are u, v, . . . , z.
a – States are q, p, etc.
HT
TT
TT: Flip first coin
a TT: Flip second coin
Final state
7
9/8/10
8
9/8/10
9
9/8/10
Example
1,2,3
q
• Design an NFA to accept strings over alphabet 1
1
{1, 2, 3} such that the last symbol appears 1
previously, without any intervening higher p
symbol, e.g., r
t
2
2
• … 11
• … 21112
• … 312123
3
3
– Trick: use start state to mean "I guess I haven't seen
the symbol that matches the ending symbol yet." s
– Three other states represent a guess that the matching
symbol has been seen, and remembers what that
symbol is. 1,2
10
9/8/10
Formal NFA
Example
• N = (Q, Σ, δ, q0, F) where all is as DFA, but: Here is a DFA that accepts a language L
– δ(q, a) is a set of states, rather than a single state.
consisting of all strings over Σ(a,b) that
• Extension to begin with either aa or bb
– Basis: (q, ε) = {q}.
– Induction: Let: a
• (q, w) = {p1, p2, …, pk}. 1
36
1,2
a
• δ (pi, a) = Si for i = 1, 2 … , k. b
a,b
• Then (q, wa) = S1 ∪ S2 ∪ … ∪ Sk.
0
4
• Language of an NFA a,b
– An NFA accepts w if any path from the start state to an b
a
accepting state is labeled w. Formally:
L(N) = {w | (q0, w) ∩ F ≠ Φ }.
2
t
5
b
a,b
11
9/8/10
Proof
Proof Idea • Let N = (Q,Σ,δ,q0,F) be an NFA recognizing some language A
• Construct a DFA recognizing A
• If a language is recognized by an NFA, – M = (Q’,Σ,δ’,q0’,F’)
show the existence of a DFA that also 1. Q’ = the set of subsets of N
recognizes it 2. For R ∈ Q’ and a ∈ Σ let δ’(R,a) = {q ∈ Q | q ∈ δ(r,a) for some r
∈ R
• Convert NFA to an equivalent DFA that – If R is a state of M, it is also a set of states of N (because of 1 above). When
M reads a symbol a in a state R, it shows where a takes each state in R.
simulates the NFA Because each state may go to a set of states, we take the union of all these
sets. This can be written as:
– Proof by construction
!' (R, a) = U! (r, a)
• Intuitively, can simulate the NFA by – q0={q0}
r"R
keeping track of all the states you can get • M starts in the state corresponding to the collection containing just the start state of
N.
to on a given input – F’ = {R ∈ Q’|R contains an accept state of N}.
• The machine M accepts if one of the possible states that N could be in at this point
is an accept state.
12
9/8/10
1,2,3
q
NFA With ε-Transitions
1
1
1
• Allow ε to be a label on arcs
p
r
t
– Nothing else changes: acceptance of w is still the
2
2
existence of a path from the start state to an
accepting state with label w.
3
– But ε can appear on arcs, and means the empty
3
string (i.e., no visible contribution to w)
s
– When an arc labeled ε is traversed, no input is
consumed
1,2
13
9/8/10
Example
0
DFAs and NFA-ε’s
• ε-transitions are a convenience, but do
1
ε
not increase the power of FA's.
q
r
s
• For any NFA-ε there is an equivalent
0
ε
(i.e., accepts the same language) DFA
• The construction is similar to the NFA-to-
1
DFA construction
ε ε
001 is accepted by the path q, s, r, q, r, s, with label 0 01 = 001.
Example 0
Creating a DFA from a NFA-ε
(or, eliminating ε-transitions) 1
1. Compute ε-closure for all states: q
r
ε
s
ECLOSE(q) = {q}
1. Compute the ε-closure for each state (set of states ECLOSE(r) = {r,s}
ECLOSE(s) = {r,s}
0
ε
reachable from that state on ε-transitions only).
2. Compute δ: 1
2. Start state is ε-CLOSE(q0).
δ({q},0) = ECLOSE({s})={r,s}
3. Compute δ for each a ∈ Σ and each set S (each of δ({q},1) = ECLOSE({r})={r,s}
the ε-CLOSE’d sets) as follows: δ({r,s},0) = ECLOSE({q})={q}
δ({r,s},1) = ECLOSE({q})={q}
If a state p ∈ S can reach state q on input a (not ε), then
RESULTING DFA:
add a transition on input a from S to ε-CLOSE(q).
3. Final states FD ={{r,s}}
0,1
4. The set of final states includes those sets that q r,s
14