equivalence, dfa, ndfa sequential machine theory prof. k. j. hintz department of electrical and...

53
Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by Marek Perkowski

Post on 19-Dec-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Equivalence, DFA, NDFAEquivalence, DFA, NDFA

Sequential Machine Theory

Prof. K. J. HintzDepartment of Electrical and Computer

Engineering

Lecture 2

Updated and modified by Marek Perkowski

Page 2: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Equivalence Relation on AEquivalence Relation on AEquivalence Relation on AEquivalence Relation on A

• An Equivalence Relation (Not Relationship) Is Not an Equality Relation

• A Relation is an Equivalence Relation if and only if (iff) it is:– Reflexive– Symmetric– Transitive

Page 3: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Equivalence Relation on AEquivalence Relation on A

A

A

A

A

on ~ relation eequivalenc an is

e)(transitiv '',','','',' ',

)(symmetric ',,' ',

)(reflexive ', ,

R

RRR,

RR

R

then

aaaaaaaaa

and

aaaaaa

and

aaaa

if

Page 4: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Non-Algebraic Equivalence Relation Example

Non-Algebraic Equivalence Relation Example

Equivalence Relation on the Set of All Triangles on a Plane

“is congruent to” or “is similar to”

– Reflexive, each triangle is similar to itself,

Page 5: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Equivalence Relation ExampleEquivalence Relation Example

Symmetric, if

is similar to

then

is similar to

Page 6: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Equivalence Relation ExampleEquivalence Relation Example

Transitive, if

is similar to

and

is similar to

then

is similar to

Page 7: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Inclusion RelationInclusion Relation

ji

jiji

jjjj

iiii

ji

iff

then

, also are states all

)" in included is " as (read

,,,

,,,

, states, ofset theon defined partitions 2 Given

321

321

BBB

BBB

BBB

S

Page 8: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Inclusion Relation ExampleInclusion Relation Example

, in" included is"

,

5,4,3,2,1

5,4,3,2,1

5,4,3,2,1

21

21

2

14131211

1

or,

then

and

let

BBBB

Illustrate a bigger lattice graphically

Page 9: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Partition NotationPartition Notation

• Overbar Indicates States Which Are Elements of the Same -block.

• Single States Are Not Normally Listed

1

11 12 13 14

1 2

1 2 3 4 5

1 2 3 4 5

1 2 1 2 3 4 5

, , ,

,

,

B B B B

is written as

and

Page 10: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Relations May Be OrderingsRelations May Be Orderings

• Partial Ordering

• Total Ordering, aka Chain

• Well Ordering (not discussed here)

Page 11: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Partial Ordering (PO)Partial Ordering (PO)Partial Ordering (PO)Partial Ordering (PO)

• Given an Inclusion Relation, R: s s’, Defined on some Elements of the Set S such that s, s’ S, R Is a Partial Ordering If It Is:– Reflexive– Anti-Symmetric (asymmetric)– Transitive– Not all orderings are specified, therefore partial

Illustrate on a lattice

Page 12: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Properties of Partial OrderingsProperties of Partial Orderings

– Reflexive• s s for all s S

– Anti-Symmetric (asymmetric)If

and

then

s s

s s

s s s s

'

, S

e.g., let : “older than”

if Sam is older than Bill,

then Bill cannot be older

than Sam

But if this symbol means older or the same age, then OK

Page 13: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Properties of POProperties of PO

– TransitiveIf

and

then

s s

s s

s s

'

e.g., If the Redskins beat the Patriots

and the Patriots beat the Cowboys

then the Redskins will beat the Cowboys

Page 14: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Total OrderingTotal Ordering

• aka– Chain, simply ordered set, totally ordered set

• A Partial Ordering for Which All Orderings Are Specified

• A Chain Is “Connected” Because

s s s s s s or , S

Page 15: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

POSETPOSET

• Partially Ordered SET– A set on which a partial ordering is specified– ( S, ) where is defined– Not a chain since not all elements are

connected

• We Will Revisit This Concept in a later part of the Course

Page 16: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Finite AutomataFinite Automata

A Deterministic semi-automaton*, aka Completely Specified Deterministic Semi-automaton is a Triple

with no Mealy machine output function, Beta ()

* Ginzburg, 1968

,,

or ,,,

ΣK

IS

M

M

Page 17: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

FSM Set PropertiesFSM Set Properties

,,,,,,,,,

,

inputs ofset finite A,,,,

states ofset finite A,,,,

1210

1210

ihgfedcba

m

n

sississis

S

iiiiI

ssss

ISSIS

KS

SIsa sc

ib

Page 18: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Language RecognizerLanguage Recognizer

• aka, Rabin-Scott Automata (machine), Automaton, Language Recognizer

• A Recognizer Is a Quintuple of Sets

with S, I, as before

M rs S I F, , , , s0

s

s sp q

0

the single, unique, initial state

A finite set of final statesF S, ,

Page 19: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Kleene StarKleene Star

• a* = e, a, aa, aaa, aaaa, ...

• The Kleene Star, *, means NONE or more occurrences of something

• Star is an overloaded operator so be aware of context

• a+= ONE or more occurrences of something.

• a+ is Kleene Star less the null string, .

Page 20: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Kleene ClosureKleene Closure

• Kleene Closure Is Not Identical to Kleene Star– “*” Symbol is the same (overloaded)

• Kleene Closure/Star Closure– Found in descriptions of formal language– Language consisting of all strings over some

alphabet

Page 21: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

StringString

• An Ordered Concatenation of Symbols From an Alphabet

• Used in Place of “Word” to Decouple From Common Concept of Word in Informal Language

• If = { a, 1, 0, b, % } then a “1%0b” is a string.

Page 22: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

RecognizerRecognizer

If x I*, i.e., a string of input symbols selected from the set of allowable input symbols,

and the application of x to the recognizer results in a final state F,

then the recognizer “accepts” the string.

Page 23: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

StringsStrings

A String, x, Is Accepted by a Recognizer Left-most Letter First, i.e.,

if the input to a recognizer is a string w,

and if w = w’

then is the first letter of the string which causes a state

transition. Subsequent letters from left to right do the same.

Page 24: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

State TransitionState Transition

Let There Be Two Configurations for a Machine

somefor

',',

relation, by the related are which',' and ,

1 ww

iff

wqwq

wqwqM

R,

1

q q’S

Page 25: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

String ExampleString Example

Let

w = a b b a

then

w = a w’

and

w’ = b b a

Page 26: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Recognizer as Directed GraphRecognizer as Directed GraphRecognizer as Directed GraphRecognizer as Directed Graph

• Arbitrary State

• State Transition

• Start (initial) State

• Final State

1

q

q q’

-

+ or

or

Page 27: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Let I = { a, b }

• Accepts no strings since no final state

• Accepts all strings

• Dead State

Recognizer ExamplesRecognizer Examples

a, b

-

a, b

a, b

Page 28: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Recognizer ExamplesRecognizer Examples

• Accepts only , the null string

a,b

a,b

+/-

This is start and final state

Page 29: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Recognizer ExampleRecognizer Example

This Recognizer Accepts the Language

L= { ab, a (aa) b, a (aa) (aa) b, ...

ab (bb), ab (bb) (bb), ... }

L = a (aa)* b ( b (aa)* b )*

- a

a

b

b

Page 30: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

New Example: Rabin-Scott MachineNew Example: Rabin-Scott Machine

S

F

1 2 3 4

1

40

, , ,

, , ;I a

s

M rs S I F, , , , s0

ps\input a + ;1 2 3 32 3 1 43 3 3 34 3 3 3

4

Now we transform this table to a graph

Page 31: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

The same Rabin-Scott machine as a graph

The same Rabin-Scott machine as a graph

L (M) = { x I* |* ( 1, x ) = 4 }

L (M) = { a; , a+a; , a+a+a; , ... }

aa

2

3 4

+

+ ;

;

a + ;

a + ;

1

Page 32: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Non-Deterministic FSMNon-Deterministic FSM

A Non-deterministic Finite Automata Is a Quintuple with S, I, s0, F

as in a recognizer, but, M nd S I F, , , , s0

,,,,,,

,,,,,,

functiona not relation,a is

,,* *

jhged

fedcba

sssxs

sxssxs

SISSIS

Page 33: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Non-Deterministic FSMNon-Deterministic FSM

• State May Change– to two (or any) different states in response to

the same input at the same state– in response to a string rather than just a single

element from the set of inputs– in response to a null string input

Page 34: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

DFA-NDFA TheoremDFA-NDFA Theorem

• Every NDFA Can Be Replaced by an Equivalent DFA

• Equivalent Means Not Only Accepting All Strings Accepted by the NDFA, but Also NOT Accepting Any Other strings

Page 35: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

NDFA ExampleNDFA Example

Non-deterministic Since

( ( 1, a ), 2 ) and ( ( 1, a ), 3 )

1

ab

2

3 4a

b

1

Page 36: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

NDFA ExampleNDFA Example

Non-deterministic Since Not Completely Specified

ab

4

1

abb

L = ab abb,

Page 37: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

NDFA ExampleNDFA Example

Non-deterministic Since State Changes in Response to a Null String.

ab

2

3 4a

1

bb

Page 38: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

NDFA to DFANDFA to DFANDFA to DFANDFA to DFA• Theorem

– For each NDFA there is an equivalent DFA

• Constructive Proof• 4 Difficulties to Resolve

– Missing transitions– Single transitions due to | strings | > 1– Transitions due to strings– Multiple transitions

Page 39: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Problem: Missing TransitionsProblem: Missing Transitions

• I = { a, b }

• In DFA, all i I must be accounted for in each state

a

b ?

Page 40: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Solution: Missing TransitionsSolution: Missing Transitions

Add a “sink” state which is not a final state and terminate all missing transitions there.

a

b

a, b

a, b

Page 41: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Problem: | strings | > 1Problem: | strings | > 1

• Single transition due to string of size > 1

• Add intermediate states and “sink”, other characters in those states go to “sink” state

a

ab

a, b

b

a

Page 42: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Problem: StringsProblem: Strings

Can’t just combine states sincea

ab

a bb

a

b

Page 43: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Solution: Strings & Multiple Transitions

Solution: Strings & Multiple Transitions

• Eliminate by defining the set of next states which occur in response to no input, call this function E( )

• E( ) is called the “equivalents of ( )

Page 44: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

NDFA ExampleNDFA Example

> 1

2

3

4

a b

b a

b

a

Page 45: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

State EquivalentsState Equivalents

E( 1 ) = {self, explicit alternative} = { 1, 3 }

E( 2 ) = { 2 }

E( 3 ) = { 3 }

E( 4 ) = { 4 }

• Define a new machine based on the old using the E( ) states

> 1

2

3

4

a b

b a

b

a

Page 46: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

New MachineNew Machine

E a

E b

E a

E b

E a

E b

E a

E b E E b

1 2 3 4

1 5

2 5

2 3

3 3 4

3 5

4 5

4 1 4 4 1 3 4

, , , ,

, , ,

, ,

, ,

, , ,

, ,

, ,

, , , , , , ,

state 5 is new dead state

> 1

2

3

4

a b

b a

b

a

Page 47: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

New Machine Transition TableNew Machine Transition Table

Equivalent

OldState

NewState

Inputa

Inputb

E ( 1 ) { 1, 3 } A { 2,3,4 } = F 5 = EE ( 2 ) 2 B 5 = E 3 = CE ( 3 ) 3 C { 3, 4 } = G 5 = EE ( 4 ) 4 D 5 = E { E( 1 ), 4 }

{ 1, 3, 4 } = H

> 1

2

3

4

a b

b a

b

a

Page 48: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

New Machine Transition TableNew Machine Transition Table

Equivalent

Old State

New State

Input a

Input b

E ( 5 ) 5 E 5 = E 5 = E 2, 3, 4 F { 5, 3, 4 } = I { 3, 5, E(1), 4}

{ 1, 3, 4, 5} = J 3, 4 G { 3, 4, 5 } = I { 5, E(1), 4}

{ 1, 3, 4, 5} = J

1, 3, 4 H 2, 3, 4, 5 = L { 5, E(1), 4} { 1, 3, 4, 5} = J

> 1

2

3

4

a b

b a

b

a

Page 49: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

New Machine Transition TableNew Machine Transition TableOldState

NewState

Inputa

Inputb

3, 4, 5 I { 3, 4, 5 } = I { 5, E(1), 4}{ 1, 3, 4, 5} = J

1, 3, 4, 5 J { 2, 3, 4, 5 }= L { 5, E(1), 4}{ 1, 3, 4, 5} = J

2, 3, 4, 5 L { 5, 3, 4 } = I { 3, 5, 4, E(1) }{ 1, 3, 4, 5} = J

> 1

2

3

4

a b

b a

b

a

Page 50: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

DFA Equivalent of NDFADFA Equivalent of NDFA

> 1

2

3

4

a b

b a

b

a

Page 51: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Reduced DFA EquivalentReduced DFA Equivalent

Page 52: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

Comparison of both machinesComparison of both machines

Discuss other methods of doing this transformation

Page 53: Equivalence, DFA, NDFA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 2 Updated and modified by

HomeworkHomeworkHomeworkHomework• This is only homework example. Another homework may

be assigned.• 1. Describe any problem from real life, possibly related to

your previous research, experience from other classes or otherwise as a non-deterministic finite automaton NDA. You may use Kleene star and empty symbols, if necessary.

• 2. Convert it to a deterministic automaton DA.• 3. Try to minimize DA to Minimized MDA.• 4. Realize MDA using JK Flip-Flops and logic gates. • 5. Analyze its behavior using the logical diagram. Compare

to the initial description. Draw and write conclusions.