Regular Languages (RLs)¶
Welcome to Week 3!
This week we will discover that Deterministic and Non-deterministic FAs recognize the same class of languages, which we will call Regular Languages.
Why are they called "regular"? Stay tuned for another week!
Learning Objectives for this week
- Use the subset construction method to convert an NFA to an equivalent DFA.
- Define the class of regular languages (RL's) through DFAs/DFAs.
- Specify and simulate \(\varepsilon\)-NFAs.
- Show that RL's are closed under the 3 regular operations: union, concatenation, and star.
- Using closure of RL's under the regular operations to build \(\varepsilon\)-NFAs.
- Define Regular Expressions (RegEx's). [Recursive definition.]
- Use the GNFA algorithm to convert an NFA into an equivalent RegEx.
- Define the class of RL's through RegEx's.
Ask & Answer Questions
Don't forget: you can use Teams or the Aula's feed to raise questions for me and the rest of the class.
Add your questions to the Community Feed and take a look at others' questions. If you see a question which you'd like to answer then just go ahead and participate in the discussion!
Pre-class Activity¶
Let \(\Sigma=\{0,1\}\), and let us experiment with simple NFA to DFA conversions. We will see later in the lecture how to do this correctly, but for now just experiment!
The important property to keep in mind for DFAs is that there must be exactly one transition for each symbol, i.e. in our case: for each state there must be
- exactly one transition for
0
- exactly one transition for
1
Consider the following NFA. Add the missing transition(s) to turn it into a DFA.
Show solution
We need to tell the NFA what to do at C
to turn it into a DFA.
The NFA should reject at C
, and since D
can process the rest of the string without accepting it then we can use it.
Consider the following NFA. Add one state and the missing transitions to turn it into a DFA.
Show solution
We need to tell the NFA what to do at B
and C
to turn it into a DFA.
The NFA should reject after B
and C
. We can add a trap state: a (non-accepting) state the you cannot escape (like D
in the previous example).
The following NFA has multiple transitions from A. How could we turn it into a DFA?
Show solution
Here the only strings accepted by the NFA are 0
and 00
.
We reuse some of the NFAs states and add a trap state.
Lecture videos¶
The PDF slides are available for download.
You are encouraged to download these. You can follow the videos without downloading them though.
This week's content covers three sub-topics:
⅓) Conversion between NFAs and DFAs¶
DFAs are essentially a special case of NFAs: they just do not take the freedom granted by non-determinism.
NFAs on the other hand are cannot always be considered as DFAs. Sometimes they are, and sometimes they just need a trap state to complete the missing transitions, but often they need more work to be converted to an equivalent DFA. Let us learn the method for doing so. ("Subset Construction Method")
Ready for some lab exercises?
If you wish to pause here and take some exercises then you can.
⅔) Regular Expressions¶
OK. We have just seen that DFAs are NFAs are essentially the same, and they both can recognise the same class of languages (=sets of strings), which we have called regular languages (RL's).
Let us now study some properties of these regular languages.
There are three distinguished operations that we can link to programming constructs: selection, sequencing, and iteration. (i.e., if-then-else
, blocks of code in sequence, for/while
loops.)
Here we call them slightly differently: union, concatenation, and star.
These regular operations give us another way to talk about RL. Instead of creating a machine that accepts or rejects strings, we will be able to describe the string pattern for the strings in the language.
Ready for some lab exercises?
If you wish to pause here and take some exercises then you can.
3/3) GNFA Algorithm¶
Finally, we will show that regular expressions (RegEx's) are as powerful as NFAs/DFAs by showing how to convert NFAs into equivalent RegEx's using a method called the GNFA algorithm.
Ready for some lab exercises?
Now you can attempt the last part of the lab exercises.