Вы находитесь на странице: 1из 28

# Introduction:

## We will study the relationships between languages, machines, and

grammars. A language is a set of strings over a finite alphabet,
where a string is the concatenation of zero or more symbols from
the alphabet. Machines will always include a means of reading
input from an input tape, one symbol at a time, and will contain
some amount of finite state control. Additional storage and types
in different ways provide for variations in the machine models,
and may allow machines to perform harder tasks or perform the
same tasks faster. Machines with output capabilities may also be
considered as generators of languages (they output exactly the
strings of the language delimited in some fashion) or computers
(given an input string, the machine may produce an output string
and halt, or if the function is not defined for that input string, it
may not halt). For the most part, we will consider machines as
language recognizers, that is, given an input string, the machine
will execute for some number of steps and halt in an accepting
state or not (it may not halt, or it may halt in a non-accepting
state). A general term for an automata. A machine could
be a Turing Machine, a pushdown automata, a finite
state machine or any other restricted version of a Turing
machine

Basics :Sets

## • Importance: languages are sets

• A set is a collection of "things," called the elements or members
of the set. It is essential to have a criterion for determining, for
any given thing, whether it is or is not a member of the given
set. This criterion is called the membership criterion of the set.
• There are two common ways of indicating the members of a set:
o List all the elements, e.g. {a, e, i, o, u}
o Provide some sort of an algorithm or rule, such as a
grammar
• Notation:
o To indicate that x is a member of set S, we write x S
o We denote the empty set (the set with no members) as {}
or
o If every element of set A is also an element of set B, we
say that A is a subset of B, and write A B
o If every element of set A is also an element of set B, but B
also has some elements not contained in A, we say that A
is a proper subset of B, and write A B
Operations on Sets
• The union of sets A and B, written A B, is a set that contains
everything that is in A, or in B, or in both.
• The intersection of sets A and B, written A B, is a set that
contains exactly those elements that are in both A and B.
• The set difference of set A and set B, written A - B, is a set that
contains everything that is in A but not in B.
• The complement of a set A, written as -A or (better) A with a bar
drawn over it, is the set containing everything that is not in A.
This is almost always used in the context of some universal set U
that contains "everything" (meaning "everything we are
interested in at the moment"). Then -A is shorthand for U - A.

The cardinality of a set A, written |A|, is the number of elements in a
set A.

## The powerset of a set Q, written 2 , is the set of all subsets of Q. The

notation suggests the fact that a set containing n elements has a
powerset containing 2 elements.

Two sets are disjoint if they have no elements in common, that is, if A
B= .

Graphs :

## • Importance: Automata are graphs.

• A graph consists of two sets
o A set V of vertices (or nodes), and
o A set E of edges (or arcs).
• An edge consists of a pair of vertices in V. If the edges are
ordered, the graph is a digraph (a contraction of "directed
graph").
• A walk is a sequence of edges, where the finish vertex of each
edge is the start vertex of the next edge. Example: (a, e), (e, i),
(i, o), (o, u).
• A path is a walk with no repeated edges.
• A simple path is a path with no repeated vertices.

Trees
Importance: Trees are used in some algorithms.

## • A tree is a kind of digraph:

o It has one distinguished vertex called the root;
o There is exactly one path from the root to each vertex; and
o The level of a vertex is the length of the path to it from the
root.
• Terminology:
o if there is an edge from A to B, then A is the parent of B,
and B is the child of A.
o A leaf is a node with no children.
o The height of a tree is the largest level number of any
vertex.

Fundamental Concepts
There are three fundamental concepts that we will be working on:

Languages :

## o A language is a subset of the set of all possible strings

formed from a given set of symbols.
o There must be a membership criterion for determining
whether a particular string in in the set.

Grammar :

## o A grammar is a formal system for accepting or rejecting

strings.
o A grammar may be used as the membership criterion for a
language.

Automata :

## o An automaton is a simplified, formalized model of a

computer.
o An automaton may be used to compute the membership
function for a language.
o Automata can also compute other kinds of things.

## There is no formal definition for "automaton"--instead, there are

various kinds of automata, each with it's own formal definition.

Generally, an automaton has some form of input, has some form of output, has internal
states, may or may not have some form of storage, is hard-wired rather than
programmable.
An automaton that computes a Boolean (yes-no) function is called an
acceptor. Acceptors may be used as the membership criterion of a
language.

## An automaton that produces more general output (typically a string) is

called a transducer.

## Logic circuit design: arithmetic and logic units, buers, Programming

utilities: lex, grep, awk, perl , Text editors: pattern-matching,
Computers.

## Finite Automata also called a Finite State Machine, FA,

DFA or FSM which is defined formally as

## M = (Q, Sigma, delta, q0, F) is a definition of a Finite

Automata.

Where Q a finite set of states often called q0, q1, ... , qn or s0, s1, ... ,
sn.
There is no requirement, in general, that every state be reachable,
sigma a finite input alphabet , delta a transition function mapping Q
cross sigma to Q( delta is typically given as a table with all states
listed on the right, input symbols
listed across the top and next state in the table) as
| 0 | 1 |
----+-----+-----+----
s0 | s1 | s2 |
----+-----+-----+----
s1| s2 | s0 |
----+-----+-----+----
s2 s2 | s1 |
----+-----+-----+----

When the transition table, delta, has all single entries, the machine
may be refereed to as a Deterministic Finite Automata, DFA.

## There is no requirement, in general, that every entry in the table must

contain a state. If a machine tries to go to an empty table entry it
"crashes". The remainder of the input, if any, is unread. The machine
does not accept and can not possibly be in a final state.
When every state/input pair has at most one target state, the
automata
is called deterministic. q0 the initial state from the set Q.
By definition this is the state the automata is in when it starts.
The automata gets the first symbol from the input, then goes from
the starting state to the state designated by the transition function.
F a set of final states from the set Q also known as accepting states.
The machine stops after the last input symbols is read and the
corresponding state transition occurs. If the machines state when
stopped is in F then the machine is said to accept the input string.
F can be a null set in which case only the empty language is accepted.
There is no requirement, in general, that any final state be reachable.
A machine defines a language, the set of all strings accepted by
the machine. This language is usually denoted L(M). The machine that
accepts a language L is usually denoted M(L).
There is a Finite Automata, as defined here, for every Regular
Language and
a Regular language for every Finite Automata.
Another common way to define a Finite Automata is via a diagram.
The states are shown as circles, often unlabeled, the initial state has
an arrow pointing to it, the final states have a double circle, the
transition function is shown as directed arcs with the input symbol(s)
on the arc.

DFAs are:

## • Deterministic--there is no element of choice

• Finite--only a finite number of states and arcs
• Acceptors--produce only a yes/no answer

## One designated state is the start state.

Some states (possibly including the start state) can be designated as final states.
Arcs between states represent state transitions -- each such arc is
labeled with the symbol that triggers the transition.

Example DFA

## Example input string: 10011100

Operation

head" at the beginning of the input string;
• while there are still characters in the string:
o From the current state, follow the arc that is labeled with
the character just read; the state that the arc points to
becomes the next current state;
• When all characters have been read, accept the string if the
current state is a final state, otherwise reject the string.

Sample trace: q0 1 q1 0 q3 0 q1 1 q0 1 q1 1 q0 0 q2 0 q0

## Formal Definition of a DFA

A deterministic finite acceptor or dfa is a quintuple:
M = (Q, , , q0, F)
where

## • Q is a finite set of states,

• is a finite set of symbols, the input alphabet,
• :Q Q is a transition function,
• q0 Q is the initial state,
• F Q is a set of final states.

Note: The fact that is a function implies that every vertex has an outgoing arc for each
member of .We can also define an extended transition function as
:Q Q.
If a DFA M = (Q, , , q0, F) is used as a membership criterion, then the
set of strings accepted by M is a language. That is,
L(M) = {w : (q0, w) F}.Languages that can be defined by dfas are called regular
languages.

## Nondeterministic Finite Acceptors

A finite-state automaton can be nondeterministic in either or both of
two ways:

A state may have two or more arcs emanating from it labeled with the
same symbol. When the symbol occurs in the input, either arc may be
followed.
A state may have one or more arcs emanating from it labeled with
(the empty string) . These arcs may optionally be followed without
looking at the input or consuming an input symbol. Due to
nondeterminism, the same string may cause an nfa to end up in one of
several different states, some of which may be final while others are
not. The string is accepted if any possible ending state is a final state.

Example NFAs

## Formal Definition of NFAs:

A nondeterministic finite acceptor or nfa is defined by the quintuple

## M = (Q, Σ, δ, q0, F) Where Q is a finite set of states, is a finite set of

symbols, the input alphabet, : Q ( { } ) 2 is a transition
function,q0 Q is the initial state, Q is a set of final states.
These are all the same as for a dfa except for the definition of :
Transitions on are allowed in addition to transitions on elements of ,
and tThe range of is 2 rather than Q. This means that the values of
are not elements of Q, but rather are sets of elements of Q.
The language defined by nfa M is defined as L(M) = {w : (q0, w)
F }

## M = (Q, sigma, delta, q0, F) is the same as for deterministic finite

automata
above with the exception that delta can have sets of states.

## delta for a nondeterministic machine looks like:

| 0 | 1 |
----+---------+---------+
s0 | {s1,s2} | {s2} |
----+---------+---------+
s1 | {s0,s2} | phi |
----+---------+---------+
s2 | phi | {s1} |
----+---------+---------+

## A string is accepted if any sequence of transitions ends in a Final

state.There could be more than one sequence of transitions that end in
a Final state. Think of each transition that has more than one state as
causing a tree to branch. All branches are in some state and all
branches transition on every input. Any branch that reaches phi, the
null or nonexistent state,terminates.Any NFA can be converted to a
DFA but the DFA may require exponentially more states than the NFA.

DFA = NFA
Two acceptors are equivalent if the accept the same language.A DFA is just a special
case of an NFA that happens not to have any null transitions or multiple transitions on the
same symbol. So DFAs are not more powerful than NFAs. For any NFA, we can
construct an equivalent DFA . So NFAs are not more powerful than DFAs. DFAs and
NFAs define the same class of languages -- the regular languages.To translate an
NFA into a DFA, the trick is to label each state in the DFA with a set of
states from the NFA. Each state in the DFA summarizes all the states
that the NFA might be in. If the NFA contains |Q| states, the resultant
DFA could contain as many as |2 | states. (Usually far fewer states will
be needed.)
From NFA to DFA
Consider the following NFA:

## What states can we be in (in the NFA) before

the start state, A. But there is a
t ransition from A to B, so we could
also be in state B. For the DFA, we
construct the composite state {A, B}.

## State {A,B} lacks a transition for x. From A, x takes us to A (in the

NFA), and the null transition might take us to B; from B, x takes us
to B. So in the DFA, x takes us from {A,B} to {A,B}.

State {A,B} also needs a transition for y. In the NFA, (A,y)=C and
(B,y)=C, so we need to add a state {C} and an arc y from {A,B}
to {C}.

## In the NFA, (C,x)=A, but then a null transition might or

might not take us to B, so we need to add an arc x from
{C} to {A,B}.Also, there are two arcs from C labeled y,
going to states B and C. So in the DFA we need to add
the state {B,C} and the arc y from {C} to this new
state.In the NFA, (B,x)=B and (C,x)=A (and
by a transition we might get back to B), so we
need an x arc from {B,C} to {A,B}. (B,y)=C,
while (C,y) is either B or C, so we have an arc
labeled y from {B,C} to {B,C}.
We now have a transition from every state for every
symbol in . The only remaining chore is to mark all the
final states. In the original NFA, B was a final state, so in
the DFA, every state containing B is a final state.

moves) to nfa :

## Definition :epsilon is the zero length string, so it can be any where in

the input string, front, back, between any symbols. There is a
conversion algorithm from a NFA with epsilon transitions to a NFA
without epsilon transitions.

## Consider the NFA-epsilon move machine M = { Q, sigma, delta, q0, F}

Q = { q0, q1, q2 }, sigma = { a, b, c } and epsilon moves
q0 = q0, F = { q2 }

## sigma plus epsilon

delta | a | b | c |epsilon
------+------+------+------+-------
q0 | {q0} | phi | phi | {q1}
------+------+------+------+-------
q1 | phi | {q2} | phi | {q2}
------+------+------+------+-------
q2 | phi | phi | {q2} | phi
------+------+------+------+-------
The corresponding NFA with epsilon moves is as follows:
The language accepted by the above NFA with epsilon moves is the set
of strings over {a,b,c} including the null string and all strings with any
number of a's followed by any number of b's followed by any number
of c's. ("any number" includes zero). Now convert the NFA with epsilon
moves to a NFA M = ( Q', sigma, delta', q0', F').First determine the
states of the new machine,
Q' = the epsilon closure of the states in the NFA with epsilon moves.
There will be the same number of states but the names can be
constructed by writing the state name as the set of states in the
epsilon closure. The epsilon closure is the initial state and all states
that can be reached by one or more epsilon moves. Thus q0 in the
NFA-epsilon becomes {q0,q1,q2} because the machine can move
from q0 to q1 by an epsilon move, then check q1 and find that it can
move from q1 to q2 by an epsilon move. q1 in the NFA-epsilon
becomes {q1,q2} because the machine can move from q1 to q2 by an
epsilon move. q2 in the NFA-epsilon becomes {q2} just to keep the
notation the same. q2 can go nowhere except q2, that is what phi
means, on an epsilon move. We do not show the epsilon transition of a
state to itself here, but, beware, we will take into account the state to
itself epsilon transition when converting NFA's to regular expressions.
The initial state of our new machine is {q0,q1,q2} the epsilon closure
of q0 .The final state(s) of our new machine is the new state(s) that
contain a state symbol that was a final state in the original machine.
The new machine accepts the same language as the old machine,thus
same sigma.
So far we have for our new NFA
Q' = { {q0,q1,q2}, {q1,q2}, {q2} } or renamed { qx, qy, qz }
sigma = { a, b, c } , F' = { {q0,q1,q2}, {q1,q2}, {q2} } or renamed
{ qx, qy, qz }
q0 = {q0,q1,q2} or renamed qx

inputs

delta' | a | b | c
------------+--------------+--------------+--------------
qx or {q0,q1,q2} | | |
------------+--------------+--------------+--------------
qy or {q1,q2} | | |
------------+--------------+--------------+--------------
qz or {q2} | | |
------------+--------------+--------------+--------------

## Now we fill in the transitions. Remember that a NFA has transition

entries that are sets. Further, the names in the transition entry sets
must be only the state names from Q'. Very carefully consider each
old machine transitions in the first row. You can ignore any "phi"
entries and ignore the "epsilon" column.In the old machine
delta(q0,a)=q0 thus in the new machine
delta'({q0,q1,q2},a)={q0,q1,q2} this is just because the new machine
accepts the same language as the old machine and must at least have
the same transitions for the new state names.

inputs

delta' | a | b | c
------------+--------------+--------------+--------------
qx or {q0,q1,q2} | {{q0,q1,q2}} | |
------------+--------------+--------------+--------------
qy or {q1,q2} | | |
------------+--------------+--------------+--------------
qz or {q2} | | |
No more entries go under input a in the first row because old
delta(q1,a)=phi, delta(q2,a)=phi. Now consider the input b in the first
row, delta(q0,b)=phi,delta(q1,b)={q2} and delta(q2,b)=phi. The
reason we considered q0, q1 and q2 in the old machine was because
our new state has symbols q0, q1 and q2 in the new state name from
the epsilon closure. Since q1 is in {q0,q1,q2} and delta(q1,b)=q1
then delta'({q0,q1,q2},b)={q1,q2}. WHY {q1,q2} ?, because {q1,q2}
is the new machines name for the old machines name q1. Just
compare the zeroth column of delta to delta'. So we have
inputs
delta' | a | b | c
------------+--------------+--------------+--------------
qx or {q0,q1,q2} | {{q0,q1,q2}} | {{q1,q2}} |
------------+--------------+--------------+--------------
qy or {q1,q2} | | |
------------+--------------+--------------+--------------
qz or {q2} | | |
------------+--------------+--------------+--------------

Now, because our new qx state has a symbol q2 in its name and
delta(q2,c)=q2 is in the old machine, the new name for the old q2,
which is qz or {q2} is put into the input c transition in row 1.
inputs

delta' | a | b | c
------------+--------------+--------------+--------------
qx or {q0,q1,q2} | {{q0,q1,q2}} | {{q1,q2}} | {{q2}} or qz
------------+--------------+--------------+--------------
qy or {q1,q2} | | |
------------+--------------+--------------+--------------
qz or {q2} | | |
------------+--------------+--------------+--------------

Now, move on to row two. You are considering all transitions in the
old machine, delta, for all old machine state symbols in the name of
the new machines states.Fine the old machine state that results from
an input and translate the old machine state to the corresponding new
machine state name and put the new machine state name in the set in
delta'. Below are the "long new state names" and the renamed state
names in delta'.

inputs

delta' | a | b | c
------------+--------------+--------------+--------------
qx or {q0,q1,q2} | {{q0,q1,q2}} | {{q1,q2}} | {{q2}} or {qz}
------------+--------------+--------------+--------------
qy or {q1,q2} | phi | {{q1,q2}} | {{q2}} or {qz}
------------+--------------+--------------+--------------
qz or {q2} | phi | phi | {{q2}} or {qz}
------------+--------------+--------------+--------------

inputs
delta' | a | b | c <-- input alphabet sigma
---+------+------+-----
/ qx | {qx} | {qy} | {qz}
/ ---+------+------+-----
Q' qy | phi | {qy} | {qz}
\ ---+------+------+-----
\ qz | phi | phi | {qz}
---+------+------+-----
The figure above labeled NFA shows this state transition table.It seems
rather trivial to add the column for epsilon transitions,but we will make
good use of this in converting regular expressions to machines.
regular-expression -> NFA-epsilon -> NFA -> DFA.

## Finite State Machines with Output (Mealy and Moore Machines)

Introduction :
If a combinational logic circuit is an implementation of a Boolean
function, then a sequential logic circuit can be considered an
implementation of a finite state machine. There is a little more to it
than that (because a sequential logic circuit can contain combinational
logic circuits).If you take a course in programming languages, you will
also learn about finite state machines. Usually, you will call it a DFA
(deterministic finite automata).While finite state machines with outputs
are essentially DFAs, the purpose behind them is different.

## DFAs are used to recognize a language, L. A language is a set of

strings made from characters in the input alphabet. If a language can
be recognized by a DFA, it is said to have a regular grammar. There
are some languages that can't be recognized by a DFA (for example,
palindromes). Thus, a DFA, while reasonably powerful, there are other
(mathematical) machines that are more powerful.Often, tokens in
programming languages can be described using a regular grammar.

## A finite state machine with output is similar to describe formally.Q, a

set of states, S, an single state which is an element of Q. This is the
start state.Sigma, the input alphabet,Pi, the output alphabet,delta, a
transition function that maps a state and a letter from the input
alphabet, to a state and a letter from the output alphabet.The primary
difference is that there is no set of final states, and that the transition
function not only puts you in a new state, but also generates an output
symbol.The goal of this kind of FSM is not accepting or rejecting
strings, but generating a set of outputs given a set of inputs. Recall
that a black box takes in inputs, processes, and generates outputs.
FSMs are one way of describing how the inputs are being processed,
based on the inputs and state, to generate outputs. Thus, we're very
interested in what output is generated.In DFAs, we don't care what
output is generated. We care only whether a string has been accepted
by the DFA or not.Since we're talking about circuits, the input alphabet
is going to be the set of k bit bitstrings, while the output alphabet is
the set of m bit bitstrings.
An Example
Let's look at an example of an FSM.

Each of the circle is a state. For now, all you need to know is that, at
any given moment, you are in one state. Think of this as a game,
where there are circles drawn on the ground, and at any moment, you
are standing in exactly one circle.Each of the circle is given a unique
binary number. The number of bits used depends on the total number
of states. If there are N states, then you need ceil( lg N ) bits (the
ceiling of log base 2 of N). The states are labelled with the letter q, plus
subscripts. In this example, it's q1q0.You may have k input bits. The
input bits tell you which state to transition to. For example, if you have
2 input bits (x1x0), then there are four possible out going edges (x1x0 =
00, x1x0 = 01, x1x0 = 10, and x1x0 = 11). In general, there are 2k
outgoing edges for k bits of input.

Thus, the number of edges depends on the number of bits used in the
input.
Tracing an Example
You might be asked, what are the sequence of states and outputs,
assuming you start in state 00, and have input (1, 1, 0, 0, 1).
00 0 1 0 0
State 10
(Start) 1 0 1 1
Input 1 1 0 0 1

So, you may start in state 00, reading input 1 (see column 1 of the
table), which puts you in state 01. At that point, you read in input 1
(see column 2), and go into state 10 (column 3), etc.

Moore machines

## A Moore machine may be defined by a similar six-tuple, with the only

difference that symbols are output after the transition to a new state is
completed, and the output symbol depends only on the state just

## reached, that is, .The class of translations that may be

performed by Mealy machines and the class of translations that may
be performed by Moore machines are identical. Indeed, given a Mealy
machine, it is straightforward to construct the equivalent Moore
machine and vice versa.The goal of FSMs is to describe a circuit with
inputs and outputs. So far, we have inputs, that tell us which state we
should go to, given some initial, start state. However, the machine
generates no outputs.We modify the FSM shown above, by adding
outputs. Moore machines add outputs to each state. Thus, each state is
associated with an output. When you transition into the state, the
output corresponding to the state is produced. The information in the
state is typically written as 01/1. 01 indicates the state, while 1
indicates the output. 01/1 is short hand for q1q0 = 01/z = 1.The
number of bits in the output is arbitary, and depends on whatever your
application needs. Thus, the number of bits may be less than, equal, or
greater than the number of bits used to represent the state.Let's look
at an example of a Moore machine.
In this example, you see two bits for the state and two bits for the
output. Thus, when you see 00/01 inside one of the circles, it is
shorthand for q1q0 = 00 / z1 z0 = 01.

Moore Machines
A Moore machine is like a finite automaton except for the following
differences. In a Moore machine there are two alphabets: an input
alphabet and an output alphabet. The two alphabets may be the same
but they do not have to be. Another difference is that there are no
accept states in a Moore machine. Its purpose is not to answer yes or
no, not to accept or reject a string. It is not a language recognizer, it is
an output producer. Each state of a Moore machine produces a one-
character output immediately upon the machine's entry into that state.
At the beginning, the start state produces an output before any input
has been read. Thus the output of a Moore machine is one character
longer than its input. Formally a Moore machine can be defined as
follows:

## Def: A Moore M/c is a six tuple(Q, Σ, Δ,δ,λ,q0) where

(i) Q is afinite set of states
(ii) Σ is the input alphabet;
(iii) Δ is the output alphabet;
(iv) δ is the transition function Σ х Q into Q;
(v) λ is the output function mapping Q into Δ and
(vi) q0 is the initial state

We draw Moore machines in the same way as finite automata but the
label in a state is composed both of the name of the state and the
output character that the state produces. Run the string abab through
the following machine and you will find that the output produced is
10010.

Transition Table:

## Prese Next Output

nt State
State λ
a
b
-> q0 q 1 1
q3
q1 q3 q 0
1
q 2 q0 q 0
3
The following Moore machine might be q3 q3 q 1
considered a "counting" machine. The 2
output produced by the machine contains a 1 for each occurrence of
the substring aab found in the input string.

Mealy Machines
A Mealy machine produces output on a transition instead of on entry
into a state. Transitions are labeled i/o where i is a character in the
input alphabet and o is a character in the output alphabet. Mealy
machine are complete in the sense that there is a transition for each
character in the input alphabet leaving every state. There are no
accept states in a Mealy machine because it is not a language
recognizer, it is an output producer. Its output will be the same length
as its input. Formally it can be defined as follows:
Def: A Mealy M/c is a six tuple(Q, Σ, Δ,δ,λ,q0) where
(vii) Q is afinite set of states
(viii) Σ is the input alphabet;
(ix) Δ is the output alphabet;
(x) δ is the transition function Σ х Q into Q;
(xi) λ is the output function mapping Σ х Q into Δ and
(xii) q0 is the initial state.
Example:

The following Mealy machine takes the one's complement of its binary
input. In other words, it flips each digit from a 0 to a 1 or from a 1 to a
0.

## The only rather disconcerting characteristic of the machine is that we

must feed the input number backwards and the machine produces its
output backwards. It also does not work correctly if the input string
consists completely of 1's. In that case the answer always comes out 0.
Although Moore and Mealy machines do not accept or reject their input
strings, they do yield information about their input through the output
that they produce. Here is a Mealy machine to count the number of
occurrences of aa or bb. It produces a 1 each time it finds that it has

## just seen a double letter.

When we talk about equivalence of two Moore machines or two Mealy machines we
mean that, given the same input, they produce the same output. Since a Moore machine
outputs the symbol associated with its start state before it begins processing its input, its
output is always one longer than its input. The output of a Mealy machine is always the
same length as its input. Therefore a Moore machine cannot be equivalent to a Mealy
machine in the above sense. We say that a Moore machine is equivalent to a Mealy
machine if, given the same input, the output of the Moore machine after removing the
first character is the same as the output of the Mealy machine.Using this definition of
equivalence, our text proves that for every Moore machine there is an equivalent Mealy
machine and vice versa. It does this with two constructive algorithms: one for converting
a Moore machine to a Mealy machine and one for going the other direction.
Equivalence of Mealy and Moore machines :

We have two ways to describe a FSM: Mealy and Moore machines. Are
the two machines equivalent?Initially, you might think not. A Mealy
machine can have its output depend on both input and state. Thus, if
we ignore the state, we should be able to convert a Moore machine to
a Mealy machine.It's not so easy to see that you can convert an
arbitrary Mealy machine to a Moore machine.It turns out that the two
machines are equivalent. What does that mean? It means that given a
Moore machine, you can create a Mealy machine, such that if both
machines are fed the same sequence of inputs, they will both produce
the same sequence of outputs. You can also convert from a Mealy
machine to its equivalent Moore machine, and again generate the
same outputs given the same sequence of inputs.Actually, to be
precise we must ignore one fact about Moore machines. Moore
machines generate output even if no input has been read in. So,if you
ignore this initial output of the Moore machine, you can convert
between one machine and the other.The actual algorithm is beyond
the scope of the course. However, the basic idea of converting a Mealy
machine to a Moore machine is to increase the number of states.
Roughly speaking, if you have a Mealy machine with N states, and
there are k bits of input, you may need up to 2kN states in the
equivalent Moore machine.Effectively, the new states record
information about how that state was reached.

Summary:

## Finite state machines are one way of describing the behavior of a

circuit with state. Think of it as a very crude programming language,
which takes inputs, and uses those inputs and the state to compute
outputs, and also to determine what state to transition into.CPUs use
finite state machines as control units to sychronize the fetch, execute,
decode cycle. These machines can be rather sophisticated, however,
programs exists to convert the finite state machine into actual flip flops
and logic gates.

Minimizing dfa :

If a dfa is specified by its table (or graph), it may not be in its most
useful form. In particular, if it has been obtained 'mechanically' (e.g. by
the subset construction, or from a regular expression), chances are
that it has useless states.We have not proven that there is a unique
automaton with a minimal number of states (this will be a
consequence of the Nerode-Myhill characterization), but we will
present ways to reduce unnecessary states.There are several reasons
why states are redundant:

1. Unreachablestates
states p such that there is no string x with deltaHat(q0, x)=p
2. States from which an accepting states are unreachable
states p such that there is no string x with deltaHat(p, x) in F.
3. Duplicates.
The last category is the only interesting one, since we can eliminate
the useless states in the first two categories by standard graph
algorithms (use depth first search to find all states accessible from
q0, for all these use depth first search to eliminate the second
category.)

## Lemma Given automata M1 and M2, there are algorithms to decide

whether

• L(M1) is empty
• L(M1)=L(M2)
• L(M1)=SIGMA*
• L(M1) is included in L(M2)

The first is simply the graph accessibility problem: is there a path from
q0 to an accepting state, which can be solved by depth-first search.
The same algorithm, applied to the complementary automaton, solves
the third problem.

To test equality, remember that L1=L2 iff (L2-L1) and L1-L2 are both
empty, and regular languages are closed under difference.Two states
p, and q are not equivalent if there is some string x such that exactly
one of deltaHat(p,x) and deltaHat(q,x) is in F. For a state p, let
Xp={y | deltaHat(p,y) in F}
Xp is the language that M would accept if p were the initial state. The
condition above is equivalent to Xp not equal to Xq, which can be
tested using the Lemma above.

## Conversion algorithm from a NFA to a regular expression. Start with

the transition table for the NFA with the following state naming
conventions:
The first state is 1 or q1 or s1 which is the starting state.States are
numbered consecutively, 1, 2, 3, ... n.The transition table is a typical
NFA where the table entries are sets of states and phi the empty set is
allowed. The set F of final states must be known. We call the variable
r a regular expression. We can talk about rij being the regular
expression with i,j subscripts ij. Note r12 is just a (possibly) different
regular expression from r53 where 1,2 & 5,3 are subscripts. Because
we need multiple columns in a table we are going to build, we also use
a superscript in the naming of regular expression.

1 3 k k-1
r ,r ,r , r are just names of different regular xpressions
12 64 1k ij
We are going to build a table with n 2
rows and n+1 columns labeled

## | k=0 | k=1 | k=2 | ... | k=n

----+--------+-------+-------+-----+------
| 0 | 1 | 2 | | n
r | r | r | r | ... | r Only build column n
11 | 11 | 11 | 11 | | 11 for 1,final state
----+--------+-------+-------+-----+------
| 0 | 1 | 2 | | n The final regular exp
r | r | r | r | ... | r is then the union, +, of
12 | 12 | 12 | 12 | | 12 the column n
----+--------+-------+-------+-----+------
| 0 | 1 | 2 | | n
r | r | r | r | ... | r
13 | 13 | 13 | 13 | | 13
----+--------+-------+-------+-----+------
| 0 | 1 | 2 | |
r | r | r | r | ... |
21 | 21 | 21 | 21 | |
----+--------+-------+-------+-----+------
| 0 | 1 | 2 | |
r | r | r | r | ... |
22 | 22 | 22 | 22 | |
----+--------+-------+-------+-----+------
| 0 | 1 | 2 | |
r | r | r | r | ... |
23 | 23 | 23 | 23 | |
----+--------+-------+-------+-----+------
| 0 | 1 | 2 | |
r | r | r | r | ... |
31 | 31 | 31 | 31 | |
----+--------+-------+-------+-----+------
| 0 | 1 | 2 | |
r | r | r | r | ... |
32 | 32 | 32 | 32 | |
----+--------+-------+-------+-----+------
| 0 | 1 | 2 | |
r | r | r | r | ... |
33 | 33 | 33 | 33 | |

## Note n2 rows,all pairs of numbers from 1 to n, Now, build the table

entries for the k=0 column:
/
0 / +{ x | delta(q ,x) = q } i /= j
r = / i j
ij \
\ +{ x | delta(q ,x) = q } + epsilon i = j
\ i j
where delta is the transition table function,x is some symbol from
sigma,the q's are states,
r0 could be phi, epsilon, a, 0+1, or a+b+d+epsilon.
ij
notice there are no Kleene Star or concatenation in this column.
Next, build the k=1 column:

1 0 0 * 0 0
r = r ( r ) r + r
ij i1 11 1j ij

## Next, build the k=2 column:

2 1 1 * 1 1
r = r ( r ) r + r
ij i2 22 2j ij
note: all items are from the previous column
Then, build the rest of the k=k columns:

## k k-1 k-1 * k-1 k-1

r = r (r ) r + r
ij ik kk kj ij
note: all items are from previous column
Finally, for final states p, q, r the regular expression is

n n n
r + r + r
1p 1q 1r

Note that this is from a constructive proof that every NFA has a
language for which there is a corresponding regular expression.Here I
have applied some minimization rules(identities) for regular
expressions which can be applied at every step.
Minimisation rules for Regular expressions :
1) phi is the empty set
2) epsilon is the zero length string
3) 0, 1, a, b, c, are symbols in sigma
4) x is a variable or regular expression
5) ( ... )( ... ) is concatenation
6) ( ... ) + ( ... ) is union
7) ( ... )* is the Kleene Closure = Kleene Star
8) (phi)(x) = (x)(phi) = phi
9) (epsilon)(x) = (x)(epsilon) = x
10) (phi) + (x) = (x) + (phi) = x
11) x + x = x
12) (epsilon)* = (epsilon)(epsilon) = epsilon
13) (x)* + (epsilon) = (x)* = x*
14) (x + epsilon)* = x*
15) x* (a+b) + (a+b) = x* (a+b)
16) x* y + y = x* y
17) (x + epsilon)x* = x* (x + epsilon) = x*
18) (x+epsilon)(x+epsilon)* (x+epsilon) = x*

## Now for an example:

Given M=(Q, sigma, delta, q0, F) as
delta | a | b | c Q = { q1, q2}
--------+------+------+----- sigma = { a, b, c }
q1 | {q2} | {q2} | {q1} q0 = q1
--------+------+------+----- F = { q2}
q2 | phi | phi | phi
--------+------+------+-----

## | k=0 | k=1 (using e for epsilon)

-----+-------------+------------------------------------
r | c + epsilon | (c+e)(c+e)* (c+e) + (c+e) = c*
11 | |
-----+-------------+------------------------------------
r |a+b | (c+e)(c+e)* (a+b) + (a+b) = c* (a+b)
12 | |
-----+-------------+------------------------------------
r | phi | phi (c+e)* (c+e) + phi = phi
21| |
-----+-------------+------------------------------------
r | epsilon | phi (c+e)* (a+b) + e = e
22 | |
-----+-------------+------------------------------------
| k=0 | k=1 | k=2 (using e for epsilon)
-----+-------------+----------+-------------------------
r | c + epsilon | c* |
11 | | |
-----+-------------+----------+-------------------------
r |a+b | c* (a+b) | c* (a+b)(e)* (e) + c* (a+b) only
final
12 | | | state
-----+-------------+----------+-------------------------
r | phi | phi |
21 | | |
-----+-------------+----------+-------------------------
r | epsilon |e |
22 | | |
So the final regular expression minimizes to c* (a+b)

## Converting a regular expression to a NFA - Thompson's Algorithm

We will use the rules which defined a regular expression as a basis for the construction:

## 1. The NFA representing the empty string is:

2. If the regular expression is just a character, eg. a, then the corresponding NFA is :

3. The union operator is represented by a choice of transitions from a node; thus a|b
can be represented as:

4. Concatenation simply involves connecting one NFA to the other; eg. ab is:

5. The Kleene closure must allow for taking zero or more instances of the letter from
the input; thus a* looks like:

DFA minimisation :

## Since we are interested in translating a DFA into a program, we will

want to ensure that this program is as efficient as possible. In
automata terms, one aspect of this will be to ensure that the
constructed DFA has as few states as possible. This is achieved by an
algorithm known as DFA minimisation. We take the ``optimistic''
approach: we start by assuming that all states are actually the same,
and only distinguish those which we can prove are different. As for
subset construction, the states of the minimised DFA will be sets of
states from the original DFA.Two states are different if:

one is a final state and the other isn't, or the transition function maps
them to different states, based on the same input character .We base
our algorithm on partitioning the states using this criterion.
1. Initially start with two sets of states: the final, and the non-final
states.
2. For each state-set created by the previous iteration, examine the
transitions for each state and each input symbol. If they go to a
different state-set for any two states, then these should be put
into different state-sets for the next iteration.