60
Regular Expression Manipulation FSM Model Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 6 Modifications by Marek Perkowski

Regular Expression Manipulation FSM Model

  • Upload
    cato

  • View
    48

  • Download
    0

Embed Size (px)

DESCRIPTION

Regular Expression Manipulation FSM Model. Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 6. Modifications by Marek Perkowski. Null Machine. 3 Methods for Proving That a Machine Accepts No Words By inspection - PowerPoint PPT Presentation

Citation preview

Page 1: Regular Expression Manipulation FSM Model

Regular Expression ManipulationFSM Model

Sequential Machine Theory

Prof. K. J. HintzDepartment of Electrical and Computer

Engineering

Lecture 6

Modifications by Marek Perkowski

Page 2: Regular Expression Manipulation FSM Model

Null Machine

3 Methods for Proving That a Machine Accepts No Words– By inspection

• Any path from the start state to a final state means that at least one word is accepted by the machine

– By state diagram manipulation• If a final state is relabeled as a start state, then the

machine must accept at least one word

Page 3: Regular Expression Manipulation FSM Model

Null Machine

– By converting the regular expression into a deterministic FA

• If possible, FA must accept at least one word• Conversion to FA may not be possible

– Machine may have no final states.– There is no path from the initial state to any final state.

Page 4: Regular Expression Manipulation FSM Model

State Diagram Manipulation

A procedure to determine if a machine accepts no strings

1. Remove all edges (arrows) to the start state.2. From the start state, identify all single-step “next

states.”3. Relabel these “next states” as start states and

eliminate the edges used to get there.4. go to (b)5. If a final state is relabeled as a start state, then the

machine must accept at least one word.

Page 5: Regular Expression Manipulation FSM Model

State Diagram Manipulation

Page 6: Regular Expression Manipulation FSM Model

State Diagram Manipulation

Page 7: Regular Expression Manipulation FSM Model

State Diagram Manipulation

Does Not Accept AnyWord Since There Is No Path From - To +.

Page 8: Regular Expression Manipulation FSM Model

The Complement Machine

• A Complement Machine Accepts All Expressions Other Than Those Accepted by the Original Machine

• Method– Change all non-final states into final states– Change all final states into non-final states– Leave start state unchanged

Page 9: Regular Expression Manipulation FSM Model

Language Decidability

Methods for Determining If Two Regular Expressions Define the Same Language– Language Enumeration with 1:1

correspondence between the 2 languages.– The regular languages can be accepted by

identical FAs.– Generate

L L L L Loverlap 1 2 2 1?

Page 10: Regular Expression Manipulation FSM Model

Language Overlap

• If the Overlap Language Is NOT the Null Set, Then There Is Some Word in L1 Which Is Not Accepted by L2 and Vice Versa.

• If the Overlap Language Accepts the Null String, Then the Languages Are Not Equal.

L 1L 2L 1

L 2

Page 11: Regular Expression Manipulation FSM Model

DeMorgan’s Theorem

Applies Equally Well to Sets As Well As Boolean Algebra

BABA

andBABA

Page 12: Regular Expression Manipulation FSM Model

Regular Expression Equivalence

Methodology– Construct the complement machines– Apply DeMorgan’s theorem since it is difficult

to form the intersect machine

L L L L LL L L L

overlap

1 2 2 1

1 2 2 1

Page 13: Regular Expression Manipulation FSM Model

Regular Expression Equivalence

Take the Unions of the Complemented and Non-complemented Several Times to Determine Whether Loverlap Is the Null Set or Not

Page 14: Regular Expression Manipulation FSM Model

RE Equivalence Example*

Two REs are represented by their equivalent FAs (FA1 does = FA2)

*Cohen, Prob. 2, page 233.

Page 15: Regular Expression Manipulation FSM Model

RE Equivalence Example

Form the Complement Machines

Page 16: Regular Expression Manipulation FSM Model

RE Equivalence Example

Make the Product Machine of FA2 and the Complement of FA1.

Page 17: Regular Expression Manipulation FSM Model

RE Equivalence Example

• States of Product Machine, FA1-bar & FA2• Only One Start State / Multiple Final States

Start/Final -/+

New State State Vector

-/+ 1 ( p1, y1 )

+ 2 ( p1, y2 )

+ 3 ( p1, y3 )

Page 18: Regular Expression Manipulation FSM Model

RE Equivalence Example

Start/Final

-/+ New State State

Vector 4 ( p2, y1 )

+ 5 ( p2, y2 )

6 ( p2, y3 )

Page 19: Regular Expression Manipulation FSM Model

Product Machine State Table

Start/Final -/+

Present State a b

-/+ 1 5 3 + 2 5 3 + 3 5 3 4 5 3

+ 5 5 3 6 5 3

Page 20: Regular Expression Manipulation FSM Model

State Diagram of Product

FA1-Bar, FA2

Page 21: Regular Expression Manipulation FSM Model

Reduced State Diagram

Non-Reachable States Removed

Page 22: Regular Expression Manipulation FSM Model

RE Equivalence Example

• Take the Complement Of the Union by changing final states to non-final and vice-versa

• No Final States, So Complement FA Accepts No Words

21 LL

Page 23: Regular Expression Manipulation FSM Model

RE Equivalence Example

Do the Same for the Right Term of Loverlap

Page 24: Regular Expression Manipulation FSM Model

RE Equivalence Example

• Application of Same Procedure to Preceding Machine Also Results in No Recognizable Words.

• Since Both Terms of Loverlap are Null, Then REs Are Equivalent Since Their Union Is Null.

Page 25: Regular Expression Manipulation FSM Model

Moore & Mealy Machines

• The Behavior of Sequential Machines Depends on Previous Inputs.– Moore Machine

• Output only depends on present state– Mealy Machine

• Output depends on both the present state and the present input

Page 26: Regular Expression Manipulation FSM Model

Moore & Mealy Machines

Equivalent Descriptive Methods– Transition (state) table– Transition (state) diagram– Operational descriptions using set theory– (Language recognized by the machine)

Page 27: Regular Expression Manipulation FSM Model

Moore Machine

Present State

InputComb

Ckt

Memory

Comb Ckt

Output Is Only a Function of Present State

Output

Page 28: Regular Expression Manipulation FSM Model

Primitive State Diagram, Moore

Legend

state/output

input

A/0

C/0 D/0

B/1

etc.

off

on

off

Page 29: Regular Expression Manipulation FSM Model

Moore Machine State Diagram

Legend

s1s0/z

x1x0

00/1

10/1 11/1

01/0

etc.

00

10

01

Page 30: Regular Expression Manipulation FSM Model

Mealy Machine

Output Is Function of Present State AND Present Input

Present State

InputComb

Ckt

Memory

Comb Ckt

Output

Page 31: Regular Expression Manipulation FSM Model

Primitive State Diagram, Mealy

Legend

state

input/output

A

C D

B

etc.

off/1

on/0

off /0

Page 32: Regular Expression Manipulation FSM Model

Mealy Machine State Diagram

Legend

s1s0

x1x0 /z

00

10 11

01

etc.

00 /1

10 /0

01 /1

Page 33: Regular Expression Manipulation FSM Model

Transition Table

Present State

Variables

Input Variables

Next State

Variables

Output Variables

si xj sk zm

Page 34: Regular Expression Manipulation FSM Model

FSM Design Approaches

• “One-Hot”– One flip-flop is used to represent each state– Costly in terms of discrete hardware, but trivial to

design– Efficient in FPGAs because FF part of each CLB

• Binary Coded State– n flip-flops used to store 2n states– Most efficient– Need to account for unused states

Page 35: Regular Expression Manipulation FSM Model

FSM and Clocks

• Synchronous FSMs may change state only when a unique input, the clock, occurs

• Asynchronous FSMs may change state when input changes

• Next state depends on present input and present state for both Moore and Mealy

Page 36: Regular Expression Manipulation FSM Model

Synchronous versus Asynchronous Machines in Design

• Synchronous FSMs– Easier to design, turn the crank– Slower operation

• Asynchronous– Harder to design because of potential for races,

iterative solutions– Faster operation

Page 37: Regular Expression Manipulation FSM Model

Mealy “0101” Detector

M = ( S, I, O, )S: { A, B, C, D }I: { ‘0’, ‘1’ }O: { 0, 1 } = { not detected, detected}next slidenext slide

Page 38: Regular Expression Manipulation FSM Model

Mealy Transition/Output Table

Present InputPresentState ‘0’ ‘1’

A B/0 A/0B B/0 C/0C D/0 A/0D B/0 C/1

Next State/Output

Page 39: Regular Expression Manipulation FSM Model

“0101“ State Diagram

A

DC

B

‘1’/0 ‘0’/0

‘0’/0

‘1’/0‘1’/0

‘0’/0

‘1’/1

‘0’/0

Page 40: Regular Expression Manipulation FSM Model

Moore “0101” Detector

M = ( S, I, O, )S: { A, B, C, D, E }I: { ‘0’, ‘1’ }O: { 0, 1 } = { not detected, detected} next slidenext slide

Page 41: Regular Expression Manipulation FSM Model

Moore Transition/Output Table

Present InputPresentState ‘0’ ‘1’

Output()

A B A 0B B C 0C D A 0D B E 0E D A 1

Next State

Page 42: Regular Expression Manipulation FSM Model

Moore “0101“ State Diagram

A/0

D/0C/0

B/0‘1’

‘0’‘0’

‘1’‘1’

‘0’

‘0’

‘0’ detected

“01” det“010” det

E/1

“0101” det‘1’

‘0’‘1’

Page 43: Regular Expression Manipulation FSM Model

Asynchronous FSM

Fundamental Mode Assumption– Only one input can change at a time

• Analysis too complicated if multiple inputs are allowed to change simultaneously

– Circuit must be allowed to settle to its final value before an input is allowed to change

• Behavior is unpredictable (nondeterministic) if circuit not allowed to settle

Page 44: Regular Expression Manipulation FSM Model

Asynch. Design Difficulties

Delay in Feedback Path– Not reproducible from implementation to

implementation– Variable

• may be temperature or electrical parameter dependent within the same device

– Analog• not known exactly

Page 45: Regular Expression Manipulation FSM Model

Stable State

• PS = present state• NS = next state• PS = NS = Stability

– Machine may pass through none or more intermediate states on the way to a stable state

– Desired behavior since only time delay separates PS from NS

• Oscillation– Machine never stabilizes in a single state

Page 46: Regular Expression Manipulation FSM Model

Races

• A Race Occurs in a Transition From One State to the Next When More Than One Next State Variables Changes in Response to a Change in an Input

• Slight Environment Differences Can Cause Different State Transitions to Occur– Supply voltage– Temperature, etc.

Page 47: Regular Expression Manipulation FSM Model

Races

01

10

11 00

PS

desired NS

if Y1 changes first

if Y2 changes first

Page 48: Regular Expression Manipulation FSM Model

Types of Races

• Non-Critical– Machine stabilizes in desired state, but may

transition through other states on the way• Critical

– Machine does not stabilize in the desired state

Page 49: Regular Expression Manipulation FSM Model

Races

01

10

11 00

PS

desired NS

non- critical race

if Y1 changes first

if Y2 changes first

critical race

00

Page 50: Regular Expression Manipulation FSM Model

Asynchronous FSM Benefits

• Fastest FSM• Economical

– No need for clock generator• Output Changes When Signals Change, Not When

Clock Occurs• Data Can Be Passed Between Two Circuits Which

Are Not Synchronized• In some technologies, like quantum, clock is just

not possible to exist

Page 51: Regular Expression Manipulation FSM Model

Asynchronous FSM Example

next

statepresent

statey1

y2

input

Page 52: Regular Expression Manipulation FSM Model

Next State Variables

12

2212

2211

2211211

,,

,,

yxy

yxyyyxY

yxyyxyx

yxyyxyxyyxY

Page 53: Regular Expression Manipulation FSM Model

Sequential Machines Problems

Three Problems of Sequential Machines– State minimization problem

• Determine all equivalent states of a sequential machine, and,

• Eliminate redundant states– Machine Decomposition

• Separate large machines into an interconnected set of smaller machines

• Easier to design and analyze small machines

Page 54: Regular Expression Manipulation FSM Model

Sequential Machine Problems

– State assignment problem• There is no guidance on which binary number to

assign to which state in a primitive state table• Complexity of implementation is dependent on

mapping of states to binary numbers• Unsolved problem

– Design all machines and compare– Benefit of decomposition of large machine into smaller

machines.

Page 55: Regular Expression Manipulation FSM Model

Set Theoretic Description

Moore Machine is an ordered quintuple

Moore= S I O

SIO

S I SS O

, , , ,

, , ,, , ,

, , ,

whereFinite set of states , s s sFinite set of inputs , i i iFinite set of outputs , o o o

Next state function which maps Output function which maps

1 2 n

1 2 m

1 2 l

Page 56: Regular Expression Manipulation FSM Model

Set Theoretic Description

Mealy Machine is an ordered quintuple

OISSIS

OIS

OIS

maps whichfunctionOutput maps whichfunction stateNext

o,,o,o, outputs ofset Finitei,,i,i, inputs ofset Finites,,s,s, states ofset Finite

where,,,,

l21

m21

n21

=Mealy

Page 57: Regular Expression Manipulation FSM Model

Recursive Definitions of Delta

State Transition for Moore & Mealy– Single-valued, else not deterministic.– At least a partial function– Not necessarily injective or surjective– Shield’s nomenclature

:

: , , ,

S I S

S I S

s i sk k k1

Page 58: Regular Expression Manipulation FSM Model

Recursive Definitions of Delta

*

*

is none or more occurrances of the definitionof a particular mapping from Let

. ., a stringthen define

* , , . ., the response to a null string is no state change

S I S

SII

sax i e

s e s i e

Page 59: Regular Expression Manipulation FSM Model

Recursive Definitions of Beta

• Causal, No Output for No Input.• For a Given Input Sequence, There Will Be

a Deterministic Output Sequence of the Same Length As the Input.

OISOIS

,,,::

1 kkk ois

Page 60: Regular Expression Manipulation FSM Model

Recursive Definitions of Lambda

Same Caveats As Beta

xxsasxas

sos

kkk

k

kk

,,*.,.,*,*

,,::

21

1

OSOS

sk sk-1