FSA Lecture 1 - PowerPoint PPT Presentation

About This Presentation
Title:

FSA Lecture 1

Description:

FSA Lecture 1 Finite State Machines Creating a Automaton Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such that L(M) = L ... – PowerPoint PPT presentation

Number of Views:130
Avg rating:3.0/5.0
Slides: 87
Provided by: GAN108
Category:
Tags: fsa | alphabet | lecture

less

Transcript and Presenter's Notes

Title: FSA Lecture 1


1
FSA Lecture 1
Finite State Machines
2
Creating a Automaton
  • Given a language L over an alphabet ?, design a
    deterministic finite automaton (DFA) M such that
    L(M) L.

3
Example 1
  • L1 w w is a string over 0, 1 that
    contains an even number of 0s and an
    odd number of 1s
  • MethodDefine nodes to represent when a)
    both an even number of 0s and 1s have been seen
    in the input b) both an odd number of 0s and
    1s have been seen in the input c) an even
    number of 0s and an odd number of 1s have been
    seen in the input d) an even number of 1s and
    an odd number of 0s have been seen in the input

4
Example 1
1
qee
qeo
1
0
0
0
0
1
qoe
qoo
1
5
(No Transcript)
6
Example 2
  • L2 w w is a string over 0, 1 that does
    not contain an even number of 0s
    and an odd number of 1s L1

7
Example 2
1
qeo
qee
1
0
0
0
0
1
qoe
qoo
1
8
Example 3
  • L3 w w is a string over 0, 1 such that
    w ? 3 ?, 0, 1, 00, 01, 10, 11, 000,
    001, 010, 011, 100, 101, 110, 111

9
Example 3
0, 1
0, 1
0, 1
q2
q3
q0
q1
0, 1
q4
0, 1
10
Example 4
  • L4 w w is a string over 0, 1 such that w
    contains the substring 11 w w x11y,
    where x and y are strings over 0, 1

11
Example 4
0
0, 1
q0
q1
1
1
q2
0
12
Machine M accepts string w
  • If there exists a sequence of states r0, r1, ,
    rn in Q such that 1) r0 q0
    2) ? (ri , wi1) ri1, for i0,,n-1
    3) rn in FNote w w1w2wn

13
Regular Languages
  • Machine M recognizes language A if A w M
    accepts w
  • A language is called regular if some finite
    automaton recognizes it.

14
Regular Operations
  • Let A and B be languages.
  • UnionA ? B x x in A or x in B
  • ConcatenationA ? B xy x in A and y in B
  • StarA x1x2xk k ?0 and each xj in
    ANote ? is always a member of A.

15
Regular languages are closed under union
  • Let A1 and A2 be regular languages. We want to
    show A1?A2 is a regular language. Since A1 and A2
    are regular languages there exists a finite
    automaton M1 and there exists a finite automaton
    M2 such that M1 recognizes A1 and M2 recognizes
    A2. Assume M1 (Q1, ?, ?1, q1, F1) and M2
    (Q2, ?, ?2, q2, F2) It suffices to create a
    finite automaton M that recognizes A1?A2.

16
Continue
  • Let a be a symbol in ? and states r1 in Q1 and r2
    in Q2. Define M (Q, ?, ?, q0, F) where
  • Q Q1 x Q2
    states
  • ?((r1, r2), a) (?1(r1, a), ?2(r2,
    a)) transition function q0 (q1, q2)
    start state F (F1 x Q2) ? (Q1 x F2)
    final states

17
Regular languages are closed under concatenation
  • Let A1 and A2 be regular languages. We want to
    show A1 ? A2 is a regular language. Since A1 and
    A2 are regular languages there exists a finite
    automaton M1 and there exists a finite automaton
    M2 such that M1 recognizes A1 and M2 recognizes
    A2. Assume M1 (Q1, ?, ?1, q1, F1) and M2
    (Q2, ?, ?2, q2, F2) It suffices to create a
    finite automaton M that recognizes A1 ? A2.
    There is a problem since M doesnt know where to
    subdivide the input string into the part accepted
    by M1 and the remaining part that will be
    accepted by M2. We will return to this later.

18
Non-Deterministic Automaton
  • NFAs generalize DFAs.
  • In a DFA, each state has exactly one transition
    for each symbol in the alphabet.
  • In an NFA, at any state there may be zero or more
    transitions for a symbol in the alphabet.
  • In a DFA, a label on a transition arrow is a
    symbol in the alphabet.
  • In an NFA, a label on a transition arrow is a
    symbol in the alphabet or ?.

19
Example
0, 1
0, 1
0, ?
1
1
q1
q2
q3
q4
20
Non-Deterministic Automaton
  • NFAs generalize DFAs.
  • In a DFA, each state has exactly one transition
    for each symbol in the alphabet.
  • In an NFA, at any state there may be zero or more
    transitions for a symbol in the alphabet.
  • In a DFA, a label on a transition arrow is a
    symbol in the alphabet.
  • In an NFA, a label on a transition arrow is a
    symbol in the alphabet or ?.

21
Example
0, 1
0, 1
0, ?
1
1
q1
q2
q3
q4
22
Input010110
q1
0
q1
1
1
1
q1
q2
q3
0
0
q1
q3
1
1
1
1
q1
q2
q3
q4
1
1
1
1
1
q3
q2
q1
q4
q4
0
0
0
0
q3
q1
q4
q4
23
Non-Deterministic Finite Automaton
  • N (Q, ?, ?, q0, F)Q is a finite set of
    states ? is a finite alphabet ? Q x (? ? ?)
    ? ?(Q) F ? Q is a set of accept states

?(Q) is the powerset of Q X X ? Q
24
Machine N accepts string w
  • If there exists a sequence of states r0, r1, ,
    rn in Q such that 1) r0 q0
    2) ri1 in ? (ri , wi1) for i0,,n-1
    3) rn in FNote w w1w2wn

25
Are NFAs more powerful than DFAs?
  • Every deterministic finite automaton has an
    equivalent non-deterministic finite automaton.
    (see next slide)
  • Every non-deterministic finite automaton has an
    equivalent deterministic finite automaton.

26
Non-deterministic?
0
0, 1
q0
q1
1
1
q2
0
Non-deterministic interpretation
Deterministic interpretation
27
Deterministic Equivalent?
1
a
b
?
3
2
a
a, b
28
DFA from NFA Construction
  • Assume no ? edges.Let N (Q, ?, ?, q0, F)be an
    NFA that recognizes language A. We construct a
    DFA called M (Q, ?, ?, q0, F)1) Q
    ?(Q) 2) For R in Q and a in ? let
    ?(R,a) q in Q q in ?(r,a) for some r in R
    ? ?(r,a)
    r in R

Q , 1, 2, 3, 1,2, 1,3, 2,3,
1,2,3
?(1,2,b) ?(1,b) ? ?(2,b) 2 ? 3 2,3
29
Continued
  • 3) q0 q0
  • 4) F R in Q R contains an accept state
    of NAssume ? edges, then we need these
    modifications.Let R be a state of M. Define
    E(R) q q can be reached from R traveling
    along 0 or more ? edgesModify ?(R,a) q in
    Q q in E(?(r,a)) for some r in R
  • ? E(?(r,a))
    transition function
    r in R ?(1,2,b)
    E(?(1,b)) ? E(?(2,b)) E(2) ? E(3) 2,3
    ?(3,a) E(?(3,a))
    E(1) 1,3
  • q0 E(q0) start state

30
Deterministic Equivalent?
1
Deterministic Equivalent
a
b
?
3
2
a
a, b
Start state q0 E(1) 1,3Final states F
1, 1,2, 1,3, 1,2,3
31
Final Solution
a
a, b
3

a
b
1,3
b
b
b
a
2
2,3
a
1,2,3
a
b
b
32
Regular languages are closed under union
  • Let A1 and A2 be regular languages. We want to
    show A1?A2 is a regular language. Since A1 and A2
    are regular languages there exists an NFA N1 and
    there exists an NFA N2 such that N1 recognizes A1
    and N2 recognizes A2. Assume N1 (Q1, ?, ?1,
    q1, F1) and N2 (Q2, ?, ?2, q2, F2) It suffices
    to create a NFA N that recognizes A1?A2.

33
Construction of NFA
q1
N1
N
?
q2
q0
N2
?
N (Q, ?, ?, q0, F)Q q0? Q1 ? Q2F F1 ?
F2 ?1 (q,a)
q in Q1 ?(q,a) ?2 (q,a) q in Q2
q1, q2 q q0 and a?
q q0 and a??
34
Regular languages are closed under concatenation
  • Let A1 and A2 be regular languages. We want to
    show A1 ? A2 is a regular language. Since A1 and
    A2 are regular languages there exists an NFA N1
    and there exists an NFA N2 such that N1
    recognizes A1 and N2 recognizes A2. Assume N1
    (Q1, ?, ?1, q1, F1) and N2 (Q2, ?, ?2, q2, F2)
    It suffices to create a NFA N that recognizes A1
    ? A2.

35
Construction of NFA
q1
N1
N
?
q2
q1
N2
?
q2
N (Q, ?, ?, q1, F2)Q Q1 ? Q2F F2
?1 (q,a)
q in Q1 and q not in F1 ?(q,a) ?2
(q,a) q in Q2
?1 (q,a) ? q2 q in F1 and a?
?1 (q,a) q in F1
and a??
36
Regular languages are closed under the star
operation
  • Let A be a regular language. We want to show A
    is a regular language. Since A is regular
    language there exists an NFA N1 such that N1
    recognizes A.Assume N1 (Q1, ?, ?1, q1, F1) It
    suffices to create a NFA N that recognizes A.

37
Regular languages are closed under union
  • Let A1 and A2 be regular languages. We want to
    show A1?A2 is a regular language. Since A1 and A2
    are regular languages there exists an NFA N1 and
    there exists an NFA N2 such that N1 recognizes A1
    and N2 recognizes A2. Assume N1 (Q1, ?, ?1,
    q1, F1) and N2 (Q2, ?, ?2, q2, F2) It suffices
    to create a NFA N that recognizes A1?A2.

38
Construction of NFA
q1
N1
N
?
q2
q0
N2
?
N (Q, ?, ?, q0, F)Q q0? Q1 ? Q2F F1 ?
F2 ?1 (q,a)
q in Q1 ?(q,a) ?2 (q,a) q in Q2
q1, q2 q q0 and a?
q q0 and a??
39
Regular languages are closed under concatenation
  • Let A1 and A2 be regular languages. We want to
    show A1 ? A2 is a regular language. Since A1 and
    A2 are regular languages there exists an NFA N1
    and there exists an NFA N2 such that N1
    recognizes A1 and N2 recognizes A2. Assume N1
    (Q1, ?, ?1, q1, F1) and N2 (Q2, ?, ?2, q2, F2)
    It suffices to create a NFA N that recognizes A1
    ? A2.

40
Construction of NFA
q1
N1
N
?
q2
q1
N2
?
q2
N (Q, ?, ?, q1, F2)Q Q1 ? Q2F F2
?1 (q,a)
q in Q1 and q not in F1 ?(q,a) ?2
(q,a) q in Q2
?1 (q,a) ? q2 q in F1 and a?
?1 (q,a) q in F1
and a??
41
Regular languages are closed under the star
operation
  • Let A be a regular language. We want to show A
    is a regular language. Since A is regular
    language there exists an NFA N1 such that N1
    recognizes A.Assume N1 (Q1, ?, ?1, q1, F1) It
    suffices to create a NFA N that recognizes A.

42
Construct NFA
N1
N
q1
?
?
q1
?
q0
N (Q, ?, ?, q0, F)Q q0? Q1 F F1 ? q0
?1 (q,a)
q in Q1 and q not in F1 ?(q,a)
?1 (q,a) q in F1 and a??
?1 (q,a) ? q1 q in F1 and a?
q1 q
q0 and a?
q q0 and a??
43
Regular Expressions
  • R is a regular expression if1) x for some x in ?
    (note regular expression x represents language
    x)2) ? (empty string) (note regular
    expression ? represents language ?) 3) ?
    (empty set)4) (R1 ? R2) where R1 and R2 are
    regular expressions5) (R1 ? R2) where R1 and R2
    are regular expressions6) (R1) where R1 is a
    regular expressionIf R is a regular expression
    then L(R) is the language of R.

44
Examples
  • 00 w w contains at least one zero
  • ? ?
  • 11 ? 00 11, 00
  • 0 ?1 w w begins with a 0 and ends in a 1
  • (01) ?, 01, 0101, 010101, 01010101,
  • 10 w w contains any number of 1s followed by
    exactly one 0

45
Using Regular Expressions
46
Beginning or End?
47
Regular Expressions vs. Regular Languages
  • A language is regular if and only if some regular
    expression describes it.Part a) If a regular
    expression describes a language then it is
    regular.Part b) If a language is regular then a
    regular expression describes it.

48
x
  • NFA that recognizes x

x
49
?
  • NFA that recognizes ?

50
?
  • NFA that recognizes ?

51
R1 ? R2, R1 ? R2, or R1
  • Construct a machine the same way we did to show
    regular languages are closed under ?, ?, or .

52
NFA to recognize (0 ? 11)
53
NFA to recognize (0 ? 11)
54
Part b) If a language is regular then a regular
expression describes it.
  • Properties of GNFA1) The start state has
    transition arrows going to every other state but
    no arrows coming in from any other state.2)
    There is one accept state, and it has arrows
    coming in from every other state but no arrows
    going to any other state. The accept state is not
    the same as the final state.3) Except for the
    start and accept states, one arrow goes from
    every state to every other state and also from
    each state to itself.4) The labels on each edge
    is a regular expression.

55
Example GNFA
aa
ab
ab ? ba
start
accept
a
(aa)
?
b
ab
b
56
Generalize Non-deterministic Finite Automaton
  • GNFA is a 5-tuple (Q, ?, ?, qstart, qaccept) ?
    (Q qaccept) x (Q qstart) ? ? (all regular
    expressions over ?)
    (qs, qt) ? R

R
qt
qs
57
(No Transcript)
58
Example
a
1
b
b
2
?
2
a, b
a ?b
a
?
1
ab(a ?b)
b(a ?b)
59
Example 1.36 (b to c)
new(s,2) old(s,2) ? old(s,1) old(1,1)
old(1,2) ? ? ?
? a
anew(s,3) old(s,3) ? old(s,1) old(1,1)
old(1,3) ? ? ?
? b
bnew(2,2) old(2,2) ? old(2,1) old(1,1)
old(1,2) b ? a
? a b
? aa new(3,3) old(3,3) ? old(3,1)
old(1,1) old(1,3) ?
? b ? b
bb
60
Example 1.36 (b to c)
new(2,3) old(2,3) ? old(2,1) old(1,1)
old(1,3) ? ? a
? b
abnew(3,2) old(3,2) ? old(3,1) old(1,1)
old(1,2) a ? b
? a a
? ba
61
Example 1.36 (c to d)
new(s,a) old(s,a) ? old(s,2) old(2,2)
old(2,a) ? ? a
(aa ?b) ? a(aa
?b) new(s,3) old(s,3) ? old(s,2) old(2,2)
old(2,3) b ? a
(aa ?b) ab b ?
a(aa ?b) abnew(3,a) old(3,a) ? old(3,2)
old(2,2) old(2,a) ?
? (ba ?a) (aa ?b) ?
(ba ?a) (aa ?b) ? ? new(3,3) old(3,3) ?
old(3,2) old(2,2) old(2,3)
bb ? (ba ?a) (aa ?b) ab
62
Example 1.36 (d to e)
new(s,a) old(s,a) ? old(s,3)
old(3,3) old(3,a) a(aa ?b) ?
(b ? a(aa ?b) ab)(bb ? (ba ?a) (aa ?b) ab)
((ba ?a) (aa ?b) ? ?)
63
Part b) If a language is regular then a regular
expression describes it.
  • Properties of GNFA1) The start state has
    transition arrows going to every other state but
    no arrows coming in from any other state.2)
    There is one accept state, and it has arrows
    coming in from every other state but no arrows
    going to any other state. The accept state is not
    the same as the final state.3) Except for the
    start and accept states, one arrow goes from
    every state to every other state and also from
    each state to itself.4) The labels on each edge
    is a regular expression.

64
Example GNFA
aa
ab
ab ? ba
start
accept
a
(aa)
?
b
ab
b
65
Generalize Non-deterministic Finite Automaton
  • GNFA is a 5-tuple (Q, ?, ?, qstart, qaccept) ?
    (Q qaccept) x (Q qstart) ? ? (all regular
    expressions over ?)
    (qs, qt) ? R

R
qt
qs
66
(No Transcript)
67
Example
a
1
b
b
2
?
2
a, b
a ?b
new(1,qaccept) old(1, qaccept) ? old(1,2)
old(2,2) old(2, qaccept)
? ? b (a ? b)
?
b(a ? b)
a
?
1
ab(a ?b)
b(a ?b)
new(qstart, qaccept) old(qstart, qaccept) ?
old(qstart,1) old(1,1) old(1, qaccept)
? ?
? a b(a ?b)

ab(a ?b)
68
Example
Remove vertex 2new(1,qaccept) old(1, qaccept)
? old(1,2) old(2,2) old(2, qaccept)
? ? b
(a ? b) ?
b(a ? b) Remove vertx
1new(qstart, qaccept) old(qstart, qaccept) ?
old(qstart,1) old(1,1) old(1, qaccept)
? ?
? a b(a ?b)

ab(a ?b)
69
Example 1.36
b
b
a
?
1
2
s
a
?
b
a
a
b
3
?
aa?b
a
a(aa ?b)
s
2
s
?
ba?a
ab
b
a
(ba ?a) (aa ?b) ? ?
b ? a(aa ?b) ab
3
3
?
bb
bb? (ba ?a) (aa ?b)ab
70
Example 1.36 (b to c)
new(s,2) old(s,2) ? old(s,1) old(1,1)
old(1,2) ? ? ?
? a
anew(s,3) old(s,3) ? old(s,1) old(1,1)
old(1,3) ? ? ?
? b
bnew(2,2) old(2,2) ? old(2,1) old(1,1)
old(1,2) b ? a
? a b
? aa new(3,3) old(3,3) ? old(3,1)
old(1,1) old(1,3) ?
? b ? b
bb
Remove vertex 1
71
Example 1.36 (b to c)
new(2,3) old(2,3) ? old(2,1) old(1,1)
old(1,3) ? ? a
? b
abnew(3,2) old(3,2) ? old(3,1) old(1,1)
old(1,2) a ? b
? a a
? ba
Remove vertex 1
72
Example 1.36 (c to d)
new(s,a) old(s,a) ? old(s,2) old(2,2)
old(2,a) ? ? a
(aa ?b) ? a(aa
?b) new(s,3) old(s,3) ? old(s,2) old(2,2)
old(2,3) b ? a
(aa ?b) ab b ?
a(aa ?b) abnew(3,a) old(3,a) ? old(3,2)
old(2,2) old(2,a) ?
? (ba ?a) (aa ?b) ?
(ba ?a) (aa ?b) ? ? new(3,3) old(3,3) ?
old(3,2) old(2,2) old(2,3)
bb ? (ba ?a) (aa ?b) ab
Remove vertex 2
73
Example 1.36 (d to e)
new(s,a) old(s,a) ? old(s,3)
old(3,3) old(3,a) a(aa ?b) ?
(b ? a(aa ?b) ab)(bb ? (ba ?a) (aa ?b) ab)
((ba ?a) (aa ?b) ? ?)
Remove vertex 3
s
a(aa ?b) ? (b ? a(aa ?b) ab)(bb ? (ba ?a) (aa
?b) ab) ((ba ?a) (aa ?b) ? ?)
74
Pumping Lemma
  • Purpose Used to prove a language is not regular.
  • What does it say?All strings in a regular
    language can be pumped if they are at least as
    long as the pumping length p. Suppose xyz
    represents a string in the language whose length
    is at least as long as p. There is a section of
    the string (say y) that can be repeated, i.e.,
    xykz, where kgt0 is also a member of the
    language.

75
Pumping Lemma
  • If A is a regular language, then there is a
    number p (the pumping length) where, if s is any
    string in A of length at least p, then s can be
    divided into three pieces, s xyz satisfying the
    following conditions 1) for each
    k?0, the string xykz is in A.
    2) y gt 0 3) xy ?
    p.(Note form of this theorem is R?S)

76
Sketch Proof
  • Since A is a regular language there exists a DFA
    M (Q,?,?,q1,F) with p states that recognizes
    A.
  • Either A has strings of length at least p or it
    doesnt. Case 1 Suppose no string in A has
    length at least p Then the
    Pumping Lemma (R?S) is vacuously
    true since the antecedent R is False.
    Case 2 See next page.

77
Sketch Proof
  • Let s be a string in A of length n, where n is at
    least p. Starting in q1, M processes the string s
    by visiting n1 states (namely, r1 q1, r2,
    rn1).By the Pigeonhole Principle (n1 pigeons
    and p nests), some state must have been visited
    more than once (say qx).

78
Sketch Proof
  • s s1 s2 s3 s s sn q1
    r2 r3 qx qx rn1

y
z
x
qx
q1
79
Nonregular Languages
  • Consider the language L0n1n n?0. Assume L is
    a regular language. Because of this, there exists
    a DFA with p states that recognizes L. Consider
    the string s 0p1p from L. Since its length is
    at least as long as p, it follows from the
    Pumping Lemma that 1) s
    xyz and xykz in A for k?0
    2) y gt 0
    3) xy ? p

80
NonRegular Languages
  • By (3) xy consists of all 0s. Case 1 xy
    p xy 0p-u 0u
    where ugt0 and z 1p Consider xz 0p-u
    1p. Pumping Lemma says xz in L. This is
    a contradiction. Case 2 xy lt p
    xy 0t where t lt p and z 0p-t
    1p xy 0t-v0v where v gt 0
    Consider xy2z 0t-v0v 0v 0p-t 1p
    0pv 1p. Pumping Lemma says xy2z in
    L. This is a contradiction.
  • Therefore L is not regular.

81
Another s
  • What if s (01)p was chosen instead?s (01)p
    xyzRegardless how y is chosen, y can always be
    pumped. For example, if y (01)k then it
    can be pumped.

82
Are Regular Languages Closed Under Other
Operations?
  • Closed under union
  • Closed under intersection (see page 46)
  • Closed under complement (see exercise 1.10)
  • Closed under concatenation
  • Closed under star

83
Nonregular Languages
  • Consider the language L2w in ? w has the
    same number of 0s as 1s. Show L2 is not
    regular.We know the language A 01 is
    regularsince it can be represented using regular
    expressions. Suppose L2 is regular thenA ? L2
    0n1n n?0is regular is a contradiction.Therefo
    re L2 is not regular.

84
Minimum Pumping Length
  • The minimum pumping length for a regular language
    A is the smallest p that is a pumping length of A.

85
Minimum Pumping Length
  • What is the minimum pumping length for 01?s
    0 xyz ? x ?, y 0, z ? by Pumping Lemma
    Cant pump y!Let p be greater than zero.s
    01p xyz ? x ?, y 0, z 1p cant pump y

    x 0, y 1, z 1p-1 can pump y,
    xy2 x ?, y 01,
    z 1p-1 cant pump y

2
86
Minimum Pumping Length
  • What is the minimum pumping length for 11?s
    11 xyz ? x ?, y 1, z 1 cant pump y
    x 1, y 1, z ?
    cant pump y x ? , y
    11, z ? cant pump yminimum pumping
    length is 3 (vacuously true)

3
Write a Comment
User Comments (0)
About PowerShow.com