Вы находитесь на странице: 1из 16

CS 25

Automata Theory & Formal Languages

Lecture 4

EQUIVALENCE OF FINITE AUTOMATA WITH


REGULAR EXPRESSIONS:

Regular expressions and finite automata are equivalent in their


descriptive power.
A language is regular if and only if some regular expression
describes it.

GENERALIZED NONDETERMINISTIC FINITE


AUTOMATA (GNFA)

NFA wherein transition arrows may have any regular expressions as labels.

Special Form:
1. There are transitions going from the initial state to all other states, and there
are no transitions into the initial state.
2. There is a single accept state that has only transitions coming into it (and no
outgoing transitions).
3. The accept state is distinct from the initial state.
4. Except for the initial and accepting states, all other states are connected to all
other states via a transition. In particular, each state has a transition to itself.

CONVERTING GNFA TO SPECIAL FORM


1. Add new start state with an arrow to the old start state.
2. Add new accept state with arrows pointing from the old accept
states.
3. If there are multiple arrows between 2 states and in same
direction, we replace each with a single arrow whose label is the
union of the previous labels.
4. Add arrows labeled between states that had no arrows.

FORMAL DEFINITION OF A GNFA


5-tuple (Q, , , qstart, qaccept), where
1. Q is a finite set called states
is the input alphabet
: (Q-{qaccept}) X(Q-{qstartt}) R is the transition function
4. qstart the start state
5. qaccept is the accept state

CONVERTING DFA TO REGULAR EXPRESSION

1.Convert DFA to a GNFA, adding new initial and


final states.
2.Remove all states one-by-one, until we have
only the initial and final states.
3.Output regular expression is the label on the
(single) transition left in the GNFA.

CONVERTING GNFA TO REGULAR EXPRESSION

If k (number of states) > 2, construct an equivalent GNFA form with


k-1 states; repeat until k=2.
If k=2, there is only a single arrow from the start to the accept state.
The label on this arrow is the regular expression.

CONVERTING GNFA TO REGULAR EXPRESSION


Algorithm for ripping a single state:
For every state qrip do
For every incoming state qi do
For every outgoing state qj do
Remove all transition paths from qi to qj via qrip by
creating a direct transition between qi and qj .

EXAMPLE OF CONVERTING DFA/NFA TO REGULAR


EXPRESSION
1. The original 3-state DFA.

EXAMPLE OF CONVERTING DFA/NFA TO REGULAR


EXPRESSION
2. Convert to 5-state GNFA (null transitions are unrepresented).

EXAMPLE OF CONVERTING DFA/NFA TO REGULAR


EXPRESSION
3. Convert to 4-state GNFA by eliminating state A.

EXAMPLE OF CONVERTING DFA/NFA TO REGULAR


EXPRESSION
4. Convert to 3-state GNFA by eliminating state B.

EXAMPLE OF CONVERTING DFA/NFA TO REGULAR


EXPRESSION
5. Convert to 2-state GNFA by eliminating state C.

Thus, the automata is equivalent to the regular expression (ab*a U b)(a U b)*.

EXERCISE:

Convert the given DFA below to an equivalent Regular Expression.

b
1

a, b
a

Algebraic Laws for REs

Union and concatenation behave sort of like


addition and multiplication.

Union is commutative and associative; concatenation


is associative.

Concatenation distributes over union.

Exception: Concatenation is not commutative.

15

Identities and Annihilators

is the identity for .


R = R.
is the identity for concatenation.
R = R = R.
is the annihilator for concatenation.
R = R = .

16

Вам также может понравиться