Equivalence of NFAs and DFAs

Now, we already know that each DFA is also an NFA just by the definition. However, is it then possible to convert an NFA to it’s equivalent DFA? Obviously yes, you just split each one out on the given path and what not. Not too sure how things like two many transitions would work though

Definition of Equivalence:

Consider two finite state machines M 1 and M 2:

  • M 1 and M 2 are equivalent if they describe the same language
  • Pasted image 20261114192022.png
  • Pasted image 20261114192041.png
  • This NFA and DFA are equivalent. They both only accept letters that start with the letter a. The only difference is that the NFA does not have the dummy node for the letter B, instead choosing to automatically reject the string at the start state.

Algorithm: NFA to DFA:

  • The following example accepts all strings that end with ab over the alphabet {a,b}:
  • Pasted image 20261114192242.png

Now, in order to convert this into a corresponding DFA, we create a new {q0} initial state, the curly brackets are important because they represent a set of states in the NFA, since there could be more of course.
Pasted image 20261114192354.png

Now, you add in each state in the new DFA, this being basically setting up the transitions that are possible from the initial state over the alphabet. This obviously leads to a new state right, the interesting thing here though of course is the letter a in our NFA. We can either stay at q0 or go to q1, so we set the node as the representation of this with the set {q0, q1}
Pasted image 20261114192536.png

With this of course we know that there is only one transition that we have possible for B, we already have a state that B leads us to, so we just have it loop back around like it does in the original NFA
Pasted image 20261114192700.png

Now then this of course needs to continue onward with this for each new state. That of which we currently only have one of, which is the state of {q1}. Because we have more than one item in the set, each new transition is calculated with the transition function, so: δ({q0,q1},a) = δ(q0,a) + δ(q1, a). Now at this current moment with know that δ(q0,a) = {q0,q1} as we have proven with the current transition that we got going on, then we also would know that δ(q1, a) = ∅ because it has no current transitions, so we end up with {q0, q1} right. Now we do the same math but with b, and we know that δ({q0,q1},b) = δ(q0,b) + δ(q1, b) and δ(q0,b)={q0} and then δ(q1,b)=q2. So, we have a new state, and therefore we end up with this:
Pasted image 20261114193225.png
Pasted image 20261114193255.png

Now of course that we have this we need to deal with what the fuck happens whenever we are still in the possible state of the q0 inside of the {q0, q2}, and this is done by adding in the possible different a transitions
Pasted image 20261114193418.png

So, there is no no longer any unexpanded state right. All states containing at least one accept state from the original NFA, will be an accept state in this DFA. So we need to make sure that this is showcased as follows:

Pasted image 20261114193519.png

This is obviously then just the only set of states with the accept state of q2. This is now the equivalent NFA

Example 2:
Pasted image 20261114195109.png

Pasted image 20261114195226.png
All states containing zero are the ones that get the double circle btw


Regular or Non-Regular?

A language is regular if it can be accepted by a finite automaton, or if it can be accepted by a regular expression.

  • Note that EVERY FINITE language is regular.

Now, the thing is that we know that for very large languages where things might get complicated with the strings that the language is supposed to represent. So, how can we make it easier?

  • We want to try and break it into smaller regular languages
  • Then build it up again using the closure properties

These are some of those closure properties:

Pasted image 20261114195637.png

So, this basically means that all of the basic operations that we can do on two regular languages, in turn then also results in a regular language. So if we take the union, the intersection, the product/concatenation, or the Kleene Star of a given language, all of this results in a regular language as well.

Non-regular languages

There is NO finite automaton that admits to this given language. Now, can we test all possible finite automata? No, we cannot. Equally, if no regular expressions exist with the same language, then the language is not regular. However we cannot test every single regular expression.

So how should we do it? Well let us start with an example of a non-regular language:

  • L = {a^nb^n | n ∈ ℕ} so a given a to the power of n with the concatenation of b to the power of n
  • L = {xx|x ∈ {a,b}*} this is the language of all binary strings that are made of concatenation of two identical strings
  • L = {a^n! | n ∈ ℕ} this is over a unary alphabet, and is all strings in the form of n factorial numbers of a
  • L = {xx^R|x∈{a,b}*} this is the language that is all binary strings made of the concatenation of it’s string, and it’s reverse
  • L = {a^n^2 | n ∈ ℕ} This language is a unary alphabet, and is all strings in the form of n squared numbers of a
  • L = {a^n|n∈ℕ, n is a prime number} this language represents the prime numbers of a

How can we then prove that a given language is not Regular? We can use the closure properties, like intersection for example:

  • Prove L = {x ∈ {a,b}* | #a in x = #b in x} is not regular, this is a language with all binary strings that have an equal number of a and b

  • So, some strings in this language are: {ab, aabb, abab, abba, baab, ...}

  • We can prove by contradiction, the best right. So we need to assume that L is in fact regular and then showcase that this cannot be true.

  • But by the closure properties, if L is regular, then L' = {x ∈ a*b*} is regular. This is the language of all binary strings with not equal numbers of a and b

  • We know if L and L' are then regular, then L ∩ L'

  • So, we know that L ∩ L' = {a^nb^n | n ∈ ℕ} and this describes all strings with equal numbers of a in the front and b in the back

  • However, we know from the previous examples that that language is NOT regular, and so we have proven by contradiction that L is also not regular

Pasted image 20261114201205.png


Pumping Lemma

Pumping Lemma can be used to help prove that a language is NOT regular. It captures and explains a property of regular languages. Closure properties are useful, but it can be very difficult to find out a good method of using them in order to prove that a language is not regular. So the pumping lemma comes in for rescue.

Pumping Lemma is about finding a loop or a repeated pattern. Look at the following automaton

Pasted image 20261114204819.png

Some of the given strings in the automaton do not have repeating states, however, some of them do. So

  • If the length of the input is greater than or equal to the number of states, then there are repeating states.

Think of this kind of like the pigeon hole principle. If you have more given elements in your string then you have possible states in your automaton, then you end up with having to repeat one or more of the states. There is basically never more input then there is the number of states

Actual Pumping Lemma Statement

If L is a regular language, then there is a number p (the pumping length) where, if s is any string in L of length at least p, then s may be divided into three pieces: s=xyz that satisfy the following conditions:

  1. for each i ≥ 0, xy^iz ∈ L,
  2. |y| > 0 and
  3. |xy| ≤ p

What does it mean?

  • If all of the s in the language have a limited length, then the language is finite, and so is regular.
  • We choose p to be the number of states in the finite automaton representing L.
  • If |s| ≥ p, and s is a string in L, then we know we must have a repeated state by the Pigeonhole Principle, we can call this state qm
  • Thus, we know this imaginary automaton to have at the very least these three states, with whatever bullshit in between:

Pasted image 20261114205654.png

We have three parts here right, we know if we need to repeat a state we need to be able to first go some route whatever before we hit the state once, and then we need to venture off that middle state, hit some other stuff, and come back to that state we know has to repeat, at which point we move forward towards the accepting state. Hence the three xyz states.

The lemma says that y is also not empty, and that the first condition also holds, as we can loop over y as many times as we want to for any given string, the pigeonhole principle guarantees at least one, but it could be very many.

How does it work?

Well, whenever we want to showcase that the language is not regular then we take the following steps:

  • We assume that the given language L is in fact regular, we attempt a proof by contradiction
  • Assume a value p is the pumping length, or the length of the string, it is an arbitrary value that does not need to be found or specified
  • We then construct an arbitrary string s, whose length is at least the length of size p
  • Now, we know that the pumping lemma says: s = xyz and for all i ≥ 0, xy^iz ∈ z
  • Condition 2 of the lemma then says: There is a y such that |xy| ≤ p
  • You then investigate this y
  • You need to prove that for one i ≥ 0, xy^iz ∉ L
  • At this point we end up with our contradiction and then boom bang, we are all good

Example:

Prove L = {a^nb^n | n ∈ ℕ} is not regular.

  • We first need to assume that L is regular
  • We also then assume some value p and a string s that is of length either greater than or equal to the value represented by p
  • Let s = a^pb^p, |s| > p clearly the length of S is greater than p here as well right
  • So, with accordance to the pumping lemma, we can represent s = xyz
  • We also then understand these following properties are satisfied: for any i ≥ 0, xy^iz ∈ L.
  • Let us try this for i=2. We then have two cases in this idea then:
    1. y is only a. So, xyyz will then have more a than it has b
    2. y is only b. So, xyyz will then have more b than it has a
    3. y has a and b. So xyyz will have a and b jumbled up, so not in the way as ordered by the language
  • Clearly our language dictates that we have an equal number of both a and b, and hence whenever i=2 we have shown that xyyz ∉ L. This is a contradiction.
  • Therefore, by proof using contradiction, we can say that L is not a regular language

Pasted image 20261114211151.png

Pasted image 20261114211406.png

Pasted image 20261114211618.png

Weekly Practice:

“Regular languages part 2.pdf” could not be found.

Week 10 Exercises:

Now it’s time to put into practice the concepts that you have learnt so far in Week 10. Attempt the following exercises. If you get stuck, you can refer to the hints and tips on the next page.

Please note that these exercises are optional, further practice – but we strongly recommend that you engage with them in order to test your knowledge and see where you might need to do additional study.

  1. Convert the following NFA to its equivalent DFA:

Image description: There are six states. State ‘A’ is the starting state. States ‘A’, ‘B’, ’C’, ’E’ and ‘F’ are accepting states. There is a self-edge from A to A labelled with 1. There is a transition from A to B labelled with 0. Other transitions are: from B to A labelled with 1. From B to C labelled with 0. From C to A labelled with 1. From C to E labelled with 1. Self-edge from E to E labelled with 1. From C to G labelled with 0. From E to F labelled with 0. From F to E labelled with 1. From F to G labeled with 0 and finally self-edge from G to G labelled with 0 and 1.

  1. Convert the following NFA to its equivalent DFA:

Image description: This NFA has three states. Q1 is the starting state and accepting state. Transitions are: from q1 to q2 labelled with b, from q1 to q3 labelled with b. From q2 to q2 (self-edge) labelled with a. From q2 to q3 labelled with a and b. From q3 to q1 labelled with a.

  1. Using Pumping Lemma, prove that the following language is not regular:

L = {0n1n2n| n>0}

  1. Using Pumping Lemma, prove that the following language is not regular:

L = {an| n=2k , k>0}

Reading For Non-Regular Languages

“Sipser pp77 82 Accessible.pdf” could not be found.

Notes for Non-Regular Languages Reading

Finite automata are VERY powerful, and can describe a very large number of things. The main issue with this however is that they do have some limitations, in the sense that they cannot keep their state. For the book’s example lets look at the language defined by L = {0^n1^n, n >= 0}.

Attempting to make a DFA that would then recognize L, we understand that our machine seems to need to remember how many 0 s have been seen so far as it reads the input. The issue is that the number of zeros is not limited, so we need to somehow keep track of an unlimited number of possibilities, but we cannot do so with any finite number states.

Now, it may seem that through the understanding of us needing to have what may be unlimited memory that we are not regular, this is not directly the case, take for example the languages defined over the binary alphabet:

  • C = {w | w has an equal number of 1 and 0}
  • D = {w | w has an equal number of occurrences of 01 and 10 as substrings}

Now looking at this we assume that yes, each of these machines needs to count in each case, and so neither is regular. This is true in the case of C, however, it is not true in the case of D, as D is in fact regular. Therefore, only needing to keep track or well count, does not disqualify a language as regular.

So how can we prove this?

The Pumping Lemma for Regular Languages

The pumping lemma is a theorem that states that all regular languages have a special property. If we can show that a language therefore does not have this property, then we can say that this language is then not regular.

This special property is in essence the idea that all strings in the language can be “pumped” if they are at least as long as a certain special value, that is called the pumping length. Basically the idea of the pigeon hole principle, where if you have a string in a finite state machine that is longer than all of the possible states of the machine, you will eventually have to repeat a state within of that machine:

Pasted image 20261115194836.png

Now this basically states that you can break up this string into three given sub strings right, and you can basically repeat the middle element, which cannot be an empty string, as many times as possible and still have it be an element in the language. Basically, there is a repeatable pattern that we have going on here right.

We have to follow the pigeon hole principle and some state needs to be repeated and it needs to exist otherwise if it doesn’t then the whole theorem sort of breaks down right. Now let us look at the proof for this.


Pumping Lemma proof

So basically imagine you have a DFA that is defined with all of the five different elements it needs to have, and that it recognizes some language A. We then assign a pumping length p to be some number of states M.

We then show that any string s in the language of A of length at least p may be broken down into three pieces x,y,z. Satisfying our three conditions. Now, what if none of the strings are of at least length P? Well then shit becomes even easier because then the theorem becomes vacuously true.

Now of course we know by the pigeon hole principle that if we have an input string with length greater than the number of states within of our state machine then we must land on a single state more than once if our language is in fact regular:

Pasted image 20261115195448.png

This diagram then shows string s and how because it is larger than whatever the state value is we eventually hit the same state twice right. Meaning because of this we have a pattern and we can make the string s arbitrarily long in order to hit this patter an arbitrary amount of times, hence the reason why y^i works right.

Now then, we divide this string into three pieces. Why three pieces? Well think about it, we know we have some starting state, we do not know what it is, but we are assuming this automaton exists, is DFA, and therefore has an accepting state on our string s. So with this we know we have some start, and then we much hit at least one in between node, we might hit it multiple different times of course, or even only once, this node can also be the same node as the start or end point as x or z can be equal to epsilon. However we hit this point multiple times, and then we eventually end up at an accepting state.
Pasted image 20261115200139.png
Pasted image 20261115200213.png


Now in order to use the pumping lemma, what you do is you first assume that B is regular in order to obtain a contradiction. You then apply the pumping lemma in order to prove there must exist a pumping length p such that all strings of length p or greater in B can be pumped. Next, you find a string s in B that has a length of P or greater, but in fact cannot be pumped. You then finally demonstrate that s cannot be pumped by considering all of the ways you can divide s into x, y, z, and then showcasing how an xy^iz with some value of i >= 0 is not in fact a part of the language B.

This then contradicts your original assumption, and hence you prove that the language is not regular. Sometimes the finding of this S does in fact take a bit of creative thinking, and you may need to find a couple of different candidates before you find the correct one. A good tip is to try and find members of B that seem to showcase the non-regularity of the language, like remembering state or something.

Example:

Pasted image 20261115201229.png

So we assume that B is in fact regular. We then let p be the pumping length given by the pumping lemma. We then choose some string s = 0^p1^p s is inherently a member of the language B, and it is clear that the length of S is more than p we can clearly say that the pumping lemma guarantees we can split this string into three parts xy^iz where i >= 0. so that this string is still in B. Now, we have three cases that showcase this is impossible:

  1. The string y consists of only values of zero. This therefore then means when say i = 2, that there are more zeros than there are ones, and hence s is no longer a part of b
  2. The string y consists of only values of one. This therefore then means when say i = 2, that there are more ones than there are zeros, and hence s is no longer a part of b
  3. The string y consists of both a zero and a one, in this case when we have something like y=2 we have repeating ones and zeros and so the string no longer matches with B

Given this, we have a contradiction because if we assume that B is regular it should follow the pumping lemma but it contradicts it instead, hence B is not in fact a regular language.

In this example finding the string s was easy because any string in B of length p or more would work. This is not always the case however, so the thing that you choose to bring to the power of p is something you should be careful about.

Pasted image 20261115202548.png

Pasted image 20261115202755.png