Full Transcript

**University of Science and Technology** **Faculty of Computer Science and Information Technology** **Theory of Computation** **Lecture (2): Regular Languages** **Instructor: Prof. Noureldien A. Noureldien** **Regular Languages** The theory of computation begins with a question: What is a comp...

**University of Science and Technology** **Faculty of Computer Science and Information Technology** **Theory of Computation** **Lecture (2): Regular Languages** **Instructor: Prof. Noureldien A. Noureldien** **Regular Languages** The theory of computation begins with a question: What is a computer? It is perhaps a silly question, but these real computers are quite complicate. To understand how computers works we use an idealized **[computer called a computational model]**. As with any model in science, a computational model may be accurate in some ways but perhaps not in others. **[Thus, we will use several different computational models, depending on the features we want to focus on]**. We begin with the simplest model, called the finite state machine or finite automaton. **Finite Automata** Finite automata are good **[models for computers with an extremely limited amount of memory]**. What can a computer do with such a small memory? Many useful things! In fact, we interact with such computers all the time, as they lie at the heart of various electromechanical devices. These devices are used in speech processing and in optical character recognition. **Markov chains [have been used to model and predict price changes in financial markets]**. We will now take a closer look at finite automata from a mathematical perspective. In beginning to describe the mathematical theory of finite automata, we do so in the abstract, without reference to any particular application. The following figure depicts a finite automaton called M1. FIGURE 1.4 A finite automaton called M1 that has three states **Figure 1.4 is called the state diagram of M1**. **It has three states, labeled q1, q2, and q3**. The **[start state, q1, is indicated]** by the arrow pointing at it from nowhere. **[The accept state, q2,]** is the one with a double circle. **The arrows going from one state to another are called transitions**. When this automaton receives an input string such as 1101, it processes that string and produces an output. **[The output is either accept or reject]**. We will consider only this yes/no type of output for now to keep things simple. The processing begins in M1's start state. The automaton receives the symbols from the input string one by one from left to right. **[After reading each symbol, M1 moves from one state to another along the transition that has that symbol as its label]**. **When it reads the last symbol, M1 produces its output. The output is accept if M1 is now in an accept state and reject if it is not**. For example, when we feed the input string 1101 into the machine M1 in Figure 1.4, the processing proceeds as follows: 1\. Start in state q1. 2\. Read 1, follow transition from q1 to q2. 3\. Read 1, follow transition from q2 to q2. 4\. Read 0, follow transition from q2 to q3. 5\. Read 1, follow transition from q3 to q2. 6\. Accept because M1 is in an accept state q2 at the end of the input. Experimenting with this machine on a variety of input strings reveals that it accepts the strings 1, 01, 11, and 0101010101. In fact, M1 **[accepts any string that ends with a 1,]** as it goes to its accept state q2 whenever it reads the symbol 1. In addition, it accepts strings 100, 0100, 110000, and 0101000000, and **any string that ends with an even** **number of 0s following the last 1**. It rejects other strings, such as 0, 10, 101000. Can you describe the language consisting of all strings that M1 accepts? We will do so shortly. **Formal Definition of a Finite Automation** In the preceding section, we used state diagrams to introduce finite automata. Now we define finite automata formally A finite automaton has several parts. - It has a set of states and - It has set of rules for going from one state to another, depending on the input symbol. - It has an input alphabet that indicates the allowed input symbols. - It has a start state and - It has a set of accept states. The formal definition says that a finite automaton is a list of those five objects: set of states, input alphabet, rules for moving, start state, and accept states. In mathematical language, a list of five elements is often called a 5-tuple. Hence, we define a finite automaton to be a 5-tuple consisting of these five parts. We can use the notation of the formal definition to describe individual finite automata by specifying each of the five parts listed in Definition 1.5. For example, let's return to the finite automaton M1 we discussed earlier, redrawn here for convenience. **[If A is the set of all strings that machine M accepts, we say that A is the *language of machine* M and write L(M) = A. We say that M *recognizes* A or that M *accepts* A. ]** Because the term *accept* has different meanings when we refer to machines accepting strings and machines accepting languages, we prefer the term *recognize* for languages in order to avoid confusion. A machine may accept several strings, but it always recognizes only one language. If the machine accepts no strings, it still recognizes one language namely, the empty language. A good way to begin **[understanding any machine is to try it on some sample input strings.]** When you do these "experiments" to see how the machine is working, its method of functioning often becomes apparent. On the sample string 1101, the machine M2 starts in its start state q1 and proceeds first to state q2 after reading the first 1, and then to states q2, q1, and q2 after reading 1, 0, and 1. The string is accepted because q2 is an accept state. But string 110 leaves M2 in state q1, so it is rejected. After trying a few more examples, you would see that M2 accepts all strings that end in a 1. **[Thus L(M2) = {w\| w ends in a 1}.]** Machine M3 is similar to M2 except for the location of the accept state. As usual, the machine accepts all strings that leave it in an accept state when it has finished reading. Note that because the start state is also an accept state, M3 accepts the empty string \". As soon as a machine begins reading the empty string, it is at the end; so if the start state is an accept state, \" is accepted. In addition to the empty string, this machine accepts any string ending with a 0. Here, **[L(M3) = {w\| w is the empty string \" or ends in a 0}.]** MachineM5 keeps a running count of the sum of the numerical input symbols it reads, modulo 3. Every time it receives the RESET symbol, it resets the count to 0. **It accepts if the sumis 0 modulo 3, or in other words, if the sumis a multiple of** **3.**

Use Quizgecko on...
Browser
Browser