UNIT – 1 : FINITE AUTOMATA & REGULAR EXPRESSION
Basic Machine:
Generality: "Basic machine" is a broad and generic term used to refer to the
simplest and most fundamental models of computation. It includes various
types of abstract machines that are used to describe and study computation in
a foundational way.
Types: Basic machines can encompass different models, such as finite
automata (finite state machines), Turing machines, pushdown automata, and
more. These models vary in their computational power and complexity.
Application: Basic machines are used to understand the theoretical limits and
capabilities of computation. They serve as foundational building blocks for
formal language theory and the classification of languages into different
classes (e.g., regular, context-free, context-sensitive, recursively enumerable).
Finite State Machine:
A Finite State Machine (FSM) or finite-state automaton is an abstract machine
used in the study of computation and language that has only a finite, constant
amount of memory.
Finite state machine is used to recognize patterns.
Finite automata machine takes the string of symbol as input and changes its
state accordingly. In the input, when a desired symbol is found then the
transition occurs.
While transition, the automata can either move to the next state or stay in the
same state.
FA has two states: accept state or reject state. When the input string is
successfully processed and the automata reached its final state then it will
accept.
A Finite Automata consists of following:
Q: finite set of states
∑: finite set of input symbol
q0: initial state
F: final state
δ: Transition function, can be define as δ: Q x ∑ → Q
A finite automaton consists of the following components:
States: The system or machine can exist in a finite set of states. Each state
represents a particular condition or configuration of the system.
Transitions: Transitions describe how the system moves from one state to
another based on inputs. They are represented by arrows or directed edges and
are labelled with input symbols. For a given state and input symbol, there is a
defined transition to another state or states.
Inputs: The machine receives inputs from an input alphabet, which is a finite
set of symbols. These symbols trigger the transitions in the automaton.
Start State: The automaton has a designated start state from which the
computation begins. It represents the initial configuration of the system.
Final state: Representing the successful end of the machine.
Dead/Dummy State: Having no meaning in the generation of the string. It is
only designed to full the requirements of the finite state machines that every
state has one transition for each alphabet.
Accepting States: Some states in the automaton are marked as accepting or
final states. When the machine reaches an accepting state after processing a
sequence of inputs, it signifies that the input sequence is accepted by the
automaton. Accepting states indicate the successful recognition of a specific
pattern or language.
Rules of Finite Automata (Finite State Machine FSM):
1. Every state has strictly one transition for each alphabet. Suppose there two
alphabets in the languages L={a,b}, then each state has strictly had two
transitions. One transition for alphabet a and one transition for alphabet b. Let’s
have another example, Suppose there three alphabets in the languages L={a,b,c},
then each state has strictly three transitions. One transition for alphabet a, one
transition for alphabet b and one transition for alphabet c.
2. If the generation of any alphabet from a transition is the cause of generating
some strings that are not the part of the language, and it becomes very necessary
to put that alphabet on some transition, then generates the alphabet and move the
machine to the dead/dummy state. Dummy state means that machine will not
generate any string.
3. Every string that is part of the language should be accepted by the FSA and
every string that is not part of the language should be rejected by the FSA.
4. Every language that can be generated by a regular expression can be generated
by FSA.
Applications of Finite Automata:
Finite automata have several practical applications across various fields. Here are
some notable applications:
Lexical Analysis: Finite automata are extensively used in compiler design for
lexical analysis, which involves tokenizing and scanning the source code of a
programming language. Lexical analyzers employ finite automata to
recognize and classify different lexical units such as keywords, identifiers,
operators, and literals.
Pattern Recognition: Finite automata are employed in pattern-matching and
recognition tasks. They can be used to search for specific patterns or sequences
of characters within a given input. Applications include text processing, string
matching, and searching algorithms.
Network Protocol Analysis: Finite automata are used in network protocol
analysis and packet filtering. They can be employed to define rules and match
patterns in network traffic, enabling functionalities like intrusion detection,
firewalls, and network monitoring.
Digital Circuit Design: Finite automata can model the behavior of digital
circuits and aid in their design and testing. Sequential circuits, such as counters
and state machines, can be represented and analyzed using finite automata.
Natural Language Processing: Finite automata are used in natural language
processing for tasks such as text tokenization, morphological analysis, and
part-of-speech tagging. They help in parsing and understanding the structure
of natural language sentences.
Vending Machines: Finite automata are an appropriate model for designing
and implementing the control logic of vending machines. They can manage
the states and transitions required to process user inputs and dispense the
appropriate products.
Regular Expression Processing: Finite automata are closely related to
regular expressions, a powerful tool for specifying patterns in strings. Regular
expression engines often utilize finite automata to efficiently match and
process regular expressions.
DNA Sequence Analysis: Finite automata find applications in bioinformatics
for analyzing DNA sequences. They can be used to identify specific patterns
or motifs within DNA sequences, aiding in gene identification, sequence
alignment, and genetic research.
Transition System:
Transition Graphs:
Transition graph can be interpreted as a flowchart for an algorithm recognizing a
language. A transition graph consists of three things:
1. A finite set of states, at least one of which is designated the start state and
some of which are designated as final states.
2. An alphabet Σ of possible input symbols from which the input strings are
formed.
3. A finite set of transitions that show the change of state from the given state
on a given input.
A successful path through the transition graph is a series of edges forming a path
beginning at the start state and ending at one of the final states.
Example – This example shows transition table for NFA (non-deterministic finite
automata).
Transition Tables:
A transition table is a tabular representation of the transition function that takes
two arguments and returns a state.
A transition table gives the information about –
1. Rows represent different states.
2. Columns represent input symbols.
3. Entries represent the different next state.
4. The final state is represented by a star or double circle.
5. The start state is always denoted by a small arrow.
For the transition graph in the above figure the transition table would be as
follows:
Explanation of above table –
1. First column indicates all the present states, Next for input 0 and 1
respectively.
2. When the present state is q0, for input 0 the next state will become q0. For
input 1 the next state is q1.
3. When the present state is q1, for input 0 the next state is q1 or q2, and for 1
input the next state is q2.
4. When the current state is q2 for input 0, the next state will become q1, and for
1 input the next state will become Nil.
5. The small straight arrow on q0 indicates that it is a start state and circle on to
q3 indicates that it is a final state.
FA is characterized into two ways:
1. DFA (Deterministic Finite Automata)
2. NDFA (Non-Deterministic Finite Automata)
Deterministic Finite Automata (DFA):
In DFA, the state to which the machine will move can be determined for each
input symbol. As a result, it's known as a Deterministic Automaton. The machine
is known as a Deterministic Finite Machine or Deterministic Finite Automaton
because it has a finite number of states.
DFA consists of 5 tuples {Q, Σ, q, F, δ} -
Q: a set of all states.
Σ: a set of input symbols. (Symbols which machine takes as input)
q: Initial state. (Starting state of a machine)
F: a set of the final state.
δ: Transition Function, defined as δ: Q X Σ → Q.
In a DFA, the machine only goes to one state for each input character. Every state
for each input symbol has a transition function defined. DFA doesn't accept the
null move, which means the DFA cannot change the state without any input
character. One thing to keep in mind is that a pattern can have several DFAs.
A DFA with the fewest possible states is generally preferred. It can contain
multiple final states. It is used in Lexical Analysis in compilers.
Example:
L1 = Set of all strings that start with ‘0’
= {0,00,01,000,010,011,000,............}
Application of DFA (Deterministic Finite Automata):
The different applications of deterministic finite automata are as follows −
Protocol analysis text parsing.
Video game character behavior.
Security analysis.
CPU control units.
Natural language processing Speech recognition, etc.
Question: Construct transition table of DFA for a given diagram -
Q= {q0,q1,q2}
Σ ={0,1}
q0= {q0}
F= {q2}
Transition diagram:
Transition Table:
Present state Next state for input 0 Next state for input 1
->q0 q0 q1
q1 q2 q1
*q2 q2 q2
Explanation:
Step 1 − In the above table q0 is the initial state, on input ‘0’ the q0 state
goes to itself and on input ‘1’ it goes to state q1.
Step 2 − q1 is the intermediate state, on input ‘0’ q1 goes to q2 state and on
input ‘1’, q1 goes to itself.
Step 3 − q2 is the final state, q2 on ‘0’ goes to q2 itself and input ‘1’ goes
to q2 itself.
Non-Deterministic Finite Automata (NDFA):
NFA stands for non-deterministic finite automata. It is easy to construct an NFA
when compared to DFA for a given regular language.
The finite automata are called NFA when there exist many paths for specific input
from the current state to the next state.
Each NFA can be translated into DFA but every NFA is Non DFA
NFA is defined in the same way as DFA but with the following two exceptions,
which are as follows −
1. It contains multiple next states.
2. It contains ε transitions.
Non-deterministic finite automata also have five states which are same as DFA,
but with different transition function, as shown follows − δ: Q X Σ → 2Q
Non-deterministic finite automata is defined as a 5 tuple,
M = (Q, Σ, δ, q0, F) Where,
Q: Finite set of states
Σ: Finite set of the input symbol
q0: Initial state
F: Final state
δ: Transition function: Q X Σ → 2Q
Example:
The transition diagram is as follows −
Fig. State Transition Diagram for NFA with Σ = {a, b}
State Transition Table for above Automaton,
Symbol⇢
⇣State\ a b
q0 {q0,q1} q0
q1 ∅ ∅
One important thing to note is, in NFA, if any path for an input string leads to a
final state, then the input string is accepted. For example, in the above NFA,
there are multiple paths for the input string “00”. Since one of the paths leads to
a final state, “00” is accepted by the above NFA.
Some Important Points:
Justification:
Since all the tuples in DFA and NFA are the same except for one of the tuples,
which is Transition Function (δ)
In case of DFA
δ:QxΣ→Q
In case of NFA
δ : Q x Σ → 2Q
Now if you observe you’ll find out Q x Σ → Q is part of Q x Σ → 2Q.
On the RHS side, Q is the subset of 2Q which indicates Q is contained in 2Q or Q
is a part of 2Q, however, the reverse isn’t true. So mathematically, we can conclude
that every DFA is NFA but not vice-versa. Yet there is a way to convert an NFA
to DFA, so there exists an equivalent DFA for every NFA.
1. Both NFA and DFA have the same power and each NFA can be translated into
a DFA.
2. There can be multiple final states in both DFA and NFA.
3. NFA is more of a theoretical concept.
4. DFA is used in Lexical Analysis in Compiler.
5. If the number of states in the NFA is N then, its DFA can have maximum
2N number of states.
Equivalence of DFA and NDFA:
In contrast to the NFA (NDFA), the Deterministic Finite Automata (DFA) has -
No ε-transition (null transition).
For every (q, a) with q ∈ Q and a ∈ Σ at most one successor state.
Deterministic finite automata can simulate the behaviour of NFA by
increasing the number of states.
In Deterministic Finite Automata (DFA), for each state, there is at most one
transition for each possible input.
In non-deterministic finite automata, there can be more than one transition
from a given state for a given possible input.
If a language L is accepted by an NFA, then there is a DFA that accepts L.
All DFA are NDFA, but not all NFA are DFA.
All NDFA and DFA have the same power.
Processing of an input string is more time consuming when NFA is used and
less time consuming when DFA is used.
Difference Between DFA and NFA:
DFA NFA
DFA stands for Deterministic Finite NFA stands for Nondeterministic Finite
Automata. Automata.
For each symbolic representation of the No need to specify how does the NFA react
alphabet, there is only one state according to some symbol.
transition in DFA.
DFA cannot use Empty String NFA can use Empty String transition.
transition.
DFA can be understood as one machine. NFA can be understood as multiple little
machines computing at the same time.
In DFA, the next possible state is In NFA, each pair of state and input symbol
distinctly set. can have many possible next states.
DFA is more difficult to construct. NFA is easier to construct.
DFA rejects the string in case it NFA rejects the string in the event of all
terminates in a state that is different branches dying or refusing the string.
from the accepting state.
Time needed for executing an input Time needed for executing an input string
string is less. is more.
All DFA are NFA. Not all NFA are DFA.
DFA requires more space. NFA requires less space then DFA.
Dead configuration is not allowed. Dead configuration is allowed.
eg: if we give input as 0 on q0 state so eg: if we give input as 0 on q0 state so we
we must give 1 as input to q0 as self can give next input 1 on q1 which will go
loop. to next state.
δ: Q x Σ → Q i.e. next possible state δ: Q x (Σ U ε) → 2Q i.e. next possible state
belongs to Q. belongs to power set of Q.
Backtracking is allowed in DFA. Backtracking is not always possible in
NFA.
Conversion of Regular expression to Conversion of Regular expression to NFA
DFA is difficult. is simpler compared to DFA.
Epsilon move is not allowed in DFA Epsilon move is allowed in NFA
DFA allows only one move for single There can be choice (more than one move)
input alphabet. for single input alphabet.
Decision Properties:
Decision properties refer to questions or properties related to finite automata
(FAs) that can be decided algorithmically or answered with a yes or no based on
the behaviour and structure of the automaton. Here are some common decision
properties of finite automata:
1. Emptiness:
- Property: Does the automaton accept any strings?
- Decision Question: Is the language recognized by the finite automaton
empty?
- Algorithm: One can check whether there exists a path from the initial state to
an accepting state by performing a reachability analysis on the automaton's state-
transition graph.
2. Universality:
- Property: Does the automaton accept all possible input strings (universal
language)?
- Decision Question: Is the language recognized by the finite automaton equal
to the set of all strings over its alphabet?
- Algorithm: Compare the set of strings recognized by the automaton to the set
of all possible strings.
3. Equivalence:
- Property: Are two finite automata equivalent, i.e., do they recognize the same
language?
- Decision Question: Given two finite automata, are their languages
equivalent?
- Algorithm: Convert the automata into a standard form (e.g., minimal DFAs)
and check if they are isomorphic (structurally identical).
4. Membership:
- Property: Does the automaton accept a specific input string?
- Decision Question: Given an input string, does the finite automaton accept it?
- Algorithm: Simulate the automaton's behavior on the input string and check
if it reaches an accepting state.
5. Finiteness:
- Property: Is the set of states in the finite automaton finite?
- Decision Question: Is the set of states in the finite automaton finite?
- Algorithm: Count the number of distinct states in the automaton's state-
transition graph.
6. Equivalence to Regular Expression:
- Property: Can the language recognized by the finite automaton be expressed
as a regular expression?
- Decision Question: Given a finite automaton, can its language be described
by a regular expression?
- Algorithm: Use algorithms for converting FAs to regular expressions (e.g.,
Arden's theorem or state elimination).
7. Minimality:
- Property: Is the given DFA minimal, i.e., does it have the smallest number of
states that recognizes the same language?
- Decision Question: Given a DFA, is it the minimal DFA for its language?
- Algorithm: Construct the minimal DFA using minimization algorithms (e.g.,
the Hopcroft minimization algorithm).
8. Determinism:
- Property: Is the given automaton deterministic?
- Decision Question: Given an automaton, is it a deterministic finite automaton
(DFA)?
- Algorithm: Check whether there is exactly one transition for each state and
input symbol combination.
Minimization of Finite Automata:
The term minimization refers to the construction of finite automata with a
minimum number of states, which is equivalent to the given finite
automata. The number of states used in finite automata directly depend upon the
size of the automata that we have used. So, it is important to reduce the number
of states. We minimize the finite automata by detecting those states of automata
whose presence or absence does not affect the language accepted by the finite
automata.
Some important concepts used in the minimization of finite automata -
Unreachable state
Dead State
Unreachable state: Unreachable state is that state in which finite automata never
reaches during the transition from one state to another state.
In the above DFA, we have unreachable state E, because on any input from the
initial state, we are unable to reach to that state. This state is useless in finite
automata. So, the best solution is to eliminate these types of states to minimize
the finite automata.
Dead State: It is a non-accepting state, which goes itself for every possible input
symbol.
In the above DFA, we have q5, and q6 are dead states because every possible
input symbol goes to itself.
Minimization of Deterministic Finite Automata:
The following steps are used to minimize a Deterministic Finite Automata.
Step1: First of all, we detect the unreachable state.
Step2: After detecting the unreachable state, in the second step, we eliminate the
unreachable state (if found).
Step3: Identify the equivalent states and merge them.
a. In this, we divide all the states into two groups:
b. Group A: This group contains all accepting states of automata.
c. Group B: This group contains all non-accepting states of automata.
This step is repeated for every group. Find group the input lead to if there are
differences the partition the group into sets containing states which go to the same
groups under the inputs.
The resulting final partition contains equivalent states now merge them into
a single state.
Step4: In this step, we detect dead states.
Step5: After detecting the dead states, the last step is to eliminate dead states.
Example:
Minimize the following DFA –
Solution:
Step1: Detect unreachable states.
Start form initial state. Add q0 to temporary state (T)
T = {q0}
Now, for all states in temporary state set T, find transition from each state
on each input symbol in ?. If resulting state is not in T add that state in T.
(NOTE: Below ? = δ)
Repeat previous step until T does not change
Finally we get T as:
Now we will find unreachable states
Step2: In this step, we eliminate the unreachable state found in first step.
Step3: Identify the equivalent steps and merge them.
First of all, divide the states into two groups
Group A – q3, q4,q5 (contains accepting state)
Group B – q0, q1,q2 (contains non-accepting state)
Check Group A for input a
δ (q3, a) = q3
δ (q4, a) = q4
δ (q5, a) = q5
In Similar way, check group A for input b
δ (q3, b) = q1
δ (q4, b) = q5
δ (q5, b) = q4
q1 belongs to group B for input b, and q4 and q5 belong to group A for input b.
So, we partition group A as:
Group A1 - q3
Group A2 – q4, q5
Group B – q0, q1, q2
Now, we check Group B – q0, q1, q2 for both input symbols
For input a, we have:
δ (q0, a) = q1
δ (q1, a) = q3
δ (q2, a) = q3
For input b, we have
δ (q0, b) = q2
δ (q1, b) = q4
δ (q2, b) = q5
q2 belongs to group B and q4, q4 belongs to group A2 for input b. So, we partition
group B as:
Group B1 – q0
Group B2 – q1, q2
Check Group A2 for input a
Check Group A2 for input b
As both belong to the same group, the further division is not possible.
Now, we check Group B2 for input a and b
δ (q1, a) = q3
δ (q2, a) = q3
δ (q1, b) = q4
δ (q2, b) = q5
q4 and q5 belong to group A2 for input b. So no further partitioning is possible.
Finally, the following groups are formed:
Group A1 – q3
Group A2 – q4, q5
Group B1 – q0
Group B2 – q1, q2
The resulting automata is given below:
Step4: In this step, we detected dead states. There are no dead states in the above
DFA; hence it is minimized.
Conversion from NFA to DFA:
A Non-deterministic Finite Automata (NFA) is a finite state machine, in which,
the move from one state to another is not fully deterministic, i.e., for a particular
symbol, there may be more than one moves leading to different states.
There are two ways of conversion from NFA to DFA, which are given below:
Conversion from NFA to DFA using Transition Table
Conversion from NFA to DFA using Transition diagram
Conversion from NFA to DFA using Transition Table:
In this method, we convert NFA to DFA by using the transition table of NFA. The
entries in the transition table for DFA under the input symbol(s) are in square
brackets, e.g. [q0, q1], which specifies a set, i.e., a single state whose elements
are the different states of NFA.
While converting NFA to DFA, all DFA states occupy a final state of NFA as a
member of its final state and the first state in the state’s column in the transition
table of NFA is assigned as the initial state of DFA.
Example: Find the DFA equivalent to the given NFA whose transition table is
given below:
Solution: Firstly, we construct the transition table of DFA from the transition
table of NFA. The first row of the transition table will be the same as the NFA
transition table. The partial transition table of DFA is given below:
Now, we have two states [A, B] and [A] on the left side of the table in the state
column. All the states that appear in the symbol column must appear in state
column. So, we write [A, B] in the left column of the next row
Now we find transitions on the state [A, B] for input symbols 0 and 1. To find
these transitions, use the transition table of NFA. On input 0 from state A, we can
move to state A, B and on input 0 from state B, we can move to state C. In DFA,
on input 0 from state [A, B], we can move to state [A, B, C]. This step follows
for all states of DFA.
We stop these steps when there are no more states under the input columns. Now
we will mark the initial and final states of DFA. In NFA, we have D as the final
state. So, in DFA, every state where D appears will be the final state. And the
first row [A] of the transition table of DFA will be marked as the initial state.
Following is the transition table of DFA
Conversion from NFA to DFA using Transition diagram
In this, if we are given a transition table of NFA, then first we will draw the
transition diagram of NFA from the transition table of NFA. There are various
steps for converting NFA to DFA, which are given below:
Step1: Create a transition diagram with the initial state of NFA. For example,
suppose {q0} as an initial state. Mark it as the initial state of DFA.
Step2: Repeat the following steps until no more edges are missing.
Take any vertex {qi, qj, …qk} of Transition diagram that has no transitions
specified for some input alphabet 0.
Compute δ (qi, 0) U δ (qj, 0) U ………………… U δ (qk,0)
Let the result of these transitions after union is {ql, qm …qn}
Create a vertex (new state) labeled {ql, qm …qn}, if it does not already
exist in the transition diagram of DFA.
Add an edge labeled b from state {qi, qj …qk} to state {ql, qm …qn} to
Transition diagram
Step3: Every state of the Transition diagram in which the final state of NFA
appears, make it the final state.
Example:
Convert the following NFA to DFA
Solution:
Step1: We have initial state q0 in NFA. It means in DFA, we have {q0} as start
state create a vertex for {q0}.
Step2: In the second step, we find transitions on input 0 and 1 from state {q0}.
δ ({q0}, 0) = {q0}
In this step, no need to create a vertex in the diagram because vertex {q0} already
exists. So, in this, we simply add a self-loop from state {q0} with label 0.
Again we find
δ ({q0}, 1) = {q0,q1}
Create a new vertex as shown below
Now, we will find transitions from state {q0, q1}
δ ({q0,q1}, 0) = δ (q0,0) U δ (q1,0)
= {q0}
δ ({q0,q1}, 1) = δ (q0,1) U δ (q1,1)
= {q0, q1, q2}
Now, create a new vertex as shown below
Now, we will find transitions from state {q0, q1, q2}
δ ({q0,q1,q2}, 0) = δ (q0,0) U δ (q1,0) U δ (q2,0)
= {q0, q2}
δ ({q0,q1,q2}, 1) = δ (q0,1) U δ (q1,1) U δ (q2,1)
= {q0, q1, q2}
Again create a new vertex
Now, we will find transitions from state {q0, q2}
δ ({q0,q2}, 0) = δ (q0,0) U δ (q2,0)
= {q0, q2}
δ ({q0,q2}, 1) = δ (q0,1) U δ (q2,1)
= {q0, q1, q2}
The moves are shown below
The vertex {q0, q2} and {q0, q1, q2} contains q2, which is the final state of NFA.
So, these are also the final states of DFA.
The final DFA is shown below.
Finite Automata with Output:
The Finite State machine is similar to Finite Automata, except that it has the
additional capacity of producing output.
Finite State machine = Finite Automata + Output Capabilities
Types of Finite Automata that generates output are:
Moore Machine
Mealy Machine
The Mealy and Moore machine are commonly used to describe the behaviour of
sequential circuits, which include flip-flops, in which, the output of the circuits is
related to both functions of the specific inputs and function of the previous state.
Moore Machine:
The output of the Moore machine depends only on the present state. The general
architecture of the Moore machine is:
In this, if the machine has N no of states, then it will require N-flip-flops, where
M is the smallest number such that N<=2M. If the input string is of length n, then
the output string will be of length n+1.
A Moore machine can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where −
Q is a finite set of states.
∑ is a finite set of symbols called the input alphabet.
O is a finite set of symbols called the output alphabet.
δ is the input transition function where δ: Q × ∑ → Q
X is the output transition function where X: Q → O
q0 is the initial state from where any input is processed (q0 ∈ Q).
Transition table of Moore Machine:
In this transition table, we have input alphabet ∑ = {0, 1}and output alphabet O
= {0, 1}. It takes input as {0, 1} and produces output in the form of {a, b}. Moore
machine transition table also has the same input and output alphabet.
Transition diagram of Moore Machine:
To create a transition diagram for a given problem, apply the following steps:
First of all, determine the number of states needed from the given problem
description.
Represent each state with the help of a circle.
From each state, draw an arrow causing event from the current state to the
next state. If some particular input, the machine remains on the same state,
then add this transition with the help of self-loop on the same state in the
transition diagram.
At last, write the value of the output in each state.
In Moore machine, initial state is indicated by an arrow. Each state contains two
things, first is the name of the state, and the second is the output of the state.
Mealy Machine:
In the Mealy machine, value of the output function depends on the current state q
(t) and current input i (t). The architecture of mealy machine is given below:
In this, if the machine has N no of states, then it will require N-flip-flops, where
M is the smallest number such that N<=2M. In a mealy machine, if the input string
of length n, then the output string will also be of length n.
It can be described by a 6 tuple (Q, ∑, O, δ, X, q 0) where −
Q is a finite set of states.
∑ is a finite set of symbols called the input alphabet.
O is a finite set of symbols called the output alphabet.
δ is the input transition function where δ: Q × ∑ → Q
X is the output transition function where X: Q × ∑ → O
q0 is the initial state from where any input is processed (q0 ∈ Q).
Transition table of Mealy Machine:
The output of the mealy machine depends on the current state and diagram. The
transition table of the mealy machine is given below:
Transition diagram of a mealy machine:
To create a transition diagram for a given problem, apply the following steps:
First of all, determine the number of states needed for the given problem
description.
Represent each state with the help of a circle.
From each state, draw an arrow causing event from the current state to the
next state. If some particular input, the machine remains on the same state,
then add this transition with the help of self-loop on the same state in the
transition diagram.
At last, write the output values along with the input values on the paths
between the states.
In the mealy machine, each arc is labelled with two things:
First is the input symbol
The second is the output on the state.
Difference Between Mealy Machine and Moore Machine:
Parameters Mealy Machine Moore Machine
Definition A Mealy Machine changes its A Moore Machine’s output
output on the basis of its depends only on the current state.
present state and current input. It does not depend on the current
input.
Output Mealy Machine places its Moore machine also places its
output on the transition. output on the transition.
States It has comparatively fewer or It has comparatively fewer or the
the same states as that of the same states as that of the Mealy
Moore machine. machine.
Value of the When the input logic is done Whenever a change occurs in the
Output in the present state, then the state, the output function’s value
Function value of the output function becomes the function of its current
becomes a function of state along with the changes at the
transitions and changes. edges of the clock.
Reaction to A Mealy machine reacts In a Moore Machine, one requires
the Inputs comparatively faster to inputs more logic for decoding the output.
than the Moore machine. As a result, it leads to more delays
Generally, it reacts in the very in the circuit. Generally, these
same clock cycle. react after one clock cycle.
State and The asynchronous generation The state and output- both change
Output of output through its state the synchronous to its clock edge.
alters to synchronous on the
present clock.
Requirement A Mealy Machine generally The states for synthesis required
of States requires only a very few states for this machine are also more.
for the process of synthesis.
Requirement It requires very little hardware One requires more hardware to
of Hardware for designing a Mealy design a Moore Machine.
Machine.
Counter You cannot refer to the You can refer to the counter as a
counter as a Mealy Machine. Moore Machine.
Design The designing process doesn’t It is very easy to design.
need to be very easy.
Minimization of Finite Automata with Output:
The method to minimize the Moore and Mealy machine is very much similar to
the method that we have used to minimize the DFA.
Methods to Minimize the Finite Automata with Output
Step1: Detect the unreachable states.
Step2: Eliminate the unreachable states (if find).
Step3: Identify equivalent states and merge them.
Equivalent states can also be found the same way as in the case of minimizing the
DFA. But there is only one difference. Initially, we have group A and group B
contains the following:
Group A: All states with a similar type of outputs for all possible inputs.
Group B: All states with other similar types of outputs for all possible
inputs.
Example:
Minimize the following Moore machine.
Solution:
Step1: Detect the unreachable states
Start form initial state. Add q0 to temporary state (T)
Initially T = {q0}
δ(q0, a) = q7
δ(q0, b) = q1
Now, T = {q0, q1, q7}
Again we check all possible states with input a and b.
δ (q1, a) = q0
δ (q1, b) = q3
δ (q3, a) = q7
δ (q3, b) = q6
δ (q7, a) = q4
δ (q7, b) = q0
T = {q0, q1, q3, q4, q6, q7}
Again we check all possible states for input a and b.
δ (q4, a) = q5
δ (q4, b) = q6
δ (q6, a) = q3
δ (q6, b) = q0
T = {q0, q1, q3, q4, q5, q6, q7}
Now, again we check all possible states for input a and b.
δ (q5, a) = q2
δ (q5, b) = q3
δ (q2, a) = q5
δ (q2, b) = q1
Finally, T = {q0, q2, q1, q3, q4, q5, q6, q7}
U= Q – T
= δ (There is no unreachable state)
Step2: There is no unreachable states to remove.
Step3: Identify equivalent states and merge them.
Initially, we have,
Group A: qo, q1, q3, q6 (contains all states with output b)
Group B: q2, q4, q5, q7 (contains all states with output a)
Now, we check both the groups for both the input symbols. For input symbol a,
we have
δ (q0, a) = q7
δ (q1, b) = q0
δ (q3, a) = q7
δ (q6, b) = q3
q7 belongs too group B and q0, q3 belongs to group A for input a. since q7 belongs
to group B so we partition group A as:
Group A: qo, q3
Group A2: q1, q6
Group B: q2, q4, q5, q7
Now, we check Group B for input a
δ (q2, a) = q5
δ (q4, a) = q5
δ (q5, a) = q2
δ (q7, b) = q4
Since q2, q4 and q5 belong to the same Group B. Now for input b, we have
δ (q2, b) = q1
δ (q4, b) = q6
δ (q5, b) = q3
δ (q7, b) = q0
q1, q6 belongs to Group A2
q3, q0 belongs to Group A1
After portioning group B, we have
Group A1: qo, q3
Group A2: q1, q6
Group B1: q2, q4
Group B2: q5, q7
Now let us check Group A1 for input a
δ (q0, a) = q7
δ (q3, a) = q7
q7 belongs to Group B2; for input b, we have
δ (q0, b) = q1
δ (q3, b) = q6
q1 and q6 belong to Group A2; thus, the further partition of Group A1 is not
possible.
Similarly for Group A2
δ (q1, b) = q0
δ (q6, b) = q3
q0, q3 belongs to Group A1
δ (q1, b) = q3
δ (q6, b) = q0
q0, q3 belongs to Group A1; thus, the further partition of Group A2 is not
possible
Similarly for Group B1
δ (q2, a) = q5
δ (q4, a) = q5
δ (q2, b) = q1
δ (q4, b) = q6
q5 belongs to Group B2, and q1 and q6 belongs to Group A2; further partition
of Group B1 is not possible
Similarly for Group B2
δ (q5, a) = q2
δ (q7, a) = q4
δ (q5, b) = q3
δ (q7, b) = q0
q2, q4 belongs to Group B1 and q0, q3 belongs to Group A1. Thus further
portioning of Group B2 is not possible.
Finally, we have the following partitions:
Group A1: qo, q3
Group A2: q1, q6
Group B1: q2, q4
Group B2: q5, q7
After merging these states, the minimized Moore machine is shown in the
following figure:
Conversion from Moore Machine to Mealy Machine:
Method for conversion of Moore machine to Mealy machine -
Theorem:
If M =(Q, ∑, O, δ, X, q0) is a Moore machine, then there exists a mealy machine
M’ = (Q, ∑, O, δ’, X, q0) equivalent to M.
Proof:
If M’ = (Q, ∑, O, δ’, X, q0) is a Mealy machine, we can define δ’ to be δ (δ (q, a))
for all state q and input symbols a. The M’ will be equivalent to M since they
enter the same sequence of states on the same input, and with each
transition M’ has the same output that M associate with the state entered.
There are two methods for converting a Moore Machine to Mealy Machine
Converting a Moore Machine to Mealy Machine using transition diagram
Converting a Moore Machine to Mealy Machine using transition table
Converting a Moore Machine to Mealy Machine using transition diagram -
The steps involved in this method are:
1. To redraw the original states without the output. The starting state remains
the same.
2. Draw the transitions as they are on the original machine.
3. Add output to the transitions based on their destination's output symbol in
the original machine.
Example
Let's take a simple Moore machine:
1. We redraw the states without the output:
2. Draw transitions:
3. Now we add output to the transitions based on the transition's destination:
By transition table -
The steps involved in this method are:
1. To rewrite the table, excluding the output column.
2. To add the output to the destination columns adjacent to the destination
state. The output will be according to the output of the destination state in
the Moore machine transition table.
Example:
Let's take the transition table of the previous example is:
1. We will rewrite the table above without the output table:
2. Now, we'll add the output symbols to the destination symbols by looking at
the original table:
For example, for q0, the destination state for 1 is q1. As a result, we see that
the output against q1 in the original table is b, so the output here will also
become b.
This is the final transition table of the Mealy machine.
Conclusion: While transforming a Moore machine having n states
and m outputs, there can be at most n states in the Mealy machine.
Conversion from Mealy to Moore Machine:
By transition diagram -
The steps involved in this method are:
1. Select the initial state and draw the transitions by adding the output symbol
of that transition to the destination state.
2. Repeat the process for every single transition.
3. If a conflict occurs, that is, if a state requires to give two different outputs,
make a duplicate state.
4. Add transitions for all duplicate states on all input symbols.
Example
Let's take a simple Mealy machine:
1. We take the initial state and draw its first transition:
The transition had an output b, that is now transferred to our destination
node q1. Now, for the second transition of state q0:
2. We repeat the process:
3. We encounter a conflict on the transition q1→q1 as it has an output a, but the
state q1 already has an input b. So, we make a duplicate state:
4. Now we add transitions to the new state:
For example, we know from the Mealy machine that q1 at 0 goes to q0 and
gives an output a, so we use the same logic to form the new transition.
Our final Moore machine is shown in the image above.
By transition table -
The steps involved in this method are:
1. Find the states that have more than one output associated with them in each
column. For such states, divide them into two.
2. Rewrite the transition table, including the new states, and add an output
column. Then, fill in the destination state entries using the original table.
3. Check for the output of each state in the destination column and fill in the
output column.
4. Remove the output symbols from the destination columns.
Example
Let's take the transition table of the previous example:
1. We see that in the destination columns, the state q1 has two different outputs
for the input symbols; hence we will make them into two states q1a (q1 with
output a) and q1b (q1 with output b).
2. Now let's form the transition table:
For example, the transition of q0 on 0 is towards q1 in the Mealy machine, but in
this case, we have split q1 in two states. As a result, we see the corresponding
output of that transition. In this case, the output is b; therefore, the destination
will be q1b.
3. Now we fill in the output column:
For example, the q0 state has the output a in both columns of the destination;
thus, the final output is also a.
4. Remove the output from the destination columns:
The table above is the final Moore machine.
Conclusion: While transforming a Mealy machine having n states and m outputs,
there can be at most n×m states in the Moore machine.
Alphabet (Σ):
The alphabet is a finite, non-empty set of symbols or characters. For example,
in a language for arithmetic expressions, the alphabet might include symbols
like {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, -, *, /, (, )}.
It is the basic set of symbols from which words in a language are constructed.
The set of all possible words that can be formed using the symbols from the
alphabet is known as the Kleene closure (Σ*).
In notational terms, Σ represents the alphabet of a language.
Words (Strings):
Words, also known as strings, are sequences of symbols drawn from the
alphabet Σ.
A word is finite, meaning it has a definite length, even if that length is zero.
The empty string, denoted as ε, is a word with zero symbols.
The length of a word w is often represented as |w|, which is the number of
symbols in w.
Words are the basic units used to represent and manipulate information in
formal languages and are central to various applications, such as text
processing, pattern matching, and formal grammar.
For example, if Σ = {a, b}, then "aabab" and "b" are words over the alphabet
Σ.
Operations on Words:
- Concatenation: The operation of combining two words to form a longer
word.
For example, if x = "abc" and y = "def," the concatenation of x and y is denoted
as xy and results in "abcdef."
- Kleene Star (Closure): The Kleene star operation, denoted by A*, represents
the set of all possible combinations of zero or more words from set A.
For example, if A = {"0", "1"}, then A includes {"", "0", "1", "00", "01", "10",
"11", "000", ...}.
- Union: The union of two sets of words A and B, denoted as A ∪ B, is the set
of all words that belong to either A or B.
- Intersection: The intersection of two sets of words A and B, denoted as A ∩
B, is the set of words that belong to both A and B.
- Complement: The complement of a set of words A, denoted as Ā, represents
the set of all words that do not belong to A.
Regular Expression:
Regular expressions are also referred as rational expressions, which are used
to describe the algebraic description of regular languages. It is generally a
sequence of characters that is used to find a string in language. Regular
expressions play an important role in computer science applications, which
involves:
It is used by many text editors and utilities to search block of text for certain
pattern.
It is also used to design the compliers for programming languages.
Like other expressions, such as arithmetic expressions, logical expressions etc.,
regular expression also have permitted symbols and operators. Only defined
symbols can be used to build a regular expression. For example:
(a U b) a*
The regular expression has two parts:
First is (a U b) and second is a*
The symbols a and b are shorthand for sets {a} and {b}. In this (a U b) means
({a} U {b}). In this, {a, b} and {a}* means that the language consisting of all
strings having any number of a’s (e.g., ɸ, a, aa….}.
Both expressions and parts are combined to form the value of the entire
expression.
Regular Languages are the most restricted types of languages and are accepted
by finite automata.
Regular Expressions are used to denote regular languages. An expression is
regular if:
ɸ is a regular expression for regular language ɸ.
ɛ is a regular expression for regular language {ɛ}.
If a ∈ Σ (Σ represents the input alphabet), a is regular expression with language
{a}.
If a and b are regular expression, a + b is also a regular expression with
language {a, b}.
If a and b are regular expression, ab (concatenation of a and b) is also regular.
If a is regular expression, a* (0 or more times a) is also regular.
Regular Expression Regular Languages
set of vowels (a ∪ e ∪ i ∪ o ∪ u) {a, e, i, o, u}
a followed by 0 or (a.b*) {a, ab, abb, abbb, abbbb,….}
more b
any no. of vowels v*.c* { ε , a ,aou, aiou, b, abcd…..}
followed by any no. where ε represent empty string
( where v – vowels
of consonants (in case 0 vowels and o
and c – consonants)
consonants )
Regular Grammar: A grammar is regular if it has rules of form A → a or A →
aB or A → ɛ where ɛ is a special symbol called NULL.
Regular Languages: A language is regular if it can be expressed in terms of
regular expression.
Regular Sets: Any set that represents the value of the Regular Expression is
called a Regular Set.
Closure Properties of Regular Sets:
Property 1 - The union of two regular set is regular.
Proof − Let us take two regular expressions
RE1 = a(aa)* and RE2 = (aa)*
So, L1 = {a, aaa, aaaaa,.....} (Strings of odd length excluding Null)
and L2 ={ ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 ∪ L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......}
(Strings of all possible lengths including Null)
RE (L1 ∪ L2) = a* (which is a regular expression itself)
Hence, proved.
Property 2 - The intersection of two regular set is regular.
Proof − Let us take two regular expressions
RE1 = a(a*) and RE2 = (aa)*
So, L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even length excluding Null)
RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself.
Hence, proved.
Property 3 - The complement of a regular set is regular.
Proof − Let us take a regular expression −
RE = (aa)*
So, L = {ε, aa, aaaa, aaaaaa, .......} (Strings of even length including Null)
Complement of L is all the strings that is not in L.
So, L’ = {a, aaa, aaaaa, .....} (Strings of odd length excluding Null)
RE (L’) = a(aa)* which is a regular expression itself.
Hence, proved.
Property 4 - The difference of two regular set is regular.
Proof − Let us take two regular expressions −
RE1 = a (a*) and RE2 = (aa)*
So, L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}
(Strings of all odd lengths excluding Null)
RE (L1 – L2) = a (aa)* which is a regular expression.
Hence, proved.
Property 5 - The reversal of a regular set is regular.
Proof − We have to prove LR is also regular if L is a regular set.
Let, L = {01, 10, 11, 10}
RE (L) = 01 + 10 + 11 + 10
LR = {10, 01, 11, 01}
RE (LR) = 01 + 10 + 11 + 10 which is regular
Hence, proved.
Property 6 - The closure of a regular set is regular.
Proof − If L = {a, aaa, aaaaa, .......} (Strings of odd length excluding Null)
i.e., RE (L) = a (aa)*
L* = {a, aa, aaa, aaaa , aaaaa,……………} (Strings of all lengths excluding Null)
RE (L*) = a (a)*
Hence, proved.
Property 7 - The concatenation of two regular sets is regular.
Proof − Let RE1 = (0+1)*0 and RE2 = 01(0+1)*
Here, L1 = {0, 00, 10, 000, 010, ......} (Set of strings ending in 0)
and L2 = {01, 010,011,.....} (Set of strings beginning with 01)
Then, L1 L2 = {001,0010,0011,0001,00010,00011,1001,10010,.............}
Set of strings containing 001 as a substring which can be represented by an RE −
(0 + 1)*001(0 + 1)*
Hence, proved.
Identities For Regular Expressions:
Two regular expressions P and Q are equivalent (we write P = Q) if P and Q
represent the same set of strings. We now give the identities for regular
expressions; these are useful for simplifying regular expressions.
1. Ø + R = R
2. ØR = RØ = Ø
3. ∧R = R∧ = R
4. ∧* = ∧ and Ø* = ∧
5. R+R=R
6. R*R* = R*
7. RR* = R*R
8. (R*)* = R*
9. ∧ + RR* = R* = ∧ + R*R
10. (PQ)*P = P(QP)*
11. (P+Q)* = (P*Q*)* = (P* + Q*)*
12. (P + Q)R = PR + QR and R(P + Q) = RP + RQ
Precedence of Regular Expression Operators:
If we are using parenthesis with regular expressions, then the evaluation of
regular expression is performed on the basis of operator’s precedence.
For Regular expression, the order of precedence is given below:
The star operator (*) has highest precedence.
Concatenation operator (.) has next precedence.
Union operator (+) has lowest precedence.
Relationship Between Finite Automata and Regular Expression:
The relationship between FA and RE is as follows –
The above figure explains that it is easy to convert
RE to Non-deterministic finite automata (NFA) with epsilon moves.
NFA with epsilon moves to without epsilon moves.
NFA without epsilon moves to Deterministic Finite Automata (DFA).
DFA can be converted easily to RE.
Arden's Theorem:
In order to find out a regular expression of a Finite Automaton, we use Arden’s
Theorem along with the properties of regular expressions.
Statement −
Let P and Q be two regular expressions. If P does not contain null string, then
R = Q + RP has a unique solution that is R = QP*
Proof −
R = Q + (Q + RP)P [After putting the value R = Q + RP]
= Q + QP + RPP
When we put the value of R recursively again and again, we get the following
equation −
R = Q + QP + QP2 + QP3…..
R = Q (ε + P + P2 + P3 + …. )
R = QP* [As P* represents (ε + P + P2 + P3 + ….) ]
Hence, proved.
Assumptions for Applying Arden’s Theorem -
The transition diagram must not have NULL transitions
It must have only one initial state
Method
Step 1 − Create equations as the following form for all the states of the DFA
having n states with initial state q1.
q1 = q1R11 + q2R21 + … + qnRn1 + ε
q2 = q1R12 + q2R22 + … + qnRn2
…………………………
…………………………
…………………………
…………………………
qn = q1R1n + q2R2n + … + qnRnn
Rij represents the set of labels of edges from qi to qj, if no such edge exists,
then Rij = ∅
Step 2 − Solve these equations to get the equation for the final state in terms of Rij
Problem
Construct a regular expression corresponding to the automata given below −
Solution −
Here the initial state and final state is q1.
The equations for the three states q1, q2, and q3 are as follows −
q1 = q1a + q3a + ε (ε move is because q1 is the initial state0
q2 = q1b + q2b + q3b
q3 = q 2 a
Now, we will solve these three equations −
q2 = q1b + q2b + q3b
= q1b + q2b + (q2a)b (Substituting value of q3)
= q1b + q2(b + ab)
= q1b (b + ab)* (Applying Arden’s Theorem)
q1 = q1a + q3a + ε
= q1a + q2aa + ε (Substituting value of q3)
= q1a + q1b(b + ab*)aa + ε (Substituting value of q2)
= q1(a + b(b + ab)*aa) + ε
= ε (a+ b(b + ab)*aa)*
= (a + b(b + ab)*aa)*
Hence, the regular expression is (a + b(b + ab)*aa)*.
Problem
Construct a regular expression corresponding to the automata given below −
Solution −
Here the initial state is q1 and the final state is q2
Now we write down the equations −
q1 = q10 + ε
q2 = q11 + q20
q3 = q21 + q30 + q31
Now, we will solve these three equations −
q1 = ε0* [As, εR = R]
So, q1 = 0*
q2 = 0*1 + q20
So, q2 = 0*1(0)* [By Arden’s theorem]
Hence, the regular expression is 0*10*.
Conversion of Finite Automata to Regular Expression:
Every finite automaton has an equivalent regular expression.
The conversion of a finite automaton to a regular expression is done through
the state elimination method.
State elimination method:
The State elimination method follows the following general set of rules:
1. Add a new initial state (I). Make a null transition from the old initial state
to the new initial state.
2. Add a new final state (F). Make null transition(s) to the new final state.
3. Eliminate all states, except I and F, in the given finite automaton. Perform
the elimination of states by checking the in-degrees and out-degrees of
states and taking a cross product.
After steps 1 and 2, the I state will not have any inward transitions, and the
state F state will not have any outward transitions.
Example
Let's consider the following finite automaton:
Step 1: Add an initial state
Add a new initial state, I. Make a null transition from state I to state q0.
Step 2: Add a final state
Add a new final state, F. Make a null transition from state q3 to state F.
Step 3: State elimination
Perform the elimination of states other than I and F.
Step 3.1
Eliminate state q0.
Step 3.2
Eliminate state q3. Concatenate transitions from stateq3 to state F as per the basic
rules of writing regular expressions.
Step 3.3
Eliminate q1. Check for the in-degree and out-degree of state q1. Write the
regular expressions for the new transitions acquired after removing state q1.
Step 3.4
Eliminate state q2.
Step 3.5
Put it all together.
Result
The resultant regular expression for the given finite automaton is as follows:
a.a *. (a + b) + ((a.a *. a) + b). (b.a *. a) *. b.a *.(a + b).
Conversion of Regular Expression to Finite Automata:
As the regular expressions can be constructed from Finite Automata using the
State Elimination Method, the reverse method, state decomposition method can
be used to construct Finite Automata from the given regular expressions.
Note: This method will construct NFA (with or without ε-transitions, depending
on the expression) for the given regular expression, which can be further
converted to DFA using NFA to DFA conversion.
State Decomposition Method:
Theorem: Every language defined by a regular expression is also defined by a
Finite Automata.
Proof: Let’s assume L = L(R) for a regular expression R. We prove that L = L(M)
for some ε-NFA M with:
1) Exactly one accepting state.
2) No incoming edges at the initial state.
3) No outgoing edges at the accepting state.
The proof is done by structural induction on R by following the steps below:
Step 1: Create a starting state, say q1, and a final state, say q2. Label the transition
q1 to q2 as the given regular expression, R, as in Fig 1. But, if R is (Q)*, Kleene’s
closure of another regular expression Q, then create a single initial state, which
will also be the final state, as in Fig 2 –
Figure 1 Figure 2
Step 2: Repeat the following rules (state decomposition method) by considering
the least precedency regular expression operator first until no operator is left in
the expression. Precedence of operators in regular expressions is defined as
Union < Concatenation < Kleene’s Closure.
Union operator (+) can be eliminated by introducing parallel edges between the
two states as follows.
Fig 3: Removal of Union Operator 1
The concatenation operator (‘.’ or no operator at all) can be eliminated by
introducing a new state between the states as follows.
Fig 4: Removal of Concatena on Operator 1
Kleene’s Closure (*) can be eliminated by introducing self-loops on states
based on the following conditions:
1. If there is only one outgoing edge at the left-most state, i.e., A in transition A -
> B, then introduce self-loop on state A and label edge A to B as an ε-transition,
as shown in Fig 5.
Figure 5
2. Else if there is only one incoming edge at the right-most state, i.e., B in
transition A -> B, then introduce self-loop on state B and label edge A to B as an
ε-transition, as shown in Fig 6.
Figure 6
3. Else introduce a new state between two states having self-loop labeled as the
expression. The new state will have ε-transitions with the previous states as
follows, as shown in Fig 7.
Figure 7
Example: Construct Finite Automata for the regular expression, R = (ab + ba)*
Solution:
Step 1: As the given expression, R, is of the form (Q)*, so we will create a single
initial state that will also be the final state, having self-loop labeled (ab + ba), as
shown in Fig 8. (Refer Fig 2 above)
Figure 8
Step 2:
A. As the least precedency operator in the expression is a union(+). So we will
introduce parallel edges (parallel self-loops here) for ‘ab’ and ‘ba’, as shown in
Fig 9.
Figure 9
B. Now we have two labels with concatenation operators (no operator mentioned
between two variables is concatenation), so we remove them one by one by
introducing new states, q1 and q2 as shown in Fig 10 and Fig 11. (Refer Fig 4
above)
Figure 10
Figure 11
Step 3: As no operators are left, we can say that Fig 11 is the required finite
automata (NFA).
Pumping Lemma for Regular Languages:
The language accepted by the finite automata is called Regular Language. If we
are given a language L and asked whether it is regular or not? So, to prove a given
Language L is not regular we use a method called Pumping Lemma.
The term Pumping Lemma is made up of two words:
1. Pumping: The word pumping refers to generate many input strings by
pushing a symbol in an input string again and again.
2. Lemma: The word Lemma refers to intermediate theorem in a proof.
Pumping Lemma is used to prove that given language is not regular. So, first of
all we need to know when a language is called regular. A language is called
regular if:
Language is accepted by finite automata.
A regular grammar can be constructed to exactly generate the strings in a
language.
A regular expression can be constructed to exactly generate the strings in a
language.
Principle of Pumping Lemma:
Theorem: If A is a Regular Language, then A has a Pumping Length ‘P’ such that
any string ‘S’ where |S| ≥ P may be divided into three parts S = xyz such that the
following conditions must be true:
1.) xyiz ∈ A for every i ≥ 0
2.) |y| > 0
3.) |xy| ≤ P
In simple words, if a string y is ‘pumped’ or insert any number of times, the
resultant string still remains in A.
Pumping Lemma is used as proof of the irregularity of a language. It means, that
if a language is regular, it always satisfies the pumping lemma. If at least one
string is made from pumping, not in language A, then A is not regular.
We use the CONTRADICTION method to prove that a language is not Regular.
Means, If we can prove that the given language does not have these properties,
then we can say that it is not a regular language.
Steps to prove that a language is not Regular using Pumping Lemma:
Step 1: Assume that Language A is Regular.
Step 2: It has to have a Pumping Length (say P).
Step 3: All strings longer than P can be pumped |S| ≥ P.
Step 4: Now, find a string ‘S’ in A such that |S| ≥ P.
Step 5: Divide S into x y z strings.
Step 6: Show that xyiz ∉ A for some i.
Step 7: Then consider how S can be divided into x y z.
Step 8: Show that none of the above strings satisfies all three pumping
conditions simultaneously.
Step 9: S cannot be pumped == CONTRADICTION.
Implementation of Pumping lemma for regular languages -
Example: Using Pumping Lemma, prove that the language A = {anbn | n≥0} is
Not Regular.
Solution: We will follow the steps we have learned above to prove this.
Assume that A is Regular and has a Pumping length = P.
Let a string S = apbp.
Now divide the S into the parts, x y z.
To divide the S, let’s take the value of P = 7.
Therefore, S = aaaaaaabbbbbbb (by putting P=7 in S = apbp).
Case 1: Y consists of a string having the letter only ‘a’.
Case 2: Y consists of a string having the letter only ‘b’.
Case 3: Y consists of a string with the letters ‘a’ and ‘b’.
For all the above cases, we need to show xyiz ∉ A for some i.
Let the value of i = 2. xyiz => xy2z
In Case 1. xy2z = aa aaaa aaaa abbbbbbb
No of ‘a’ = 11, No. of ‘b’ = 7.
Since the No of ‘a’ != No. of ‘b’, but the original language has an equal number
of ‘a’ and ‘b’; therefore, this string will not lie in our language.
In Case 2. xy2z = aaaaaaabb bbbb bbbb b
No of ‘a’ = 7, No. of ‘b’ = 11.
Since the No of ‘a’ != No. of ‘b’, but the original language has an equal number
of ‘a’ and ‘b’; therefore, this string will not lie in our language.
In Case 3. xy2z = aaaa aabb aabb bbbbb
No of ‘a’ = 8, No. of ‘b’ = 9.
Since the No of ‘a’ != No. of ‘b’, but the original language has an equal number
of ‘a’ and ‘b’, and also, this string did not follow the anbn pattern; therefore, this
string will not lie in our language.
We can see at i = 2 all the above three strings do not lie in the language A =
{anbn | n≥0}.
Therefore, the language A = {anbn | n≥0} is not Regular.
Applications of Pumping Lemma:
Applying the Pumping Lemma will demonstrate that some languages are
irregular. Never utilise a language to demonstrate its regularity.
Pumping Lemma is satisfied if L is regular.
L is not regular if it does not satisfy the Pumping Lemma.
Myhill- Nerode Theorem:
Statement of Myhill Nerode Theorem -
This theorem states that a language L is regular if and only if L~ has a finite
number of equivalence classes. Furthermore, if this finite number of
equivalence classes is N, then N is the number of states in minimal DFA
(Deterministic Finite Automaton) recognizing L.
Here L~ is a relation on strings x, y such that there is no distinguishing
extension for x and y.
To understand the above statement, we need to understand what is meant
by distinguishing extension.
For a language L and a pair of strings x and y, a distinguishing extension is a
string z such that exactly one of the two strings xz and yz belongs to L.
Proof of Myhill Nerode Theorem -
Suppose L is a regular language
By definition, there is a DFA (say A) that recognizes it with finitely many states
(say n)
Let’s divide the set of all finite strings into ‘n’ subsets - S1 , S2 ……. SN, such
that when Si is given as input to automaton A, it makes it to end in state i.
Next, for every two strings x and y belonging to the same subset Si, automaton
A reaches the same state on input xz and yz for any choice of third string z, and
therefore A must accept both xz and yz or reject both of them.
Thus, not any string z can be a distinguishing extension for x and y, so they
must be related by L~.
Example of Myhill-Nerode -
Let's look into the example next.
Minimization of DFA with Myhill-Nerode theorem. Follow these steps to
achieve this:
1. Make a table for each pair of states.
In the above example, there are six states, A, B, C, D, E, F. So we'll make the
table row-wise and column-wise because we have to make the pairs. But we'll
cut the table diagonally because the pairs are repeated twice, so we'll discard the
upper part.
2. Mark all the pairs while Pદ F and Q∉F.
Now we'll mark the pairs where P is a final state and Q is a non-final state. So in
the pair, BA both are non-final states. So we'll not mark that pair. Next is the CA
pair. In this, the C is a final state, then we'll mark this pair, and this process goes
on for all the pairs. So we have to mark the pair whenever there is one final state,
and the other is non-final.
3. Mark the (P, Q) state if any unmarked state pairs exist δ(P,x),δ(Q,x) is marked.
Continue until no more markings are possible.
Firstly, we'll check the unmarked pairs. So the first pair is the BA. We'll do the δ
of BA with 0 first and then with 1.
δ(B,0)=A , δ (A,0)=B , So here the pair is AB.
Now check whether this pair is marked or not. If it is not marked, then we'll move
further.
Now check for
δ(B,1)=D , δ (A,1)=C.
Now check whether the DC pair is marked or not. We'll forward the next pair if
it is not marked.
We'll repeat this process with all the unmarked pairs, and if any pair after the
transition is marked, then we have to mark that pair on which the transition is
being done.
In the above example, it is with the FA and FB pair because after transition, it is
marked, so we have to mark the FA and FB pair also.
4. Make a single state in the minimized DFA by combining all the unmarked
pairings.
First, we'll take the unmarked pairs, which are (AB),(DC), (ED), and (EF). Now
let's combine the unmarked pairs.
Now here we'll make the AB pair as a single state, and the other three pairs are
connected with each. So instead of making three different states will make it as
one state and add the remaining F in the DFA, this will be how we'll minimize the
DFA.
This is the minimized DFA having 3 states, whereas the Original DFA was having
three states.
Power of an Alphabet:
If Σ is an alphabet, the set of all strings can be expressed as a certain length from
that alphabet by using exponential notation. The power of an alphabet is denoted
by Σk and is the set of strings of length k.
For example,
Σ ={0,1}
Σ1= {0,1} ( 21=2)
Σ2= {00,01,10,11} (22=4)
Σ3= {000,001,010,011,100,101,110,111} (23= 8)
The set of strings over an alphabet Σ is usually denoted by Σ*(Kleene closure)
For instance, Σ*= {0,1}*
={ ε,0,1,00,01,10,11,………}
Therefore, Σ*= Σ0U Σ1U Σ2U Σ3…………. With ε symbol
The set of strings over an alphabet Σ excluding ε is usually denoted by Σ+(Kleene
plus) For instance, Σ+={0,1}+
={0,1,00,10,01,11,…………}
Therefore, Σ+= Σ*- { ε}
Or
Σ+= Σ1U Σ2U Σ3…………. Without ε symbol
The power of alphabet is of two types, which are explained below −
Kleene closure (Σ*)
Kleene plus (Σ+)
Kleene Closure: Σ*
Let Σ ={a,b}
Σ*= Σ0U Σ1U Σ2U Σ3…………
={ε} U {a,b} U {aa,ab,ba,bb}...........
Set of all strings including epsilon is called Kleene closure.
Kleene Plus:Σ+
Let Σ ={a,b}
Σ+= Σ1U Σ2U Σ3…………
={a,b} U {aa,ab,ba,bb}...........
Set of all strings excluding epsilon is called kleene plus.
Σ+= Σ*- { ε}
Or
Σ+= Σ1U Σ2U Σ3
THE END