 In the previous lecture, we have discussed certain operations through which the class of regular languages is closed with respect to those operations because I reemphasize on the point that these cloned properties are helpful to understand some of the new languages to see that they are regular. In that context we have observed that reversal of a language, reversal of a regular language is regular and right quotient. Similarly, one can define left quotient and understand that regular languages are closed with respect to left quotient also with arbitrary languages. So, that is where I have stopped my previous lecture. Now, let me continue with some of these cloned properties of regular languages. Now, I introduce a new concept in the context of regular languages that we see that using this also we see that the class of regular languages are closed with respect to this particular operation. Now, before going to that new operation so called homomorphism first let me give you some overview about homomorphism that we normally discuss in case of algebras. First you understand or recollect that if you take an alphabet sigma, sigma star is a monoid with respect to concatenation the operation concatenation. Now, in case of algebras the way that we understand the homomorphism here if you consider a map f from one monoid say sigma 1 star to another monoid sigma 2 star 2 different alphabets you may choose or 2 alphabets I may say f a mapping is said to be homomorphism if it satisfies this property f of x y is equal to f x f y for all x y in sigma 1 star this is if a mapping if it satisfies this property f is called a homomorphism. Now, you look at the point that here sigma star it is not just a monoid it is in fact so called free monoid over the alphabet sigma here this is a finite alphabet. Now, what is the advantage in defining homomorphism in the context of you know this free monoid here the set of all strings over an alphabet it is sufficient to define the of mapping or the basis you need not actually define the mapping for all the elements of sigma 1 star because sigma 1 star is a countably infinite set. So, you of course, one way of giving mapping you define for every element here, but here the advantage is you just define for the basis elements here the elements of sigma and you can naturally extend using this property to for all the elements of this. So, that it is a homomorphism now to just to mention about certain trivial homomorphism if you consider the identity mapping from some alphabet sigma star to the same identity mapping is defined by f of x is equal to x for all x in sigma star you can quickly see that this mapping is identity mapping is a homomorphism and one important remark is this under any homomorphism f from say sigma 1 star to sigma 2 star the empty string will be mapped to empty string only under any homomorphism under any homomorphism f. So, here what you look at as I had remarked if you just define the elements of for the elements of sigma 1 you can naturally extend using the property of that. Now, for example, if you take sigma 1 to b say a b sigma 2 for example, say 0 1 if I define f from sigma 1 star to sigma 2 star by f of a is equal to say 0 f of b is equal to 1 I have defined only for the basis elements. Now, if you take any x in sigma 1 star what do we do this f of x will be you know f of a 1 and so on a n since it has to satisfy the property what do we get f of a 1 f of a 2 and so on f of a n because we want that property homomorphism property need to be satisfied and we are given for a and b the images. So, f of a 1 if it is a you put 0 if f of a 2 if it is b you put 1 and so on precisely the mapping is here defined by if you take any string or a b the alphabet a b the images whenever there is a you will have 0 whenever there is b in the string in the string of sigma 1 star under concentration you put 1 that is clearly a homomorphism. Now, a generalized concept of homomorphism is called substitution this is called substitution substitution in which case what do we do in instead of giving a string as an image we give a language as an image for example, a mapping f from say sigma 1 star to now we consider language means I consider power set of sigma 2 star that means the set of all subsets of sometimes people may write this as this sigma 2 star means all subsets of sigma 2 star that means all languages over sigma 2. Now, what do we do here instead of assigning a string in case of homomorphism here we assign a language for each string use assign a language l over sigma 2. Now, as I had mentioned that it is sufficient to give images for the elements of the basis that is the alphabet here. Now, homomorphism concept we may simply say it is a mapping f from sigma 1 to say sigma 2 star a mapping. So, this is how we can now define and now to see for a string the image for a string we can naturally extend using the property of homomorphism condition of homomorphism. Now, a general concept to this homomorphism is available called substitution it is called substitution where instead of assigning a string as an image what do we do we assign a language over the alphabet sigma 2 this is all subsets of sigma 2 star. So, that means here if you take any string x in sigma 1 star now the image essentially for each symbol you will be assigning one language. Now, f of x will be as per the property f of a 1 f of a 2 and so on f of a n that means here for a 1 a 2 a n x if you consider this is the condition it has to satisfy like in homomorphism. And now what are the language that you are assigning for a 1 say let me call it as l 1 l 2 and so on l n the concatenation of those languages we consider and naturally for each string we have a language over sigma 2 under the substitution. So, substitution essentially it is a general concept to homomorphism. So, where for each string you will be assigning a language instead of defining again since we are expecting this homomorphism property need to be satisfied in case of substitution as well what do we do we simply give or we simply assign a language for each symbol over sigma 1. And we naturally extend for each string and it is not only for string now as a general concept to as a generalization of this for each language naturally for example, if you consider language l over sigma 1 star under a substitution we can now talk about f of l image of l that is for each string you consider the image this is a language you take the union here x in l. This is of course, a subset of sigma 2 star because f x is a language over sigma 2 and union of languages here that is a set over that is a language over sigma 2. So, under substitution we define f l this way. Now, let us look at some of the properties related to the homomorphism and substitution the class of regular languages is closed under substitution by regular languages. This result essentially what it is saying that is let us consider f a substitution from say sigma 1 to sigma 2 star substitution from sigma 1 to sigma 2 star. Now, if l is regular of course, this is l is a language over sigma 1 then f of l as defined earlier is also regular that is what is the statement here the meaning of this statement the class of regular languages is closed under substitution by regular languages. Here you consider a substitution f this is substitution what we are targeting to understand that if l is regular f of l is also regular. Now, what do we do we take the aid of regular expressions and understand this particular result for the proof of this what do we what do I suggest here as l is regular you will have a regular expression for that since l is regular there exist a regular expression let me write r regular expression r such that l is equal to l of that regular expression r. Now, whatever the substitution that we have assume that f is a substitution and now the substituting languages since they are regular languages for each such regular language you have a regular expression. We substitute that regular expression at each symbol and the resultant one that we prove that this is this is what is represented representing that f of l. So, the claim essentially if I write r dash is a regular expression obtained by substituting let me call r a for each a in sigma 1 the regular expression the regular expression for f of a because f of a under the substitution f this is a regular language that is the information given to us since it is a regular language you will have a regular expression let me write it as r a what do I suggest in r you substitute r a wherever a is occurring the corresponding regular expression r a and obtain the regular expression let me call it as r a dash. So, the substitution of r a this is the regular expression for f of a in r now the claim is the language represented by this r dash is the desired language f of l if I can prove that if I if I can prove this claim we understand that homomorphic sorry the f of l here the image under a substitution it is a regular language because a language represented by a regular expression is regular thus you can conclude that this is a regular language you can conclude that this is a regular language before going to this let me probably to explain this let me consider an example first and then we can understand what essentially the mechanism here we are considering in this result consider this example consider the substitution h from say a b to power set of 0 1 star that means for symbol a and b I substitute the languages over 0 1 let me define h of a all the strings the set of strings over 0 1 say ending in 1 for example, for h b what I what I consider the set of strings starting with 0 let me consider these languages now if I consider the language l say a power m b power n such that m n greater than or equal to 1 you know this is a regular language consider this language what is f of l what is f of l f of l is essentially wherever you take each string here from l by definition this is union of x in l f of x. So, consider each string this is of the form a power m b power n and each symbol a the corresponding language whatever h of a is given you put it there substitute there and h of b you consider whatever is given you substitute there and for each string you get a language that language you know concatenation of all those languages that is what is f of x by definition consider all those languages and take union and this is what is f of l. Now, what is the method that we are adopting to understand this f of l very quickly is consider the regular expression corresponding to l. So, the regular expression corresponding to l is of course, this is a this is a regular language and the regular expression corresponding to this is a plus b plus this is the regular expression. Now, in this regular expression for each occurrence of a you substitute and you understand that h of a is regular h of b is also regular. So, these regular languages the corresponding regular expression you substitute in each occurrence of a in a regular expression of l and in each occurrence of b the regular expression of h b you substitute and look at the regular expression that you are getting and that is what is the process here we pursue to understand that the resultant language is regular. So, here a plus b plus is a given language and h of a is all those strings ending in ending in 1. So, the regular expression corresponding to that is 0 plus 1 whole star 1 this is the regular expression and h of b is given to you as those strings starting with 0. That means, this is the regular expression corresponding to this. Now, the suggestion is h of if I write this as in a loose sense like this of course, the language represented by a plus b plus the image of that we substitute this way that is 0 plus 1 star 1 plus and 0 0 plus 1 star. Now, you know this property a star is for a regular expression a concatenation with a is a is equal to a plus. Now, we elaborate this using this property that is 0 plus 1 whole star 1 whole star and here 0 plus 1 star 1 and similarly this side I use 0 concatenation with 0 plus 1 whole star and now 0 concatenation with 0 plus 1 whole star let me write it down here concatenation with 0 concatenation with 0 plus 1 whole star whole star. Now, you can quickly see that this is 0 plus 1 whole star 1 whole star let it be this and here 0 plus 1 whole star 1 0 because the concatenation is associative and thus I can simply write you know this 1 0 and the remaining here this is 0 plus 1 whole star and the remaining here this side is 0 concatenation with 0 plus 1 whole star whole star this is what is the resultant string. Now, let us look at this portion and this portion here in this a string is of the forms if I write x y here if I choose x to be epsilon I mean epsilon because epsilon is in this there is a regular expression for which there is a star if I consider epsilon this is simply y and here y is an element of 0 plus 1 whole star that means any arbitrary string of 0 plus 1 whole star that means over 0 1 you can get in the left side. Similarly, on the right side any string over 0 plus over 0 1 you will get and hence you understand this is in fact equal to that means 0 plus 1 and the left portion 0 plus 1 whole star is a subset of this and since it is the whole set I can quickly conclude that this is 0 plus 1 whole star 1 0 0 plus 1 whole star. Now, this is the regular expression you get and in fact from this we can understand the image of the consider the given language under the substitution h is all those strings in which 1 0 as substring. So, this is the set of all strings over 0 1 with 1 0 as substring. So, this is the language this is the image of given language under substitution. Now, whatever the mechanism that we have pursued here exactly the same thing we wanted to adopt in the proof and see that it is a regular language and in fact it is representing h of l. So, here what do we do given l we have consider the corresponding regular expression r and we have obtained r dash we have obtained r dash the regular expression by substituting r a for each a in that sigma 1 and as I have mentioned the claim here is f of l is the language represented by this. We prove this result we prove this result by induction on the number of operations of r this prove by induction proof of the claim by induction on the number of operations in r. Since, r is the regular expression there are 3 possible operations concatenation addition and cleanest r. So, we use induction on the number of operations on r now for the basis you assume the number of operations in r is 0 there are only 0 number of operations that means the possibility for r is may be empty r this r can be the regular expression epsilon r r can be simply a. If there is no operation involved the corresponding regular expression is should be one of this it can be empty epsilon r a. Now, in this first case since there is no symbol of sigma 1. So, the substitution is trivial here and hence the corresponding r dash is again phi the regular expression phi and similarly, if the regular expression is this in this case there is no symbol of sigma 1 is involved and hence here also trivially r dash is epsilon and we can see that the substitution this f of l that is also empty language and here that is singleton epsilon and in this 2 cases you can quickly see that trivially f of l is equal to the image of the language l is the same. In case of r is equal to a what are the symbol that it is a of sigma 1 the corresponding regular expression r a will be considered and if. So, in case r is equal to a here l is singleton a and now what we are doing we are considering the regular expression a and we are substituting r a in place of that and we are considering that and it is given that r a is the regular expression we have we have considered that r a is the regular expression corresponding to this f of a and this is what this is corresponding to f of a and this is what is f of l. So, by substituting here so h of l now you can understand that h of l by substituting r a in place of a we get this and thus we can understand that oh sorry. So, if there is for the basis we can see that the result is true now assume this result is true if a regular expression r has k or fewer operations assume there is this is happening if k has if r has k or fewer k number of operations or k or fewer number of operations now whatever that r dash we are obtaining what is the meaning here by substituting h our result is true that is l of r dash is h of l of r we are assuming this is happening and now consider r has k plus 1 operations for induction k plus 1 number of operations then if there are k plus 1 number of operations at least one operation we can see there the possibility is either it can be plus or the concatenation or star at least one of them is involved thus we can write r 2 b say r 1 plus r 2 in this form r if r can be it is of the form r 1 r 2 r we can say that r is of the form say some say r 1 star and understand that in each case any of this case r 1 r 2 should have k or fewer operations. So, here r 1 and r 2 have k or fewer operations so what do we do we apply induction on r 1 and r 2 and we take that assertion and proceed to understand that the result is true for k if r has k plus 1 number of operations I consider this case and observe that our assertion is true when r is equal to r 1 plus r 2 and one can similarly observe this other two cases and understand that the induction from induction the result follows let me consider the case r is r 1 plus r 2 what do you do let me write r 1 dash this is obtained from r 1 by substituting r a for each occurrence of a and by induction what we have l of r 1 dash is h of l of r 1 and similarly let me write r 2 dash is the regular expression obtained from r 2 by substituting r a for each occurrence of a of sigma 1 and from induction by inductive hypothesis because r 1 and r 2 have k or fewer operations this is happening this is inductive hypothesis this is from inductive hypothesis what do we do what we have to observe that l of r dash is h of l of r that is what we have to observe. So, let me start with l of r dash the language of r dash this is r dash is r 1 dash r 2 dash why the reason because r is of the form r 1 plus r 2 r 1 dash is the regular expression obtained from r 1 by substituting each occurrence of a by r a similarly in r 2. So, r dash by definition it is nothing else, but r 1 dash plus r 2 dash now you proceed to understand this is the manipulation with regular the regular expressions and the corresponding languages. So, this is union r 2 dash and from inductive hypothesis what do you have this is h of l of r 1 union h of l of r 2 this is from inductive hypothesis and since h is substitution you can write it this way since h is substitution we have this property and now again the regular expression h of l of r 1 plus r 2 and this is what is r. So, when plus is involved as operation here we observed that l of r dash is h of l of r similarly, if the concatenation is involved it you one can proceed this way and understand the assertion is true in when it is having k plus 1 operations or in case of cleaning star and thus by induction we have observed that substitution of regular languages is you know in regular languages it is a regular operation and thus the class of regular languages is closed with respect to substitution by regular languages. Now, an immediate consequence here is this the class of regular languages is closed with respect to homomorphism. Now, the question is when we have talked about substitution I have mentioned that substitution by regular languages and you see homomorphism is a special case of substitution and in this special case what we do from sigma 1 to sigma 2 star for each symbol you are just assigning a string. So, that means in this special case the substitution is by singleton sets of strings essentially of sigma 2 and we know this is a regular language and thus from the above result as a consequence we can quickly say that the class of regular languages is closed with respect to homomorphisms. Now, let me discuss one example here let me consider the language say a power n b power n is that m greater than equal to 0 or m greater than equal to 1 whatever let me consider this language and consider the substitution consider the substitution say f from a b to of course, power set of 0 1 star let me consider this and let me give the substitution f of a I consider 0 to the n n greater than equal to 0 and f of b I give 1 to the n n greater than equal to 0. Now, what is f of l if we look at this example you quickly see here of course, we so far we have not obtained any regular expression for this language, but the reason is because as an application of mildly wrote theorem we have observed that this is the the index of this language is infinite and from mildly wrote theorem we have observed that this is not regular and hence we cannot expect any regular expression for this. So, the previous approach because taking a regular expression substitute in the corresponding regular expressions that we do not we cannot follow here. Now, let us analyze from the definition this is equal to union h of x x is l. Now, I can write it as union n greater than equal to 0 h of a power n b power n this is the typical string in l union n greater than equal to 0 here since h is I am writing h and f interchangeably here whatever is consider let us follow the same consistently. So, this is f of a f of a and so on this is for n times because this f is satisfying this property and similarly here f of b f of b for n times this is for n times and this is also for n times, but whatever it is f of a is simply 0 star f of b is 1 star. So, f of a when we have considered this is 0 star concatenation with 0 star and so on because 0 star for n number of times the concatenation of 0 star with 0 star for n times is nothing else, but 0 star similarly this f of b case. So, whatever is the number of times that you concatenate here you understand that this is equal to this is 0 star 0 star whatever is the number of times you concatenate you get just 0 star. So, this is 0 star 1 star now that is essentially 0 power m 1 power n such that m n independently greater than equal to 0 that is the language we are getting. Now, look at here we have considered a non regular language and we have used this substitution we are substituting regular languages and of course, as a result this here f of l we have got a regular language. Now, let me state a result that is the class of regular languages is closed with respect to inverse homomorphism. So, let me elaborate this result that means if l is regular because we understood that if l is regular f of l that is homomorphic image of a regular language is regular. Now, inverse homomorphic image that means if l is regular and if you consider a homomorphism f h say for example, h inverse l is also regular is regular if l is regular h inverse l is regular for a homomorphism h that is a statement of course, here h is a mapping h is a homomorphism say for example, sigma 1 to sigma 2 star and here l is a language over sigma 1. So, these things I am not mentioning, but what is h inverse l if one is not clear the inverse image of a set is essentially collect all those strings or sigma 1 star such that the image of that should be in l this is what is h n r cell. So, here you look at this result the class of regular languages is closed with respect to inverse homomorphism look at the previous example, here I have considered a non regular language we know this is a language that is not regular and I have substituted here regular languages and I have obtained a regular language. Now, the question is under this substitution what is what is inverse image of this. So, here I have f let me use the same f as defined earlier in that example, the example shown here consider this and what is f inverse of 0 star 1 star question number 1 and whether this example will serve to counter the result in case of substitutions take this as an exercise and. So, what is the result here I have stated the class of regular language is closed with respect to inverse homomorphism. Now, whether the class of regular language is closed with respect to inverse substitutions suppose if one questions here I have considered a non regular language and I observed that the image of that is this. Now, understand what is the pre image of this particular language here is a regular language and here is a substitution and now understand what is the pre image essentially from which what we can conclude whether this result is not true in case of substitutions or not. Let us prove this result the result is if l is regular h inverse l is regular for a homomorphism h. So, what is the proof idea here is given l is regular. So, consider the corresponding you know some d f a let me say a is a d f a accepting l let me write it as q sigma 2 q sigma 2 say delta q naught f of course, here this is over sigma 2 because we are talking about inverse image. So, l is a subset of sigma 2 star and its pre image h inverse l is a language over sigma 1. So, this is sigma 2. So, sigma 2 is the alphabet here and let me consider this is we a d f a accepting l. Now, we will construct a d f a for h inverse l we construct a d f a for h inverse l to show this is regular. What is the proof idea here because h is a homomorphism carrying the languages or you know the strings from sigma 1 to sigma 1 to sigma 2 we define new transition because we consider the same state set of course, the alphabet will be sigma 1 here if I call it as a dash. So, same state set I consider and alphabet here is sigma 1 new transitions delta dash I call and the same initial state, but here the final states will be considered to be same. Now, how this transition map is defined this is defined as essentially composition of the original map with h that is how we define that means, this delta dash at any state for a symbol a in sigma 1 we define it as delta cap of q h a because in the given automaton h a is an element of sigma 2 that is a string. In the state q if you apply that string h a wherever it is going since it is a d f a this a is a d f a you have a unique state here and thus delta dash as defined here in the state q if you apply a the h a will be applied in the state q of the original automaton you will get a unique state and thus you see here for each state and a symbol you will get exactly one state and hence this is a dash is a d f a. So, this is the d f a we define and we prove that the language accepted by this a dash is h inverse l to prove this first we understand this property for each string x in sigma 1 star what do you have the image of this if you substitute in q naught in fact in any state this is nothing else, but delta cap q naught h x you look at the definition this is the same is defined for each symbol of sigma 1 now we are saying this is true for all x in sigma 1 star. So, this can be proved quickly by induction on length of x because when you take empty string you can observe and for each a in sigma 1 star that means length 1 this is straight forward from the definition of delta dash in fact you can extend this and understand that for each string of sigma 1 star you get this property. Once you understand this let me just show you that if you take any arbitrary string x in h inverse l by definition this image of this is in l that is the definition a string is in h inverse l. Now h of l is in l that means in the initial state of the original machine if you apply h x you are going to a final state that is an element of f. Now we know that this is nothing else, but this because that is the property one can observe. So, this is an element of f. So, in the initial state if you apply x if you are going to the final state of a dash that means this string x is in language accepted by a dash and thus you see any string any arbitrary string x in sigma 1 star if you take any string x in sigma 1 star what is happening x is in h inverse l if and only if x is in l of a dash and since a dash is a d of a h inverse l is regular. So, of course you can take this as an exercise and prove that this property holds that is what we have used here to prove that h inverse l is regular and hence we have this theorem.