1. Home
  2. Explore
  3. Computer Science
  4. Regular Languages Equivalences

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Regular Languages Equivalences

Speaker 1Speaker 2

Regular Languages Equivalences

9:44
0:00-9:44
  1. Hope

    Welcome back. Today we're starting with regular languages, and the big idea is that they can be described in several different, equivalent ways. Just as there are many equivalent models of Turing-complete computation, there are many equivalent models for the less powerful class of regular languages.

  2. Corey

    And having those different descriptions is useful because each one makes different properties easy to see. One viewpoint may make the machine's behavior obvious, while another makes some algebraic or computational feature much easier to analyze.

  3. Hope

    Our first viewpoint is the finite-state automaton, specifically the deterministic finite automaton, or DFA. I like to imagine it as a simple machine with a keyboard and an indicator light. You type a string of characters, the machine updates its internal state after every character, and when you're finished, the light tells you whether the string is accepted.

  4. Corey

    So the machine isn't waiting for a clock or consulting outside information. Between keystrokes it simply stays where it is. Its only changes happen when a new input character arrives.

  5. Hope

    Exactly. The crucial word is finite. A finite automaton has only a finite amount of memory, so it has only finitely many possible internal states. If we keep feeding it characters, eventually it must revisit a state it has already visited. That follows from the pigeonhole principle.

  6. Corey

    And when it revisits that state, the machine has forgotten everything that happened between the two visits. From that point forward, it behaves as though it were in that state for the first time.

  7. Hope

    Right. A finite automaton cannot remember an entire arbitrarily long input and analyze it later. As data arrives, it has to process the data using its fixed memory and discard some information. That's why finite-state machines are good abstractions for systems where the incoming data may be much larger than the system's internal memory.

  8. Corey

    That situation comes up in modern computing too. A system may receive a huge stream of data and have to decide which limited information to retain while throwing away the rest.

  9. Hope

    This contrasts with a Turing machine, which is an abstraction with effectively unlimited memory. Real computers do not literally have infinite memory, but for data sets small enough compared with their memory, they can behave as though their memory were unlimited.

  10. Corey

    Strictly speaking, a real computer also has only finitely many memory configurations. If it has a certain number of bits, then each bit can be zero or one, giving two to the power of that number of bits as possible memory states.

  11. Hope

    So a real computer is technically closer to a finite-state automaton than to an infinite-memory Turing machine. But if the data being processed is small enough, treating its memory as effectively infinite is useful. Once the input becomes large enough, the computer has to discard information and starts exhibiting finite-memory behavior.

  12. Corey

    To study a finite automaton, we usually draw all its states and the transitions between them. We would not want to do that for a desktop computer, because its enormous number of possible states would be impossible to visualize. Instead, let's use a tiny example with three states: state zero, state one, and state two.

  13. Hope

    Suppose the input alphabet has just three characters: a, b, and c. In the state diagram, an arrow labeled with a character tells us where the machine goes when it reads that character. For example, if an arrow labeled c goes from state one to state two, then reading c while in state one moves the machine to state two.

  14. Corey

    Because this is deterministic, each state has exactly one possible destination for each input character. If we were in state one and read a, the diagram cannot leave us wondering whether we go to state zero or state two. The behavior has to be completely well-defined, with no uncertainty or randomness.

  15. Hope

    The arrow entering from outside the diagram identifies the start state. In our example, the machine starts in state zero. Every new word is checked by resetting the machine to that state, so the answer depends only on the word being read, not on what the machine processed earlier.

  16. Corey

    The double circles identify accept states. If the machine is in one of those states when the input ends, the indicator light is on and the word is accepted. There can be one accept state, several accept states, or even a set of accept states chosen from all the machine's states.

  17. Hope

    Let's run the example. Start in state zero and read b. The machine stays in state zero. Then read a, and it moves from state zero to state one. If the input ends there, the machine is in the accepting state, so the string ba is accepted.

  18. Corey

    But if we continue with another a, the machine moves back to state zero. So baa is rejected if the input ends there. The string baaba, on the other hand, ends back in state one and is accepted.

  19. Hope

    The character c has a more dramatic effect in this machine. Reading c takes the machine to state two, and state two traps it there. Once the machine reaches state two, there is no way to turn the indicator light on, so a string such as bacba is rejected.

  20. Corey

    From those transitions, we can determine what the machine is actually checking. It ignores b, because reading b does not change the state. It tracks whether the number of a characters is even or odd, and it rejects any input containing c.

  21. Hope

    More precisely, the accepting state corresponds to having seen an odd number of a characters, while state zero corresponds to an even number. Each a switches between those two states. Therefore, this machine accepts exactly the strings with an odd number of a characters and no c characters, regardless of how many b characters appear.

  22. Corey

    That gives us the definition of a regular language. A word, in this mathematical setting, is simply a finite string of symbols from an alphabet. An alphabet is a finite set of symbols, and a language is any collection, or set, of words.

  23. Hope

    A language is regular exactly when some deterministic finite-state automaton accepts precisely the words in that language. So because our three-state machine recognizes the strings with an odd number of a's and no c's, that collection of strings is a regular language.

  24. Corey

    The state diagram is one way to present the automaton, but it isn't the only one. We can describe the same machine using a transition function, usually written with the lowercase Greek letter delta. The function takes the current state and the character being read, then returns the next state.

  25. Hope

    For example, if the machine is in state one and reads c, the transition function returns state two. In symbols, that is the idea behind delta of state one and c being state two. Listing all such results gives us a transition table, which can be more convenient for algorithmic purposes than a graph.

  26. Corey

    There is another useful version of the same information. Instead of one function that takes both a state and a character, we can have a separate function for each character. The function for c sends every state to state two, the function for a swaps states zero and one while leaving state two alone, and the function for b is the identity function, leaving every state unchanged.

  27. Hope

    So we can view the automaton as one transition function controlled by the input character, or as a collection of functions from the state set to itself, one function for each input symbol. Those are two perspectives on exactly the same transitions.

  28. Corey

    Formally, a finite automaton is often packaged as a tuple containing all the information needed to specify it. First comes the alphabet, usually written sigma. In our example, sigma is the finite set containing a, b, and c.

  29. Hope

    Next comes the finite set of states, which here is zero, one, and two. Then we specify the start state, state zero, the transition function, and finally the set of accept states. The accept-state set is a subset of the state set, so it can contain any number of states.

  30. Corey

    That tuple is useful because it gives a precise, compact description of the machine. The graph gives us a visual description, while the transition function gives us a more algorithmic one.

  31. Hope

    There is also a path-based viewpoint. Every accepted word corresponds to a path through the state diagram beginning at the start state and ending at an accept state. For our example, accepted inputs are exactly the paths that start at state zero and finish at state one without becoming trapped in state two.

  32. Corey

    And there is a programming viewpoint too. Imagine a program that declares a fixed collection of variables, initializes them, repeatedly reads input characters, and updates its stored information according to each character.

  33. Hope

    That program has only finitely many possible memory configurations if its variables have finite ranges. For instance, integer variables in an ordinary programming language have a bounded range, and an array of such integers also has only finitely many configurations.

  34. Corey

    The program can initialize its variables as the automaton's start state, use a loop to read characters until the end of the input, and update its memory based on each character. At the end, it could return true or false depending on whether its final memory configuration is an accepting one.

  35. Hope

    A program that counts digits illustrates the general pattern, even if the counts may eventually exceed their available range. The important structure is fixed memory, initialization, a loop over incoming characters, and memory updates driven by those characters.

  36. Corey

    So when examining a computer program, it can be useful to ask whether it fundamentally has that finite-state shape. If it does, then the tools for analyzing finite automata may also apply to the program.

  37. Hope

    Today we've seen several equivalent ways to think about regular languages: as deterministic finite automata, as transition functions, as paths through labeled graphs, and as programs with a fixed amount of memory. Switching among these perspectives lets us make different properties visible.

  38. Corey

    And this is only the beginning. Further perspectives on regular languages and finite-state automata can eventually connect them to questions in model theory, including the formulas that are true of particular structures.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent