25
State Minimization and State Minimization and Determinization Determinization EECS 290A EECS 290A Sequential Logic Synthesis and Verification Sequential Logic Synthesis and Verification

State Minimization and Determinization EECS 290A Sequential Logic Synthesis and Verification

  • View
    224

  • Download
    0

Embed Size (px)

Citation preview

State Minimization and DeterminizationState Minimization and Determinization

EECS 290A EECS 290A Sequential Logic Synthesis and VerificationSequential Logic Synthesis and Verification

OverviewOverview

Finite automata and finite state machinesFinite automata and finite state machines State minimizationState minimization DeterminizationDeterminization

A finite automaton (FA) is

( , , , , )F S r Q

where S is a set of states,

is an input alphabet,

( , ) : 2Ss S is a transition relation, r is the initial state, and

Q S is the set of

accepting states.

Finite AutomataFinite Automata

A finite state machine (FSM) is

0( , , , , , )M S I O S

where S is a set of states,

/I O are input/output alphabets,

( , ) : 2Ss i S I is the transition relation,

0S S is the set of

initial states.

Finite State MachinesFinite State Machines

o

i

ns1 ns2

cs2 cs1

0 0

( , ) : 2Os i S I is the output relation

00

10

01

1/0

0/0

-/1 1/1

0/1

FA and FSMFA and FSM

00

10

01

1/0

0/0

-/1 1/1

0/1

00

10

01

10

00

-1 11

01

-0

-1

-0

--

DC

FSM FSM FA FA Complete by adding a non-accepting stateComplete by adding a non-accepting state

FA FA FSM FSM Make prefix-closed and progressiveMake prefix-closed and progressive

FSMFA

Outline of State MinimizationOutline of State Minimization

Requirements for the automatonRequirements for the automaton Deterministic (if not, first determinize)Deterministic (if not, first determinize) Complete (if not, first complete)Complete (if not, first complete)

Definition of state equivalenceDefinition of state equivalence Two ways of computing equivalence classesTwo ways of computing equivalence classes

ImplicitImplicit ExplicitExplicit

The explicit algorithm in detailThe explicit algorithm in detail ExampleExample

State Equivalence of FAState Equivalence of FA Definition.Definition. A string is accepted by A string is accepted by

the automation in state the automation in state ss iff when iff when started in state started in state ss, it drives the , it drives the automaton into an accepting state.automaton into an accepting state.

Definition.Definition. Two states Two states s1s1 and and s2 s2 are distinguishable iff there exists are distinguishable iff there exists a string, which when started from a string, which when started from these states, is accepted in state these states, is accepted in state s1s1 and not accepted in state and not accepted in state s2s2..

Definition.Definition. States States s1s1 and and s2s2 are are equivalent if they are not equivalent if they are not distinguishable.distinguishable.

Example: Example: States States AA and and CC are distinguishable are distinguishableStatesStates B B and and C C are equivalentare equivalent

Outline of the AlgorithmOutline of the Algorithm The automaton is given byThe automaton is given by

State transition graph State transition graph The set of accepting statesThe set of accepting states

Compute the set of distance-0 distinguishable pairs by combining Compute the set of distance-0 distinguishable pairs by combining each accepting state with each non-accepting stateeach accepting state with each non-accepting state

For each pair, find all the pairs reachable in backward traversal from For each pair, find all the pairs reachable in backward traversal from the distinguishable pairs, under all input combinationsthe distinguishable pairs, under all input combinations

Collect these pairs and explore them until no new pairs can be foundCollect these pairs and explore them until no new pairs can be found The remaining pairs are pairs of equivalent statesThe remaining pairs are pairs of equivalent states Reduce the automaton by replacing each state by one selected Reduce the automaton by replacing each state by one selected

representative of its equivalence classrepresentative of its equivalence class

Implicit ImplementationImplicit Implementation The automaton is given byThe automaton is given by

Transition relation Transition relation R(x,cs,ns)R(x,cs,ns) Characteristic function of accepting states Characteristic function of accepting states A(cs)A(cs)

Compute the set of distance-0 distinguishable pairs (when one state Compute the set of distance-0 distinguishable pairs (when one state is accepting while the other is not)is accepting while the other is not)

DD00(cs,cs’) = A(cs) (cs,cs’) = A(cs) A(cs’) A(cs’) Compute the pair transition relationCompute the pair transition relation

P(cs,cs’,ns,ns’) = P(cs,cs’,ns,ns’) = x [R(x,cs,ns) & R(x,cs’,ns’)]x [R(x,cs,ns) & R(x,cs’,ns’)] Starting from the distance-0 distinguishable pairs, iteratively Starting from the distance-0 distinguishable pairs, iteratively

compute distance-k distinguishable pairs, until convergencecompute distance-k distinguishable pairs, until convergence DDi+1i+1(cs,cs’) = (cs,cs’) = ns,ns’ [P(cs,cs’,ns,ns’) & Dns,ns’ [P(cs,cs’,ns,ns’) & Dii(ns,ns’)](ns,ns’)]

The equivalence relation isThe equivalence relation is E(cs,cs’) = NOT[DE(cs,cs’) = NOT[Di+1i+1(cs,cs’)](cs,cs’)]

Reduce the automaton by replacing each state by one Reduce the automaton by replacing each state by one representative taken from its equivalence classrepresentative taken from its equivalence class

P(cs,cs’) = CompatibleProjection( E(cs,cs’), {cs} )P(cs,cs’) = CompatibleProjection( E(cs,cs’), {cs} ) R(x,cs,ns) = R(x,cs,ns) = cs’,ns’[ R(x,cs’,ns’) & P(cs,cs’) & P(ns,ns’) ]cs’,ns’[ R(x,cs’,ns’) & P(cs,cs’) & P(ns,ns’) ]

Explicit ImplementationExplicit Implementation The automaton The automaton

The linked list of statesThe linked list of states The accepting states are markedThe accepting states are marked

Additional data structuresAdditional data structures Q:Q: The FIFO queue of distinguishable state pairs to be explored The FIFO queue of distinguishable state pairs to be explored H:H: The hash table hashing every pair into The hash table hashing every pair into {visited, not visited}{visited, not visited}

InitializationInitializationfor each accepting state for each accepting state ss for each non-accepting state for each non-accepting state s’s’ insert pair insert pair (s,s’)(s,s’) into into QQ and and HH

ComputationComputationwhile while QQ is not empty, extract one pair is not empty, extract one pair (s,s’)(s,s’) from from QQ for each pair for each pair (t,t’),(t,t’), which transits into which transits into (s,s’)(s,s’) under some input under some input if if (t,t’)(t,t’) is not in is not in HH (that is, (that is, (t,t’)(t,t’) has not been visited) has not been visited) insert pair insert pair (t,t’)(t,t’) into into QQ and into and into HH

Reducing the AutomatonReducing the Automaton The automaton The automaton

The linked list of statesThe linked list of states The accepting states are markedThe accepting states are marked

The equivalence relationThe equivalence relation Maps pair Maps pair (s,s’)(s,s’) into into {distinguishable, equivalent}{distinguishable, equivalent}

• The same as hash table The same as hash table H: visited = distinguishable; not visited = equivalentH: visited = distinguishable; not visited = equivalent ComputationComputation

Construct the equivalence classes of states using the equivalence relationConstruct the equivalence classes of states using the equivalence relation Select one representative state from each equivalence classSelect one representative state from each equivalence class Create the mappingCreate the mapping of each state in the original automaton into the of each state in the original automaton into the

representative state from its equivalence classrepresentative state from its equivalence classstart the new automatonstart the new automatonadd a new state for each representative state of the old automatonadd a new state for each representative state of the old automatonfor all representative states for all representative states s1s1

for each transition for each transition (s1->s2)(s1->s2) from the representative state from the representative state s1s1 into some other state into some other state s2s2add transition from the new state corresponding to add transition from the new state corresponding to s1s1 into the new state into the new state

corresponding to corresponding to s2s2 Set the new initial state to be the new state corresponding to the Set the new initial state to be the new state corresponding to the

representative of the class, to which the original initial state belongsrepresentative of the class, to which the original initial state belongs

Example of State MinimizationExample of State Minimization

Distinguishable pairs Distinguishable pairs after initializationafter initialization

(A,DC), (C,DC), (B,DC)(A,DC), (C,DC), (B,DC) Computed Computed

distinguishable pairsdistinguishable pairs (A,DC) (A,DC) (A,C) (A,C) (A,DC) (A,DC) (A,B) (A,B)

Remaining equivalent Remaining equivalent pairspairs

(B,C)(B,C) The derived reduced The derived reduced

graph graph

Outline of DeterminizationOutline of Determinization Subset constructionSubset construction General flow of the algorithmGeneral flow of the algorithm ExamplesExamples

When the number of states is exponential (2^n-1)When the number of states is exponential (2^n-1) When the number of states is reducedWhen the number of states is reduced

Computing reachable subsets of statesComputing reachable subsets of states ExplicitExplicit

• Enumerating mintermsEnumerating minterms• Partitioning Boolean spacePartitioning Boolean space

ImplicitImplicit• Cofactoring monolithic transition relationCofactoring monolithic transition relation

HybridHybrid• Using the transition relations for each stateUsing the transition relations for each state

Determinization by Subset Determinization by Subset ConstructionConstruction

Assume that ND transitions in the ND automaton happen Assume that ND transitions in the ND automaton happen at the same timeat the same time

It means that, at any moment, the ND automaton is in a subset It means that, at any moment, the ND automaton is in a subset of its states of its states

The subset may contain more than one stateThe subset may contain more than one state The point of determinization is to enumerate through all The point of determinization is to enumerate through all

the subsets of states reachable from the initial state the subsets of states reachable from the initial state under any possible inputsunder any possible inputs

Each subset of states of the ND automaton becomes a single Each subset of states of the ND automaton becomes a single state of the new deterministic automatonstate of the new deterministic automaton

The languages accepted by the ND automaton and its The languages accepted by the ND automaton and its determinized version are the samedeterminized version are the same

Determinization AlgorithmDeterminization Algorithm The automaton The automaton

The linked lists of states The linked lists of states {s}{s}, with the accepting states marked, with the accepting states marked Additional data structuresAdditional data structures

Q:Q: The FIFO queue of reached subsets of states The FIFO queue of reached subsets of states Sk Sk H:H: The hash table mapping each reached subsets of states The hash table mapping each reached subsets of states Sk Sk into the into the

corresponding state of the determinized automatoncorresponding state of the determinized automaton InitializationInitialization

Create the initial state of the determinized automaton by creating the Create the initial state of the determinized automaton by creating the subset of states subset of states {s0}{s0} composed of the initial state of the ND automaton composed of the initial state of the ND automaton

insert insert {s0}{s0} into into QQ and and HH ComputationComputation

while while QQ is not empty, extract one subset of states is not empty, extract one subset of states SiSi from from QQ for all subsets of states Sj reachable in one transition from Sifor all subsets of states Sj reachable in one transition from Si if if SjSj is not in is not in HH (that is, (that is, SjSj has not been visited) has not been visited) create the new state of the determinized automatoncreate the new state of the determinized automaton make the new state accepting if some state of make the new state accepting if some state of SjSj is accepting is accepting insert insert SjSj into into QQ and into and into HH else find the new state corresponding to else find the new state corresponding to SjSj using the hash table using the hash table HH add the transition from add the transition from SiSi into into SjSj

Example whenExample when Subset Construction Subset Construction Leads to Exponential Number of StatesLeads to Exponential Number of States

Example when Subset Construction Example when Subset Construction Reduces Number of StatesReduces Number of States

Computing Reachable SubsetsComputing Reachable Subsets Given a subset of states, what are other subsets of states that can be Given a subset of states, what are other subsets of states that can be

reached in one transition from the given subset?reached in one transition from the given subset? Naïve explicit approach (using STG)Naïve explicit approach (using STG)

Enumerate the minterms of the Boolean space of conditionsEnumerate the minterms of the Boolean space of conditions For each minterm, find the subset of states reachable from the given For each minterm, find the subset of states reachable from the given

subset in one iterationsubset in one iteration Collect unique subsetsCollect unique subsets

State subset {2,3}

Minterm 00: 2 {1} 3 {1} {2,3} {1}

Minterm 01: 2 {3} 3 {1} {2,3} {1,3}

Minterm 10: 2 {3} 3 {1} {2,3} {1,3}

Minterm 11: 2 {3} 3 {1,3} {2,3} {1,3}

Computing Reachable SubsetsComputing Reachable Subsets Improved explicit approach (using STG)Improved explicit approach (using STG)

Compute partitioning on the condition space defined by states in the subset Compute partitioning on the condition space defined by states in the subset Compute the product of partitions for all states in the subsetCompute the product of partitions for all states in the subset Each partition corresponds to one subset of next statesEach partition corresponds to one subset of next states Collect unique subsetsCollect unique subsets This approach does not require enumerating through the mintermsThis approach does not require enumerating through the minterms

State subset {2,3}

State 2 partition: (00) {1} (01,10,11) {3}

State 3 partition: (00,01,10) {1} (11) {1,3}

Product of partitions: (00) {1} (01,10) {1,3} (11) {1,3}

Unique next state subsets: {1} and {1,3} (00) {1} (01,10,11) {1,3}

Transition Relation of the SubsetTransition Relation of the Subset Given the subset Given the subset si,si, compute compute Rsi(x,s)Rsi(x,s)

This relation for each input This relation for each input xx, gives the set of next states , gives the set of next states {sj}{sj}

Example: State subset {2,3} Input variables {x1,x2} State variables {s1,s2} Transition relation of state 2: R2(x1,x2,s1,s2) = x1’x2’s1’s2 + (x1+x2)s1s2 Transition relation of state 3: R3(x1,x2,s1,s2) = x1x2s1s2 + s1’s2 Transition relation of state subset {2,3}: R(x1,x2,s1,s2) = R2 + R3 = x1’x2’s1’s2+ (x1 + x2)s2

Code 01

Code 11

Code 10

Computing Computing Transition Relation of Transition Relation of the Subsetthe Subset

Implicit approachImplicit approach The monolithic transition relation The monolithic transition relation R(x,cs,ns)R(x,cs,ns) is available is available Restrict the monolithic transition relation Restrict the monolithic transition relation R(x,cs,ns)R(x,cs,ns) to the given to the given

subset of states subset of states Si(cs)Si(cs): : R(x,s) = R(x,s) = cs [R(x,cs,ns) & Si(cs)]cs [R(x,cs,ns) & Si(cs)]ns ns ss

Hybrid approachHybrid approach The individual state transition relations The individual state transition relations Ri(x,s)Ri(x,s) are available are available Add the transition relations for all states in the subsetAdd the transition relations for all states in the subset R(x,s) R(x,s)

= = iSiSi Ri(x,s)Ri(x,s)

Computing Reachable SubsetsComputing Reachable Subsetsusing using Transition Relation of the SubsetTransition Relation of the Subset

Compute Compute orthonormal expansionorthonormal expansion of the transition of the transition relation of the subset relation of the subset R(x,s)R(x,s) w.r.t. variables in w.r.t. variables in {x}{x}

R(x,s) = i [ fi(x) & gi(s) ], where (1) fi(x) & fj(x) = 0, i j (2) gi(s) = gj(s) i = j

In the orthonormal expansion, functions In the orthonormal expansion, functions gi(s)gi(s) are sets are sets of next states reachable under conditions of next states reachable under conditions fi(x) fi(x) from the from the given subsetgiven subset

Computing Orthonormal Expansion Computing Orthonormal Expansion using BDD Variable Orderingusing BDD Variable Ordering

Orthonormal expansion is

R(x,s) = i [ fi(x) & gi(s) ], where

(1) fi(x) & fj(x) = 0, i j

(2) gi(s) = gj(s) i = j BDD represents the function as a set of disjoint BDD represents the function as a set of disjoint

paths - condition (1)paths - condition (1) BDD reduction guarantees merging identical BDD reduction guarantees merging identical

cofactors - condition (2)cofactors - condition (2) Building BDD with variables Building BDD with variables {x1,x2}{x1,x2} on top lead to on top lead to

the orthonormal expansionthe orthonormal expansion

Example: Example: R(x1,x2,s1,s2) = x1’x2’s1’s2 + (x1+x2)s2

s1’s2 encodes state {1} (condition x1’x2’) s2 encodes state subset {1,3} (condition x1+x2)

x1

x2

s1

s2

Code 01

Code 11

Code 10

Computing Orthonormal Expansion Computing Orthonormal Expansion using General Methodusing General Method

Given a state subsetGiven a state subset Si Si and and its transition relation its transition relation R(x,s)R(x,s)

while while R(x,s) R(x,s) is not empty, enumerate through the elements is not empty, enumerate through the elements of the expansion (reachable subsets):of the expansion (reachable subsets):

Extract one minterm Extract one minterm m(x,s) m(x,s) from from R(x,s)R(x,s) Restrict Restrict m(x,s) m(x,s) to only input variables to only input variables x x (call it (call it m(x)m(x))) Find Find SjSj reachable from reachable from SiSi under under m(x)m(x): : Sj(s) = Sj(s) = x[R(x,s) & m(x)]x[R(x,s) & m(x)] Find Find Cij(x)Cij(x) labeling transition labeling transition Si Si Sj Sj: : Cij(x)=Cij(x)=s[R(x,s) s[R(x,s) Sj(s)] Sj(s)] Subtract this transition from Subtract this transition from R(x,s): R(x,s) = R(x,s) & NOT(Cij(x))R(x,s): R(x,s) = R(x,s) & NOT(Cij(x))

ExampleExampleR(x1,x2,s1,s2) = x1’x2’s1’s2 + (x1+x2)s2

Extract minterm: Extract minterm: m(x,s) = m(x,s) = x1x2s1s2Restrict to variables x: m(x) = x1x2

Find the related set of states: Sj(s) = Sj(s) = s2 (subset {1,3})Find the related condition: Cij(x) = x1+x2Subtract this transition from the relation: R(x1,x2,s1,s2) = x1’x2’s1’s2

Extract minterm: Extract minterm: m(x,s) = m(x,s) = x1’x2’s1’s2Restrict to variables x: m(x) = x1’x2’

Find the related set of states: Sj(s) = Sj(s) = s1’s2 (subset {1})Find the related condition: Cij(x) = x1’x2’Subtract this transition from the relation: R(x1,x2,s1,s2) = 0

Quit the while-loop