Sunteți pe pagina 1din 6

3/26/2013

Lecture Objective
Moore Machines

Mealy Machines

Finite Automata with Output


Moore = Mealy

Moore Machine Definition


Moore machine is a collection of five things: 1. A finite set of states q0, q1, q2, ..., where q0 is designated as the start state.

Notes
We did not assume that the input alphabet is the same as the output alphabet . To keep the output alphabet separate from the input alphabet, we give it a different name (instead of ) and use number symbols {0, 1, } (instead of {a, b, }). We refer to input symbols as letters, whereas we refer to output symbols as characters. We adopt the policy that a Moore machine always begins by printing the character dictated by the mandatory start state. So, if the input string has 7 letters, then the output string will have 8 characters, because it includes 8 states in its path.

2. An alphabet of letters for forming the input string = {a, b, c, }. 3. An alphabet of possible output characters = {0, 1, 2, }. 4. A transition table that shows for each state and each input letter what state is reached next. 5. An output table that shows what character from is printed by each state as it is entered.

Notes Contd.
A Moore machine does not define a language of accepted words, because there is no such thing as a final state. Every possible input string creates an output string. The processing is terminated when the last input letter is read and the last output character is printed. There are some subtle ways to turn Moore machines into language definers.
5

Example: Moore machine defined by a table


Input alphabet: = {a, b} Output alphabet: = {0, 1} Names of states: q0, q1, q2, q3 with q0 being the start state. Transition and output table (combined): Old State q0 q1 q2 q3 Output by Old State 1 0 0 1 New state after a q1 q3 q0 q1
6

New state after b q3 q1 q3 q2

3/26/2013

Pictorial Representation
Moore machines have pictorial representations similar to FAs. The difference is that inside each state, in addition to the state name, we also specify the output character printed by that state, using the format state name/output.

Example

Given the input string abab, the output sequence is 10010.

Hence, the Moore machine in the above example has the following pictorial representation:
7

Note that the length of the output string is one longer than the length of the input string.

Example
Suppose we are interested in knowing exactly how many times the substring aab occurs in a long input string. The following Moore machine will count this for us:

Example contd.
To get to q3, we must have come from q2 and have just read a b. To get to q2, we must have read at least two as in a row. After finding the subtring aab and tallying a 1 for it, the machine looks for the next aab. Hence, the number of 1s in the output string is exactly the number of substrings aab in the input string. Consider an FA that accepts a language L:
If we add printing character 0 to any non-final state and 1 to each final state, then the 1s in any output string mark the end position of all substrings that are words in L. In a similar way, a Moore machine can be said to define the language of all input strings whose output ends with a 1.

Every state of this machine prints out a 0, except for q3, which prints a 1.
9

The Moore machine above with q0 = - and q3 = + accepts all words that end with aab.

10

Melay machine Definition


A Mealy machine is a collection of four things: 1. A finite set of states q0, q1, q2, ..., where q0 is designated as the start state. 2. An alphabet of letters for forming the input string = {a, b, }. 3. An alphabet of possible output characters = {0, 1, }. 4. A pictorial representation with states represented by small circles and directed edges indicating transition between states.
Each edge is labeled with a compound symbol of the form i/o where i is an input letter and o is an output character. Every state must have exactly one outgoing edge for each possible input letter. The edge we travel is determined by the input letter i. While traveling on the edge, we must print the output character o.

Example

Given the input string aaabb, the output is 01110. In a Mealy machine the output string has the same number of characters as the input string has letters.
12

11

3/26/2013

Example
A Mealy machine does not define a language by accepting and rejecting input strings: It has no final states. However, there is a sense in which a Mealy machine can recognize a language, as we will see later. Note the following notation simplification: The following Mealy machine prints out the 1s complement of an input bit string. This means that it will produce a bit string that has a 1 whenever the input string has a 0, and a 0 whenever the input has a 1.

If the input string is 001010, the output will be 110101


13 14

Example
Although a Mealy machine does not accept or reject an input string, it can recognize a language by making its output string answer some question about the input. Consider the language of all words that have a double letter (aa or bb) in them. We can build a Mealy machine that can take an input string of as and bs, and print out an output string of 0s and 1s such that if the n-th output character is a 1, it means that the n-th input letter is the second letter in a pair of double letters. The complete picture of this machine is as follows:
15

If the input string is ababbaab, the output will be 00001010. This machine recognizes the occurrences of aa or bb. Note that the triple letter word aaa produces the output 011 since the second and third letters are both the back end of a pair of double as.
16

Moore = Melay
So far, we have define that two machines are equivalent if they accept the same language. In this sense, we cannot compare a Mealy machine and a Moore machine because they are not language definers. Definition: Given the Mealy machine Me and the Moore machine Mo (which prints the automatic start state character x), we say that these two machines are equivalent if for every input string, the output string from Mo is exactly x concatenated with the output string from Me.
17

Defining Languages by Regular Expression

3/26/2013

Language-Defining Symbols
We now introduce the use of the Kleene star, applied not to a set, but directly to the letter x and written as a superscript: x*. This simple expression indicates some sequence of xs (may be none at all): x* = or x or x2 or x3 = xn for some n = 0, 1, 2, 3, Letter x is intentionally written in boldface type to distinguish it from an alphabet character. We can think of the star as an unknown power. That is, x* stands for a string of xs, but we do not specify how many, and it may be the null string .
19

Language-Defining Symbols
The notation x* can be used to define languages by writing, say L4 = language (x*) Since x* is any string of xs, L4 is then the language of all possible strings of xs of any length (including ). We should not confuse x* (which is a languagedefining symbol) with L4 (which is the name we have given to a certain language).

20

Regular Expression
Given the alphabet = {a, b}, suppose we wish to define the language L that contains all words of the form one a followed by some number of bs (maybe no bs at all); that is L = {a, ab, abb, abbb, abbbb, } Using the language-defining symbol, we may write

L = language (ab*)
This equation obviously means that L is the language in which the words are the concatenation of an initial a with some or no bs. From now on, for convenience, we will simply say some bs to mean some or no bs. When we want to mean some positive number of bs, we will explicitly say so.
21

We can apply the Kleene star to the whole string ab if we want: (ab)* = or ab or abab or ababab Observe that (ab)* a*b* because the language defined by the expression on the left contains the word abab, whereas the language defined by the expression on the right does not.

22

Plus Sign
If we want to define the language L1 = {x; xx; xxx; } using the language-defining symbol, we can write L1 = language(xx*) which means that each word of L1 must start with an x followed by some (or no) xs. Note that we can also define L1 using the notation + (as an exponent) introduced in Chapter 2: L1 = language(x+) which means that each word of L1 is a string of some positive number of xs.
23 24

Let us introduce another use of the plus sign. By the expression x+y where x and y are strings of characters from an alphabet, we mean either x or y. Care should be taken so as not to confuse this notation with the notation + (as an exponent).

3/26/2013

Example
Consider the language T over the alphabet = {a; b; c}: T = {a; c; ab; cb; abb; cbb; abbb; cbbb; abbbb; cbbbb; } In other words, all the words in T begin with either an a or a c and then are followed by some number of bs. Using the above plus sign notation, we may write this as T = language((a+ c)b*)
25

Example
Consider a finite language L that contains all the strings of as and bs of length three exactly: L = {aaa, aab, aba, abb, baa, bab, bba, bbb} Note that the first letter of each word in L is either an a or a b; so are the second letter and third letter of each word in L. Thus, we may write L = language((a+ b)(a + b)(a + b)) or for short, L = language((a+ b)3)
26

Example
In general, if we want to refer to the set of all possible strings of as and bs of any length whatsoever, we could write language((a + b)*) This is the set of all possible strings of letters from the alphabet = {a, b}, including the null string. This is powerful notation. For instance, we can describe all the words that begin with first an a, followed by anything (i.e., as many choices as we want of either a or b) as a(a + b)*
27

Difference
It is important to be clear about the difference of the following regular expressions r1 = a*+b* r2 = (a+b)* Here r1 does not generate any string of concatenation of a and b, while r2 generates such strings. The language generated by any regular expression is called a regular language.

28

Equivalent Regular Expressions


Two regular expressions are said to be equivalent if they generate the same language. Example Consider the following regular expressions r1 = (a + b)* (aa + bb) r2 = (a + b)*aa + ( a + b)*bb then both regular expressions define the language of strings ending in aa or bb.

Example
Consider the language defined by the expression (a + b)*a(a + b)* At the beginning of any word in this language we have (a + b)*, which is any string of as and bs, then comes an a, then another any string. For example, the word abbaab can be considered to come from this expression by 3 different choices: a(bbaab) or (abb)a(ab) or (abba)a(b)
30

29

3/26/2013

Example contd.
This language is the set of all words over the alphabet = {a, b} that have at least one a. The only words left out are those that have only bs and the word . The language of all words that have at least two as can be defined by the expression: (a + b)*a(a + b)*a(a + b)*

Example
The language of all words that have at least one a and at least one b is somewhat trickier. If we write (a + b)*a(a + b)*b(a + b)* then we are requiring that an a must precede a b in the word. Such words as ba and bbaaaa are not included in this language. Since we know that either the a comes before the b or the b comes before the a, we can define the language by the expression (a + b)*a(a + b)*b(a + b)* + (a + b)*b(a + b)*a(a + b)*

31

32

Examples
Note that (a + b*)* = (a + b)* since the internal * adds nothing to the language. However, (aa + ab*)* (aa + ab)* since the language on the left includes the word abbabb, whereas the language on the right does not. (The language on the right cannot contain any word with a double b.)
33

Introducing EVEN-EVEN
Consider the regular expression E = [aa + bb + (ab + ba)(aa + bb)*(ab + ba)]* This expression represents all the words that are made up of syllables of three types: type1 = aa type2 = bb type3 = (ab + ba)(aa + bb)*(ab + ba) Every word of the language defined by E contains an even number of as and an even number of bs. All strings with an even number of as and an even number of bs belong to the language defined by E.

34

S-ar putea să vă placă și