Unit I
Unit I
Introduction to formal proof – Additional forms of proof – Inductive proofs –Finite Automata (FA) –
Deterministic Finite Automata (DFA)– Non-deterministic Finite Automata (NFA) – Finite Automata with
Epsilon transitions.
In theoretical computer science, the theory of computation is the branch that deals with
whether and how efficiently problems can be solved on a model of computation, using an
algorithm. The field is divided into three major branches: automata theory, computability theory
and computational complexity theory.
In order to perform a rigorous study of computation, computer scientists work with a
mathematical abstraction of computers called a model of computation. There are several
models in use, but the most commonly examined is the Turing machine.
Automata theory
In theoretical computer science, automata theory is the study of abstract machines (or
more appropriately, abstract 'mathematical' machines or systems) and the computational
problems that can be solved using these machines. These abstract machines are called automata.
This automaton consists of
• states (represented in the figure by circles),
• and transitions (represented by arrows).
As the automaton sees a symbol of input, it makes a transition (or jump) to another state,
according to its transition function (which takes the current state and the recent symbol as its
inputs).
Uses of Automata: compiler design and parsing.
Introduction to formal
proof: Basic Symbols used :
U – Union ∩- Conjunction ϵ - Empty String Φ – NULL set
7- negation ‘ – compliment = > implies
Logic relations:
a b = > 7a U b
7(a∩b)=7a U 7b
Relations:
Let a and b be two sets a relation R contains aXb.
Relations used in TOC:
Reflexive: a = a
Symmetric: aRb = > bRa
Transition: aRb, bRc = > aRc
If a given relation is reflexive, symmentric and transitive then the relation is called equivalence
relation.
Deductive proof: Consists of sequence of statements whose truth lead us from some
initial statement called the hypothesis or the give statement to a conclusion statement.
For any sets a,b,c if a∩b = Φ and c is a subset of b the prove that a∩c
=Φ Given : a∩b=Φ and c subset b
Assume: a∩c Φ
Then
= > a∩b Φ = > a∩c=Φ(i.e., the assumption is wrong)
Proof by mathematical Induction:
Languages :
Symbols :
Symbols are indivisible objects or entity that cannot be defined. That is, symbols are the
atoms of the world of languages. A symbol is any single object such as , a, 0, 1, #,
begin, or do.
Alphabets :
Example :
Example : 0110, 11, 001 are three strings over the binary alphabet { 0, 1 } .
aab, abcb, b, cc are four strings over the alphabet { a, b, c }.
It is not the case that a string over some alphabet should contain all the symbols from
the alphabet. For example, the string cc over the alphabet { a, b, c } does not contain
the symbols a and b. Hence, it is true that a string over an alphabet is also a string over
any superset of that alphabet.
Length of a string :
The number of symbols in a string w is called its length, denoted by |w|.
Convention : We will use small case letters towards the beginning of the English
alphabet to denote symbols of an alphabet and small case letters towards the end to
denote strings over an alphabet. That is, (symbols) and
are strings.
Example : Consider the string 011 over the binary alphabet. All the prefixes, suffixes
and substrings of this string are listed below.
Note that x is a prefix (suffix or substring) to x, for any string x and ε is a prefix (suffix
or substring) to any string.
In the above example, all prefixes except 011 are proper prefixes.
Powers of Strings : For any string x and integer , we use to denote the string
formed by sequentially concatenating n copies of x. We can also give an inductive
definition of as follows: = e, if
n = 0 ; otherwise
Powers of Alphabets :
We write (for some integer k) to denote the set of strings of length k with
symbols from . In other words,
= { w | w is a string over and | w | = k}. Hence, for any alphabet, denotes the set
of all strings of length zero. That is, = { e }. For the binary alphabet { 0, 1 } we
have the following.
The set contains all the strings that can be generated by iteratively concatenating
symbols from any number of times.
Example : If = { a, b }, then = { ε, a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, …}.
Please note that if , then that is . It may look odd that one can
proceed from the empty set to a non-empty set by iterated concatenation. But there is a
reason for this and we accept this convention
The set of all nonempty strings over an alphabet is denoted by . That is,
Note that is infinite. It contains no infinite strings but strings of arbitrary lengths.
Reversal :
For any string the reversal of the string is .
7
CS2303 THEORY OF COMPUTATION
Languages :
A language over an alphabet is a set of strings over that alphabet. Therefore, a
language L is any subset of . That is, any is a language.
Example :
Set operations on languages : Since languages are set of strings we can apply set
operations to languages. Here are some simple examples (though there is nothing new
in it).
Example : { 0, 11, 01, 011 } { 1, 01, 110 } = { 0, 11, 01, 011, 111 }
Complement : Usually, is the universe that a complement is taken with respect to.
Thus for a language L, the complement is L(bar) = { | }.
Example : Let L = { x | |x| is even }. Then its complement is the language { | |x|
is odd }.
Similarly we can define other usual set operations on languages like relative
complement, symmetric difference, etc.
Reversal of a language :
The reversal of a language L, denoted as , is defined as: .
Example :
8
CS2303 THEORY OF COMPUTATION
Note that ,
1. in general.
2.
3.
and so on.
= ( Union n in N )
Thus is the set of all strings derivable by any number of concatenations of strings
in L. It is also useful to define
(Generates) (Recognizes)
Grammar Language Automata
An automata is an abstract computing device (or machine). There are different varities
of such abstract machines (also called models of computation) which can be defined
mathematically.
10
CS2303 THEORY OF COMPUTATION
• The automaton can produce output of some form. If the output in response to an
input string is binary (say, accept or reject), then it is called an accepter. If it
produces an output sequence in response to an input sequence, then it is called
a transducer(or automaton with output).
• The automaton may have a temporary storage, consisting of an unlimited
number of cells, each capable of holding a symbol from an alphabet ( whcih may
be different from the input alphabet). The automaton can both read and change
the contents of the storage cells in the temporary storage. The accusing
capability of this storage varies depending on the type of the storage.
• The most important feature of the automaton is its control unit, which can be
in any one of a finite number of interval states at any point. It can change state
in some defined manner determined by a transition function.
11
CS2303 THEORY OF COMPUTATION
Finite Automata
Let us first give some intuitive idea about a state of a system and state transitions
before describing finite automata.
Some examples of state transition systems are: digital systems, vending machines, etc.
A system containing only a finite number of states and transitions among them is
called a finite-state transition system.
1. A tape to hold the input string. The tape is divided into a finite number of cells.
Each cell holds a symbol from .
2. A tape head for reading symbols from the tape
3. A control , which itself consists of 3 things:
o finite number of states that the machine is allowed to be in (zero or
more states are designated as accept or final states),
o a current state, initially set to a start state,
12
CS2303 THEORY OF COMPUTATION
An automaton processes a string on the tape by repeating the following actions until
the tape head has traversed the entire string:
1. The tape head reads the current tape cell and sends the symbol s found there to
the control. Then the tape head moves to the next cell.
2. he control takes s and the current state and consults the state transition
function to get the next state, which becomes the new current state.
Once the entire string has been processed, the state in which the automation enters is
examined. If it is an accept state , the input string is accepted ; otherwise, the string is
rejected . Summarizing all the above we can formulate the following formal definition:
Acceptance of Strings :
The language accepted or recognized by a DFA M is the set of all strings accepted by
That is, is the state the automation reaches when it starts from the state q and
finish processing the string w. Formally, we can give an inductive definition as follows:
The language of the DFA M is the set of strings that can take the start state to one of
the accepting states i.e.
L(M) = { | M accepts w }
={ | }
Example 1 :
It is a formal description of a DFA. But it is hard to comprehend. For ex. The language
of the DFA is any string over { 0, 1} having at least one 1
We can describe the same DFA by transition table or state transition diagram as
following:
Transition Table :
0 1
14
CS2303 THEORY OF COMPUTATION
Explanation : We cannot reach find state w/0 or in the i/p string. There can be any
no. of 0's at the beginning. ( The self-loop at on label 0 indicates it ). Similarly
there can be any no. of 0's & 1's in any order at the end of the string.
Transition table :
0 1
A state transition diagram or simply a transition diagram is a directed graph which can
be constructed as follows:
15
CS2303 THEORY OF COMPUTATION
5.
6. Here is an informal description how a DFA operates. An input to a DFA can be
any string . Put a pointer to the start state q. Read the input string w from
left to right, one symbol at a time, moving the pointer according to the transition
function, . If the next symbol of w is a and the pointer is on state p, move the
pointer to . When the end of the input string w is encountered, the pointer is
on some state, r. The string is said to be accepted by the DFA if and rejected if
. Note that there is no formal mechanism for moving the pointer.
7. A language is said to be regular if L = L(M) for some DFA M.
Basis :
i) is a RE
ii) is a RE
iii) , a is RE.
Recursive Step :
i)
ii)
16
CS2303 THEORY OF COMPUTATION
iii)
iv)
Notation : If r is a RE over some alphabet then L(r) is the language associate with r .
We can define the language L(r) associated with (or described by) a REs as follows.
= L(0)*L(0) ∪ L(1)
={ , 0,00,000,........} {0,1}
Precedence Rule
2) Use a set of precedence rules to evaluate the options of REs in some order.
Like other algebras mod in mathematics.
i) The star operator precedes concatenation and concatenation precedes union (+)
operator.
ii) It is also important to note that concatenation & union (+) operators are
associative and union operation is commutative.
Using these precedence rule, we find that the RE ab+c represents the language
L(ab) L(c) i.e. it should be grouped as ((ab)+c).
18
CS2303 THEORY OF COMPUTATION
Example : It is easy to see that the RE (0+1)*(0+11) represents the language of all
strings over {0,1} which are either ended with 0 or 11.
Example : The regular expression r =(00)*(11)*1 denotes the set of all strings with an
even number of 0's followed by an odd number of 1's i.e.
Note : The notation is used to represent the RE rr*. Similarly, represents the RE
rr, denotes r, and so on.
Exercise : Give a RE r over {0,1} s.t. L(r)={ has at least one pair
of consecutive 1's}
Solution : Every string in L(r) must contain 00 somewhere, but what comes before
and what goes before is completely arbitrary. Considering these observations we can
write the REs as (0+1)*11(0+1)*.
Example : Consider the RE 0*10*10*. It is not difficult to see that this RE describes the
set of strings over {0,1} that contains exactly two 1's. The presence of two 1's in the
RE and any no of 0's before, between and after the 1's ensure it.
Example : Consider the language of strings over {0,1} containing two or more 1's.
Solution : There must be at least two 1's in the RE somewhere and what comes before,
between, and after is completely arbitrary. Hence we can write the RE as
(0+1)*1(0+1)*1(0+1)* . But following two REs also represent the same language, each
ensuring presence of least two 1's somewhere in the string
i) 0*10*1(0+1)*
ii) (0+1)*10*10*
19
CS2303 THEORY OF COMPUTATION
Alternative Solution :
The language can be viewed as repetitions of the strings 0 and 01. Hence get the RE as
r = (0+10)*(1+ ).This is a shorter expression but represents the same language.
Recall that, language that is accepted by some FAs are known as Regular language.
The two concepts : REs and Regular language are essentially same i.e. (for) every
regular language can be developed by (there is) a RE, and for every RE there is a
Regular Langauge. This fact is rather suprising, because RE approach to describing
language is fundamentally differnet from the FA approach. But REs and FA are
equivalent in their descriptive power. We can put this fact in the focus of the following
Theorem.
This Theorem has two directions, and are stated & proved below as a separate lemma
RE to FA :
Proof : To prove the lemma, we apply structured index on the expression r. First, we
show how to construct FA for the basis elements: , and for any . Then we show
how to combine these Finite Automata into Complex Automata that accept the Union,
Concatenation, Kleen Closure of the languages accepted by the original smaller
automata.
20
CS2303 THEORY OF COMPUTATION
Use of NFAs is helpful in the case i.e. we construct NFAs for every REs which
are represented by transition diagram only.
Basis :
Since the start state is also the accept step, and there is no any transition defined, it
will accept the only string and nothing else.
• Case (iii) : r = a for some . Then L(r) = {a}, and the following NFA
N accepts L(r).
Induction :
21
CS2303 THEORY OF COMPUTATION
Assume that the start of the theorem is true for REs and . Hence we can assume
that we have automata and that accepts languages denoted by REs and ,
respectively i.e. and . The FAs are
represented schematically as shown below.
Each has an initial state and a final state. There are four cases to consider.
Create a new (initial) start state and give - transition to the initial state of and
.This is the initial state of .
• Create a final state and give -transition from the two final state of
and . is the only final state of and final state of and will be
ordinary states in .
• All the state of and are also state of .
22
CS2303 THEORY OF COMPUTATION
= by following transition of
Starts at initial state and enters the start state of either or follwoing the
transition i.e. without consuming any input. WLOG, assume that, it enters the start state
of . From this point onward it has to follow only the transition of to enter the final
state of , because this is the only way to enter the final state of M by following the
e-transition.(Which is the last transition & no input is taken at hte transition). Hence the
whole input w is considered while traversing from the start state of to the final
state of . Therefore must accept .
Say, or .
WLOG, say
Therefore when process the string w , it starts at the initial state and enters the final
state when w consumed totally, by following its transition. Then also accepts w, by
starting at state and taking -transition enters the start state of -follows the moves
of to enter the final state of consuming input w thus takes -transition to
. Hence proved
Case(iv) : Let =( ). Then the FA is also the FA for ( ), since the use of
parentheses does not change the language denoted by the expression
the behaviour of a process might depend on some messages from other processes
that might arrive at arbitrary times with arbitrary contents.
It is easy to construct and comprehend an NFA than DFA for a given regular
language. The concept of NFA can also be used in proving many theorems and
results. Hence, it plays an important role in this subject.
In the context of FA nondeterminism can be incorporated naturally. That is, an NFA is
defined in the same way as the DFA but with the following two exceptions:
• multiple next state.
• - transitions.
- transitions :
In an -transition, the tape head doesn't do anything- it doesnot read and it doesnot move.
However, the state of the automata can be changed - that is can go to zero, one
or more states. This is written formally as implying that the next
state could by any one of w/o consuming the next input symbol.
Acceptance :
Informally, an NFA is said to accept its input if it is possible to start in some start state
and process , moving according to the transition rules and making choices along the way
whenever the next state is not uniquely defined, such that when is completely processed
(i.e. end of is reached), the automata is in an accept state. There may be several
possible paths through the automation in response to an input since the start state is not
determined and there are choices along the way because of multiple next states. Some of
these paths may lead to accpet states while others may not. The
25
CS2303 THEORY OF COMPUTATION
automation is said to accept if at least one computation path on input starting from at
least one start state leads to an accept state- otherwise, the automation rejects input
. Alternatively, we can say that, is accepted iff there exists a path with label from
some start state to some accept state. Since there is no mechanism for determining which
state to start in or which of the possible next moves to take (including the - transitions) in
response to an input symbol we can think that the automation is having some "guessing"
power to chose the correct one in case the input is accepted
Example 1 : Consider the language L = { {0, 1}* | The 3rd symbol from the right
is 1}. The following four-state automation accepts L.
The m/c is not deterministic since there are two transitions from state on input 1 and
no transition (zero transition) from on both 0 & 1.
For any string whose 3rd symbol from the right is a 1, there exists a sequence of legal
transitions leading from the start state q, to the accept state . But for any string
where 3rd symbol from the right is 0, there is no possible sequence of legal
tranisitons leading from and . Hence m/c accepts L. How does it accept any string
L?
From the discussion of the acceptance by an NFA, we can give the formal definition of a
language accepted by an NFA as follows :
given by .
That is, L(N) is the set of all strings w in such that contains at least one
accepting state.
26
CS2303 THEORY OF COMPUTATION
Removing ϵ-transition:
- transitions do not increase the power of an NFA . That is, any - NFA ( NFA with
transition), we can always construct an equivalent NFA without -transitions. The
equivalent NFA must keep track where the NFA goes at every step during
computation. This can be done by adding extra transitions for removal of every -
transitions from the - NFA as follows.
We construct
i.e.
27
CS2303 THEORY OF COMPUTATION
Basis : , then
But by definition of .
By definition of extension of
By inductions hypothesis.
Assuming that
By definition of
Since
28
CS2303 THEORY OF COMPUTATION
If (and thus is not in F ), then with leads to an accepting state in N' iff it
lead to an accepting state in N ( by the construction of N' and N ).
Let . If w cannot lead to in N , then . (Since can add transitions to get an accept
state). So there is no harm in making an accept state in N'.
Transition Diagram
0 1
Transition diagram for ' for the equivalent NFA without - moves
29
CS2303 THEORY OF COMPUTATION
0 1
Since the start state q0 must be final state in the equivalent NFA .
-closures:
The concept used in the above construction can be made more formal by defining the
-closure for a state (or a set of states). The idea of -closure is that, when moving
from a state p to a state q (or from a set of states Si to a set of states Sj ) an input
, we need to take account of all -moves that could be made after the transition.
Formally, for a given state q,
-closures:
-closures:
So, in the construction of equivalent NFA N' without -transition from any NFA with
30
CS2303 THEORY OF COMPUTATION
It is worth noting that a DFA is a special type of NFA and hence the class of languages
accepted by DFA s is a subset of the class of languages accepted by NFA s.
Surprisingly, these two classes are in fact equal. NFA s appeared to have more power
than DFA s because of generality enjoyed in terms of -transition and multiple next
states. But they are no more powerful than DFA s in terms of the languages they
accept.
Proof: A DFA is just a special type of an NFA . In a DFA , the transition functions is
defined from whereas in case of an NFA it is defined from and
be a DFA . We construct an equivalent NFA
as follows.
i. e
If and
Then it is clear from the above construction of N that there is a sequence of states (in N)
Hence ,
Given any NFA we need to construct as equivalent DFA i.e. the DFA need to simulate
the behaviour of the NFA . For this, the DFA have to keep track of all the states where
the NFA could be in at every step during processing a given input string.
31
CS2303 THEORY OF COMPUTATION
There are possible subsets of states for any NFA with n states. Every subset
corresponds to one of the possibilities that the equivalent DFA must keep track of. Thus,
the equivalent DFA will have states.
The formal constructions of an equivalent DFA for any NFA is given below. We
first consider an NFA without transitions and then we incorporate the affects of
transitions later.
as follows
i.e.
where
That is,
To show that this construction works we need to show that L(D)=L(N) i.e.
Or,
32
CS2303 THEORY OF COMPUTATION
So, by definition.
Inductive step
Now,
Now, given any NFA with -transition, we can first construct an equivalent NFA without
-transition and then use the above construction process to construct an equivalent
DFA , thus, proving the equivalence of NFA s and DFA s..
It is also possible to construct an equivalent DFA directly from any given NFA with -
transition by integrating the concept of -closure in the above construction.
- closure :
33
CS2303 THEORY OF COMPUTATION
In the equivalent DFA , at every step, we need to modify the transition functions to
keep track of all the states where the NFA can go on -transitions. This is done by
Besides this the initial state of the DFA D has to be modified to keep track of all the
states that can be reached from the initial state of NFA on zero or more -transitions.
This can be done by changing the initial state to -closure ( ).
It is clear that, at every step in the processing of an input string by the DFA D , it enters
a state that corresponds to the subset of states that the NFA N could be in at that
particular point. This has been proved in the constructions of an equivalent NFA for any
-NFA
If the number of states in the NFA is n , then there are states in the DFA . That
is, each state in the DFA is a subset of state of the NFA .
But, it is important to note that most of these states are inaccessible from the start state
and hence can be removed from the DFA without changing the accepted language. Thus,
in fact, the number of states in the equivalent DFA would be much less
than .
Example : Consider the NFA given below.
0 1
{ }
34
CS2303 THEORY OF COMPUTATION
0 1
1. If is the start state of the NFA, then make - closure ( ) the start state of
the equivalent DFA . This is definitely the only accessible state.
2. If we have already computed a set of states which are accessible. Then
Following these steps in the above example, we get the transition table given below
36
CS2303 THEORY OF COMPUTATION