meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

18
Theory of Computation (With Automata Theory) Equivalence of Regular Expressions and Finite Automata *Property of STI Page 1 of 18 TOPIC TITLE: Equivalence of Regular Expressions and Finite Automata Specific Objectives: At the end of the topic session, the students are expected to: Cognitive: 1. Convert a finite automaton into its equivalent regular expression. Affective: 1. Listen to others with respect. 2. Participate in class discussions actively. MATERIALS/EQUIPMENT: o topic slides o OHP TOPIC PREPARATION: o Have the students review related topics that were discussed in previous courses. o Prepare the slides to be presented in class. o It is imperative for the instructor to incorporate various kinds of teaching strategies while discussing the suggested topics. o Prepare additional examples on the topic to be presented.

Upload: meljun-cortes

Post on 21-Jan-2017

31 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 1 of 18

TOPIC TITLE: Equivalence of Regular Expressions and Finite Automata

Specific Objectives:

At the end of the topic session, the students are expected to:

Cognitive:

1. Convert a finite automaton into its equivalent regular expression.

Affective:

1. Listen to others with respect. 2. Participate in class discussions actively.

MATERIALS/EQUIPMENT:

o topic slides o OHP

TOPIC PREPARATION:

o Have the students review related topics that were discussed in previous courses.

o Prepare the slides to be presented in class. o It is imperative for the instructor to incorporate various kinds of

teaching strategies while discussing the suggested topics. o Prepare additional examples on the topic to be presented.

Page 2: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 2 of 18

Equivalence of Regular Expressions and Finite Automata Page 1 of 20

Equivalence of Regular Expressions and Finite Automata

Finite Automata to Regular Expressions

The discussions in the previous lesson concentrated on proving that a language is regular if and only if some regular expression describes it. Recall that to determine if a language is regular if and only if some regular expression describes it, it must be shown that:

1. If a language is described by a regular expression, then it is a regular language.

2. If a language is regular, then there is a regular expression that describes it.

The first part had already been established since it was shown that if a language is described by a regular expression, then it is a regular language. This was accomplished by showing that a regular expression describing a language can be converted to an NFA. And since the language now has an NFA, then it follows that it is a regular language.

Equivalence of Regular Expressions and Finite Automata Page 2 of 20

This lesson will now try to establish the second part by proving that if a language is regular, then there is a regular expression that describes it. Corollary 1 states that if a language is regular, then there is an NFA that recognizes it. But is there a regular expression that describes the language? Therefore, a procedure must be outlined for converting the NFA of a regular language into a regular expression. If this can be done, then it can be said that every regular language has a regular expression describing it.

Page 3: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 3 of 18

Equivalence of Regular Expressions and Finite Automata Page 3 of 20

The procedure that will be presented here is for the conversion of a DFA into a regular expression. If the given finite automaton is an NFA, simply convert it first to its equivalent DFA using the procedure outlined in previous lessons. Before discussing the conversion process, it is appropriate to first introduce a new type of finite automaton called a generalized nondeterministic finite automaton (GNFA).

Equivalence of Regular Expressions and Finite Automata Page 4 of 20

Generalized Nondeterministic Finite Automaton

Recall that the state diagram of an NFA/DFA is represented by a graph composed of nodes (representing states) and directed edges (representing the transition from one state to another). One characteristic of NFAs is that transition edges are labeled using one input symbol from the given alphabet. Although there were finite automata presented in previous lessons with transitions labeled with two symbols, these actually represent two edges, one for each symbol. Hence, if two states, qi and qj, are connected with a directed edge labeled with a 0, then the finite automaton moves from state qi to state qj if the input arriving is equal to 0. One main difference between a GNFA and an ordinary NFA is that a transition in a GNFA is labeled using a regular expression. Example:

0*

10*1

q1

0*10*q2q0

0*

In the given example, the edge connecting q0 to q1 is labeled with the regular expression 0*10*. Take note that it is still possible for a GNFA to have transitions labeled with a single input symbol only, (0, 1, or ε). This is because a single input symbol is a valid regular expression as discussed in the previous lesson.

Page 4: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 4 of 18

Equivalence of Regular Expressions and Finite Automata Page 5 of 20

The following are the major characteristics of a GNFA: It has a start state that has an outgoing transition to every other state. If the GNFA is currently in the start state, it can go directly to any other state. However, the start state has no incoming transitions from any other state (indegree = 0). Hence, if the GNFA is currently in some other state, it cannot go back to the start state. Also, the start state cannot be a final state. A GNFA can only have one final state. The final state has an incoming transition from every other state. If the GNFA is currently in some other state, it can go directly to the final state without passing through some intermediate state. The final state also has no outgoing transitions to any other state (outdegree = 0). Hence, once the GNFA reaches the final state, it can longer go back to another state. Every state (excluding the start and final states) has one and only one outgoing transition to every other state (including itself). For example, in the given GNFA, there is only one edge connected state q1 to state q2. There is also one edge connecting state q1 to itself.

Equivalence of Regular Expressions and Finite Automata Page 6 of 20

In an NFA, a state transition may occur upon the arrival of a single input symbol. A GNFA may accept blocks of input symbols (strings with length > 1) that match the regular expression label on the outgoing transition edge before going to another state. Examples: In the given example, the label of the outgoing transition edge connecting state q0 to state q1 is the regular expression 0*10*. This regular expression represents all strings that have exactly one 1. Hence, the GNFA will go from state q0 to state q1 if it receives strings such as such as 1, 01, 010, and 000100 since these are strings that belong to the language of 0*10*. State q1 has a transition loop labeled with the regular expression 10*1. This regular expression represents all strings that have exactly two 1s. Hence, if the GNFA is at state q1, it will stay there as long as it receives input strings such as 11,

101, and 10001 since these are strings that belong to the language of 10*1. The following are sample strings that will be accepted by the given GNFA:

The empty string ε since there is a transition edge connecting the start state q0 to the final state q2 labeled with 0*. The empty string is one of the strings generated by 0*. For the same reason, the GNFA will also accept strings such as 0, 00, 000, etc. The string 11111 since the first 1 will cause the GNFA to move from state q0 to state q1. The next two 1s will cause the GNFA to move from q1 to q1. And the final two 1s will again cause the GNFA to move from q1 to q1. And since the label of the outgoing transition edge connecting state q1 to the final state q2 is 0*, the empty string will cause the GNFA to move from state q1 to state q2 without any additional input symbol or string. Hence, the GNFA ends up in the final state thereby accepting the input string 11111. The string 1111010000 since the first 1 will cause the GNFA to move from state q0 to state q1. The next 11 will cause the GNFA to move from q1 to q1. The next 101 will again cause the GNFA to move from q1 to q1. And the last 0000 will cause the GNFA to move from q1 to q2. Hence, the GNFA ends up in the final state thereby accepting the input string 1111010000.

Page 5: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 5 of 18

Equivalence of Regular Expressions and Finite Automata Page 7 of 20

The first step in converting a DFA to a regular expression is to convert the DFA to a GNFA. The following outlines the procedure for doing this:

1. Create a new start state and add an ε-transition connecting this state to the original start state of the DFA. There is a possibility that a state of the DFA has a transition edge going to the original start state. Since this is not allowed for GNFAs, this step ensures that the new start state of the resulting GNFA has no incoming transition edges.

2. Create a new final state and add ε-transitions connecting all final states of the DFA to this state. Convert all final states of the DFA to ordinary states. This step ensures that the resulting GNFA has only one final state and that it has no outgoing transition edges.

3. If a transition is labeled with multiple symbols, change the label to the union of the symbols. For example:

If the DFA has two states such as

qi

0, 1qj

This means that there are actually two edges connecting qi to qj. One is labeled with a 0 while the other is labeled with a 1. This is not allowed in GNFAs. To remedy this, the label will have to be changed to 0+1 (which is the union of the two input symbols 0 and 1). The state diagram is therefore changed to

qi

0+1qj

There is now only one transition edge connecting qi to qj, and its label is the regular expression 0+1.

Page 6: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 6 of 18

Equivalence of Regular Expressions and Finite Automata Page 8 of 20

4. States that are not connected must be connected with a transition

labeled . This step ensures that all states have a direct connection with every other state. This does not change the meaning of the DFA since

transitions with labels equal to (the empty language) are not really used.

In the actual conversion process that will be presented earlier, this step may be omitted.

Example: Convert the following DFA to a GNFA:

q0 q1

1

0, 10

Applying steps 1 and 2 gives

q0

1

0, 10

qstart qfinalq1

A new state, called qstart, was added which will be the start state of the resulting GNFA. It is connected to the original start state (q0) of the DFA by an ε-transition.

Another state, called qfinal, was added which will be the final state of the resulting GNFA. The old final state (q1) of the DFA is connected to the new final state by an ε-transition. Then, q1 is converted to an ordinary

state so that there will be only one final state.

Page 7: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 7 of 18

Equivalence of Regular Expressions and Finite Automata Page 9 of 20

Applying step 3 gives

q0

1

0 + 10

qstart qfinalq1

The label (0, 1) of the loop transition edge connecting state q1 to itself was changed to the union of the two symbols 0+1. Applying step 4 gives

q0

1

0 + 10

qstart qfinalq1

Since there are no transitions from qstart to q1, from qstart to qfinal, from q0

to qfinal, and from q1 to q0, transitions with labels equal were added to connect these states..

Equivalence of Regular Expressions and Finite Automata Page 10 of 20

GNFA to Regular Expression

After constructing the GNFA, the next step is to eliminate states until there are only two states left—the start and final states. The procedure will be as follows:

1. If the number of states is greater than two, reduce the total number of states by one: – Choose a state to be removed. This state will be referred to as qrip .

The start and final state cannot be selected as qrip.

Page 8: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 8 of 18

Equivalence of Regular Expressions and Finite Automata Page 11 of 20

– Remove qrip from the GNFA.

– To make up for the removal of qrip, reconnect the loose transitions. The GNFA must be repaired by changing the label of the remaining transition edges. Removing a state from a finite automaton will result in some lost computations. Particularly if a certain computation has to pass through the state that was removed. It is therefore important to restore the integrity of the GNFA by making sure that these computations are maintained. This is accomplished by reconnecting the “loose” connections (the connections originally involving the state that was removed). This is done by changing the labels of the remaining transition edges and making sure that the lost computations are integrated into these labels. For example, assume that there are three states namely qi, qrip, and qj. The new label of the edge from state qi, to state qj is a regular expression that describes all strings that would take the machine from qi to qj either directly or via qrip.

Equivalence of Regular Expressions and Finite Automata Page 12 of 20

Here is an example to demonstrate this. Below is the state diagram of a portion of a GNFA showing the three states; qi, qrip, and qj.

qrip

R3

R2

qi qj

R1

R4

There are currently two paths for the GNFA to move from state qi to state qj. One is via a direct connection through a transition edge with regular expression R4 as its label. This means that if the input string belongs to the language of R4, the GNFA will move from state qi to qj.

The second path passes through state qrip. If the first part of the input string corresponds to regular expression R1, then the GNFA will move from state qi to state qrip. If the second part of input string is composed of zero or more concatenations of the regular expression R2, then the GNFA will remain in state qrip. Finally, if the third part of the input string corresponds to regular expression R3, then the GNFA will move from state qrip to state qj. In other words, if the input string corresponds to the combined regular expression R1R2*R3, then the GNFA moves from qi to qj via qrip. In summary, the GNFA moves from state qi to state qj if the input string corresponds to R4 OR R1R2*R3.

Removing qrip means that the second computation (the one involving R1R2*R3) will be lost. To restore this, the label of the transition edge connecting state qi to state qj must be revised to R1R2*R3 + R4 as shown below.

Page 9: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 9 of 18

qi qj

R1R2*R3+R4

The GNFA then moves from state qi to state qj if the input string belongs either to the language of regular expression R1R2*R3 or to the language of regular expression R4. The integrity of the GNFA is thereby preserved even if one state was removed. In other words, the two state diagrams are equivalent.

Equivalence of Regular Expressions and Finite Automata Page 13 of 20

– Keep on eliminating states until there are only two states left.

2. If the number of remaining states is equal to 2, which are the start and final states, then the conversion is complete. The label of the transition edge connecting qstart to qfinal is the regular expression that is equivalent to the given GNFA.

Equivalence of Regular Expressions and Finite Automata Page 14 of 20

Example:

Convert the following DFA into a regular expression:

q0 q1

1

0, 10

The first step in the conversion process is to convert the DFA into its equivalent GNFA. This is accomplished by first creating a new start state and then adding an ε-transition connecting this state to the original start state of the DFA which is state q0. Then, create a new final state and add an ε-transition connecting the final state of the DFA (state q1) to this state. Finally, convert q1 (the final state of the DFA) to an ordinary state. Next, take care of the transitions that are labeled with multiple symbols. There is only one in this example, and that is the loop transition connecting q1 to itself. Change the label of this edge to the union of the symbols (0 + 1). This results in

Page 10: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 10 of 18

q0

1

0 + 10

qstart qfinalq1

There is no need to connect states that are not connected by using a

transition edge whose label is . This is not necessary in the DFA to regular expression conversion process.

Equivalence of Regular Expressions and Finite Automata Page 15 of 20

Since the resulting GNFA has more than two states, the next step now is to remove extra states one at a time. Starting with state q0, qrip will be q0. Remember that states qstart and qfinal cannot be removed. There are two states that link directly with q0. These are states qstart and q1. Try to analyze the computations involved if the GNFA will move between these states via q0. If the first part of the input string is the empty string ε, the GNFA will move from qstart to q0. Then, if the second part of the input string is composed of zero or more concatenations of 0, then the GNFA will stay at state q1. Finally, if the third part of the input string is a 1, then the GNFA moves from state q1 to state q2. In other words, the GNFA will move from qstart to q1 (via q0) if the input string corresponds to the regular expression ε0*1. This expression can be simplified to 0*1 since

concatenating the empty string to a regular expression will not change that expression. Hence, removing q0 will not change the GNFA provided qstart and q1 are connected through a transition edge whose label is equal to the regular expression 0*1. The resulting GNFA will therefore be

0 + 1

qstart qfinalq1

0*1

Since the resulting GNFA still has more than two states, the next step is to remove another state. Obviously, state q1 will be the next qrip. There are two states that have a direct link with q1. These are states qstart and qfinal.

Try to analyze the computations involved if the GNFA will move between these states via q1. If the first part of the input string corresponds to the expression 0*1, then the GNFA will move from qstart to q1. If the second part of the input string is composed of zero or more concatenations of the expression (0 + 1), then the GNFA will remain at q1. Finally, if the third part of the input string is the empty string ε, the GNFA will move from q1 to qfinal. In other words, the GNFA will move from state qstart to state qfinal (via q1) if the input string corresponds to the regular expression 0*1(0 + 1)*ε. This expression can be simplified to 0*1(0 + 1)*. Hence, removing q1 will not change the GNFA provided qstart and qfinal are connected by a transition edge with label equal to the regular expression 0*1(0 + 1)*. The resulting GNFA will therefore be given by

qstart qfinal

0*1(0+1)*

Since the number of states is equal to 2, which are the start and final states, then the conversion is complete. The label of the transition edge connecting qstart to qfinal

Page 11: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 11 of 18

is the regular expression that is equivalent to the given GNFA. The expression for the DFA is therefore R = 0*1(0 + 1)*.

Equivalence of Regular Expressions and Finite Automata Page 16 of 20

Example:

Convert the following DFA into a regular expression:

q0

1

q2

1

q1

0

0

0

1

The first step in the conversion process is to convert the DFA into its equivalent GNFA. This is accomplished by first creating a new start state and adding an ε-transition connecting this state to the original start state of the DFA which is state q0. Then, create a new final state and add ε-transitions connecting the final states of the DFA (states q1 and q2) to this state. Finally, convert states q1 and q2 (the final states of the DFA) to ordinary states. The GNFA will therefore be

q0

1

1

0

0

0

1

qstart qfinal

q2q1

Equivalence of Regular Expressions and Finite Automata Page 17 of 20

Since the resulting GNFA has more than two states, the next step is to remove one of the extra states. Let this state be state q0. Then, qrip here will be state q0. Remember that states qstart and qfinal cannot be removed. There are three states that have a direct link with q0. These are states qstart, q1, and q2. Try to analyze the computations involved if the GNFA will move between these states via q0. First consider the pair of states qstart and q1. There can only be movement from state qstart to state q1 (movement from q1 to qstart is not possible by definition of a GNFA). If the first part of the input string is the empty string ε, the GNFA will move from state qstart to state q0. If the second part of the input string is 0, then the GNFA will move from state q0 to state q1. In other words, the GNFA will move from state qstart to state q1 (via state q0) if the input string corresponds to the regular expression ε0. This expression can be simplified to 0. To preserve this computation, there must be a connecting edge from qstart to q1 with 0 as its label after state q0 is removed.

Next consider the pair of states qstart and q2. There can only be movement from state qstart to state q2 (movement from q2 to qstart is not possible). If the first part of the input string is the empty string ε, the GNFA will move from state qstart to state q0. Then, if the second part of the input string is 1, the GNFA will move from

Page 12: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 12 of 18

state q0 to state q2. In other words, the GNFA will move from state qstart to state q2 (via state q0) if the input string corresponds to the regular expression ε1. This expression can be simplified to 1. To preserve this computation, there must be a connecting edge from state qstart to state q2 with 1 as its label after state q0 is removed. Finally, consider the pair of states q1 and q2. There can be two movements between these states. There is movement from state q1 to state q2 via state q0 and another movement from state q2 to state q1 via a direct connection and via state q0.

1. Consider first the movement from state q1 to state q2 (via q0). If the first part of the input string is 0, the GNFA will move from state q1 to state q0. Then, if the second part of the input string is 1, the GNFA will move from state q0 to state q2. In other words, the GNFA will move from state q1 to state q2 (via q0) if the input string corresponds to the regular expression 01. Hence, there must be a connecting edge from state q1 to state q2 with 01 as its label after state q0 is removed.

2. Consider next the movement from state q2 to state q1. There are two paths for this. The first is through a direct connection via a transition edge from state q2 to state q1 with label 0. Hence, if the input is 0, the GNFA moves from state q2 to state q1.

The second path is via state q0. If the first part of the input string is 1, the GNFA will move from state q2 to state q0. Then, if the second part of the input string is 0, the GNFA will move from state q0 to state q1. In other words, the GNFA will move from state q2 to state q1 (via state q0) if the input string corresponds to the regular expression 10. Hence, there must be a connecting edge from state q2 to state q1 with 01 as its label. Combining the two paths for moving from state q2 to state q1, there must now be a connecting edge from q2 to q1 with the expression 0 + 10 as its label. This is because the GNFA will move from state q2 to state q1 if the input is 0 (via the direct connection) or 01 (via state q0). Hence, the label of the transition edge connecting state q2 to state q1 must be changed from 0 to 0+10 after state q0 is removed.

Lastly, consider also the possibility of the GNFA moving from state q1 back to state q1 and state q2 back to state q2 (loops).

There are two paths from q1 to q1. If the input symbol is 1, then the GNFA stays at state q1. The other path is for the GNFA to move from state q1 to state q0 and then back to state q1. This will happen if the input string is 00. In effect, the GNFA will move from state q1 back to state q1 if the input string is 00 or 1. Hence, the label of the loop transition at state q1 must be changed from 1 to 00 + 1. The path from q2 back to q2 is via q0. This is taken when the input is 11. Hence, a loop transition at state q2 must be added with label 11. After removing state q0, the following changes must be made:

1. There must be a connecting edge from state qstart to state q1 with 0 as its

label. 2. There must be a connecting edge from state qstart to state q2 with 1 as its

label. 3. There must be a connecting edge from state q1 to state q2 with 01 as its

label. 4. The label of the transition edge connecting state q2 to state q1 must be

changed from 0 to 0 + 10. 5. The label of the loop transition at state q1 must be changed to from 1 to

00 + 1. 6. A loop transition at state q2 must be added with label 11.

Page 13: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 13 of 18

The resulting GNFA will therefore be

00+1

0

qstart qfinal

q2q1

11

1

0+10

01

Since the resulting GNFA still has more than two states, the next step is to remove another state. Let this be state q1. The qrip here will then be q1. There are three states that have a direct link with q1. These are states qstart, q2, and qfinal. Again, try to analyze the computations involved if the GNFA will move between these states via q1. First, consider the pair of states qstart and q2. There can only be movement from state qstart to state q2 (movement from q2 to qstart is not possible) and there are two paths for this. The first is through a direct connection using a transition edge from state qstart to state q2 with label 1. If the input is 1, the GNFA will move from state qstart directly to state q2. The second path is via state q1. If the first part of the input string is a 0, then the GNFA will move from state qstart to state q1. If the

second part of the input string is composed of zero or more concatenations of (00 + 1), then the GNFA will stay at state q1. And, if the third part of the input string is 01, then the GNFA will move from state q1 to state q2. In other words, the GNFA will move from state qstart to state q2 (via state q1) if the input string corresponds to the regular expression 0(00 + 1)*01. Combining the two paths from state qstart to state q2, there must now be a transition edge connecting state qstart to state q2 with a label equal to the expression 0(00 + 1)*01 + 1. This is because the GNFA will move from state qstart to state q2 if the input is 0(00 + 1)*01 (via state q1) or if the input is 1 (via the direct connection). Hence, the label of the transition edge connecting state qstart to state q2 must be changed from 1 to 0(00 + 1)*01 + 1 after q1 is removed. Next, consider the pair of states qstart and qfinal. There can only be movement from state qstart to state qfinal (movement from qfinal to qstart is not possible). If the first part of the input string is a 0, then the GNFA will move from state qstart to state q1. If the second part of the input string is composed of zero or more concatenations of (00 + 1), then the GNFA will stay at state q1. And, if the third part of the input string is the empty string ε, then the GNFA will move from state q1 to state qfinal. In other words, the GNFA will move from state qstart to state qfinal (via state q1) if the input string corresponds to the regular expression 0(00 + 1)*ε. This expression can be simplified to 0(00 + 1)*. To preserve this computation, there must be a connecting edge from state qstart to state qfinal with the expression 0(00 + 1)* as its label after state q1 is removed. Next, consider the pair of states q2 and qfinal. There can only be movement from state q2 to state qfinal (movement from qfinal to q2 is not possible), and there are two paths for this. The first is through a direct connection using a transition edge from state q2 to state qfinal with label ε. Hence, if the input is the empty string, the GNFA will move from state q2 to state qfinal. The second is via state q1. If the first part of the input string is a 0 + 10, then the GNFA will move from state q2 to state q1. If the second part of the input string is composed of zero or more concatenations of (00 + 1), then the GNFA will stay at state q1. And, if the third part of the input string is the empty string ε, then the GNFA will move from state q1 to state qfinal. In other

Page 14: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 14 of 18

words, the GNFA will move from state q2 to state qfinal (via state q1) if the input string corresponds to the regular expression (0 + 10)(00 + 1)*ε. This expression

can be simplified to (0 + 10)(00 + 1)*. Combining the two, there must now be a transition edge connecting state q2 to state qfinal with a label equal to the expression (0 + 10)(00 + 1)*+ ε. This is because the GNFA will move from state q2 to state qfinal if the input is (0 + 10)(00 + 1)* (via state q1) or if the input is ε (via the direct connection). Hence, the label of the transition edge connecting state q2 to state qfinal must be changed from ε to (0 + 10)(00 + 1)* + ε after q1 is removed. Lastly, consider also the possibility of the GNFA moving from state q2 back to state q2. There are two paths for this. If the input string is 11, then the GNFA stays at state q2. The other is for the GNFA to move from state q2 to state q1 and then back to state q2. If the first part of the input string is 0 + 10, the GNFA will move from state q2 to state q1. If the second part of the input string is composed of zero or more concatenations of the expression (00 + 1), then the GNFA stays at state q1. If the third part of the input string is 01, the GNFA will move from state q1 back to state q2. In other words, the GNFA will move from state q2 back to state q2 if the

input string corresponds to the expression (0 + 10)(00 + 1)*01. In effect, the GNFA will move from state q2 back to state q2 if the input string corresponds to (0 + 10)(00 + 1)*01 or 11. So the label of the loop transition at state q2 must be changed from 11 to (0 + 10)(00 + 1)*01 + 11.

So after removing state q1, the following changes must be made:

1. The label of the transition edge connecting state qstart to state q2 must be

changed from 1 to 0(00 + 1)*01 + 1. 2. There must be a connecting edge from state qstart to state qfinal with the

expression 0(00 + 1)* as its label. 3. The label of the transition edge connecting state q2 to state qfinal must be

changed from ε to (0 + 10)(00 + 1)* + ε. 4. The label of the loop transition at state q2 must be changed from 11 to

(0 + 10)(00 + 1)*01 + 11.

The resulting GNFA will therefore be

0(00+1)*01+1

qstart qfinal

q2

(0+10)(00+1)*01+11

(0+10)(00+1)*+

0(00+1)*

Page 15: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 15 of 18

Equivalence of Regular Expressions and Finite Automata Page 18 of 20

Since the resulting GNFA still has three states, the next step is to remove one more state. Obviously, state q2 will be the next qrip.

There are two states that have a direct link with q2. These are states qstart and qfinal. Try to analyze the computations involved if the GNFA will move between these states via q2.

There can only be movement from state qstart to state qfinal (movement from qfinal to qstart is not possible) and there are two paths for this. The first is through a direct connection using a transition edge from state qstart to state qfinal with

label 0(00 + 1)*. So if the input string corresponds to the expression 0(00 + 1)*, the GNFA will move from state qstart to state qfinal. The second path is via state q2. If the first part of the input string corresponds to the expression 0(00 + 1)*01 + 1, then the GNFA will move from qstart to q2. If the second part of the input string is composed of zero or more concatenations of the expression ((0 + 10)(00 + 1)*01 + 11), then the GNFA will remain at q2. And finally, if the third part of the string corresponds to the expression (0 + 10)(00 + 1)* + ε, the GNFA will move from q2 to qfinal. In other words, the GNFA will move from qstart to qfinal (via q1) if the input string corresponds to the regular expression

(0(00 + 1)*01 + 1)((0 + 10)(00 + 1)*01 + 11)*((0 + 10)(00 + 1)* + ε)

Combining the two paths from state qstart to state qfinal, there must now be a transition edge connecting state qstart to state qfinal with a label equal to the expression

(0(00+1)*01+1)((0+10)(00+1)*01+11)*((0+10)(00+1)*+ε)+(0(00+1)*) The final GNFA will therefore be:

qstart qfinal

(0(00+1)*01+1) ((0+10)(00+1)*01+11)* ((0+10)(00+1)*+ ) + (0(00+1)*)

Since the number of states is equal to 2, which are the start and final states, then the conversion is complete. The label of the transition edge connecting qstart to qfinal is the regular expression that is equivalent to the given GNFA. The expression for the given DFA is therefore

R = (0(00+1)*01+1)((0+10)(00+1)*01+11)*((0+10)(00+1)*+ε)+(0(00+1)*)

Page 16: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 16 of 18

Equivalence of Regular Expressions and Finite Automata Page 19 of 20

Have the students convert the following DFAs into a single regular expression. Let them work on it for 10 to 15 minutes each and then discuss with them the step by step solution for each.

1

0

q0

0 1

q1

0,1q2q0 q1

0

1

1

0

Solution for first DFA: Converting the DFA into its equivalent GNFA,

1

0

0 1

q1

qfinal

q0qstart

Removing state q0,

0*1

1+00*1

q1

qfinal

qstart

00*

Removing state q1,

qfinal

qstart

(0*1)(1+00*1)*00*+

Page 17: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 17 of 18

The regular expression is

R = (0*1)(1 + 00*1)*00 + ε

Solution for second DFA: Converting the DFA into its equivalent GNFA,

0+1q1

0

1

1

0

qfinal

q0qstart q2

Removing state q0,

0+1q1

0

1

0(0+1)+1

qfinal

qstart q2

0+

0(0+1)0*1

Removing state q1,

(0+1)0*1

qfinal

qstart q2

0+

(0(0+1)+1)0*1+0(0+1)0*1

Removing state q2,

((0+1)0*1)((0(0+1)+1)0*1+0(0+1)0*1)*(0+ ) +

qfinal

qstart

The regular expression is

R = ((0+1)0*1)((0(0+1)+1)0*1+0(0+1)0*1)*(0+ε) + ε

Page 18: Meljun cortes automata_lecture_equivalence of regular expressions and finite automata_part 2_1

Theory of Computation (With Automata Theory)

Equivalence of Regular Expressions and Finite Automata *Property of STI Page 18 of 18

Equivalence of Regular Expressions and Finite Automata Page 20 of 20

There is now a procedure for converting a finite automaton to a regular expression. It can therefore be said that if a language is regular, then there is a regular expression that describes it. Since the previous lesson had shown that if a language is described by a regular expression, then it is a regular language by outlining a procedure to convert a regular expression to a finite automaton, it can now be said that a language is regular if and only if some regular expression describes it. All of these can now be formalized through the following theorem and lemmas: Theorem 5

A language is regular if and only if some regular expression describes it. Lemma 5.1

If a language is described by a regular expression, then it is regular. Lemma 5.2

If a language is regular, then it is described by a regular expression.

[The Equivalence of Regular Expressions and Finite Automata, Pages 1–20 of 20]