T ak es a state and input sym b ol as argumen ts. - - PDF document

t ak es a state and input sym b ol as argumen ts returns
SMART_READER_LITE
LIVE PREVIEW

T ak es a state and input sym b ol as argumen ts. - - PDF document

F ormal Deniti on of Finite Automaton 1. Finite set of states , t ypically Q . 2. Alphab et of input symb ols , t ypically . 3. One state is the start/initial state, t ypically q . 0 4. Zero or more


slide-1
SLIDE 1 F
  • rmal
Deniti
  • n
  • f
Finite Automaton 1. Finite set
  • f
states, t ypically Q. 2. Alphab et
  • f
input symb
  • ls,
t ypically . 3. One state is the start/initial state, t ypically q . 4. Zero
  • r
more nal/ac c epting states; the set is t ypically F . 5. A tr ansition function, t ypically
  • .
This function:

T ak es a state and input sym b
  • l
as argumen ts.

Returns a state.

One \rule"
  • f
  • w
  • uld
b e written
  • (q
; a) = p, where q and p are states, and a is an input sym b
  • l.

In tuitiv ely: if the F A is in state q , and input a is receiv ed, then the F A go es to state p (note: q = p OK).
  • A
F A is represen ted as the v e-tuple: A = (Q; ;
  • ;
q ; F ). Example: Clamping Logic W e ma y think
  • f
an accepting state as represen ting a \1"
  • utput
and nonaccepting states as represen ting \0"
  • ut.
A \clamping" circuit w aits for a 1 input, and forev er after mak es a 1
  • utput.
Ho w ev er, to a v
  • id
clamping
  • n
spurious noise, w e'll design a F A that w aits for t w
  • 1's
in a ro w, and \clamps"
  • nly
then. In general, w e ma y think
  • f
a state as represen ting a summary
  • f
the history
  • f
what has b een seen
  • n
the input so far. The states w e need are: 1. State q , the start state, sa ys that the most recen t input (if there w as
  • ne)
w as not a 1, and w e ha v e nev er seen t w
  • 1's
in a ro w. 2. State q 1 sa ys w e ha v e nev er seen 11, but the previous input w as 1. 3. State q 2 is the
  • nly
accepting state; it sa ys that w e ha v e at some time seen 11.
  • Th
us, A = (fq ; q 1 ; q 2 g; f0; 1g;
  • ;
q ; fq 2 g), where
  • is
giv en b y: 1
slide-2
SLIDE 2 1 ! q q q 1 q 1 q q 2 q 2 q 2 q 2
  • By
marking the start state with ! and accepting states with , the tr ansition table that denes
  • also
sp ecies the en tire F A. Con v en tions It helps if w e can a v
  • id
men tioning the t yp e
  • f
ev ery name b y follo wing some rules:
  • Input
sym b
  • ls
are a, b, etc.,
  • r
digits.
  • Strings
  • f
input sym b
  • ls
are u; v ; : : : ; z .
  • States
are q , p, etc. T ransition Diagram A F A can b e represen ted b y a graph; no des = states; arc from q to p is lab eled b y the set
  • f
input sym b
  • ls
a suc h that
  • (q
; a) = p.
  • No
arc if no suc h a.
  • Start
state indicated b y w
  • rd
\start" and an arro w.
  • Accepting
states get double circles. Example F
  • r
the clamping F A: Start q q 1 q 2 1 1 0,1 Extension
  • f
  • to
P aths In tuitiv ely , a F A ac c epts a string w = a 1 a 2
  • a
n if there is a path in the transition diagram that: 1. Begins at the start state, 2. Ends at an accepting states, and 3. Has sequence
  • f
lab els a 1 ; a 2 ; : : : ; a n . F
  • rmally
, w e extend transition function
  • to
^
  • (q
; w ), where w can b e an y string
  • f
input sym b
  • ls:
2
slide-3
SLIDE 3
  • Basis:
^
  • (q
; ) = q (i.e.,
  • n
no input, the F A do esn't go an ywhere.
  • Induction:
^
  • (q
; w a) =
  • ^
  • (q
; w ); a
  • ,
where w is a string, and a a single sym b
  • l
(i.e., see where the F A go es
  • n
w , then lo
  • k
for the transition
  • n
the last sym b
  • l
from that state).
  • Imp
  • rtan
t fact with a straigh tforw ard, inductiv e pro
  • f:
^
  • really
represen ts paths. That is, if w = a 1 a 2
  • a
n , and
  • (p
i ; a i ) = p i+1 for all i = 0; 1; : : : ; n
  • 1,
then ^
  • (p
; w ) = p n . Acceptance
  • f
Strings A F A A = (Q; ;
  • ;
q ; F ) accepts string w if ^
  • (q
; w ) is in F . Language
  • f
a F A F A A accepts the language L(A) = fw j ^
  • (q
; w ) is in F g. Aside: T yp e Errors A ma jor source
  • f
confusion when dealing with automata (or mathematics in general) is making \t yp e errors."
  • Example:
Don't confuse A, a F A, i.e., a program, with L(A), whic h is
  • f
t yp e \set
  • f
strings."
  • Example:
the start state q is
  • f
t yp e \state," but the accepting states F is
  • f
t yp e \set
  • f
states."
  • T
ric kier example: Is a a sym b
  • l
  • r
a string
  • f
length 1?

Answ er: it dep ends
  • n
the con text, e.g., is it used in
  • (q
; a), where it is a sym b
  • l,
  • r
^
  • (q
; a), where it is a string? Nondetermini st ic Finite Automata Allo w (deterministic) F A to ha v e a c hoice
  • f
  • r
more next states for eac h state-input pair.
  • Imp
  • rtan
t to
  • l
for designing string pro cessors, e.g., grep, lexical analyzers.
  • But
\imaginary , " in the sense that it has to b e implemen ted deterministically . Example In this somewhat con triv ed example, w e shall design an NF A to accept strings
  • v
er alphab et f1; 2; 3g suc h that the last sym b
  • l
app ears 3
slide-4
SLIDE 4 previously , without an y in terv ening higher sym b
  • l,
e.g.,
  • 11,
  • 21112,
  • 312123.
  • T
ric k: use start state to mean \I guess I ha v en't seen the sym b
  • l
that matc hes the ending sym b
  • l
y et.
  • Three
  • ther
states represen t a guess that the matc hing sym b
  • l
has b een seen, and remem b ers what that sym b
  • l
is. 1 1 2 2 3 3 1 1,2 p q r s t 1,2,3 Start F
  • rmal
NF A N = (Q; ;
  • ;
q ; F ), where all is as DF A, but:
  • (q
; a) is a set
  • f
states, rather than a single state. Extension to ^
  • Basis:
^
  • (q
; ) = fq g.
  • Induction:
Let:

^
  • (q
; w ) = fp 1 ; p 2 ; : : : ; p k g.

  • (p
i ; a) = S i for i = 1; 2 : : : ; k . Then ^
  • (q
; w a) = S 1 [ S 2 [
  • [
S k . Language
  • f
an NF A An NF A accepts w if any path from the start state to an accepting state is lab eled w . F
  • rmally:
  • L(N
) = fw j ^
  • (q
; w ) \ F 6= ;g. Subset Construction
  • F
  • r
ev ery NF A there is an e quivalent (accepts the same language) DF A.
  • But
the DF A can ha v e exp
  • nen
tially man y states. 4
slide-5
SLIDE 5 Let N = (Q N ; ;
  • N
; q ; F N ) b e an NF A. The equiv alen t DF A constructed b y the subset construction is D = (Q D ; ;
  • D
; fq g; F D ), where: 1. Q D = 2 Q N ;. i.e., Q D is the set
  • f
all subsets
  • f
Q N . 2. F N is the set
  • f
sets S in Q D suc h that S \ F 6= ;.
  • D
(fq 1 ; q 2 ; : : : ; q k g; a) =
  • N
(p 1 ; a) [
  • N
(p 2 ; a) [
  • [
  • N
(p k ; a).
  • Key
theorem (induction
  • n
jw j, pro
  • f
in b
  • k):
^
  • D
(fq g; w ) = ^
  • N
(q ; w ).
  • Consequence:
L(D ) = L(N ). Example: Subset Construction F rom Previous NF A An imp
  • rtan
t practical tric k, used in lexical analyzers and
  • ther
text-pro cessors is to ignore the (often man y) states that are not accessible from the start state (i.e., no path leads there).
  • F
  • r
the NF A example ab
  • v
e,
  • f
the 32 p
  • ssible
subsets,
  • nly
15 are accessible. Computing transitions \on demand" giv es the follo wing
  • D
: 1 2 3 ! p pq pr ps pq pq t pr ps pq t pq t pr ps pr pq r pr t ps pr t pq r pr t ps ps pq s pr s pst pst pq s pr s pst pr s pq r s pr st pst pr st pq r s pr st pst pq s pq st pr s pst pq st pq st pr s pst pq r pq r t pr t ps pq r t pq r t pr t ps pq r s pq r st pr st pst pq r st pq r st pr st pst 5