fsa lecture 1 finite state machines. creating a automaton given a language l over an alphabet ,...

86
FSA Lecture 1 Finite State Machines

Post on 21-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

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

FSA Lecture 1

Finite State Machines

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

Creating a Automaton

Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such that L(M) = L.

Page 3: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example 1

L1 = { w | w is a string over {0, 1} that contains an even number of 0s and an odd number of 1s }

Method:Define 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

Page 4: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

qoe qoo

qee

1

01

0 00

1

1

qeo

Example 1

Page 5: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such
Page 6: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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

Page 7: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

qeo

1

01

0 00

1

1

Example 2

qee

qoeqoo

Page 8: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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}

Page 9: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example 3

q0 q1q2

0, 1 0, 1q3

0, 1

0, 1

q4

0, 1

Page 10: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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}}

Page 11: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example 4

q0 q1

0

1

0

1q2

0, 1

0 1q0 q0 q1q1 q0 q2q2 q2 q2

Page 12: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Machine M accepts string w

If there exists a sequence of states r0, r1, …, rn in Q such that 1) r0 = q0 2) (ri , wi+1) = ri+1, for i=0,…,n-1 3) rn in F

Note: w = w1w2…wn

Page 13: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Regular Languages

Machine M recognizes language A if A = {w| M accepts w}

A language is called regular if some finite automaton recognizes it.

Page 14: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Regular Operations

Let A and B be languages. Union

A B = { x | x in A or x in B}

ConcatenationA B = {xy | x in A and y in B}

StarA* = {x1x2…xk | k 0 and each xj in A}

Note: is always a member of A*.

Page 15: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Regular languages are closed under union

Let A1 and A2 be regular languages. We want to show A1A2 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 A1A2.

Page 16: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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

Page 17: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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 doesn’t 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.

Page 18: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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 .

Page 19: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example

q1 q2 q3

0, 1

1 0, 1

0, 1

q4

Page 20: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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 .

Page 21: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example

q1 q2 q3

0, 1

1 0, 1

0, 1

q4

Page 22: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

q1

q1

q1

q2

q1

q3

q2 q4q3

q3q1

q4q4q3q2q1

q3q1 q4 q4

0

1 11

00

11

1 1

0 0 0 0

1 1 1 1 1

Input:010110

Page 23: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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}

Page 24: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Machine N accepts string w

If there exists a sequence of states r0, r1, …, rn in Q such that 1) r0 = q0 2) ri+1 in (ri , wi+1) for i=0,…,n-1 3) rn in F

Note: w = w1w2…wn (ri , wi+1) is a set of states

Page 25: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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.

Page 26: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Non-deterministic?

q0 q1

0

1

0

1q2

0, 1

0 1q0 q0 q1q1 q0 q2q2 q2 q2

0 1{q0} {q0} {q1}{q1} {q0} {q2}{q2} {q2} {q2}

Non-deterministic interpretationDeterministic interpretation

Page 27: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Deterministic Equivalent?

1

2 3

b

a, b

a

a

Page 28: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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}

Page 29: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Continued …

3) q0’ = { q0}

4) F’ = {R in Q’| R contains an accept state of N}

Assume 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 edges}

Modify ’(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

Page 30: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Deterministic Equivalent?

1

2 3

b

a, b

a

a

a b{ } { } { }{1} { } {2}{2} {2,3} {3}{3} {1,3} { }

{1,2} {2,3} {2,3}{1,3} {1,3} {2}{2,3} {1,2,3} {3}

{1,2,3} {1,2,3} {2,3}

Deterministic Equivalent

Start state q0’= E({1}) = {1,3}Final states F’ = {{1}, {1,2}, {1,3}, {1,2,3}}

Page 31: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Final Solutiona

{1,3}

{2}

b

{3}a

{ }b

b

{2,3}a

b

a, b

a

b

a

{1,2,3}

b

{1,2}

a, b {1}

a

Page 32: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Regular languages are closed under union

Let A1 and A2 be regular languages. We want to show A1A2 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 A1A2.

Page 33: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Construction of NFA

N1

N2

q0

N = (Q, , , q0, F)Q = {q0} Q1 Q2

F = 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

Nq1

q2

Page 34: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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.

Page 35: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Construction of NFA

N1

N2

N = (Q, , , q1, F2)Q = Q1 Q2

F = 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

q1

q2

q1q2

N

Page 36: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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*.

Page 37: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Regular languages are closed under union

Let A1 and A2 be regular languages. We want to show A1A2 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 A1A2.

Page 38: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Construction of NFA

N1

N2

q0

N = (Q, , , q0, F)Q = {q0} Q1 Q2

F = 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

Nq1

q2

Page 39: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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.

Page 40: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Construction of NFA

N1

N2

N = (Q, , , q1, F2)Q = Q1 Q2

F = 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

q1

q2

q1q2

N

Page 41: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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*.

Page 42: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Construct NFA

N1

N

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

q0

q1

q1

Page 43: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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 expression

If R is a regular expression then L(R) is the language of R.

Page 44: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Examples

0*0 {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, …} 1*0 = {w| w contains any number of 1s followed by exactly one 0}

Page 45: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Using Regular Expressions

Page 46: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Beginning or End?

Page 47: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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.

Page 48: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

x

NFA that recognizes {x}

x

Page 49: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

NFA that recognizes {}

Page 50: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

NFA that recognizes

Page 51: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

R1 R2, R1 R2, or R1*

Construct a machine the same way we did to show regular languages are closed under , , or *.

Page 52: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

NFA to recognize (0 11)*

0 1

11

0

11

Page 53: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

NFA to recognize (0 11)*

0

11

0

11

Page 54: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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.

Page 55: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example GNFA

start accept

ab*

b

ab ba

b*

ab

aa

(aa)*a*

Page 56: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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

qsqt

R

Page 57: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such
Page 58: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example

1a

b

a, b

2

b

a b

2

1a

qstart

qaccept

1a

qstart

qaccept

b(a b)*

qstart

qaccept

a*b(a b)*

Page 59: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example 1.36 (b to c)

new(s,2) = old(s,2) old(s,1) old(1,1)* old(1,2) = * a = a

new(s,3) = old(s,3) old(s,1) old(1,1)* old(1,3) = * b = b

new(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

Page 60: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example 1.36 (b to c)

new(2,3) = old(2,3) old(2,1) old(1,1)* old(1,3) = a * b = ab

new(3,2) = old(3,2) old(3,1) old(1,1)* old(1,2) = a b * a = a ba

Page 61: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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)* ab

new(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

Page 62: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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)* )

Page 63: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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.

Page 64: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example GNFA

start accept

ab*

b

ab ba

b*

ab

aa

(aa)*a*

Page 65: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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

qsqt

R

Page 66: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such
Page 67: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example

1a

b

a, b

2

b

a b

2

1a

qstart

qaccept

1a

qstart

qaccept

b(a b)*

qstart

qaccept

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)*

new(qstart, qaccept) = old(qstart, qaccept) old(qstart,1) old(1,1)* old(1, qaccept) = a* b(a b)* = a*b(a b)*

Page 68: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example

Remove vertex 2:new(1,qaccept) = old(1, qaccept) old(1,2) old(2,2)* old(2, qaccept) = b (a b)* = b(a b)*

Remove vertx 1:|new(qstart, qaccept) = old(qstart, qaccept) old(qstart,1) old(1,1)* old(1, qaccept) = a* b(a b)* = a*b(a b)*

Page 69: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example 1.36

s

b

1

3

2

a

a

ab

b

1

3

2

a

a

ab

b a

b

s

3

2

a

abb a

baa

aab

bb

s

3

a

(ba a) (aa b)* b a(aa b)* ab

a(aa b)*

bb (ba a) (aa b)*ab

Page 70: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example 1.36 (b to c)

new(s,2) = old(s,2) old(s,1) old(1,1)* old(1,2) = * a = a

new(s,3) = old(s,3) old(s,1) old(1,1)* old(1,3) = * b = b

new(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

Page 71: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Example 1.36 (b to c)

new(2,3) = old(2,3) old(2,1) old(1,1)* old(1,3) = a * b = ab

new(3,2) = old(3,2) old(3,1) old(1,1)* old(1,2) = a b * a = a ba

Remove vertex 1

Page 72: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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)* ab

new(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

Page 73: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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

a(aa b)* (b a(aa b)* ab)(bb (ba a) (aa b)* ab)* ((ba a) (aa b)* )

Page 74: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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 k>=0 is also a member of the language.

Page 75: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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 k0, the string xykz is in A. 2) |y| > 0 3) |xy| p.

(Note form of this theorem is: RS)

Page 76: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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 doesn’t. Case 1: Suppose no string in A has length at least p Then the Pumping Lemma (RS) is vacuously true since the antecedent R is False.

Case 2: See next page.

Page 77: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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 n+1 states (namely, r1= q1,

r2, … rn+1).By the Pigeonhole Principle (n+1 pigeons and p nests), some state must have been visited more than once (say qx).

Page 78: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Sketch Proof

s = s1 s2 s3 … s’ … s” … sn

q1 r2 r3 … qx … qx … rn+1

q1

qx

rn+1

x

y

zRepetition first occurs when see the

(p+1) state

Page 79: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Nonregular Languages

Consider the language L={0n1n | n0}. 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 k0 2) |y| > 0 3) |xy| p

Choose carefully

Page 80: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

NonRegular Languages

By (3) xy consists of all 0s. Case 1: |xy| = p xy = 0p-u 0u where u>0 and z = 1p

Consider xz = 0p-u 1p. Pumping Lemma says xz in L. This is a contradiction.

Case 2: |xy| < p xy = 0t where t < p and z = 0p-t 1p

xy = 0t-v0v where v > 0 Consider xy2z = 0t-v0v 0v 0p-t 1p = 0p+v 1p. Pumping Lemma says xy2z in L. This is a contradiction.

Therefore L is not regular.

Page 81: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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.

Page 82: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

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

Page 83: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Nonregular Languages

Consider the language L2={w in * | w has the same number of 0s as 1s}. Show L2 is not regular.

We know the language A = 0*1* is regularsince it can be represented using regular expressions. Suppose L2 is regular thenA L2 = {0n1n | n0}is regular is a contradiction.Therefore L2 is not regular.

Page 84: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Minimum Pumping Length

The minimum pumping length for a regular language A is the smallest p that is a pumping length of A.

Page 85: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Minimum Pumping Length

What is the minimum pumping length for 01*?

s = 0 = xyz x = , y = 0, z = by Pumping Lemma Can’t pump y!

Let p be greater than zero.s = 01p = xyz x = , y = 0, z = 1p can’t pump y x = 0, y = 1, z = 1p-1 can pump y, |xy|=2 x = , y = 01, z = 1p-1 can’t pump y

2

Page 86: FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such

Minimum Pumping Length

What is the minimum pumping length for 11?

s = 11 = xyz x = , y = 1, z = 1 can’t pump y x = 1, y = 1, z = can’t pump y x = , y = 11, z = can’t pump y

minimum pumping length is 3 (vacuously true)

3