finite automata (fas) - george mason universityhenryh/330/trans-pdf/9.pdf · finite automata (fas)...

23
Finite Automata (FAs) Automata: The General Idea Diagrams and Language Recognition Formal Notation Nondeterministic Finite Automata Removing Nondeterminism

Upload: votruc

Post on 25-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Finite Automata(FAs)

• Automata: The General Idea

• Diagrams and Language Recognition

• Formal Notation

• Nondeterministic Finite Automata

• Removing Nondeterminism

Page 2: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Why FAs ?

• Recognition : Is string x in language L?

• Simplest way to specify some languages

• Equivalences among representation systems

• First in a family of models of computation

Page 3: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

States:the essence of FAs

• State : a model of the entire internal memory

• FA’s memory : knowing what state it’s in.

• State to state transitions, based on input

• State-transition diagrams (next)

Page 4: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

State Transition Diagramsfor some languages

a

b c

b

c c

a b,c

a,b a,c L,a

{a, bc} {ab, ac}

{aa,ac,ba,bc, aaa,aca,baa,bca} {b,cc,ab,acc,aab,aacc,…}

a

b{l, a,b,aa,ab,bb,aaa,aab,abb,bbb,…}

a b

b{l, a,bb,aa,abb,bba,bbbb,aaa,…}

ab

b

c

{ab, ac}

a

a

Page 5: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Reading a State Transition Diagram

What to do with the… state: string:

start at the beginning: start state; start of stringgo right on to the end: follow an arrow; use up a symbolthen stop: accepting state; end of string

Page 6: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Conventionsfor State Transition Diagrams

• Arrow with 2 labels: shorthand for 2 transitions.

• If the start state is an accepting state, L is accepted.

• Stopping at an accepting state is optional.

• Rejection: if input ends at a non-accepting state.

• Rejection: if (state, input) pair has no arrow.

Page 7: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

From Description to Diagram

Find a state-transition diagram for strings overS = {a,b} that have an odd number of b’s.

b

ba aevenb’s

oddb’s

Using states to keep trackof whether the number ofb’s so far is odd or even.

Page 8: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Description to Diagram

Find a state-transition diagram for those strings overS = {a,b} that have both an odd number of a’s andan odd number of b’s.

b b

a

a

even a’seven b’s

odd a’seven b’s

Using states to refecteven/odd combinations.

b b

aa

even a’sodd b’s

odd a’sodd b’s

Page 9: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Formal Notation:The Quintuple

A finite automaton, M, is a quintuple, (Q, S, q0, d, A),where

• Q is a finite set of states,

• S is a finite set of symbols,

• q0 Œ Q and q0 is the start state,

• d : Q ¥ S Æ Q,

• A Õ Q and A is the set of accepting states.

Page 10: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Example of a Quintuple

Let M = (Q, S, q0, d, A)

be the FA with

Q = {q0} ,

S = {a} ,

A = {q0} , and

d(q0, a) = q0.

• Draw the state-transition diagram.

• What is its language?

Page 11: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Formal Notation,a Diagram

and a Trap state

Let M = ({q0,q1,q2}, {a,d}, q0, d, {q1}), …

where d is specified by this table:

d a d

q0 q1 q2

q1 q1 q1

q2 q2 q2

• Which is the trap state?

• Draw the Diagram.

Page 12: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

The Diagram, with Trap State

aa,d

a,d d

q0

q2

q1

• Trap state is shown dotted …

• … as are the transitions to and from it.

• What (else) tells you it’s the trap state?

• What language is expressed?

Page 13: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

The Language

• The language of the diagram is {a} {a,d}*

• What has this to do with programming languages?

Page 14: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

d*is a Function

Let M = (Q, S, q0, d, A) be an FA.

• d* is a function.

• It maps a state and a string …

• to a resulting state:

d* : Q ¥ S * Æ Q

Page 15: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Recursive Definition of d*

For any q ΠQ,

d*(q, L) = q

For any q ΠQ, any s ΠS and any x ΠS*,

d*(q, xs) = d (d*(q,x), s).

Page 16: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

The Language of an Automaton

Given a finite automaton M, where

M = (Q, S, q0, d, A) ,

M’s language, L(M), the strings it accepts:

L(M) = { x Œ S* ˙ d*(q0, x) Œ A }

M rejects the strings of (the complement) S * \ L(M) .

Page 17: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Recognizing the Language of an Automaton

Let M be the FA, (Q,S,q0,A,d),

x the input string, and

“‹” the assignment operator.

Let dequeue remove and returnthe first symbol of a string.

q ‹ q0while x ≠ L do

s ‹ dequeue(x)q ‹ d(q, s)

return q ΠA

Page 18: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

NonDeterminism

• Definition: 2+ transitions/arrows

with the same input/label, and

from the same state

• Motivating Examples

All strings ending in abb, or

Results of L–removal (later)

Page 19: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Removing NonDeterminism:The Subset Construction

• Think of partial knowledge as a set of states.

• New machine: states are ‘states of mind.’

• So new state is a set of old states.

• New start state contains just the old one.

• New state accepts if it includes old accepters.

Page 20: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

L-Elimination

• For each L*ai path from qj to qk, add an a i

transition from qj to qk.

• For each L* path from qj to an accepting stateqk, make qj accepting.

• Remove all L-transitions.

Page 21: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Tidying Up afterL-Elimination

• No Unreachables: Remove unreachable states andtransitions from them.

• Careful Merging: A set of states can be merged ifthey agree about acceptance and destination

¸ all or none of them are accepting and

¸ all would have the same transition destination,– if any – for each label, after completion of themerger.

Page 22: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Example Using 3 Simplifications

Each diagram accepts the language of {a}*

¸ The first one is from {a}* in Figure 10.2.

¸ L-elimination yields the second.

¸ Eliminate an unreachable state to get the second.

¸ Then carefully merge to get the last one.

aa

aa

a

a

LLL

a

L

Page 23: Finite Automata (FAs) - George Mason Universityhenryh/330/Trans-pdf/9.pdf · Finite Automata (FAs) • Automata: The General Idea • Diagrams and Language Recognition • Formal

Equivalenceswe have shown

• the languages from 3 language ops

• … are within the capacity of DFA diagrams

• … and of NFA-Ls

• … and NFAs (without Ls)

• …and DFAs