 Today, we will consider a generalization of NFAs because NFAs themselves were a generalization of DFS and now we are considering a generalization of NFAs and that generalization is that such automata NFAs with epsilon transitions will allow transitions not only on symbols as well as on the empty string epsilon. Now, here is a this this is an example of such an automaton. Let us first informally understand how this epsilon transitions work. First notice that all there are three states in this machine M and all these three states are final states and yet as we will see it is not the case that this automaton accepts all strings. Now, you see for example, the automaton is in this state and from this state it can take an epsilon transition to this state. What does it mean? That imagine this let me name these states as P, U and R at some point of time the machine M is in state P and let us say a 2 came now. The next symbol is the symbol 2 recall as you can see in this transition diagram that the alphabet that the machine uses is 0 1 and 2. Now, in this is the state sequence and in this state sequence for at some point of time the machine is in state P and the symbol 2 comes. Now, what the machine can do? It has the choice of not using this symbol immediately what is on the input, but it can take a transition like this epsilon and then it would be in Q, but then again from this Q it can again take another epsilon to go to the state R. In other words we are thinking of this 2 as if there were 2 epsilon and followed by 2, but of course 2 epsilon followed by 2 is of course the string 2 itself and therefore, when such transitions are allowed you see what the machine can do? It is in state P takes this epsilon transition to go to Q from Q takes epsilon transition to go to R and now it consumes the symbol 2 and therefore, it can be in the state R just on the symbol 2 because it has the ability to make transitions on epsilon. First of all we should understand that suppose I have an input string a 1 a 2 a n and I have a machine some machine which does allow epsilon transitions and what do I think about these where these where do these epsilon slide? One way of thinking of the string is that the it is of course same as infinitely many other strings which are obtained by padding 0 or more epsilon either in front of the entire string or between 2 symbols or at the end of the string. So, for example, this as you can see because epsilon is the empty string this is surely same as epsilon epsilon a 1 epsilon epsilon epsilon a 2 so on a n n may be 4 epsilon. When I say that the machine some machine with epsilon transition has on the input such a string and then I would like to figure out which all states the machine can go to on scanning this string I need to take care of all such strings not just the string a 1 a 2 a n, but as I said padding 0 or more epsilon in between 2 symbols in front of the string as well as at the end of the string. So, it appears that now we have a hard task to figure out even which all states the machine can be given an input string because there are any number of epsilon that can be there all over the string as we will see that this problem can be taken care of quite nicely and simply, but before that maybe we should understand this particular example a little bit. So, if we see this machine we can of course see that the string 0 0 1 1 1 2 will be accepted by this machine why because on the first 0 of course the machine remains here in state p second 0 machine remains here and now it takes an epsilon transition it considers their as if there is an epsilon here between this 0 and the 1 comes to state q and then remains in state q for the next 3 symbols which are all once which it can and now it takes an epsilon transition to go to r and there is this 2 and so it comes back to 2. Therefore, what I am seeing is that it is possible for the machine to go from its initial state to one of its final states right using the transition including of course epsilon transition. So, therefore, this string is in the language of the machine m remember that for an NFA what we said was a string is accepted by the NFA if such a string can take the machine from its initial state to one of the final states which this can do on the on the other hand if it had not seen or used the epsilon the way I just told you it might have been in some other state. In fact, it will be in some other state which is all right, but having considered that an epsilon here on which the machine makes transition another epsilon here the machine makes the transition on these 2 epsilon the machine can go from its initial state to one of its final states right at the end of the string. On the other hand can this machine accept the string let us say 2 1 1 and I claim that this string is not accepted by this machine because what happens the first symbol itself is to right to consume this symbol the only way the machine can do so is to go all the way up to this state which of course it can do right in the beginning it takes 2 epsilon transitions it considers that there are 2 epsilon in front. So, then it right in the beginning taking those 2 epsilon transitions it comes to this state R and now it consumes this symbol 2 after that what can it do now a 1 is there there are no epsilon transitions possible from here. So, no transition will be defined even if the machine consumes the first symbol and we should be able to convince ourselves that there is no way how many epsilon transitions you may put either in front or in between 2 symbols or at the end this particular string will not be accepted by the machine in let me describe the language accepted by this machine and later on we will definitely see the justification for that l n is the language in which I claim the strings are of the form 0 i 1 j 2 k where the constraints on i j k is really nothing except that each one can be 0 and all that we have to ensure for a string to be in this language the way we have defined that you may have 0 or more number of 0s, but all of them they must be in the beginning followed by 0 or more number of 1s followed by 0 or more number of 2s. In fact you see for example, let us just take 0 1 1 indeed first 0 it is here then takes an epsilon transition remains here for the next 2 talking of the string 0 1 1 and it is easy to see the machine can go from this state the initial state to q on 0 1 1 and q is a final state. Therefore, this will be in the language and so on in this manner can at least intuitively convince ourselves that this is the language accepted by the machine m which has epsilon transition. Now, our question will be can n f a is with epsilon transitions actually can be in accept some language which is not regular question is relevant. Obviously, because when we started with d f a our definition was regular languages are precisely those languages which can be accepted by d f a then we generalize the notion of d f a to n f a is non deterministic finite automata and that generalization was in this form that we said from a state on a symbol in case of an n f a they can be 0 1 or more transitions unlike in case of d f a where there is precisely exactly one transition possible. And yet with this generalization one result that we had seen that a language a is accepted by an n f a if and only if a least and we prove this result by taking an n f a and finding an q l n d f a by you know that d f a had set of all subset of the state space of machine accepted I mean the n f a machine and we showed that particular d f a will accept the same language. So, this result tells me that n f a is also will precisely capture will precisely accept the same class of languages which is the class of regular language and now we have yet another generalization we have added epsilon transitions to d f n f a. So, the question is that is it true that a language a is accepted by an n f a now if I put this with epsilon transitions if and only if a is accepted by d f a is it true because if it is in that case of course that even giving this extra power of epsilon transitions we do not go beyond the class of regular languages. On the other hand if it is the case that using epsilon transitions we can do more than what a d f a or an n f a can do and we have something interesting and in fact will show that the answer is yes the above is and let us prove this fact that an n f a with epsilon transitions and we will prove it in the same manner that is given an n f a with epsilon transitions will construct a d f a which will accept the same language. And therefore if that construction if we manage to show then of course the answer is yes that even n f a with epsilon transitions will accept languages which are which can be accepted by d f a. In order to consider this question we need to take care of this problem that I mentioned before that now since there are epsilon transitions available to the machine the input is in not be consumed symbol by symbol we need to take care of the possibility of epsilon transitions between two symbols maybe at the end of the string as well as before the string. Now it might appear since there are many many in fact infinitely many strings which are possible in this manner by plugging in 0 or more epsilon's all over that the problem is going to be something which is horrendously difficult. But as it happens there is a very simple notion which will let me handle all these infinite strings from one simple input string to all possible strings with lots of epsilon's all over in between symbols etcetera. And that simple idea which will let me take care of all these all this this the all these situations is the notion of epsilon closure. Now this let me first define epsilon closure for any state let us say p i informally it is the set of all states p j. So, you understand p i is a element of the set of states of the machine and epsilon closure of a state is the set of all q j such that q j is reachable from p i using 0 or epsilon transition. We can understand this definition more clearly we just look at this example above. So, what is the epsilon closure of this state p? Now remember epsilon closure is going to give me a subset of states each of which can be reached from the state using only epsilon transition 0 or more. So, things which are all the states which can be reached from the state p j. So, it is not difficult to see the epsilon closure of this state p is p q and r why because of course, p you can reach from p using 0 epsilon you are just there q you can go using just one epsilon and r also you can go from p using 2 epsilon. So, let me let me do the rest other two states what is the epsilon closure of it is not difficult to see it is q the set consisting of q and r and epsilon closure of that state itself. And given a transition diagram you can compute epsilon closure of any state by simple reachability algorithm many of which we know. Now how do we handle what is the set of states the machine can go to on an input string using any number of epsilon transitions. So, what I am trying to say is that suppose m is an n f a with epsilon transitions q f it is like it is this definition is like n f a where is the distinction between plane n f s which do not have epsilon transition it is here that delta is now a mapping from q cross sigma union epsilon to power setup. Why because there are epsilon transitions. So, you are in a state course you can consume an input symbol as well as you can use an epsilon to go to some other state of number. Now if we manage to define delta hat properly what do you want delta hat to be delta hat should be as before that it should it should be a map from q cross sigma star to power setup of q and the idea would be the mapping we should be we should define it this manner such that delta hat of let us say p and x is the set of all states m can be in starting. Now I am not putting epsilon explicitly in this because the string x as I know is same as a string you know suppose x is just suppose x is a 1 a 2 a 3, but this is also same as epsilon epsilon a 1 a 2 epsilon a 3 epsilon epsilon right. So, delta hat must take care of all these epsilon transitions because by string x when I give x the machine can either take it as just plain simple sequence of symbols or course it can take it in this manner that between symbols before or after the string there are epsilon as many as it wishes to have. So, all such strings which are actually same as the string x in fact what I am trying to say is even when you pad in all pad into this string all these epsilon the string actually is same because epsilon is the empty string. So, my delta hat should be able to handle all this and how do I handle that. So, before formally defining delta hat let me work out this example and the situation will be quite clear. So, let us see what is delta hat of epsilon for this from the start state p delta hat p epsilon. So, this is of course the empty string epsilon and now I am asking which all states the machine can be this particular machine can be in the beginning without consuming any symbols from the input. Now, as we can see it can be of course it can be in p as well as it can be in q because it just uses one epsilon as well as it can be in r. So, now do you see that if delta hat of p epsilon is the epsilon closure of the start state of this machine p m and this is just simply this which is of course as we have seen here is p and now let us see the machine is in a after scanning some string some portion of an input string the machine is in some of these you know some of these states. This notion of epsilon closure of course can be extended to subset of states rather than a single state where p is the subset of q the set of all states of the machine and this is simply the union of epsilon closure of q i where q i is this set that is easy to see or rather this is really a definition but it makes sense that is which all I can ask the same thing that the meaning of when I have a set of states rather than a single state what I am trying to find out through this definition is the set of all states the machine can be or the set of all states reachable using only epsilon transitions from any one of the states in this set of states p. So, this is clear and now let us say I just have this string 0 1 and I want to know which all states this particular machine can be on this string 0 and 1. Now let us assume inductively that I know delta hat of p which is the initial state of this machine and for this 0 1 that is I know which all states the machine can be starting from p on consuming one symbol and of course, now any number of epsilon. So, you see this string can be thought in terms of there are any number of epsilon here any number of epsilon here and any number of epsilon here. So, suppose using after 0 if you use some epsilon transitions and you are in some state let us say p I starting from p do you see that by definition p I will be a member of this set of whether you use 0 epsilon or 1 epsilon or any number of epsilon all those things must be taken care of by my definition of delta hat. So, in that case if I know that delta hat p 0 is some r which is the subset of q now what is going to be delta hat of p 0 1. So, you see what I need to take care of is that this 0 with some epsilon's before some epsilon's after all the states that one could reach that is already there in this capital R. So, do you see that so I take any state let us say r from capital R and then take delta of r and now this 1 has come. 1 and I will get a number of states let us see, but now I need to look at the effect of having epsilon's. So, then all I need to do is to take epsilon closure of is this clear. So, let me define r dash more clearly what is r dash therefore, r dash is this is the union of all r in capital R once more. So, delta hat of p of 0 with any number of epsilon's etcetera can take me to one of these states r now a 1 comes just using that 1 from that these set of states we can go to any one of these states the machine can go to any one of these states r dash, but now after that after that 1 of course, there can be any number of epsilon's which the machine can use. So, we take the epsilon's you see epsilon closure has the it is a built in device of taking care of 0 or more number of epsilon's transitions you think it will come clear because you are just saying which all states 1 can reach using 0 or more number of epsilon's alright. So, this definition from that example we can complete inductively the definition of delta hat because we have already given the base condition and then the induction will follow using this idea. Let me instead of writing all that let me do it for this particular example what the corresponding DFA will be if I take care of epsilon's transition. In other words what we are saying is from an NFA using some idea we found that found from an NFA we can go to a DFA which will accept the same language and I will show you that I can do the same for this NFA also which has epsilon's transition. So, I am attempting to get a equivalent DFA equivalent in the sense which will accept the same language as this NFA with epsilon transition using the idea that we had used to construct equivalent DFA from NFA. So, let us see initially which all states if remember the DFA in general will have a states the subsets of the state space of m of course m's set of states is p q and r. So, let me ask initially which of this subset of states the machine can be without it has not seen any input, but then it could have seen the it could have used the epsilon's initially of course the machine is in the state p, but without consuming any input symbol just using epsilon's it can also be in q it can also be in r. So, my DFA clearly will have a state corresponding to alright this is the initial state of the DFA if I manage to build the DFA and now let me think of the transitions from this state on the symbols and this there are only three symbols 0 1 2. So, on 0 which are the states this though that NFA can be suppose it is in any one of these states NFA is in any one of these states p q or r which all states it can be when it sees a 0. So, the m is in any one of these states p q or r and now a 0 came to me right p on 0 of course it moves to p, but then on this same 0 it has just used 1 0, but it can now use some epsilon and therefore, I need to take the epsilon closure of this which is epsilon closure of p I know is p q r it can from p of course it can go to p q r from q on 0 which all states it can be if it is already in q this machine m now a 0 has come you see that there is no transition defined on q and therefore, q on 0. So, this is the effect of the input symbol 0 will be in the state pi sub subset of states which is empty and similarly from r you can see on 0 it will go to there are no transitions. So, this is on 0 from r it can go to the empty state only. So, on 0 if the machine was in any one of these states the machine m was in any one of these states it can be in any one of these states p q r by taking the union of these that is what I mean. So, you see therefore, on 0 if I am thinking in terms of a DFA which had this state which is a subset of this set of states of m on 0 it comes back to it the same state and now let us consider what happens from this state a 1 comes again what is the meaning that the machine machine m is in this state that means it is in any one of these states p q r r and now a 1 has come now from p on 1 which all states the machine can be do I need to consider the machine m is the that is first it will take some epsilon and then to q and then to then what is the effect I do not need to see the way I said that if I am using this idea clearly then I just see I am in p a 1 has come can I go to any state actually from p on 1 let us say I do not go anywhere. So, this is empty, but from q on 1 I can come to q and from r on 1 from r on 1 nothing is defined. So, it is empty state, but now I need to take a closure of q and closure of q is q r. So, on 1 it will go to state which is this is same idea that we had used for NFA, but only thing we are doing is we are taking care of the a possible epsilon transitions and in doing all this if you notice what we are doing that the machine is already here that means having considered possible epsilon's before now it is in here and now it is about a particular symbol. So, now 0 1 and now let us say 2 comes here which all states the machine can be. So, you can see the same ideas pi p on 2 it will there is no transition defined q on 2 no transition defined, but r on 2 it can be here back r, but now I need to take the closure of this closure of r is of course r itself. So, I am in q and r and let me expand these states we are supposing we are in this machine capital M machine is in one of these states q r and now a 0 comes you see from q on 0 cannot go anywhere no transition is defined from r on 0 no transition is defined take the epsilon closure of this. So, it epsilon closure also will give me only the empty state set of states empty set and. So, therefore, from here on 0 I go to a state which basically corresponds to the empty subset of the set of states of m what about 1 if a 1 comes in let us do this from q on 1 I can remain here I can go to q r on 1 there is no transition defined. So, this is empty and now I will take the epsilon closure of this which is q 1 epsilon closure of q is q r. So, if a 1 comes here we are back to this state and if a g if a 2 comes let us do that we are in any one of these states and now 2 came from q on 2 we have no transition defined. So, this is q on 2 we go to empty state set r on 2 we come to r and now take the closure which of course means we are in. So, this state is completely defined for all the symbols its transitions this state also and now this state, but that is easy to see r on 0 what will happen? So, this is r the machine is in r now a 0 comes no transition is defined which means we come here r on 1 again the same situation. So, we will come here 0 as well as on 1 from this state to this one. However, on 2 we will come here we remain here and then take the closure which is r itself and if 1 is in this state the machine is in empty state then whatever be the transition symbol input symbol 1 remains there. So, what should be the final states as before in case of NFA construction NFA to DFA construction all those subsets in which has at least one final state. Now, you see all these 3 states p q and r where final states. So, therefore, wherever p q or r any one of these occur. So, which is this as well as this as well as this all these 3 states are final and of course, there is this is not a final state and I claim now this by the way this is a DFA clearly because from every state there is exactly on every symbol 0 1 or 2 there is exactly one transition and it is the construction was similar from NFA to DFA only thing is here we took care of epsilon transitions by taking care of epsilon closure. Now, let us just understand step back and understand whether this machine indeed accepts this language you see you start from this now this is a DFA we start here and now any number of 0's are there 0 or more number of 0's 1 is here and if that j and k are 0 what is of course, there is nothing else then it is this state and that is an accepting state and therefore, that string will be accepted on the other hand let us say the string was some 1's no 0's some 1's and 2's. So, the machine will start here some 1's came. So, it will here and then on 1's will be here and then some 2's came it is here and it will be here and then finally, on some 1's followed by some 2's on such strings the machine will be in this state which is an accepting state and that is alright, but on the other hand let us take 2 1 this just the string 2 1 and clearly the string according to this definition should not be in the accepted by this NFA that we kind of once are good and what about this DFA what I am claiming to be the equivalent DFA. So, initially you are here now a 2 came 1 is here and now a 1 came on 1 you go here which is of course, not an accepting state. So, therefore, the string 2 1 will not be accepted and this machine m dash which is a DFA I claim using our understanding. So, this machine m dash so far that we have built dash this machine m dash and this epsilon machine the NFA with epsilon transition they both these machines accept the same language. I have tried to show through an example though that every NFA with epsilon transition there is a DFA which accepts the same language and the construction that we had seen similar to NFA to DFA construction only we took care of epsilon transitions and the heart of the matter in a way is epsilon closure notion and the details that the proof the formal proof of this idea that the construction is correct can be seen any textbook on theory of computation. But what I would like to do now is to quickly show you why such machines can be of use because the reason for that is the reason for asking this question is that we know that any NFA with epsilon transitions there is a corresponding DFA to accept the same language as that of that machine. So, what is good with such NFAs with epsilon transitions and you see the reason is same as the case with NFAs what we saw with NFAs was that yes NFAs do not accept any language which is not regular that is which cannot be accepted by DFA and yet NFA is an interesting concept because certain languages it was for certain languages it was very easy for much easier to construct an NFA to accept than DFA's. Similar is the case with NFAs with epsilon transitions. So, let me give you one or two examples supposing I would like to show that L 1 and L 2 are regular then so is that is L 1 union L 2 what I mean is L 1 and L 2 are regular then L 1 union L 2 is also regular. Now, we actually prove this using few lectures back actually we have a proof for this I consider two DFA's M 1 M 2 accepting L 1 and L 2 respectively then another DFA constructed which as its state space at the Cartesian product of the two state spaces M 1 and M 2 state spaces, but you see using now this notion of epsilon transition it becomes so simple this proof we will have this. So, I have these two NFAs DFA's so this is M 1 and I had another machine for L 2 and in some number of final states and consider this new machine. So, this is M 2 now just consider another machine which is obtained like this that I have add a new state and from this state I have epsilon transitions to the two initial states of the two machines M 1 and M 2. Now, quite easy to see that this machine M is now one machine this machine M will accept because supposing a string is in L M 1 union L M 2 supposing in particular it is in this L 1. So, it will be accepted by this machine on that string the machine chooses to take this epsilon non-deterministically chooses from this to come to this state and then you know it is like a DFA here. So, it goes to one of the accepting states. So, for the combined machine all these are accepting states the accepting states of M 1 union the accepting states of M 2. Now, let us take another example which is this a little more involved than this particular example for that I need to take use the notion of reversal string and that idea is very simple. So, reversal of a string if you give me a string X then on I use X R to denote reverse of X. So, what do I mean by this supposing X was 0 1 1 supposing this is X X reverse is of course, you write the string the other way round 0 1 1 0. So, using this idea of course, you can talk of reversal of a language. So, what is L is a language where L is a subset of sigma star what is L R which I this is the reversal of the set of L it is the set of all strings X such that X in sigma star X R is in L and the idea of the use of epsilon is from this result that if L is regular. So, let me give you the construction and then one can argue why it is. So, L is regular. So, let D F A M accept L. So, in picture as a number of accepting states this is L essentially L M of L is L and supposing there is on symbol A it was here. So, this is L is L on symbol B comes here. Now, consider another machine which is like this we take the same machine what we do is from the old accepting states of this machine I do not mark them as accepting now, but I have a new initial state and have epsilon transitions to these. This was the situation supposing this is P this is Q this is R P U R what we do is in this machine now we reverse all the arrows. So, there was an arrow which means there was a transition from P on A it could go to it the D F A went to Q now I reverse the arrow and this had the initial state here that is the one which I make final states. This construction is very simple I am going from machine M I am going first of all I reverse all the arrows in the transition diagram and mark the old initial state as the only final state. And then I add a new state have epsilon transitions to the old final states and now I claim that this machine M dash language accepted by M dash is L R very first of all let us understand why this is an N F A of course, two reasons one is that there are epsilon transitions so non deterministically from the initial state this machine can either go here or here, but non determinism also comes because we have reverse arrows consider for example, that two it is possible in a D F A that on A you came here as well as on A you came here. When you reverse the arrows as we did here the direction of the arrow so this is now going this way and this is going this way you see that on reversal of the arrow directions from this state on A one could either go here or could go there there are two transitions defined and similarly you will be able to make an example where from a state on a symbol nothing no transition is defined because of the reversal of the arrow. And very quickly why if X is in the language why X R will be accepted and the reason is this because X is accepted there was a path in the D F A from the initial to one of the final states and what is X R is just the string in the reverse manner. So, now the last symbol will be the first symbol so whatever the final state X had gone to this machine this new machine will come to that state on epsilon transition it can I mean it can choose to do so and then it will follow the arrows in the reverse manner to come here and this is the acceptance. So, in other words once more that suppose there was a string X which took the machine from the initial state of M to one of the final states let me draw it here see X had taken to this final state this is in M and this is the final state right. So, let us think of A B B A some string like this and now this what happens here the reverse machine M dash there is a path from this state to this state on the same symbols but going the other way A A B B A because A to Q from here some state here to here right. So, this was the last state and those the transition here but now the arrows are reversed. So, this last state can take the machine from here to here and here to here it is easy to see that this particular path there is a path in this machine from the state to this one but how did the machine go here non-deterministically from the initials. So, it is not difficult to see that the way we have defined this new machine will accept precisely all those strings whose reversal is a string in the language.