Close
Close Window

OpenDSA Complete Catalog

Chapter 35 Regular Languages

| About   «  35.3. More Regular Expressions Exercises   ::   Contents   ::   35.5. Regular Grammars  »

35.4. The Power of Regular Expressions

Now that we know the definition for Regular Expressions and have a bit of experience with writing them, the next order of business is understanding how powerful they are. In particular, a natural question to ask is: What is the relationship between Regular Expressions and Regular Languages? Recall that a Regular Language is defined to be any langauge that can be accepted by a DFA (and equivalently, any language that can be accepted by a NFA).

In this section, we will use our standard approach of simulation to show that Regular Expressions are equivalent to Regular Languages. By this, we mean that a Regular Expression can be converted to a representation for a Regular Language (in particular, a NFA). Therefore, any Regular Expression represents a Regular Language. Going the other way, any Regular Language (in the form of an NFA) can be converted to a Regular Expression. Thus, any Regular Language can be represented by a Reglar Language. The conclusion is then that these are equivalent.

35.4.1. Every Regular Expression has an Equivalent NFA

1 / 13 Settings
<<<>

Part 1. Recall that we define the term regular language to mean the languages that are recognized by a DFA. And we know these are the same as the languages recognized by an NFA, because we know that every NFA can be converted to a DFA (and vice versa).

Now, we will show the relationship between regular languages (and thus, DFAs and NFAs) and Regular Expressions.

Proficient Saving... Error Saving
Server Error
Resubmit

Summary: We have now shown that (1) an RE consisting of λ or of a single symbol from the alphabet can be represented by an NFA, and (2) we can convert any NFA to an equivalent NFA with a single final state. This simplifies the rest of the constructions that we will use.

1 / 12 Settings
<<<>

Part 2. In Part 1, we showed how to convert the base case REs ($\lambda$ and any symbol from $\Sigma$) to NFAs. And we showed that any NFA can be converted to an equivalent NFA with a single final state.

Now we will see how to convert more complex REs to an NFA.

Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit


1 / 12 Settings
<<<>

Part 3. Next, we will define a construction for the NFA that can accept the RE $r \cdot s$, given that we have NFAs that are equivalent to $r$ and $s$.

Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit


1 / 12 Settings
<<<>

Part 4. The last operator that we need to implement is the Kleene star ($*$) operator. The operator will concatenate the language with itself zero or more times.

Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit

Now let’s spell out the entire induction proof.

Summary: Using an inductive argument, we have now demonstrated that we can convert any RE to an NFA. So, all REs accept a regular language.

35.4.2. Converting a Regular Expression to a NFA

1 / 20 Settings
<<<>

We now have a proof that any RegEx can be converted to a NFA. And we know some mechanics: In particular, we know how to combine two NFAs that represent RegExs into a single NFA using one of the RegEx builder rules. Unfortunately, that does not really help us when faced with a complex RegEx that we want to convert to an NFA. In this frameset, we show an algorithm for doing this.

Created with Raphaël 2.1.2
Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit

35.4.3. Regular Expression to Minimized DFA Example

1 / 30 Settings
<<<>>>

In this example, we will convert the regular expression ab*+c to a minimized DFA.

Proficient Saving... Error Saving
Server Error
Resubmit

35.4.4. Converting NFAs to Regular Expressions

1 / 32 Settings
<<<>

Since every regular expression has an NFA that implements it, this means that the regular expressions are a subset of the regular languages. The next question is: Does every regular language have a regular expression?

Perhaps you thought it fairly intuitive to see that any regular expression can be implemented as a NFA. But for most of us, going the other way is not at all obvious. The proof that any NFA can be converted to a regular expression is rather difficult, and we are just going to give a sketch.

Proficient Saving... Error Saving
Server Error
Resubmit

35.4.5. Summary

We have now demonstrated the following:

  • Any RegEx can be represented by an NFA or a DFA.

  • Any NFA (or DFA) can be represented by a RegEx.

Thus, all languages that can be represented by regular expression are regular, and all regular languages can be represented by a regular expression.

   «  35.3. More Regular Expressions Exercises   ::   Contents   ::   35.5. Regular Grammars  »

Close Window