0% found this document useful (0 votes)
89 views39 pages

Unit 1 Theory of Computation Notes

Uploaded by

vaishnavich1702
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views39 pages

Unit 1 Theory of Computation Notes

Uploaded by

vaishnavich1702
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

THEORY OF COMPUTATION

FINITE AUTOMATA AND REGULAR EXPRESSIONS


UNIT 1

Introduction of Finite Automata


 Finite automata are abstract machines used to recognize patterns in input
sequences, forming the basis for understanding regular languages in
computer science.
 Consist of states, transitions, and input symbols, processing each symbol
step-by-step.
 If ends in an accepting state after processing the input, then the input is
accepted; otherwise, rejected.
 Finite automata come in deterministic (DFA) and non-deterministic (NFA),
both of which can recognize the same set of regular languages.
 Widely used in text processing, compilers, and network protocols.

Fig :- Features of Finite Automata Diagram

Features of Finite Automata


 Input: Set of symbols or characters provided to the machine.
 Output: Accept or reject based on the input pattern.
 States of Automata: The conditions or configurations of the machine.
 State Relation: The transitions between states.
 Output Relation: Based on the final state, the output decision is made.
Formal Definition of Finite Automata
A finite automaton can be defined as a tuple:
{ Q, Σ, q, F, δ }, where:
 Q: Finite set of states
 Σ: Set of input symbols
 q: Initial state
 F: Set of final states
 δ: Transition function
Types of Finite Automata
There are two types of finite automata:
 Deterministic Finite Automata (DFA)
 Non-Deterministic Finite Automata (NFA)

1. Deterministic Finite Automata (DFA)


 In DFA, for each input symbol, one can determine the state to which the
machine will move. Hence, it is called Deterministic Automaton. As it has a
finite number of states, the machine is called Deterministic Finite
Machine or Deterministic Finite Automaton.
 DFA refers to deterministic finite automata. Deterministic refers to the
uniqueness of the computation. The finite automata are deterministic FA, if
the machine reads an input string one symbol at a time.
 In DFA, there is only one path input from the current state to the next state.
It does not accept the null move, i.e. it cannot change state without any
input. It can contain multiple final states. It is used in Lexical Analysis in
compilers.
 Finite Automaton can be classified into two types –
 Deterministic Finite Automaton (DFA)
 Non-deterministic Finite Automaton (NDFA / NFA)

Formal Definition of a DFA


A Deterministic Finite automata (DFA) is a collection of defined as a 5-tuples and is
as follows −
M=(Q,Σ,δ,q0,F)
Where,
 Q is a finite set of states.
 ∑ is a finite set of symbols called the alphabet.
 δ is the transition function where δ: Q × ∑ → Q
 q0 is the initial state from where any input is processed (q0 ∈ Q).
 F is a set of final state/states of Q (F ⊆ Q).

Example 1
Let a deterministic finite automaton be →
Q = {a, b, c},
∑ = {0, 1},
q0 = {a},
F = {c}, and

Transition Table
Transition function δ as shown by the following table −

Present State Next State for Input 0 Next State for Input 1

a a B

b c A

c b C
Example 2:-

Minimize the following DFA


Solution
Make a transition Table.

π0={{5},{1,2,3,4}}
For input a, on {1,,2,3,4}ofπ0

For input b, on {1, 2, 3, 4} of π0

∴{1,2,3,4} will be split into {1,3}and{2,4}


∴π1={{5},{1,3},{2,4}}
For input symbol a on {1, 3} of π1
Similarly for input symbol a on {2, 4} of π1

For input symbol b on {1, 3} of π1

Similarly for input symbol b on {2, 4} of π1

Subset in π1 i.e., {1, 3} & {2, 4} will not be splitted.


πfinal={{5},{1,3},{2,4}}
There will be 3 states of DFA.
{5},{1,3}and{2,4}
Minimized DFA will be −
Application of Deterministic Finite Automata (DFA)
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.

2) Non-Deterministic Finite Automata (NFA)

In NDFA, for a particular input symbol, the machine can move to any combination
of the states in the machine. In other words, the exact state to which the machine
moves cannot be determined. Hence, it is called Non-deterministic Automaton. As
it has finite number of states, the machine is called Non-deterministic Finite
Machine or Non-deterministic Finite Automaton.
NFA is similar to DFA but includes the following features:
 It can transition to multiple states for the same input.
 It allows null (ϵ) moves, where the machine can change states without
consuming any input.
Formal Definition of an NDFA:-
An NDFA can be represented by a 5-tuple (Q, ∑, δ, q0, F) where –
 Q is a finite set of states.
 ∑ is a finite set of symbols called the alphabets.
 δ is the transition function where δ: Q × ∑ → 2Q
 q0 is the initial state from where any input is processed (q0 ∈ Q).
 F is a set of final state/states of Q (F ⊆ Q).

Example1:-
Let a non-deterministic finite automaton be →
Q = {a, b, c}
∑ = {0, 1}
q0 = {a}
F = {c}

The transition function δ as shown below −


Present State Next State for Input 0 Next State for Input 1

a a, b B

b C a, c

c b, c C

Its graphical representation would be as follows −


DFA vs NDFA

The following table lists the differences between DFA and NDFA.

DFA NDFA

The transition from a state can be to


The transition from a state is to a single
multiple next states for each input
particular next state for each input symbol.
symbol. Hence it is called non-
Hence it is called deterministic.
deterministic.

Empty string transitions are not seen in DFA. NDFA permits empty string transitions.

In NDFA, backtracking is not always


Backtracking is allowed in DFA
possible.

Requires more space. Requires less space.

A string is accepted by a NDFA, if at least


A string is accepted by a DFA, if it transits to
one of all possible transitions ends in a
a final state.
final state.
1. Moore Machines :-
In this type of machine the future state of the machine is decided by the current
state and current input symbols of the machine. The output symbol at a given time
depends only on the present state of the machine.
Moore Machines are finite state machines with output value and its output
depends only on the present state. It can be defined as (Q, q0, ∑, O, δ, λ) where:
 Q is a finite set of states.
 q0 is the initial state.
 ∑ is the input alphabet.
 O is the output alphabet.
 δ is the transition function which maps Q×∑ → Q.
 λ is the output function which maps Q → O.

In the Moore machine shown in Figure 1, the output is represented with each inp
ut state separated by /. The length of output for a Moore Machine is greater than
input by 1.
 Input: 1,1
 Transition: δ (q0,1,1)=> δ(q2,1)=>q2
 Output: 000 (0 for q0, 0 for q2 and again 0 for q2)

Conversion From Moore Machine to Mealy Machine


Let us take the Moore machine of Figure 1 and its transition table is shown in T
able 1.
Step 1. Construct an empty mealy machine using all states of the
Moore machine as shown in Table 2.

Input=0 Input=1

Present State Next State Output Next State Output

q0

q10

q11

q20

q21

Table 2
Step 2: Next state for each state can also be directly found from Moore machi
ne transition Table as:
Input=0 Input=1

Present State Next State Output Next State Output

q0 q10 q20

q10 q10 q21

q11 q10 q21

q20 q11 q20

q21 q11 q20

Table 3
Step 3: As we can see output corresponds to each input in the
Moore machine transition table. Use this to fill the Output entries.
Example: Output corresponding to q10, q11, q20 and q21 are 0, 1, 0 and 1 res
pectively.

Input=0 Input=1

Present State Next State Output Next State Output

q0 q10 0 q20 0

q10 q10 0 q21 1


Input=0 Input=1

q11 q10 0 q21 1

q20 q11 1 q20 0

q21 q11 1 q20 0

Table 4
Step 4: As we can see from Table 6, q10 and q11 are similar to each other (sa
me value of next state and Output for
different Inputs). Similarly, q20 and q21 are also similar. So, q11 and q21 can b
e eliminated.

Input=0 Input=1

Present State Next State Output Next State Output

q0 q10 0 q20 0

q10 q10 0 q21 1

q20 q11 1 q20 0

Table 5
This is the same mealy machine shown in Table 1. So we have converted Mealy
to Moore machine and converted back Moore to Mealy.
Note: Number of statAes in the mealy machine can’t be greater than
number of states in moore machine.
Example: The Finite state machine is
described by the following state diagram with A as starting state, where an arc
label is x / y and x stands for 1-bit input and y stands for 2-bit output.

Moore to Mealy Machines

Outputs the sum of the present and the previous bits of the input.
1. Outputs 01 whenever the input sequence contains 11.
2. Outputs 00 whenever the input sequence contains 10.
3. None of these.
Solution: Let us take different inputs and its output and check which option w
orks:
Input: 01
Output: 00 01 (For 0, Output is 00 and state is A. Then, for 1, Output is 01 and
state will be B)
Input: 11
Output: 01 10 (For 1, Output is 01 and state is B. Then, for 1, Output is 10 and
state is C)
As we can see, it is giving the binary sum of the
present and previous bit. For the first bit, the previous bit is taken as 0.

2. Mealy Machines:-
In the mealy machine the output symbol at a given time is a function of the present
input as well as the present state of the machine therefore the transition graph of
the mealy machine cannot be further simplified.
Mealy machines are also finite state machines with output value and their output
depends on the present state and current input symbol.
It can be defined as (Q, q0, ∑, O, δ, λ’) where:
 Q is a finite set of states.
 q0 is the initial state.
 ∑ is the input alphabet.
 O is the output alphabet.
 δ is the transition function which maps Q×∑ → Q.
 'λ’ is the output function that maps Q×∑→ O.
Figure 2: Mealy Machines
In the mealy machine shown in Figure 1, the output is represented with
each input symbol for each state separated by /. The length
of output for a mealy machine is equal to the length of input.
 Input: 1,1
 Transition: δ (q0,1,1)=> δ(q2,1)=>q2
 Output: 00 (q0 to q2 transition has Output 0 and q2 to q2 transition also ha
s Output 0)

Conversion From Mealy to Moore Machine


 Let us take the transition table of the mealy machine shown in Figure 2.
Input=0 Input=1

Present State Next State Output Next State Output

q0 q1 0 q2 0
Input=0 Input=1

q1 q1 0 q2 1

q2 q1 1 q2 0
Table 1
 Step 1. First, find out those states which have more than 1 output associat
ed with them. q1 and q2 are the states
which have both output 0 and 1 associated with them.
 Step 2 Create two states for these states. For q1, two states will be q10 (a
state with output 0) and q11 (a state with output 1).
Similarly, for q2, two states will be q20 and q21.
 Step 3: Create an empty Moore machine with a
newly generated state. For more machines, Output will be associated with
each state irrespective of inputs.

Input=0 Input=1

Present State Next State Next State Output

q0

q10

q11

q20

q21
Table 2
 Step 4: Fill in the entries of the next state using the
mealy machine transition table shown in Table 1. For q0 on input 0, the
next state is q10 (q1 with output 0).
 Similarly, for q0 on input 1, the next state is q20 (q2 with output 0).
 For q1 (both q10 and q11) on input 0, the next state is q10.
 Similarly, for q1(both q10 and q11), next state is q21.
 For q10, the output will be 0 and for q11, the output will be 1.
 Similarly, other entries can be filled.
Input=0 Input=1

Present State Next State Next State Output

q0 q10 q20 0

q10 q10 q21 0

q11 q10 q21 1

q20 q11 q20 0

q21 q11 q20 1


Table 3

Regular Expressions :-
A regular expression (RE) is way of describing a set of strings (language) using
specific symbols and rules.
A string is accepted by a finite automaton M is written as :
Where ,
L(M) = { x ∈ Σ | δ(s, x) ∈ F }*
 S = start state
 F = set of final (accept) states
 (s,x) = Transition on input string x
Regular set :-
 A set is said to be regular if it can be accepted by some finite automaton.
 Example:- The set of all strings over {a,b} that contain at least three
consecutive a’ s is regular.
Key Points :-
 Regular expressions are used to represent regular languages.
 They can be converted into finite automata (FA) and vice versa.
 They are widely used in pattern matching ,searching , and lexical analysis.

Operators OF Regular Expression:-


The definition of regular expression includes three basic
operators : Union , Concatenation and Closure.
If P and Q are regular expression then P+Q is a regular expression denoting the
union of L(p) and L(q) , that is ,
L(p+q) = L(p) U L(q)
The language defined by regular expression , r = p+q is L(p+q) = L(p) U L(q) ={ a,b}
Union
The union of two regular languages, L1 and L2, which are represented using L1 ∪
L2, is also regular and which represents the set of strings that are either in L1 or L2
or both.
Example:
L1 = (1+0).(1+0) = {00 , 10, 11, 01} and
L2 = {∈ , 100}
then L1 ∪ L2 = {∈, 00, 10, 11, 01, 100}.
2. Concatenation
The concatenation of two regular languages, L1 and L2, which are represented
using L1.L2 is also regular and which represents the set of strings that are formed
by taking any string in L1 concatenating it with any string in L2.
Example:
L1 = { 0,1 } and L2 = { 00, 11} then L1.L2 = {000, 011, 100, 111}.

Building Regular Expressions :-


We have defined regular expressions recursively using basis and induction.
Basic clause consists of two parts induction clause has four parts, one for each of
the three operators and one for the parentheses.
Every regular expression represents a language , as per the interpretation of
operators used in it the * and + , and of juxtaposition of expression as
concatenation . there is a simple correspondence between regular expression and
language they denote.
Also strings of length one or more are represented using positive closure instead of
* as L(a+)={a,aa,aaa,……} and L(b+)={b,bb,bbb…..}
Any string made up of any combination of a’s and b’s of any length are represented
using regular expression (a+b)*

String of specific finite length :-


 Strings of length one
r=(a+b),L(r)=(a,b)
 Strings of length two
r=(a+b)(a+b),L(r) = {aa,ab,ba,bb}
 Strings of length three
r=(a+b)(a+b)(a+b)
 Strings of length six
r= (a+b)(a+b)(a+b)(a+b)(a+b)(a+b)

Precedence of Operators:-
Regular expression operators have precedence and associativity associated with
like boolean algebras. These operators can be can be written as per their increasing
order of precedence as : +,* the closure (both * and +) have highest precedence .
Next in precedence comes the concatenation also known as dot operator ,denoted
as .

Characteristics of Regular Expressions :-


Regular expression is language defining notation, which is in terms of algebraic
decription.
The language accepted by finite automata regular language is easily decribed by
simple expressions called as regular expression .
It is more precise and formal as compared to any natural language.
In contrast to the transition graph regular expressions can be conveniently written
out in a line from left to right .
Regular expressions represent finite automata and regular [Link]
expressions are possible for a given finite automata hence a regular expression may
not be unique .

Algebric Laws of Regular Expressions :-


Like arithmetic expressions the regular expressions have a algebraic laws.
There are two situations when we need these laws .
One is situation in which we need to check whether the two regular expressions
are equivalent and the other is when we need to simplify regular expression.
In many situations we want to decide whether two regular expressions define the
same language are not .
r1 = (aa+ab+ba+bb)*
r2 = ((ba+ab)*(aa+bb)*)*

r2 = ((ba+ab)+(aa+bb))*
= (ba+ab+aa+bb)*

1. Identities & Annihilators:-


 Identity : leaves the operand unchanged .
Example :- a+0 = a, a.1 =a
 Annihilator : Makes result fixed (mostly 0)
Example :- a.0 = 0
For regular expressions:

εP=P (ε is identity of concatenation)


ϕ+L=L ; 𝜙𝐿=𝐿𝜙=𝜙

2. Idempotent Laws & Closures

R+R=R
RR∗=R∗R=R∗
(R*)* =R ∗

3. Commutative & Associative Laws


Union is commutative:
p+q=q+p
Concatenation is not commutative:
pq≠qp
Associative laws:
Union:
(p+q)+r=p+(q+r)
Concatenation: (pq)r=p(qr)

4. Distributive Laws
p(q+r)=pq+pr (Left distributive)
(p+q)r=pr+qr (Right distributive)

5. Miscellaneous Laws
(p ∗ q ∗) ∗=(p+q) ∗
(PQ) ∗P=P(QP) ∗

6. Arden’s Law

If equation is r = q + rp
r=rp* ,

Regular Expression
A regular expression represents a regular language and describes a regular
set.

Operators of Regular Expressions

OR (|): Binary Operator, Combines two patterns, Example: a|b → {a, b}.

Concatenation (.): Binary Operator, Joins two patterns in sequence,


Example: ab → {ab}.

Kleene Star (*): Unary Operator, Allows repetition (zero or more times),
Example: a* → {ε, a, aa, aaa, ...}.
Kleene Plus (+): Unary Operator, Allows repetition (one or more times),
Example: a+ → {a, aa, aaa, ...}.

LanguageOverΣ
Languages over an alphabet (Σ) can be classified as:
Finite Set:
Always a Regular Language.
Infinite Set:
L Over |Σ| = 1:
o If it forms an Arithmetic Progression (AP) → Regular Language.
o If it does not form an AP → Non-Regular.
L Over |Σ| > 1:
o Can be either a Regular Language or a Non-Regular Language,
depending on the conditions.

NFA with ε-Moves :-

A Non-deterministic Finite Automaton (NFA) with ε-moves allows transitions


without consuming any input symbol. These transitions are called epsilon (ε)
transitions, representing the ability to move from one state to another
spontaneously.

Key Points:
 An NFA with ε-moves can change states without reading any symbol.
 These automata are useful in proving the equivalence between regular
expressions and finite automata.
 ε-transitions simplify the construction of NFAs but do not increase the
expressive power because every NFA with ε-moves has an equivalent NFA
without them.

ε-Closure:-
The ε-closure of a state q is the set of states reachable from q by only ε-
transitions. It includes:
1. The state q itself.
2. All states reachable through a chain of ε-transitions from q.
This concept is crucial when converting an NFA with ε-moves to an
equivalent DFA or NFA without ε-moves.

Transition Function (δ):


The transition function is extended to include ε, and for each state and
symbol (including ε), it returns the set of reachable states.

Diagram:-
Consider the following NFA with ε-transitions:

0 ε ε
q0 ----> q1 ----> q2
^
|
Start

 q0 is the start state.


 There is a transition from q0 to q1 on input 0.
 There are ε-transitions from q1 to q2.

Transition Table (δ):


State 0 1 2 Ε

q0 {q1} ∅ ∅ {q1}

q1 ∅ {q1} ∅ {q2}

q2 ∅ ∅ {q2} ∅

ε-Closure:
The ε-closure of a state q is the set of all states reachable from q via any
number of ε-transitions.
 ε-closure(q0) = {q0, q1, q2}
 ε-closure(q1) = {q1, q2}
 ε-closure(q2) = {q2}

Key Points:
 ε-transitions allow an automaton to spontaneously change states.
 They are useful for breaking down complex transitions and for converting
regular expressions into NFAs.
 Every NFA with ε-moves can be converted into an equivalent DFA
(deterministic finite automaton).

Conversion from NFA (with ε-moves) to DFA :-


To convert a Non-deterministic Finite Automaton (NFA) with ε-moves into a
Deterministic Finite Automaton (DFA), we use two primary methods:

1. Indirect Method:
1. Convert NFA with ε-moves to NFA without ε-moves:
In the first method , we can convert NFA with ε moves and then NFA without ε
Moves is to the DFA i.e NFA with ε moves to DFA conversion is achieved in 2
succesive phases
Use ε-closure to remove ε-transitions.
Update transition functions accordingly.

2. Convert resulting NFA to DFA:


Apply subset construction method (powerset construction) to build an
equivalent DFA.
NFA (with ε) → NFA (without ε) → DFA
3. Direct Method:
The direct method of converting NFA with ε moves to DFA start with initial state
and go on adding state as are required starting with the start state Qs we divide
same of each state in 2 parts 1st as the original state and the 2nd part as the ε
closure of the state itself. We shall see the method by considering one example.

In this method, we directly construct the DFA from the given NFA with ε-moves:
The ε-closures are used directly during subset construction.
Transitions in the DFA are defined over sets of ε-closures.

Regular Expression And Finite Automata


We have defined regular language as those that are recognized by finite automata
and have shown that they are also those languages that are represented by regular
expression and that are defined by regular grammar (regular grammar we shall
study in next chapter)
For every DFA there is a regular expression denoting its language.
Regular expression is the language which is used to describe the language and is
accepted by finite automata. Regular expressions are the most effective way to
represent any language. Let Σ be an alphabet which denotes the input set.
Regular Expression to DFA
Method1 :- Indirect Method
In this method we construct an NFA with ε transition from a regular expression and
then we convert the ε into DFA using the any of the methods .

First, an ε-NFA is created from the regular expression.

The ε-NFA is then converted to a DFA by eliminating ε-transitions.

This method is widely taught due to its step-by-step clarity

Method 2:- Direct Method :-


We can also construct a DFA directly from regular expression in this process a
syntax free is build for regular expression and then four function (nullable ,lastpos
and followpos) are computed by traversing .
A syntax tree is created from the regular expression.

Functions like nullable, firstpos, lastpos, and followpos are calculated.

A DFA is constructed from the syntax tree without intermediate ε-NFA.

RE To DFA (Indirect Method)


Algorithm for RE to DFA (Indirect Method)

 Step 1: Parse the regular expression into subexpressions.


 Step 2: Construct basic NFAs for each symbol (including ε).
 These are combined inductively to form larger NFAs.
 The final DFA is derived from the constructed NFA using standard conversion
methods.

RE to DFA – Direct Method


The Direct Method constructs a DFA without creating an intermediate ε-NFA.

Steps:

 Construct Syntax Tree:


Represent the expression as a tree with leaves labeled from left to right.
 Compute Functions:
o nullable: whether a node can generate an empty string.
o firstpos: possible starting positions.
o lastpos: possible ending positions.
 Compute followpos:
Which positions can follow each symbol position.

Build DFA:
Use followpos to define states and transitions.
Detailed Explanation of Functions

 Nullable

Determines if a subexpression can produce the empty string (ε).

 Firstpos and Lastpos

firstpos: positions where a string can begin.

lastpos: positions where it can end.

 Followpos
Tracks how symbols are connected in expressions.

Used to build the DFA’s transition table.

Table – Rules for Computing Nullable, Firstpos, and Lastpos


This table defines how to compute nullable, firstpos, and lastpos for different types
of nodes in the syntax tree of a regular expression.

Node
Nullable(n) Firstpos(n) Lastpos(n)
Type

ε True (T) ∅ ∅

symbol i False (F) {i} {i}

Nullable(L) or
L∪R Firstpos(L) ∪ Firstpos(R) Lastpos(L) ∪ Lastpos(R)
Nullable(R)

Nullable(L) and if nullable(L), Firstpos(L) ∪ if nullable(R), Lastpos(L) ∪


L·R
Nullable(R) Firstpos(R), else Firstpos(L) Lastpos(R), else Lastpos(R)

L* True (T) Firstpos(L) Lastpos(L)


Followpos Function

Definition:

The followpos function identifies which positions in the expression can


follow a given position.

It’s essential in determining how the automaton transitions from one


state to another when reading input symbols.

➤ Rules

1. Cat node rule:


o If node nnn is a concatenation node with left child LLL and
right child RRR, and iii is in lastpos of LLL, then all positions in
firstpos of RRR are in followpos of iii.
2. Star node rule:
o If node nnn is a star node and iii is in lastpos of nnn, then all
positions in firstpos of nnn are in followpos of iii.

➤ Application:

 Traverse the tree in depth-first order.


 Apply rules where concatenation or star operations occur.
 Build transitions accordingly.
Algorithm PROC-DFA for DFA Construction
Inputs:

 DDD: Set of states


 DtranDtranDtran: Transition table for DDD

➤ Algorithm Steps:

Step 1: Define start state

 The start state is the firstpos of the root node.


 Final states are those containing the marker position associated with the end
of the expression.

Step 2: Compute transitions

 While there’s an unmarked state TTT in DDD:


1. Mark TTT
2. For every input symbol aaa in the alphabet ΣΣΣ:
 Find all positions PPP in TTT where symbol aaa occurs.
 Compute UUU, the union of followpos of these positions.
 Add UUU to DDD if it’s a new state.

Step 3: Stop

 The process ends when all states have been marked.

DFA to Regular Expression Conversions


Methods:

1. Algebraic Method: Express transitions as equations and solve for the regular
expression.
2. State Elimination Method: Remove states one by one, combining paths into
regular expressions.
Why It Matters:

 Any language recognized by a DFA can be expressed as a regular expression.


 Forms the theoretical basis for lexical analyzers in programming languages.

Theorem 1.2 – DFA Language Equivalence


Statement:
If a language LLL is accepted by a DFA, it can be expressed by some regular
expression.

Proof Outline:

 Define M=(Q,Σ,δ,q1,F)M = (Q, Σ, δ, q_1, F)M=(Q,Σ,δ,q1,F) where:


o QQQ: set of states
o ΣΣΣ: input alphabet
o δδδ: transition function
o q1q_1q1: start state
o FFF: set of final states
 Using state elimination or algebraic techniques, any DFA can be converted to
a regular expression.

Introduction to State/Loop Elimination


State elimination is a systematic method for deriving the regular expression
equivalent to a given finite automaton (FA). By successively removing states and
adjusting the transitions with appropriate regular expressions, we eventually
reduce the automaton to a simpler form—either a two-state or one-state
automaton—from which the final regular expression is easily derived.
Algorithm for State Elimination

Step 1

 Identify accepting states in the DFA.


 Apply the reduction process, replacing transitions with equivalent regular
expression labels.
 Eliminate intermediate states while preserving the language.

Step 2

 Reduce the automaton to two states: a start state and an accepting state.

Step 3

 If the start state is also the final state, eliminate further states to obtain a
one-state automaton.

Step 4

 For automata with multiple final states, compute expressions for each and
sum them to obtain the final expression.

Procedure for Eliminating a State

When removing a state S from the automaton:

 Consider all paths passing through S.


 Combine paths using concatenation and closure operators.
 Update direct arcs with new regular expressions that represent removed
paths.

Key principles:

 Use r₁ + r₂ to represent alternative paths.


 Use r* for loops where transitions cycle through a state multiple times.
Arden's Theorem in Theory of Computation

A Regular Expression (RE) is a way to describe patterns of strings using


symbols and operators like union, concatenation, and star. A Deterministic
Finite Automaton (DFA) is a machine that reads input strings and decides if
they match the pattern by moving through a set of defined states without
any ambiguity. There are two methods for converting a Regular Expression
(RE) to a Deterministic Finite Automaton (DFA):
1. State/Loop Elimination
2. Arden’s Theorem

Arden’s Theorem
Theorem:
Let P, Q, and R be the regular expressions on Σ. If P does not contain ε, the
equation R = Q + RP has a unique solution given by R = QP*.

Explanation of Terms:-
 Q, P: Regular expressions.
 R: The solution for the given equation.
 Q: The regular expression independent of P.
 P: The regular expression associated with R.

The theorem allows R to be expressed in terms of Q and P using the Kleene


star operation. Whenever we get any equation in the form of R = Q + RP,
then we can directly replace it with R = QP*.

Proof of Arden’s Theorem


We start with the equation:
R=Q+RP
Substituting R = Q + RP, we get:
R = Q + (Q + RP)P
Again, substituting R = Q + RP, we get:
R = Q + QP + RPP
Now, if we keep substituting the value of R repeatedly, we get:
R = Q + QP + QP² + QP³ + ...
This can be factored as:
R = Q (ε + P + P² + P³ + ...)
Since P (P star)* represents (ε + P + P² + P³ + ...),
we can simplify the equation to:
R = QP*
Thus,
R = QP* is the unique solution of the equation R = Q + RP.
Note : Arden's theorem is used to convert given finite automata to a regular
expression.
To understand this theorem, we will solve an example.

Example for Arden's Theorem


We are given the following set of equations representing regular sets, with
states q0, q1, and q2:
1. q0 = ϵ + q11 + q2(0 + 1) ------------ (A)
2. q1 = q00 + q12 ------------ (B)
3. q2 = q01 + q10 ------------ (C)

Step 1: Substituting q2 from Eq. (C) into Eq. (A)


Substitute the expression for q2 from equation (C) into equation (A):
q0 = ϵ + q11 + (q01 + q10)(0 + 1)
Simplifying the right-hand side:
 q0 = ϵ + q11 + q01(0 + 1) + q10(0 + 1)
 q0 = ϵ + q11 + q01 + q11(0 + 1)
This simplifies to the form:
q0 = ϵ + q1(1 + 00 + 01) + q01(0 + 1)
This is of the form R = Q + RP, where:
 R = q0
 Q = [ϵ + q1(1 + 00 + 01)]
 P = 1(0+1)

Step 2: Solving for q0


The solution to this recursive equation is:
R = QP∗
Thus, the expression for q0 becomes:
q0 = [ϵ + q1(1 + 00 + 01)](1(0 + 1))∗------------ (D)

Step 3: Substituting q0 from Eq. (D) into Eq. (B)


Now, substitute the value of q0 from Eq. (D) into Eq. (B):
q1 = q02 + [ϵ + q1(1 + 00 + 01)](1(0 + 1))∗
Simplifying:
q1 = 1(0 + 1)∗0 + q1[2 + (1 + 00 + 01)(1(0 + 1))∗0]
This is again of the form R=Q+RP, where:
 R = q1
 Q = 1(0+1)∗0
 P = [2 + (1 + 00 + 01)(1(0 + 1))∗0]

Step 4: Solving for q1


The solution to this is:
q1 =1(0 + 1)∗0[2 + (1 + 00 + 01)(1(0 + 1))∗0]∗

Step 5: Substituting q1 into Eq. (D)


Now, substitute the expression for q1 into Eq. (D):
q0 = [ϵ + 1(0 + 1)∗0[2 + (1 + 00 + 01)]]
Simplifying:
q0 = [(1(0 + 1)∗)0]∗(1 + 00 + 01)(1(0 + 1))∗

Final Regular Expression


Thus, the regular expression describing the machine is given by:
q0 + q1=[ϵ + (1(0 + 1)∗0)[2 + (1 + 00 + 01)(1(0 + 1))∗0]∗] + (1 + 00 + 01)(1(0 +
1))∗ + (1(0 + 1)∗0[2 + (1 + 00 + 01)(1(0 + 1))∗0]∗)∗
What is Pumping Lemma?
Pumping Lemma is a property of regular and context-free languages. It states
that for any language in these classes, there exists a length such that any
string longer than this length can be "pumped." It means that the parts of
the string can be repeated, and the resulting string will still belong to the
same language.

Importance of the Pumping Lemma


We have seen the basic idea, but why we need this thing in automata theory?

Language Classification − it helps in distinguishing between regular and non-


regular languages and context-free and non-context-free languages.
Proof Tool − It is used to prove that certain languages do not belong to the
regular or context-free class.
Understanding Language Structure − It gives insights into the repetitive
structure of languages.
We already mentioned that the pumping lemma are used for regular
languages as well as context free languages. So let us see these two aspects
in very basic form.

Pumping Lemma for Regular Languages


Regular languages are those that can be represented by finite automata. The
Pumping Lemma for regular languages states –
For any regular language L, there exists a length p (pumping length) such that
any string s in L with length at least p can be divided into three parts, s = xyz,
satisfying the following conditions –

The length of xy is at most p.


The length of y is at least 1 (y is not empty).
For all i ≥ 0, the string xyi z is in L.

How to Use Pumping Lemma for Regular Languages?


Follow the steps given below –

Assume L is regular − Start by assuming the language L is regular.


Find a string s in L − Choose a string s from L that is at least as long as the
pumping length p.
Divide s into x, y, and z − Split the string s into three parts.
Check conditions − Verify if the conditions of the Pumping Lemma hold.
Find a contradiction − If you can find an such that xyz is not in L, then L is not
regular.

You might also like