Presentation is loading. Please wait.

Presentation is loading. Please wait.

Automata Theory CS 3313 Chapter 4 An Introduction to Finite Automata.

Similar presentations

Presentation on theme: "Automata Theory CS 3313 Chapter 4 An Introduction to Finite Automata."— Presentation transcript:

1 Automata Theory CS 3313 Chapter 4 An Introduction to Finite Automata

2 Finite State Systems: *The finite automaton is a mathematical model of a system, with discrete inputs and outputs. *The system can be in any one of a finite number of internal configurations or "states". *The control mechanism of an elevator is a good example of a finite state system. *That mechanism does not remember all previous requests for service but only the current floor, the direction of motion (up or down), and the collection of not yet satisfied requests for service. *In computer science we find many examples of finite state systems, and the theory of finite automata is a useful design tool for these systems.

3 A primary example is a switching circuit, such as the control unit of a computer. A switching circuit is composed of a finite number of gates, each of which can be in one of two conditions, usually denoted 0 and 1. Certain commonly used programs such as text editors and the lexical analyzers found in most compliers are often designed as finite state systems. For example, a lexical analyzer scans the symbols of a computer program to locate the strings of characters corresponding to identifiers, numerical constants, reserved words, and so on. In this process the lexical analyzer needs to remember only a finite amount of information, such as how long a prefix of a reserved word it has seen since startup.

4 An Example: Before formally defining finite state systems let us consider an example. A man with a wolf, goat, and cabbage is on the left bank of a river. There is a boat large enough to carry the man and only one of the other three. The man and his entourage wish to cross to the right bank, and the man can ferry each across, one at a time. However, if the man leaves the wolf and goat unattended on either shore, the wolf will surely eat the goat.

5 Similarly, if the goat and cabbage are left unattended, the goat will eat the cabbage. Is it possible to cross the river without the goat or cabbage being eaten? The problem is modeled by observing that the pertinent information is the occupants of each bank after a crossing. There are 16 subsets of the man (M), wolf (W), goat (G), and cabbage (C). *Shown in Following figure:


7 There are two equally short solutions to the problem, as can be seen by searching for paths form the initial state to the final state. Before proceeding, we should note that there are at least two important ways in which the above example is a typical of finite state systems. First, there is only one final state; in general there may be many. Second, it happens that for each transition there is a reverse transition on the same symbol, which need not be the case in general. Also, note that the term "final state", although traditional, does not mean that the computation needs halt when it is reached. We may continue making transitions.

8 Basic Definitions A finite Automaton (FA) consists of a finite set of states and a set of transition from state to state that occur on input symbols chosen from analphabet Σ. For each input symbol there is exactly one transition out of each state (possibly back to the state itself). One state, usually denoted q 0, is the initial state, in which the automaton starts. Some states are designed as final or accepting states. A directed graph, called a "transition diagram", is associated with an FA as follows:

9 The vertices of the graph correspond to the states of the FA. If there is a transition from state q to state p on input a, then there is an arc labeled "a" from state q to state p in the transition diagram. The FA accepts a string x if the sequence of transitions corresponding to the symbol of x leads from the start state to an accepting state. [Example Figure-2.2 on page-16 of text book.]

10 We formally denote a finite automaton by a 5-tuples (Q, Σ, δ, q 0, F). Where: Q is a finite set of states, Σ is a finite input alphabet, q 0 in Q is the initial state, F Q is the set of final states and δ is the transition function mapping Q X Σ to Q. *That is, δ(q 0, a) is a state for each q and input symbol a.

11 How DFA Works * A DFA can be seen as a state machine as follows:

12 1.The machine reads the leftmost symbol of the word W, in the initial state q 0. 2.The automaton moves one symbol to the right and enters a new state as define by the transition function. 3.If after reading the word W, the automaton stops in a state that belongs to F, then W is accepted, otherwise it is rejected. (q current, symbol ) = q next

13 To formally describe the behavior of an FA on a string, we must extend the transition function δ to apply to a state and a string rather than a state and a symbol. We define a function δ from Q X Σ * to Q. The intention is that δ(q, w) is the state the FA will be in after reading w starting in state q. Put another way, δ(q, w) is the unique state p such that there is a path in the transition diagram from q to p, labeled w. Formally we define: 1) δ(q, ε) = q and 2) for all strings w and input symbols a, δ(q, wa) = δ(δ(q, w), a)

14 *Thus (1) states that without reading an input symbol the FA cannot change state, and Tells us how to find the state after reading a nonempty input string wa. hat is, find the state, p= δ(q, w), after reading w. Then compute the state δ(p, a). Since δ(q, a) = δ(δ(q, ε), a) = δ(q, a) [letter w = ε in rule (2) above, there can be no disagreement between δ and δ on arguments for which both are defined. Thus we shall for convenience use δ instead of δ from here on. Convention: We shall strive to use the same symbol to mean the same thing throughout the material on finite automata. In particular, unless it is stated otherwise, the reader may assume:

15 1)Q is a set of states. Symbols q and p, with or without subscripts, are states. q 0 is the initial state. 2)Σ is an input alphabet. Symbols a and b, with or without subscripts and the digits are input symbols. 3)Δ is a transition function. 4)F is a set of final states. 5)w, x, y, and z with or without subscripts, are strings of input symbols. A string x is said to be accepted by a finite automaton M = (Q, Σ, δ, q 0, F) if δ(q 0, x) = p for some p in F. he language accepted by M, designated L(M), is the set {x | (δ 0, x) is in F}. A language is a regular set (or just regular) if it is the set accepted by some finite automaton. [Example-2.2, page-18, of text book.]

16 Non-deterministic Finite Automata Any set accepted by a non-deterministic finite automaton can also be accepted by a deterministic finite automaton. However, the non-deterministic finite automaton is a useful concept in proving theorems. Also, the concept of non-determinism plays a central role in both the theory of languages and the theory of computation, and it is useful to understand this notion fully in a very simple context initially. Later we shall meet automata whose deterministic and non- deterministic versions are known not to be equivalent. Consider modifying the finite automaton model to allow zero, one or more transitions from a state on the same input symbol.

17 This new model is called non-deterministic finite automata (NFA). [Figure-2.5, page 20, of text book.] Formally we denote a non-deterministic finite automaton by a 5 tuple (Q, Σ, δ, q 0, F), where Q, Σ, q 0, and F (states, inputs, start state and final states) have the same meaning as for a DFA, but δ is a map from Q X Σ to 2 Q. Recall 2 Q is the power set of Q, the set of all subsets of Q). The intention is that δ(q, a) is the set of all states p such that there is a transition labeled a from q to p. The function δ can be extended to a function δ mapping Q X Σ * to 2 Q and reflecting sequences of inputs as follows: 1) δ(q, ε) = {q} 2) δ(q, wa) = {p | for some state r in δ(q, w), p is in δ(r, a)}

18 Conditions (1) disallows a change in sate without an input. Condition (2) indicates that starting in state q and reading the string w followed by input symbol "a" we can be in state p if and only if one possible state we can be in after reading w is r, and from r we may go to p upon reading a. Note that δ(q, a) = δ(q, a) for a an input symbol. Thus we may again use δ in place of δ. It is also useful to extend δ to arguments in 2 Q X Σ * by 3) δ(P, w) = U q in P δ(q, w) For each set of states P Q. L(M), where M is the NFA (Q, Σ, δ, q 0, F), is {w | δ(q 0, w) contains a state in F} [Example-2.4, page-21, of text book.]

19 The equivalence of DFA's and NFA's Since every DFA is an NFA, it is clear that the class of languages accepted by NFA's includes the regular sets (the language accepted by DFA's). However, it turns out that these are the only sets accepted by NFA's. For every NFA we can construct an equivalent DFA (one which accepts the same language) [Assignment: Theorem-2.1, page 22 of the text book.] [Assignment: Example-2.5, page 23 of the text book.]

20 Finite Automata with ε-Moves We may extend our model of the non-deterministic finite automaton to include transitions on the empty input ε. The transition diagram of such an NFA accepting the language consisting of any number (including zero) of 0's followed by any number of 1's followed by any number of 2's is given in Figure-2.8 (page-24). As always, we say an NFA accepts a string w if there is some path labeled w from the initial state to a final state. Of course, edges labeled ε move be included in the path, although the ε's do not appear explicitly in w. For example, the word 002 is accepted by the NFA of Figure- 2.8 by the path q 0, q 0, q 0, q 1, q 2, q 2 with arcs labeled 0, 0, ε, ε, 2. [Assignment: example-2.7, example-2.8, example-2.9.]

21 Regular Expressions The language accepted by finite automata are easily described by simple expressions called regular expressions. L 0 = { ε } and L 1 = L L i - 1 for i 1. (Kleene Closure or just Closure) L * denotes words constructed by concatenating any number of words from L. L + is the same, but the case of zero words, whose concatenation is defined to be ε, is excluded. Note that L + contains ε if and only if L does. [Example: 2.10, page 28 of the text book.] [Example: 2.11, page 29 of the text book.] [Theorem: 2.3, page 30 of the text book.] [Example: 2.12, page 32 of the text book.] [Assignment: Example-2.13, page 34 of the text book.]

22 Two-Way Finite Automata We have viewed the finite automaton as a control unit that reads a tape, moving one square right at each move. We added non-determinism to the model, which allowed many "copies" of the control unit to exist and scan the tape simultaneously. Next we added ε-transitions, which allowed change of state without reading the input symbol or moving the tape head. Another interesting extension is to allow the tape head the ability to move left as well as right. Such a finite automaton is called a two-way finite automaton. [Assignment] [Example: 2.14, page 37 of the text book.] * [Assignment: Crossing Sequences, and Figure:2.19, page 38 of the text book.]

23 Finite Automata with Output One limitation of the finite automaton as we have defined it is that its output is limited to a binary signal: "accept" / " don't accept". There are two distinct approaches; the output may be associated with the state (called a Moore Machine) or with the transition (called a Mealy Machine). Moore Machines A Moore machine is a six-tuple (Q, Σ, Δ, δ, λ, q 0 ), where Q, Σ, δ and q 0 are as in the DFA. Δ is the output alphabet and λ is a mapping from Q to Δ giving the output associated with each state. Note that any Moore machine gives output λ(q 0 ) in response to input ε.

24 *The DFA may be viewed as a special case of a Moore machine where the output alphabet is {0, 1} and state q is "accepting" if and only if λ(q) = 1. [Example: 2.17, page 42 of the text book.] Mealy Machines A Mealy machine is also a six-tuple M = (Q, Σ, Δ, δ, λ, q 0 ), where all is as in the Moore machine, except that λ maps Q x Σ to Δ. [Example: 2.18, page 43, of the text book.] Applications of Finite Automata [Assignment: Note on Lexical Analyzer & Text Editors]

Download ppt "Automata Theory CS 3313 Chapter 4 An Introduction to Finite Automata."

Similar presentations

Ads by Google