Uploaded by mstoma11

01 Lecture On Regular Languages

advertisement
CSE 3108: Theory of Computation and
Automata
Marjia Sultana
Lecturer
Department of Computer Science and
Engineering
Begum Rokeya University, Rangpur
Schedule
• Started from 09.05.2023
- Class Time
NB: Schedule may subject to change
Grading Policy
In-course/Quizzes/Class Tests= 10%
Class Attendance= 5%
Assignment and Presentation/Class
Performance=10%
Mid-term=25%
Final Examination=50%
Total=100 %
Books Recommended
1. Introduction to the Theory of Computation
By Michael Sipser
2. Theory of Computation By Vivek Kulkarni
Chapter 01: Regular Languages
Part A: Topics
o
o
o
o
Finite Automaton
Markov Chain
Elements Of A Finite Automaton
States
- Start State
- Accept State
o Transitions
o Procedure Of A Finite Automaton
Finite Automaton
A finite-state machine (FSM) or finite-state
automaton (plural: automata), or simply a state
machine, is a mathematical model of
computation used to design both computer
programs and sequential logic circuits.
“Read once”, “no write” procedure.
Typical is its limited memory.
E.g., automatic door, elevator etc.
Example: The Controller For An
Automatic Door
An automatic door has two pads:
1. Front Pad:
- To detect the presence of a
person about to walk through
the doorway.
2. Rear Pad:
- So that the controller can
hold the door open long
enough for the person to pass
all the way through and also so
that the door does not strike
someone standing behind it as
it opens.
Example: The Controller For An
Automatic Door(Cont.)
 The controller is in either of
two states:
- OPEN
- CLOSED
Representing the corresponding
condition of the door.
 There are four possible input
conditions:
1. FRONT
2. REAR
3. BOTH
4. NEITHER
Example: The Controller For An Automatic
Door(Cont.)
 The controller moves from state to state, depending on the input it receives.
 When in the CLOSED state and receiving input NEITHER or REAR, it remains in the CLOSED state.
In addition, if the input BOTH is received, it stays CLOSED because opening the door risks
knocking someone over on the rear pad.
But if the input FRONT arrives, it moves to the OPEN state.
 In the OPEN state, if input FRONT, REAR, or BOTH is received, it remains in OPEN.
If input NEITHER arrives, it returns to CLOSED.
Markov Chain
A finite state machine can be used as a
representation of a Markov chain.
Finite automata and their probabilistic
counterparts, Markov chains, are useful
tools for pattern recognition. This device
are used in speech processing and in optical
character recognition.
Markov chains have been used to model
and predict price changes in financial
applications.
Elements Of A Finite Automaton
 A finite automaton has:
- Finite set of states
- Transitions
 A finite automaton
- receives an input string
- processes that string
- produces an output
 The input must be Boolean in nature, i.e., have binary
values 0 or 1.
 The output is either accept or reject
States And Transitions
 The machine is in only one state at a time; the state it is in
at any given time is called the current state.
 Start (or Initial) State:
- usually shown drawn with an arrow "pointing at it
from any where" .
 Accept (or Final) States:
- those at which the machine reports that the input
string is a member of the language it accepts.
- It is usually represented by a double circle.
 Current state can change from one state to another when
initiated by a triggering event or condition; this is called
a transition.
A Simple Automaton
Figure 4: A finite automaton called M1 that has three
states
Procedure Of A Finite Automaton
 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.
Procedure Of A Finite Automaton: Example
 When a finite automaton receives
the input string 1101 to the
machine M1, 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 q1 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.
Procedure Of A Finite Automaton: Example (Cont.)
 M1 accepts any string that ends
with a 1,as it goes to its accept
state q2 whenever it reads the
symbol 1 (e.g., 1, 01, 11,
0101010101).
 In addition, it accepts any
strings that ends with an even
number of 0s following the last
1 (e.g., 100, 0100, 110000, and
0101000000).
 It rejects other strings, such as
0, 10, 101000.
Classification of Finite Automata (FA)
FA
FA without Output
FA with Output
Moore Machine
Mealy Machine
DFA
NFA
-NFA
PART B: TOPICS
 Formal Definition Of A Finite Automaton
 Transition Function
 Different Examples Of Finite Automata
 Formal Definition Of Computation
 Definition Of Regular Language
 Example Of Regular Language Using Formal
Definition Of Computation
Formal Definition of Finite
Automata
We need formal definition, for two specific reasons:
First, a formal definition is precise.
Second, a formal language provides notation.
Definition
A finite automaton is a 5-tuple (Q, ∑, δ, q0, F) where:
1. Q is a finite set called the states
2. ∑ is a finite set called the alphabet
3. δ : Q × ∑ → Q is the transition function which
defines the rules for moving.
4. q0 ∈ Q is the start state also called initial state
5. F ⊆ Q is the set of accept states, also called the final
states.
A Sample Automaton
Fig: The state diagram for finite automaton M1.
We can describe M1 formally by writing :
M1=(Q,∑,δ,q, F) where
1.Q={q1, q2, q3}
2.∑={0,1}
A Sample Automaton(Cont.)
3. δ is described as
Fig.:
4. q1 Transition
is the start state and
Table
5.F={q2}
Different Examples of Finite
Automata
Examples of Finite Automata(cont.)
Here, Q={s, q1, q2, r1, r2}, ∑= {a, b},q0=s,
F={q1, r1}
Let, abb and bab be two strings.
M4 accepts all strings that start and end with a or that start and
end with b. In other words,M4 accepts strings that start and end
with the same symbol.
Formal Definition of Computation
Let M = (Q, ∑, δ, q0, F) be a finite automaton and
w = w1 w2. . . . . . wn an be a string over ∑ .
Then M accepts w if a sequence of states r0 , r1, . . . , rn in Q exists
With three conditions:
1. r 0 = q0
2. (ri, wi+1) = ri+1 for i = 0, 1, . . . , n − 1
3. rn ∈ F
 Condition (1) says the machine starts at the start state.
 Condition (2) says that the machine goes from state to state
according to its transition function .
 Condition (3) says the machine accepts its input if it ends up in
an accept state.
Definition Of Regular Language
 Regular Language:
A language is called regular
language if some finite automaton recognizes it.
An Example for Computation
Let w be the string
10(RESET)22(RESET)012
Then M5 accepts w according to the
formal definition of computation
because the sequence of states it
enters when computing on w is:
q0, q1, q1, q0, q2, q1, q0, q0, q1, q0
Which satisfies the three conditions.
L(M5)={w | the sum of symbols in w
is 0 modulo 3,except that(RESET)
resets the count to 0}
As M5 recognizes this language, it is
a regular language.
PART C: Topics
Designing Finite Automata
Regular Operations
Designing Finite Automata
EXAMPLE 1
Suppose that the alphabet is{0,1} and
that the language consists of all strings
with an odd number of 1s.we want to
construct a finite automaton E1 to
recognize this language.
Designing Finite Automata(cont.)
At first assign two states qeven
and qodd .
Designing Finite Automata(cont.)
 Next , assign the transitions.
 At first, see how to go
from one possibility to
another upon reading a
symbol.
 If state qeven represents
the even possibility and
state qodd represents the
odd possibility,we would
set the transitions to flip
state on a 1 and stay put
on a 0
Designing Finite Automata(cont.)
Set the start state to be
the state corresponding to
the possibility associated
with having seen 0 symbols
so far(the empty string E).
Here the start state
corresponds to state qeven
because 0 is an even
number.
Designing Finite Automata(cont.)
Lastly set the accept
states to be those
corresponding to
possibilities where we
want to accept the
input string .
Set qodd to be an
accept state because
we want to accept
when we have seen
an odd number of 1s.
Designing Finite Automata(cont.)
EXAMPLE 2
Design a finite automaton to
recognize the regular language of all
strings that contain the string 001 as
a substring.
Designing Finite Automata(cont.)
Assign the states q , q0 , q00 and qoo1.
We can assign the transitions by observing that from q reading a 1 we
stay in q, but reading a 0 we move to q0.
In q0 reading a 1 we return to q , but reading 0 we move to q00.
In q00 , reading a 1 we move to q001,but reading a 0 leaves we in q00.
Finally, in q001 reading a 0 or a 1 leaves we in q001.
Here the star state is q, and the only accept state is q001.
THE REGULAR OPERATIONS
 Regular Operations give us a
systematic way of constructing
languages that are apriority
regular.
 That is : No verification is
required
DEFINITION OF REGULAR
OPERATIONS
Let A and B be regular languages.we define
operations union,concatenation and star as
follows.
Union:
AUB={x|x E A or x E B}.
CONCATENATION :
A o B ={xy|x E A and y E B}
STAR:
A*={x1,x2….xk|k≥0 and each xi E A}
FUNCTIONS OF THE REGULAR
OPERATIONS
 UNION:It simply takes all the strings in both A and B and
lumps them together into one language.
 CONCATENATION:It attaches a string from A in front of a
string from B in all possible ways to get the strings in the
new languages.
 STAR:
 It is also called a unary operation, because it applies to a
single language.
 It works by attaching any number of strings in A together
to get a string in the new language.Because “any
number”includes 0 as a possibility, the empty string E is
always a member of A*,no matter what A is.
EXAMPLE OF REGULAR
OPERATIONS
Let the alphabet ∑ be the standard 26
letters{a,b….,z}.If A={good,bad} and
B={boy,girl},then
 A U B={good,bad,boy,girl}
 A o B={goodboy,goodgirl,badboy,badgirl}
A*={E,good,bad,goodgood,goodbad,ba
dgood,badbad,goodgoodgood,goodgood
bad,goodbadgood,goodbadbad,..}
Part D:Topics
. Nondeterminism
. Difference between deterministic and non
deterministic finite automation
.Formal definition of a non deterministic finite
automation
Nondeterminism:
• When a machine is in a given state and reads
the next input symbol, we know what the next
state will be – it is called deterministic
computation. In nondeterministic machine,
several choices may exist for the next state at
any point.
Difference between deterministic and non
deterministic finite automation
• In deterministic finite automation,
abbreviated DFA, every state has exactly one
exiting transition arrow for each symbol in the
alphabet.
• In nondeterministic finite automation,
abbreviated NFA, a state may have zero, one,
or many exiting arrows for each alphabet
symbol. In DFA, labels on the transition arrows
are symbols from the alphabet.
Difference between deterministic and non
deterministic finite automation (Cont.)
• This NFA has an arrow with the label ∑.In
general, an NFA may have arrows labeled with
members of the alphabet or ∑.
• Zero, one or many arrows may exit from each
state with the label ∑.
Difference between deterministic and non
deterministic finite automation (Cont.)
The computation of N1 on input 010110:
Formal definition of a non
deterministic finite automation:
• The formal definition of a nondeterministic finite
automation is similar to that of a deterministic
finite automaton. They both have states, an input
alphabet, a transition function, a start state, and
a collection of accept states. But differ in the
type of transition function. In order to write the
formal definition, we need to set up some
additional notation.
Definition:
• A nondeterministic finite automation is a 5- tuple
(Q,∑,δ,q0,F),where
1.Q is a finite set of states,
2.∑ is a finite alphabet,
3.: Q×∑→P(Q) is the transition function,
4.q0 ∈ Q is the start state, and
5.F ⊆ Q is the set of accept state.
• Here,P(Q) is called the power set of Q.
Example
Recall the NFA N1:
The formal description of N1 is
(Q,∑,δ,q1,F), where
1.Q={q1,q2,q3,q4}
2.∑={0,1}
Example (Cont.)
3. δ is given as
q1
q2
q3
q4
4.q1 is the start state, and
5.F={q4}.
0
{q1}
{q3}
{}
{q4}
1
{q1,q2}
{}
{q4}
{q4}
ɛ
{}
{q3}
{}
{}
Formal Definition Of Computation
For An DFA
• Let,N={Q,∑,,q0,F} be an NFA and w a string
over the alphabet .Then we say that N accepts
w if we can write w as w=y1y2……ym, where
each yi is the member of ∑ and a sequence of
states r0,r1,…….rm exists in Q with three
conditions:
Formal Definition Of Computation For An
DFA (Cont.)
1. r0=q0,
2.ri+1 ∈ (ri, yi+1), for 0,…….m-1, and
3.rm ∈ F
• Condition 1 says that the machine starts out in the
start state.
• Condition 2 says that state ri+1 is one of the
allowable next states when N is in state ri and
reading yi+1.
• Finally condition 3 says that the machine accepts its
input if the last state is an accept state.
DFA Example
Conversion of NFA to DFA
 Every DFA is an NFA but not vice versa
 But There is an equivalent DFA for every NFA
Conversion of NFA to DFA (Example-1)
L={ set of all strings over (o,1) that starts with
‘0’}
Design NFA for L
Conversion of NFA to DFA (Example-1)
NFA
Conversion of NFA to DFA (Example-1)
Conversion of NFA to DFA (Example-2)
Design an NFA for a language that accepts all
strings over {0,1} in which the second last
symbol is always 1. Then convert it to its
equivalent DFA.
Conversion of NFA to DFA (Example-2)
Conversion of NFA to DFA (Example-2)
Conversion of NFA to DFA (Example-3)
Find the equivalent DFA for the NFA given by
M=[{A,B,C}, (a,b), δ, A, {C}] where δ1 is given
by
Input symbol
State
a
b
A
A,B
C
B
A
B
C(accept)

A,B
*Draw NFA from transition table δ1
Conversion of NFA to DFA (Example-3)
Now δ2 is for DFA:
Input symbol
State
a
b
A
{A,B}
{C}
B
{A}
{B}
C [accept]

{A,B}
{A,B}
{A,B}
{B,C}
{B,C} [accept]
{A}
{A,B}
*Draw NFA from transition table δ2
Minimization of DFA
Minimization of DFA is required to obtain the minimal
version of any DFA which consists of the minimum number
of states possible.
Equivalent: Two states A and B are said to be equivalent if
1. δ (A,X)F and δ (B,X)F
2. δ (A,X) F and δ (B,X)  F
Here, X is any input string
Minimization of DFA (Cont..)
If |x|=0, then A and B are said to be 0 equivalent
If |x|=1, then A and B are said to be 1 equivalent
If |x|=2, then A and B are said to be 2 equivalent
…….
If |x|=n, then A and B are said to be n equivalent
*|x| denotes the length of input
Minimization of DFA (Example-1)
0 Equivalence : {A, B, C, D} {E}
1 Equivalence: {A,B,C} {D} {E}
2 Equivalence: {A,C} {B} {D} {E}
3 Equivalence: {A,C} {B} {D} {E}
Minimization of DFA (Example-1)
The states in the new minimal DFA: {A,C} {B} {D} {E}{E}
0
1
A(start)
B
C
B
B
D
C
B
0
1
{A,C}
(start)
B
{A,C}
B
B
D
D
B
E
E(accept)
B
{A,C}
C
D
B
E
E(accept)
B
C
Minimization of DFA (Example-1)
Minimization of DFA (Example-2)
Exercise: Draw a DFA with minimum states for
the following transition table
0
1
q0 (start)
q1
q5
q1
q6
q2
q2 (accept)
q0
q2
q3
q2
q6
q4
q7
q5
q5
q2
q6
q6
q6
q4
q7
q6
q2
Minimization of DFA (Example-2)
Exercise: Solution
0 Equivalence : {q0, q1, q3, q4, q5, q6, q7} {q2}
1 Equivalence: {q0, q4,q6} {q1,q7} {q3, q5} {q2}
2 Equivalence: {q0,q4} {q6} {q1,q7} {q3,q5} {q2}
3 Equivalence: {q0,q4} {q6} {q1,q7} {q3,q5} {q2}
Minimization of DFA (Example-2)
Exercise: Solution
 for a DFA
 for a DFA with minimum states
0
1
q0 (start)
q1
q5
q1
q6
0
1
{q1, q7}
{q3,q5}
q2
{q0 ,q4}
(start)
q2 (accept) q0
q2
{q6}
{q6}
{q0,q4}
q3
q2
q6
q4
q7
q5
{q1, q7}
{q6}
{q2}
q5
q2
q6
{q3,q5}
{q2}
{q6}
q6
q6
q4
{q0, q4}
{q2}
q7
q6
q2
{q2}
(accept)
Part E: Topics
1.Theorem 1
2.Regular Expression
3.Formal definition of regular expression
4.Conversion of (ab U a)* to NFA in a
sequence of stages.
Theorem 1
The class of regular language is closed
under union operation.
Proof Idea:
• Let we have regular language A1
and A2. We have to proof A1UA2 is
regular. Two NFAs is N1 and N2 for
A1 and A2 and combine them into
one new NFA N.
• Machine N must accept its input if
either N1 or N2 accept it. The new
machine has a new start state that
branches to the start states of the
old machine with ε arrows.
Theorem 1(cont…)
• Figure shows that on
the left we indicate
the start and accept
state of machine N1
and N2 with large
circles and some
additional states with
small circles. On the
right, we show how to
combine N1 and N2
into by adding
additional transition
arrows.
Theorem 1(cont…)
Proof:
• Let N1=(Q1, ∑, δ1,q1,F1) recognizes A1 and
•
N2=(Q2,∑,δ2,q2,F2) recognizes A2.
• Construction N=(Q,∑, δ,q0,F) to recognizes A1U A2.
• 1.Q={q0} UQ1UQ2
• The states of N are all the states of N1 and N2 with the addition of new
start states q0.
2.The start state q0 is the start state of N.
3.The accept states F=F1UF2.
4.Define so that for any qϵQ and any a ϵ ∑,
δ1(q,a)
q ϵ Q1
δ(q,a) =
δ2(q,a)
q ϵ Q2
{q1,q2}
q=q0 and a= €
Φ
q=q0 and a≠ €
Regular Expression
Regular Expression: Regular expression are used
for representing certain sets of strings in an
algebraic fashion.
Regular Expression
• In arithmetic, we can use the operation + and * to
build up expression such as
(5+3)*4
• Similarly, we can use the regular operation such as
union, concatenation and star to build up expression
describing languages, which are called regular
expressions. An example is,
(0 U 1)0*
• The value of the arithmetic expression is 32.The value
of a regular expression is a language.
Regular expression(cont…)
• In this case the value is the language consisting of
all string starting with 0 or 1 followed by any
number of 0s. We get this result by dissecting the
expression into its parts. First, the symbols 0
and 1 are shorthand for the sets {0} and {1}. So
(0U1) means ({0}U{1}). The value of this part is
the language {0,1}. The part 0* means {0}* and its
value is the language consisting of all string
containing any number of 0s. Second, like the *
symbol in algebra, the concatenation symbol
is implicit in regular expressions.
Regular Expression(cont…)
• Thus (0U1)0* actually is shorthand for
(0U1)o0*.The concatenation attaches the
two parts of string to obtain the value of the
entire expression.
Formal definition of regular
expression:
Say that R is a regular expression if R is
1.a for some a in the alphabet ,
2.ε,
3.Φ,
4.(R1UR2), where R1 and R2 are regular expression,
5.(R1oR2), where R1 and R2 are regular expression,
6.(R1*), where R1 is regular expression.
Cont…
• In item 1 and 2,the regular expression a and
represents the language {0} and
{},respectively. In item 3, the regular
expression represents the empty language. In
item 4,5 and 6 the expressions represents the
languages obtained by taking the union and
concatenation of the languages R1 and R2 or
the star of the languages R1 ,respectively.
Convert the regular expression (abUa)* to
an NFA in a sequence of stages:
regular expression (abUa)*
• (aba)*
• =(ab,a)*
• ={abab,aa,aba,abaa,ababa,aaa,abab……}
Exercises
.
Part F
:
Topics
 Generalized nondeterministic finite
automata (GNFA)
 Formal definition of GNFA
 Conversion between DFA to GNFA
 Conversion of GNFA to regular
expression.
.
Generalized Nondeterministic Finite Automata (GNFA)
Generalized nondeterministic finite automata are simply
nondeterministic finite automata wherein the transition arrows
may have any regular expressions as labels, instead of only
members of alphabet or ε.
The GNFA reads blocks of symbols from the input, not necessarily just
one symbol at a time as in an ordinary NFA
GNFA cont’d
•
•
A GNFA is nondeterministic and so may have several different
ways to process the same input string .
It accepts its input if its processing can cause the GNFA to be in an
accept state at the end of the input.
Condition on GNFAs
We will require that GNFAs always have a special form that meets the
following conditions.
 The start state has transition arrows going to every other state
but no arrows coming in from other state.
 There is only a single accept state and it has arrows coming in
from every other state but no arrows going to any other state.
Furthermore ,the accept state is not the same as the start.
 Except for the start and accept states, one arrow goes from
every state to every other state and also from each state to
itself.
GNFA cont’d
Example of GNFA,
Formal definition of GNFA cont’d
A generalized nondeterministic finite automata is a 5-tuple
(Q , Σ , δ ,qstart ,qaccept)
Where,
1. Q is the finite set of states.
2. Σ is the input alphabet.
3. δ : (Q – { qaccept }) X (Q – { q start })
transition function.
4. qaccept is the accept state .
5. q start is the start state.
R ,is the
Formal definition of GNFA:
A GNFA accepts for the transition function which has the form
δ : (Q – { qaccept }) X (Q – { q start })
R
R is the collection of all regular expression over the alphabet
Σ.
The domain of the transition function is ,
(Q – { qaccept }) X (Q – { q start
})
Because an arrow connects every other state to every other
state ,except that no arrow coming form to qaccept and going to
qstart
DFA to GNFA conversion
We can easily convert a DFA into a GNFA in the special form .
 We simply add a new start state with an ε arrow to the old start state
and a new accept state with ε arrows from the old accept states .
 If any arrows have multiple labels we replace each with a single
arrow whose label is the union of the previous labels.
 Finally, we add arrows labelled Ø (empty language) between states
that had no arrows .
 This last step won't change the language recognized because a
transition labelled with Ø can never be used
Converting GNFA to regular expression:
Now we show how to convert a GNFA into a regular expression.
 Say that the GNFA has k states.
 Then, because a GNFA must have a start state and an accept
state and they must be different from each other, so we can say
k ≥ 2.
 If k > 2 ,we construct as equivalent GNFA with k – 1 states.
 This step can be repeated on the new GNFA until it is reduced
to two states.
 If k == 2, the GNFA has a single arrow that goes from the start
state to the accept state. The label of this arrow is the
equivalent regular expression.
Converting GNFA to regular expression:
For example, the stages in converting a DFA with three states to an
equivalent regular expression are shown in the following figure
Fig: typical stages in converting a DFA to a regular expression.
Converting GNFA to regular expression
Let ,M be the DFA for language A ,the we convert it into GNFA ,
by
G
Adding a new start state and a new accept state
Adding transition arrows as necessary.
We will use a procedure CONVERT(G), which takes a GNFA and
returns an equivalent regular expression .It uses recursion.
Reducing states
After removing qrip we repair the machine by altering the regular expressions
labeled in transition arrows.
The new label going to form a state qi to qj is a regular expression that describes
all string that would take the machine from qi to qj either directly or via qrip
This is done with respect to any two edges going in and out of qr. It results in
getting rid of qr, thus reducing number of states by one.
Converting GNFA to regular expression:
CONVERT(G):
 Let k be the number of states of G.
 If k = 2 ,then G must consist of a start , an accept state and a single arrow between
them. Labeled with regular expression R , return the expression R.
 If K > 2 ,we select any state qrip ϵ Q different from qstart and qaccept and let G’ be the
GNFA (Q’ , Σ , δ’ ,qstart ,qaccept) where,
Q’ = Q – {qrip },
for any qi ϵ Q – {qaccept }
and any qj ϵ Q – {qstart} let
δ’ (qi ,qj) = (R1)(R2)*(R3)U(R4)
for R1 = δ(qi , qrip ), R2= δ(qrip , qrip ) , R3= δ (qrip , qj)
, R4 = δ (qi ,qj)
 Compute CONVERT(G’) and return this value.
PART G : TOPICS
 Example Of Conversion Of DFA To An Equivalent
Regular Expression
 The Pumping Lemma
 Example Of Pumping Lemma Application
Some Common Conversion
Example of Converting a two-state DFA
to an equivalent regular expression
 We begin with the two-state DFA in Fig(a)
a
1
b
2
Fig(a)
a,b
Example of Converting a two-state DFA to
an equivalent regular expression (Cont.)
 In fig(b),we make a four-state GNFA by adding a new start
state and a new accept state, called s and a respectively.
 We replace the label a , b on the self-loop at state 2 on the
DFA with the label aᴜb at the corresponding point on the
GNFA.
1
a
ε
s
a
1
b
2
b
a
a,b
Fig(b)
ε
2
aᴜb
Example of Converting a two-state DFA to
an equivalent regular expression (Cont.)
 In Fig(c), we remove state 2, and update the remaining
arrow labels.
 In this case, the only label that changes is the one from
1 to a.
 In part (b), it was Ø, but in part (c) it is b(aᴜb)*
a
s
a
s
1
ε
b
a
ε
2
ε
b(aᴜb)*
a
aᴜb
Fig (c)
1
Example of Converting a two-state DFA to
an equivalent regular expression (Cont.)
 In Fig(d), we remove state 1 from part (c) and follow
the same procedure
ε
s
a
s
1
b(aᴜb)*
a* b(aᴜb)*
a
a
Fig(d)
The Pumping Lemma
 If A is a infinite regular language
 there exists an integer number P (the pumping length)
 if any string s є A with length |s| ≥ P
 then s may be divided into three pieces, s = xyz,
satisfying the following conditions:
 for each i ≥ 0 , xyiz є A ,
 |y| > 0 , and
 |xy| ≤ P
Example of Pumping Lemma
application
Let B the language {0n1n|n ≥ 0}. We use the
pumping lemma to prove that B is not regular. The
proof is by contradiction.
• Assume that B is regular
• Suppose, p is the pumping length given by the pumping
lemma
• Choose s to be the string 0p1p. Because s is a member of B
and s has length more than p
• The pumping lemma guarantees that s can be split into
three pieces, s = xyz, where for any i ≥ 0 the string xyiz is
in B.
Example of Pumping Lemma
application (Cont.)
We consider three cases to show that B is not regular:
 The string y consists only of 0s. In this case the string xyyz has more 0s
than 1s and so it is not a member of B, violating condition 1 of the
pumping lemma. This case is a contradiction.
 The string y consists only of 1s. This case also gives a contradiction.
 The string y consists of both 0s and 1s. In this case the string xyyz may
have the same number of 0s and 1s, but they will be out of order with
some 1s before 0s. Hence it is not a member of B, which is a
contradiction.
Pumpimg Lemma
 L={anbn|n1}, n=1,2..
L={ab, aabb, aaabbb….}
We have to choose w in pumping lemma
Let p=2
|w| p
4 2
String, w= aabb
w=xyz
w=a ab b
Case 1: |xy| n
3  4 [True]
[here, xy=combine length of x,y and
n=total string length]
Pumpimg Lemma (Cont..)
Case 2: |y| 1[here, |y|=length of y]
2  1 [True]
Case 3: w=xyiz i0
w=xy2z
=a(ab) 2 b
=a abab b [*b is not the part of L]
So, L={anbn|n1} is not a regular language.
Applications of Pumping Lemma
Pumping Lemma is to be applied to show that certain
languages are not regular. It should not be used to show
a language is regular.
-If L is regular, it satisfies Pumping Lemma
-If L does not satisfy Lumping Lemma, it is not regular.
PART H : TOPICS
 Finite Automata with Output
 Moore Machine and Mealy Machine
Classification of Finite Automata
Finite Automata
FA with Output
Moore Machine
FA without Output
Mealy Machine
DFA
NFA
∈-NFA
Finite Automata with Output
Moore Machine: A Moore Machine is a machine whose output depends on
the present state only.
Formal Definition of Moore Machine:
A Moore machine is a 6-tuple (Q, ∑, ∆, δ, λ, q0) where −
1. Q: Finite set of states
2. ∑: Finite input alphabet
3. ∆: Finite output alphabet
4. δ: State transition function; δ: Q × ∑ → Q
5. λ: Machine function; λ: Q → ∆
6. q0: Initial state of the machine; q0 ∈ Q
Finite Automata with Output
Mealy Machine: A Mealy Machine is a machine whose output depends on
the present state as well as the present input.
Formal Definition of Mealy Machine:
A Mealy machine is a 6-tuple (Q, ∑, ∆, δ, λ, q0) where −
1. Q: Finite set of states
2. ∑: Finite input alphabet
3. ∆: Finite output alphabet
4. δ: State transition function; δ: Q × ∑ → Q
5. λ: Machine function; λ: Q × ∑ → ∆
6. q0: Initial state of the machine; q0 ∈ Q
Difference between Moore Machine and Mealy Machine
Moore Machine
Mealy Machine
Output depends only upon present state.
Output depends on present state as well as present input.
If input changes, output does not change.
If input changes, output also changes.
More number of states are required.
Less number of states are required.
There is more hardware requirement.
There is less hardware requirement.
Output is placed on states.
Output is placed on transitions.
Easy to design.
It is difficult to design.
Example of Moore and Mealy Machine
Moore Machine
1
0
Mealy Machine
1, b
0
A/a
1, a
0, a
B/b
A
B
1
0, b
INPUT: 1010
OUTPUT: aabab
INPUT: 1010
OUTPUT: baab
Moore to Mealy Machine Conversion
Construct a Moore Machine to find out the reminder-modulo-3 for binary number and convert it to Mealy Machine
Moore Machine
1
0
1
A/0
Mealy Machine
1
0
B/1
0
1/2
0/0
1/1
C/2
A
Value
Binary
Reminder-modulo-3
3
011
0
4
100
1
5
101
2
1/0
0/2
B
0/1
C
Applications of Moore and Mealy Machine
 Like take the example of implementation of Elevator functionality using a
state diagram.
 Each time we do a search (particularly a "pattern search") in our favorite
editor/tool, the pattern is translated into some form of finite state
machine, which does the matching.
 The lexical analysis part of our compiler/interpreter is again a finite
automaton which matches keywords and other tokens recognized by the
language.
 Any vending machine is a finite automaton which takes in coins of different
denominations and recognizes when the correct amount has been entered.
THANK YOU
Download