Regular Languages Equivalences
Transcript
Hello! In this series of videos I'd like to talk about regular languages and just like how there's a whole bunch of different equivalent Turing complete things and so they're all equivalent to each other in terms of computation power there's a whole bunch of different equivalent things that are less powerful than Turing complete things that are all all characterize the regular languages -- that are all equivalent to each other and it's not obvious at all that they're equivalent to each other. And the fact that we have lots of different equivalences allows us to reason about the regular languages in lots of different ways. We can look at one perspective and see a whole bunch of properties that are really obvious and then there'll be a bunch of things that aren't obvious about it at all and then we look at the regular languages from another perspective and we see a completely different set of things that are obvious and a completely
different set of things that aren't obvious at all and so by switching our perspectives back and forth we can learn lots of things about regular languages and we can also learn lots of things about these different presentations of regular languages. So I want to start with the most basic one: finite state automata which are also called deterministic finite automata or DFAs. The way that I like to think about these things is as just some sort of machine that has a keyboard on it and an indicator light and you type in characters into the keyboard you type in a word on the keyboard and every time you hit a key it changes something internally in the system right -- the state of the system updates the memory of the system updates to reflect the fact that you hit the key and that may or may not turn on or off the indicator light and so
your goal is to type in a word and then see when you're done is the indicator light on in which case it's a good word or if the indicator light is off it's not a good word according to the machine so here we have (this is a very abstract drawing) we have our keyboard which has a bunch of different characters on it from some finite collection of characters and then we push the buttons in some order. Every time we push a button the system changes. Any time between when we're pushing the buttons the system is not going to change it it doesn't have an internal clock or anything like that it's not connected to any other external sources of data
it just sits there while it's waiting for me to press a new key and then based on the internal state of the system the indicator light will turn on or off and the key thing the "finite" in finite automata is that there's only a finite amount of memory in this machine so if I just key smash for a little bit then eventually by the pigeonhole principle this machine will wind up in a state that it already was in before. In other words, it's going to completely forget everything that happened between the first time it wound up in that state and the next time it wound up in that state -- just completely forgets -- goes back to the original state and what this means is that these sorts of machines can't keep track of everything that we type into them right you could imagine wanting the machine to like know the entire word that I've typed in and then analyze it when I'm done typing it but these machines can't work that
way it has to be the case that they're processing the data as it comes in and they're throwing out some information because they only have a limited amount of memory so data's coming in they have a fixed amount of memory they're going to have to throw some data out every time we send data in. Finite state automata are typically presented as very simple machines with a very small number of keys that we can use to interface with the machine and a very small number of internal memory states. Finite state automata are meant to be an abstraction of systems where the amount of data coming in is much larger than the internal memory of the system and this happens all the time nowadays where you have computers that have these large data sets that are just streaming into them and they can't store the entire data set they have to decide what information they want to keep in order to do the calculations that they're trying to make and then discard all the rest of the data.
Compare this versus Turing machines: Turing machines are an abstraction of computers whose memory is effectively infinite. That is, that the type of data that they're interfacing with is much much smaller in size than the actual memory of the computer. Of course, in our real world we can't have a computer that has an infinite amount of memory in it. However, Turing machines are a really useful abstraction of computation so technically speaking your computer no matter how
powerful it is is actually much closer to a finite state automaton because it only has -- think about how much memory it has how many bits of memory it has -- each of those bits could either be a zero or a one and so it has two to the power of the number of bits of memory that your computer has possible states of its internal memory and effectively this is infinite if we have small enough data sets that we're trying to process but eventually if you try to shove a large enough data set into your computer it's going to start acting like a finite state automaton -- it's going to have to start tossing stuff out. So there's kind of this duality between Turing machines where we have an infinite tape of memory, as much memory as we could possibly want, versus a finite state automaton which we're very explicit about the fact that it has a finite amount of memory. So typically if we want to reason about a finite state automaton we really want to be able to
visualize all of its states and how those states are related to each other all at once and this makes it really difficult to analyze your desktop computer as a finite state automaton because it has this ginormous number of states we probably couldn't even fit a diagram for it within the observable universe so let's visualize the state diagram of a much simpler finite state automaton: So here I have a state diagram for a finite state automaton with three states: state 0, state 1, and state 2. And I've labeled a bunch of arrows with different characters: "a" "b" and "c" so in this case the set of possible inputs is just going to be three characters we're going to have a keyboard that only has three letters on it: "a" "b" and "c", and what each arrow means is that
when we're in this state if we read this input we wind up in this state. So if I'm in state 1 and I read the character "c" I'm going to wind up in state 2. And of course for each state we can only have one arrow coming out of that state for each character because we don't want to say "oh well if if we're in state 1 and we read an a do we go to 0 or do we go to 2" we don't want that sort of confusion we want it to be well defined in its behavior. That is, we want
it to be "deterministic": there's no uncertainty, there's no randomness in its behavior. So for each state if we read in a particular input we're going to wind up in a particular state in a well-defined way and all of that information here is here on the diagram. There's also two extra pieces of information: there's an arrow coming in from the outside world pointing to state 0 what this means is that the finite state automaton starts off in state 0. Every time we want to check
a different word on our machine we turn the machine off we reset its memory completely to its initial memory state and then we start the machine back up and when we start the machine up in this case for this machine it's going to start in state 0. Your desktop computer can store memory between different sessions but we don't want that for this type of machine because we want it to be well defined: if I type a word in every time I input the same word to this particular machine I want it to give me the same answer whether or not that word is good and then the other piece of information that we have here are these double circles: I've double circled only one state but you can double circle as many states as you want and this is what's called the "accept state". So it means that when the machine is in this state the indicator light is on it is happy with the word that I've typed in so far. So let's try running this machine so we start off in state 0
and suppose that I type the letter "b". Well, we're going to follow this arrow back to state 0 and then I'm going to type the letter "a": that's going to take me from state 0 into state 1. At this point if we stopped, if this was just the entirety of our input this indicator light would be on and that would mean that we accept the word this word is a good word it is part of our language. On the other hand maybe we could keep going: we could type in "ba" and then we could type in another "a" and now we're back in state 0, right, we do "b" we do "a" we do another "a" we're back in state zero so it's no good the indicator light goes off this word is not in our language.
on the other hand if we did something like "baaba" we would again wind up back in state 1. and of course if we saw a "c" at any time in our input it would take us into state 2 and we would be trapped in state 2 and there's no way to make the light go on if you're trapped in state 2 so if we had a word like I don't know "bacba" that would be no good. right we go "bacba" we'd wind up in state two we'd wind up in state two here and we'd be stuck in state two
and so we wouldn't reach state 1 we wouldn't reach an accept state by the end of the time that we've read this word so this is not in the language and so take a moment to think about what does this machine do how do we determine if a word is in the language or not in the language. So what this machine does is it determines whether or not there are an odd number of "a"s in the word it doesn't care how many "b"s. Notice that whenever we hit the character "b" it doesn't change the state of the machine so it it only cares about the number of "a"s and the number of "c"s and in particular the number of "a"s has to be odd has to get us to this 1 state and stay in the 1 state so it can go back and forth an odd number of times and it has to have no "c"s in it
so here because we were able to find a finite state automaton that accepted exactly this collection of words that means that this collection of words forms a regular language. Here I'm using "word" in the mathematical sense mathematically a "word" is just a string of symbols from some alphabet and an "alphabet" is just some finite set of characters so these don't actually have to be words in the English language or any other language
they just have to be strings of characters but we call them words anyway and any collection any set of words is called a "language". A language such as this one is called "regular" exactly when it is defined by some sort of deterministic finite state automaton. Now, there's actually another way of keeping track of these finite state automata these state diagrams are really useful visually but if we wanted some more algorithmic-y sort of presentation for these finite state automata
we could do it in terms of what are called "transition functions" so typically we use the letter lowercase delta to indicate our transition function and this is going to be a function that takes in two inputs: the current state and the input character that we're inputting into the machine so let's say that we're in state 1 and we type the character "c" into our machine well that means that we're in state 1 we type the character "c" into the machine we're going to wind up in state 2 so the output of the function on this input should be two and having this function here allows us to present our finite state automaton as a table, right, a table of what are the outputs if I input particular inputs into this machine and sometimes that's more convenient to have than a graph. There's actually another presentation for transition functions that's actually a little bit more useful in some circumstances
and that is to have a particular transition function for every single [input] so this is the transition function for the state "c". so if we're in state 0 and we type the letter "c" we're going to wind up in state 2. so this sort of presentation allows us to see our transitions as some sort of function from the set of states to the set of states and then we have a separate function for each possible input right a will do so the function for "c" is always going to output two the function for "a" is going to swap zero and one if we input a zero it will output a one if we input a one it will output a zero if we input a two it will leave it alone and the function for "b" will is just the identity function it will always output whatever we input so we can either have a single function that defines everything or we can have a set of functions for every input and having
these two different perspectives is sometimes very helpful and so putting this all together we very frequently define our finite state automata as a tuple of all of the information that characterizes that finite state automaton so it starts off with sigma this is the alphabet so in the case of this particular machine the alphabet is the three letters "a" "b" and "c" so this sigma is going to be the finite set just containing the symbols "a" "b" and "c" in it the alphabet we always want the alphabet to be finite. I guess you could consider cases where the alphabet is infinite but let's not consider those cases for the duration of this video series. Then we have a set of states again we want this to be finite and for this machine here the set of states is 0 1 and 2.
then we have a special state that is designated as the start state in this case the state 0 next we have our transition function and finally we have a set of accept states these are the states that get double circled these are the states that make the indicator light go on that say this is was a word that you typed in that we are happy with and the set of accept states can be any subset of the set of states it doesn't have to be just one state it can be as many states as you want and so typically when you're trying to present an automaton you think about it in terms
of this collection of information here so we've already seen kind of two different perspectives for thinking about regular languages for thinking about deterministic finite state automata: here we see the perspective of thinking about them in terms of a collection of functions from a finite set to itself right the set of states to itself and we have one function for each [input] and so we have this collection of functions and maybe we can think about finite state automata
and regular languages in terms of those we can also think about finite state automata in terms of paths through a graph here we have our graph and every accepting word every word that we accept in this machine is going to correspond to a path between 0 the start state and one of our final states in this case just the state 1 so we're talking about paths through this graph here going from here to here and so already we have two different perspectives for thinking about finite state automata for thinking about regular languages. It can also be really useful to think of finite state automata as a particular type of computer program. Here I've modified a program from Kernighan and Ritchie to count the number of each digit within a program and to count the number of "a"s within the program and it doesn't do anything with that data but it could do stuff with that data. As we can see this program is split up into three parts
we start off by declaring our variables strictly defining exactly how much memory we're going to be using of the computer each of these data types integers and then an array of integers has a limited number of possible configurations that it could be in. Integers in the C programming language only go up to about 4.3 billion which is useful for most practical purposes but understand that this is a finite number it means that if we input data that's much larger than 4.3 billion in
size and the number of each digit our digit counts are going to be off and there's nothing we can do about that except possibly invoking "malloc" the memory allocation function which sounds a bit like a demon and actually is a bit like a demon in that if you summon it wrong it can damage your computer so we like to avoid using malloc. Then we initialize our variables we set our memory into the start state of the automaton and then we have a while loop which reads in characters from the input and as long as we haven't hit the "EOF", the "end of file", the end of the input we're going to modify the memory that we have in some given way. For this program we update our digit counts but any finite state automaton can be thought of as looking at the input character and modifying the memory in some way based on that input character and if this were genuinely a finite state automaton it would look at the state of the memory at the end and either return
boolean true or boolean false yes or no based on whether it was happy with the input that had been input into it so it can be useful to think whenever you're writing a computer program does your computer program fundamentally look like this is your computer program actually a finite state automaton and if so then you can analyze it using the tools that we use to analyze finite state automata. So in the rest of this series of videos I'd like to present to you lots more ways of thinking about regular languages leading up to how regular languages and finite state automata can tell us things about model theory tell us things about the formulas that are true of particular structures. so that's it for this video and I hope to see you in a future video!

Ask anything
We've read this whole study set, so questions about it get the best answers.