0% found this document useful (0 votes)
4 views

ATC Module 1 Notes 2022

The document outlines the vision and mission of RNS Institute of Technology and its Department of Information Science and Engineering, focusing on high-quality education and professional development. It details the program educational objectives, outcomes, and specific outcomes for graduates in Information Science, emphasizing problem-solving, applied engineering skills, and lifelong learning. Additionally, it introduces the course objectives and outcomes for Automata Theory and Computability, highlighting key concepts, applications, and terminologies related to computation and formal languages.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

ATC Module 1 Notes 2022

The document outlines the vision and mission of RNS Institute of Technology and its Department of Information Science and Engineering, focusing on high-quality education and professional development. It details the program educational objectives, outcomes, and specific outcomes for graduates in Information Science, emphasizing problem-solving, applied engineering skills, and lifelong learning. Additionally, it introduces the course objectives and outcomes for Automata Theory and Computability, highlighting key concepts, applications, and terminologies related to computation and formal languages.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Automata Theory & Computability [18CS54 CBCS]

RNS INSTITUTE OF TECHNOLOGY


Dr. VISHNUVARDHAN ROAD, CHANNASANDRA, BENGALURU -560 098

Department of Information Science and Engineering

VISION of the College


Building RNSIT into a World - Class Institution

MISSION of the College

To impart high quality education in Engineering, Technology and Management with a difference, enablingstudents
to excel in their career by
1. Attracting quality Students and preparing them with a strong foundation in fundamentals so as to achieve
distinctions in various walks of life leading to outstanding contributions.
2. Imparting value based, need based, and choice based and skill based professional education to the aspiringyouth
and carving them into disciplined, World class Professionals with social responsibility.
3. Promoting excellence in Teaching, Research and Consultancy that galvanizes academic consciousnessamong
Faculty and Students.
4. Exposing Students to emerging frontiers of knowledge in various domains and make them suitable for
Industry, Entrepreneurship, Higher studies, and Research & Development.
5. Providing freedom of action and choice for all the Stake holders with better visibility.

VISION of the Department

Fostering winning professionals of Strong Informative Potentials.

MISSION of the Department

Imparting high quality education in the area of Information Science so as to graduate the students with good
fundamentals, "Information System Integration", "Software Creation" capability & suitably train them to thrive in
Industries, higher schools of learning and R & D centers with a comprehensive perspective.

PROGRAM EDUCATIONAL OBJECTIVES (PEOs)


ISE Graduates within three-four years of graduation will have
• PEO1: Acquired the fundamentals of computers and applied knowledge of Information Science & Engineering
and continue to develop their technical competencies by problem solving using programming.
• PEO2: Ability to formulate problems, attained the Proficiency to develop system/application software in a
scalable and robust manner with various platforms, tools and frameworks to provide cost effective solutions.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 1


Automata Theory & Computability [18CS54 CBCS]

• PEO3: Obtained the capacity to investigate the necessities of the software Product, adapt to technological
advancement, promote collaboration and interdisciplinary activities, Protecting Environment and developing
Comprehensive leadership.
• PEO4: Enabled to be employed and provide innovative solutions to real-world problems across different
domains.
• PEO5: Possessed communication skills, ability to work in teams, professional ethics, social responsibility,
entrepreneur and management, to achieve higher career goals, and pursue higher studies.
PROGRAM OUTCOMES (POs)

Engineering Graduates will be able to:

• PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization for the solution of complex engineering problems
• PO2: Problem analysis: Identify, formulate, research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences and
engineering sciences.
• PO3: Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for public
health and safety, and cultural, societal, and environmental considerations.
• PO4: Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
• PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools, including prediction and modeling to complex engineering activities, with an
understanding of the limitations.
• PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess
Societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
• PO7: Environment and sustainability: Understand the impact of the professional engineering solutions
in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
• PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
• PO9: Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
• PO10: Communication: Communicate effectively on complex engineering activities with the engineering
community and with the society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.
• PO11: Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
• PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 2
Automata Theory & Computability [18CS54 CBCS]

PROGRAM SPECIFIC OUTCOMES (PSOs)


ISE Graduates will have
• PSO1 – Problem Solving Abilities: Ability to demonstrate the fundamental and theoretical concepts, analyze
the real time problems and develop customized software solutions by applying the knowledge of mathematics
and algorithmic techniques.

• PSO2 – Applied Engineering Skills: Enable creative thinking, Ability to apply standard practices and
strategies, technical skills in software design, development, integration of systems and management for
improving the security, reliability and survivability of the infrastructure.

• PSO3 – General Expertise and Higher Learning: Ability to exchange knowledge effectively demonstrate
the ability of team work, documentation skills, professional ethics, entrepreneurial skills and continuing higher
education in the field of Information technology.

COURSE OBJECTIVES OF ATC


This course will enable students to
• Introduce core concepts in Automata and Theory of Computation
• Identify different Formal language Classes and their Relationships
• Design Grammars and Recognizers for different formal languages
• Prove or disprove theorems in automata theory using their properties
• Determine the decidability and intractability of Computational problems

COURSE OUTCOMES OF ATC


After studying this course, students will be able to:
• CO1: Acquire fundamental knowledge of the core concepts in Automata Theory.
• CO2: Design Finite State Machines for recognizing regular languages.
• CO3: Learn how to translate between different models of Computation and also reduction of a problem to a
formal model.
• CO4: Understand, design, analyze and interpret Context Free languages, Expressions and Grammars.
• CO5: Determine the decidability and intractability of Computational problems using Turing Machines.
• CO6: Discussion of theorems using appropriate properties and case studies in automata theory.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 3


Automata Theory & Computability [18CS54 CBCS]
MODULE 1
INTRODUCTION

Topics: Why study the Theory of Computation, Languages and Strings: Strings, Languages. A Language
Hierarchy, Computation, Finite State Machines (FSM): Deterministic FSM, Regular languages,
Designing FSM, Nondeterministic FSMs, From FSMs to Operational Systems, Simulators for FSMs,
Minimizing FSMs, Canonical form of Regular languages, Finite State Transducers, Bidirectional
Transducers.

Why Study the Theory of Computation

Programmers from the early days could never have imagined what a program of today would look like.
Today's programmers can't read code from 50 years ago. But there are mathematical properties, both of
problems and of algorithms for solving problems that depend on neither the details of today's technology
nor the programming fashion.

Theory of computation addresses some of those properties. It is useful in two key ways:
• It provides a set of abstract structures that are useful for solving certain classes of problems. These
abstract structures can be implemented on whatever hardware/ software platform is available.
• It defines provable limits to what can be computed, regardless of processor speed or memory size. An
understanding of these limits helps us to focus our design effort in areas in which it can pay off, rather
than on the computing equivalent of the search for a perpetual motion machine.

Our focus will be on analyzing problems, rather than on comparing solutions to problems. Our goal will be
to discover fundamental properties of the problems themselves:
• Is there any computational solution to the problem?
• If a solution exists, how efficient is it? More specifically, how do its time and space requirements grow
as the size of the problem grows?
• Are there groups of problems that are equivalent in the sense that if there is an efficient solution to
one member of the group there is an efficient solution to all the others?

Applications of the Theory of computation


Following are some of the applications:
• Both the design and the implementation of modern programming languages rely heavily on the
theory of context-free languages that we study further. Context- free grammars are used to document
the languages' syntax and they form the basis for the parsing techniques that all compilers use.

• We would like to build programs to manage our words, check our grammar. search the World Wide
Web, and translate from one language to another. Programs to do that also rely on the theory of context-
free languages.

• Systems such as parity checkers, vending machines. communication protocols and building security
devices can be straightforwardly described as finite state machines.

• Many interactive video games are (large. often nondeterministic) designed using finite state machines.

• DNA molecules, as well as the proteins that they describe, are strings that are made up of symbols
drawn from small alphabets (nucleotides and amino acids, respectively). They rely on techniques that
are based on both finite state machines and context-free grammars.
HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 4
Automata Theory & Computability [18CS54 CBCS]

• It is used in solving Artificial Intelligence problems, security designs, decidability & so on.

Terminologies
• An alphabet, often denoted Σ, is a finite set of input symbols or characters.
• A string is a finite sequence, possibly empty, of symbols drawn from some alphabet Σ. Given any
alphabet Σ, the shortest string that can be formed from Σ is the empty string, which we will write as
ε. The set of all possible strings over an alphabet Σ is written Σ *.
Ex:
Alphabet name Alphabet symbols Example strings
The English alphabet {a, b. c, ... ,z} ε, aabbcg, aaaaa

The binary alphabet {0,1} ε,0, 001100

• A language is a (finite or infinite) set of strings over a finite alphabet Σ.


When more than one language is used, we will use the notation ΣL to mean the alphabet from which the
strings in the language L are formed.
Ex:
Let Σ = {a, b}
Σ* = { ε, a, b, aa, ab, ba, bb, aaa, aab, ... }
Some examples of languages over Σare:
L ={ ε , a, aa, aaa, aaaa , aaaaa,...}
L= { ε , ab, aaab, abab, ..... }

Functions on Strings
• The length of a string s, which we will write as |s|, is the total number of symbols in s.
Ex: |ε| = 0
|1001101| = 7
For any symbol c and string s, we define the function #c(s) to be the number of times that the symbol
c occurs in s.
Ex: #a(abbaaa) = 4.

• The concatenation of two strings s and t, written s||t or simply st, is the string formed by appending t to s.
Ex: If x = good and y = bye, then xy = goodbye. So |xy|=|x|+|y|. The empty string, ε, is the identity for
concatenation of strings. So 6 x (x ε = ε x = x).
Concatenation, as a function defined on strings is Associative. So 6 s, t, w ((st)w = s (tw)).

• The string replication is repetition of strings. For each string w and each natural number i, the string wi is
defined as:
w 0= ε
w i+1= w i w
Ex: a3 = aaa
(bye)2 =byebye
a0b3=bbb
• String reversal.
For each string w, the reverse of w, which we will write wR, is defined as: If |w| = 0 thenwR = w = ε
.If |w| ≥1 then < a ϵ Σ( < u C Σ* (w = ua)), (i.e., the last character of w is a.) Then define wR = auR.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 5


Automata Theory & Computability [18CS54 CBCS]

THEORM 1.1: Concatenation and Reverse of Strings

Theorem: If w and x are strings, then (wx)R = xRwR.


Ex: (nametag)R = (tag)R(name)R = gateman.
Proof: The proof is by induction on |x|:
Base case: |x| = 0. Then x = ε, and (wx)R = (w ε)R = (w)R = ε wR = ε RwR = xRwR.
Prove: ∀ n ≥ 0 (((|x| = n) → ((wx)R =xRwR)) → ((|x| = n + 1) → ((wx)R= xRwR))).
Consider any string x, where |x| = n + 1.

Then x = ua for some character a and |u| = n .So,


(wx)R = (w(ua))R rewrite x as ua
= ((wu)a)R associativity of concatenation
= a(wu)R definition of reversal
= a(uRwR) induction hypothesis
= (auR)wR associativity of concatenation
= (ua)RwR definition of reversal
= xRwR rewrite ua as x

Relations on Strings

A string s is a substring of a string t iff s occurs contiguously as part of t.


Ex: aaa is a substring of aaabbbaaa
aaaaaa is not a substring of aaabbbaaa

A string s is a proper substring of a string t iff s is a substring of t and s ≠ t. Every string is a substring
(although not a proper substring) of itself. The empty string, ε, is a substring of every string.

A string s is a prefix of t iff Ǝx ϵ Σ* (t = sx). A string s is a proper prefix of a string t iff s is a prefix of t and
s≠ t. Every string is a prefix (although not a proper prefix) of itself. The empty string, ε, is a prefix of every
string.
Ex: The prefixes of abba are: ε, a, ab, abb, abba.

A string s is a suffix of t iff Ǝ x ϵ Σ* (t = xs). A string s is a proper suffix of a string iff s is a suffix of t and s
≠ t. Every string is a suffix (although not a proper suffix) of itself. The empty string, ε, is a suffix of every
string.
Ex: The suffixes of abba are: ε, a, ba, bba, abba.

Languages
A language is a (finite or infinite) set of strings over a finite alphabet Σ. When there are more than one
language that are considered, we will use the notation Σ L to mean the alphabet from which the strings in the
language L are formed.

Ex: Defining languages given an Alphabet


Let Σ = {a, b}. Σ* = { ε, a, b, aa, ab, ba, bb, aaa, aab, ... }.
Some examples of languages over Σ are:
Ø, { ε } , {a, b}, { ε , a, aa, aaa, aaaa , aaaaa}.
{ ε , a, aa , abba, aabbaa, . ; . }

Techniques for Defining Languages


There are variety of techniques for defining the languages that we wish to consider. Since languages are
sets, we can define them using any of the set-defining techniques

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 6


Automata Theory & Computability [18CS54 CBCS]

Ex: All a's precede All b's


Let L = {w C {a,b}*: a's precede all b's in w}.
The strings ε, a, aa, aabbb, and bb are in L .
The strings aba, ba, and abc are not in L.

Ex: Strings that end in a


Let L = {x : EyC {a, b}* (x = ya)}.
The strings a, aa, aaa, bbaa. and ba are in L.The
strings ε, bab. and bca are not in L.
L consists of all strings that can be formed by taking some string in {a. b}* and concatenating a single
a onto the end of it.

Note:
• Let L = {} = Ø . L is the language that contains no strings. The Empty language is different from the Empty
String.
• Let L = { ε }, the language that contains a single string, ε. Note that L is different from Ø.

Relations on languages

We define the following languages in terms of the prefix relation on strings:


L1 = {w ϵ {a, b} * : no prefix of w contains b}
= { ε , a, aa, aaa, aaaa,aaaaa, aaaaaa, ... }
L2 = { w ϵ {a, b} *: no prefix of w starts with b}
= { w ϵ {a, b} * : the first character of w is a } U { ε }.
L3 = { w ϵ{a, b}*; every prefix of w starts with b}=Ø.
L3 is equal to Ø because ε is a prefix of every string. Since ε does not start with b, no strings meet L3 's
requirement.

Using Replication to define languages


Let L = { an : n ≥ 0}. L = (ε, a, aa, aaa, aaaa, aaaaa, ... ).

Languages are sets. So, if we want to provide a computational definition of a language, we could specify
either:
• a language generator, which enumerates (lists) the elements of the language, or
• a language recognizer, which decides whether or not a candidate string is in the language and returns
True if it is and False if it isn't.
Ex: The logical definition. L = {x: Ǝy ϵ {a, b}* (x = ya )} can be turned into either a language generator
(enumerator) or a language recognizer.
In some cases, when considering an enumerator for a language we may care about the order in which the
elements of L are generated.
If there exists a total order D of the elements of Σ L , then we can use D to define on L a useful total order called
lexicographic order written as <L:
• Shorter strings precede longer ones: ∀x(∀ y(( |x| < |y|) → (x <L y))) and of strings that are the same
length sort them in dictionary order using D.
When we use lexicographic order, we will assume that D is the standard sort order on letters and numerals.
We will say that a program lexicographically enumerates the elements of L iff it enumerates them in
lexicographic order.
Ex: Lexicographic Enumeration
Let L = {x ϵ {a, b )*: all a's precede all b's }.
The lexicographic enumeration of L is:
{ε, a, b, aa, ab, bb, aaa, aab, abb, bbb, aaaa, aaab, aabb, abbb, bbbb, aaaaa...}

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 7


Automata Theory & Computability [18CS54 CBCS]

The Cardinality of a Language

It is the size of the language. The smallest language over any alphabet is Ø whose cardinality is 0. The largest
language over any alphabet Σ is Σ*.
If Σ = Ø, then Σ* = { ε } and |Σ*| = 1.

The Cardinality of Σ*
If Σ is not Ø then Σ* is countably infinite.
The elements of Σ* can be lexicographically enumerated by a straightforward procedure that:
• Enumerates all strings of length 0, then length 1, then length 2 and so forth.
• Within the strings of a given length, enumerates them in dictionary order. This enumeration is infinite
since there is no longest string in Σ*.
Since any language over Σ is a subset of Σ *, the cardinality of every language is at least 0 and at most infinity.
So all languages are either finite or countably infinite.

Functions on languages

Since languages are sets, all of the standard set operations are well-defined on languages. In particular, we will
find union, intersection, difference, and complement to be useful.Complement will be defined with Σ* as the
universe unless we explicitly state otherwise.

Ex: Set Functions applied to Languages


Let Σ = {a. b}.
• L1 ={strings with an even number of a's}= { ε, b, aba, aaaabbb,aaaaaa,. }
• L2={strings with no b’s} = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa, }
• L1 U L2 ={strings that contain b's and an even no. of a's plus all strings of
just a's } L1 ∩ L2 = { ε, aa, aaaa, aaaaaa, aaaaaaaa, }
• L2 - L1 = {a, aaa, aaaaa, aaaaaaa, .,., .. }
• ¬ (L2 - L1) = {strings with at least one b } U {strings with an even number of a's}
• Three useful operations on languages are concatenation, Kleene star, and reverse.

Concatenation
Let L1 and L2 be two languages defined over some alphabet Σ. Then their concatenation, written L1L2 is:
L1L2 = { w ϵ Σ * : Ǝ s ϵL1 (Ǝ t ϵ L2 (w=st))}
Ex: Concatenation of Languages
Let L1 = {cat, dog, mouse, bird}
L2 = { bone, food}.
L1L2={ catbone, catfood, dogbone,dogfood, mousebone, mousefood,birdbone,birdfood}
The language { ε } is the identity for concatenation of languages.
So, for all languages L, L{ ε } = { ε }L = L.

The language Ø is a zero for concatenation of languages. So, for all languages L, LØ = ØL = Ø .

Concatenation, as a function defined on languages is associative. So,for all languages L1,L2,L3: ((L1,L2)L3
=L1,(L2,L3))
Suppose that L1 = {an : n ≥ 0} and L2 = { bn : n ≥ 0}. By the definition of language concatenation,
L1L2 = { w: w consists of a’s (possibly empty) followed by b’s (possibly empty)}.
L1L2 ≠ { an bn : n ≥ 0}, since every string in { an bn : n ≥ 0} must have the same number of b's as a's. The easiest
way to avoid confusion is simply to rename conflicting variables before attempting to concatenate the expressions
that contain them.So L1L2 = { an bm : n, m ≥ 0}.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 8


Automata Theory & Computability [18CS54 CBCS]

Kleene star
Let L be a language defined over some alphabet Σ.
Then the Kleene star of L, written L* is:
L* = { ε} U {w ϵ Σ * : Ǝk ≥ 1 (Ǝw1 , w2, ... wk ϵ L (w = w1w2 ........... wk)) }
In other words, L* is the set of strings that can be formed by concatenating together zero or more strings from
L.

Ex:
Let L = {dog, cat, fish}. Then,
L* = { ε,dog, cat, fish, dogdog, dog cat, ...fishdog, . . , fishcatfish, fishdogfishcat..}

• L* always contains an infinite number of strings as long as L is not equal to either Ø or { ε } (i.e., as
long as there is at least one nonempty string any number of which can be concatenated together).
• If L = Ø , then L* = { ε }, since there are no strings that could be concatenated to ε to make it longer. If L
= { ε }. then L * is also { ε }.
• It is sometimes useful to require that at least one element of L be selected. So we define: L+ = LL*.
• Another way to describe L+ is that it is the closure of L under concatenation. Note that L+ = L*- { ε } iff ε Ø
L.

Reverse of a language
Let L = { 0, 1}+ be the set of binary strings. L does not include ε.
Let L be a language defined over some alphabet Σ. Then the reverse of L , written LR is:
LR = {w ϵ Σ*: w = xR for some x ϵ L}.
R
In other words, L is the set of strings that can be formed by taking some string in L and reversing it.

THEORM 1.2 Concatenation and Reverse of Languages


Theorem: If L1 and L2 are languages, then (L1L2)R = L2RL1R.
Proof: If x and y are strings, then ∀x (∀y ((xy)R = yRxR))
(L1L2)R = {(xy)R: x ϵ L1 and y ϵ L2} Definition of concatenation of languages
= { yRxR : xϵ L1 and y ϵ L2}
= L2RL1R Definition of concatenation of languages

A Machine-Based Hierarchy of Language Classes


1.3.1The Regular Languages
The first model to consider is the finite state machine or FSM.
Figure below shows a simple FSM that accepts strings of a’s and b's, where all a's come before all b's.
The input to an FSM is a string, which is fed to it one character at a time, left to right.
The FSM has a start state, shown in the diagram with an unlabelled arrow leading to it, and some number (zero
or more) of accepting states, which will be shown in the diagrams with double circles. The FSM starts in its
start state. As each character is read, the FSM changes state based on the transitions shown in the figure. If
FSM M is in an accepting state after reading the last character of some input strings, then M accepts s. The
example machine below will accept aab, aabbb. and bb. It will reject ba.
A simple FSM

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 9


Automata Theory & Computability [18CS54 CBCS]

The class of languages that can be accepted by some FSM is regular.

The Context-Free Languages


But there are useful simple languages that are not regular.
Consider for example: The language of balanced parentheses say L. It contains strings like (()) and ()(): it does
not contain strings like ()))
Consider another example: the language AnBn = { anbn : n ≥ 0}. In any string in AnBn, all the a's come first and
the number of a's equals the number of b's. Try to build an FSM to accept AnBn. But the problem is, "How shall
we count the a's so that we can compare them to the b's'?'' .The only memory in an FSM is in the states and we
must choose a fixed number of states when we build our machine. But there is no bound on the number of a's
we might need to count.
We can augment the FSM in a simple way and thus be able to solve this problem.
Suppose that we add one thing. a single stack. We will call any machine that consists of an FSM, plus a single
stack, a pushdown automaton or PDA. It works as follows:
• We can easily build a PDA M to accept AnBn. The idea is that each time it sees an a, M will push it
onto the stack. Then each time it sees a b it will pop an a from the stack.
• If it runs out of input and stack at the same time and it is in an accepting state, it will accept.
• Otherwise. it will reject.
• M will use the same state structure that we used in our FSM example above to guarantee that all the a's
come before all the b's.
• In diagrams of PDAs, read an arc label of the form xlylz to mean, ·'if the input is an x, and it is possible
to pop y off the stack, then take the transition, do the pop of, and push z". lf the middle argument is e,
then don't bother to check the stack. If the third argument is ε, then don't push anything.
• Using those conventions, the PDA shown in Figure below accepts AnBn.
Using a very similar sort of PDA. we can build a machine to accept balanced parenthesis and other languages
whose strings are composed of properly nested substrings.

A simple PDA that accepts AnBn.

The class of languages that can be accepted by some PDA are called context-free languages.
Note some simple limitations to the power of the PDA.
Consider the language WW = { ww: w ϵ{a, b} *} Here,2nd half of the string is an exact copy of the first half .It
is not possible to build an accepting PDA for such problems where tracing back is required.

The Decidable and Semidecidable Languages


Let AnBnCn = { anbncn : n ≥ 0}. i.e., the language composed of all strings of a's, b’s and c’s such that all the a's
come first, followed by all the b's, then all the c's, and the number of a’s equals the number of b's equals the
number of c's.
But it is easy to write a program to accept AnBnCn. So, if we want a class of machines that can capture

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 10


Automata Theory & Computability [18CS54 CBCS]

everything we can write programs to compute, we need a model that is stronger than the PDA.

To meet this need, we will introduce a third kind of machine called Turing machine .We will get rid
of the stack and replace it with an infinite tape. The tape will have a single read-write head. Only the tape
square under the read/write head can be accessed (for reading or for writing). The read/write head can be
moved one square in either direction on each move. The resulting machine is called a Turing machine. We
will also change the way that input is given to the machine. Instead of streaming it, one character at a time,
the way we did for FSMs and PDAs, we will simply write the input string onto the tape and then start the
machine with the read/write head just to the left of the first input character.

We show the structure of a Turing machine in Figure below. The arrow under the tape indicates the
location of the read/write head. At each step, a Turing machine M considers its current state and the character
that is, on the tape directly under its read/write head. Based on those two things, it chooses its next state,
chooses a character to write on the tape under the read/write head, and chooses whether to move the
read/write head one square to the right or one square to the left. A finite segment of M's tape contains the
input string. The rest is blank, but M may move the read/write head off the input string and write on the
blank squares of the tape.

The structure of a Turing machine.

• Finite state machines and pushdown automata are guaranteed to halt. They must do so when they run
out of input.

• Turing machines, on the other hand, carry no such guarantee. The input simply sits on the tape. A
Turing machine may move back and forth across its input many times. It may move back and forth
forever.
• Because of its flexibility in using its tape to record its computation, the Turing machine is a more
powerful model than either the FSM or the PDA.
• Any computation that can be written in any programming language or run on any modern computer can
be described as a Turing machine. However, when we work with Turing machines, we must be aware
of the fact that they cannot be guaranteed to halt.
• There exists no algorithm that can examine a Turing machine and tell whether or not it will halt (on any
one input or on all inputs). This fundamental result about the limits of computation is known as the
undecidability of the halting problem.
• We will use the Turing machine to define two new classes of languages:
• A language L is decidable iff there exists a Turing machine M that halts on all inputs, accepts all
strings that are in L,, and rejects all strings that are not in L. In other words, M can always say yes or
no, as appropriate.
• A language L is semidecidable iff there exists a Turing machine M that accepts all strings that are in L
and fails to accept every string that is not in L. Given a string that is not in L, M may reject or it may
loop forever. In other words. M can recognize a solution and then say yes. but it may not know when it
should give up looking for a solution and say no.
• Balanced parenthesis, AnBn, Palindrome, WW and AnBn Cn are all decidable languages. Every decidable
language is also semidecidable
• But there are languages that are semidecidable yet not decidable.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 11


Automata Theory & Computability [18CS54 CBCS]

The Computational Hierarchy and Why It Is Important

Four language classes:


1. Regular languages, which can be accepted by some finite state machine.
2. Context-free languages, which can be accepted by some pushdown automaton.
3. Decidable languages, which can be decided by some Turing machine that always halts.
4. Semidecidable languages, which can be semidecided by some Turing machine that halts on all
strings in the language.
Each of these classes is a proper subset of the next class, as illustrated in the diagram shown in figure
below:

A hierarchy of language classes.

▪ As we move outward in the language hierarchy, we have access to tools with greater and greater
expressive power.
o So, for example: we can define AnBn as a context-free language but not as a regular one.
We can define AnBnCn as a decidable language but not as a context-free or a regular one.

o Following is the comparison among all 3 machines:


▪ Computational efficiency: Finite state machines run in time that is linear in the length of the input
string. A general context-free parser based on the idea of a pushdown automaton requires time that
grows as the cube of the length of the input string. A Turing machine may require time that grows
exponentially (or faster) with the length of the input string.

▪ Decidability: There exist procedures to answer many useful questions about finite state machines. For
example. does an FSM accept some particular string? Is an FSM minimal Are two FSMs identical? A
subset of those questions can be answered for pushdown automata. None of them can be answered for
Turing machines.

▪ Clarity: There exist tools that enable designers to draw and analyze finite state machines. Every
regular language can also be described using the regular expression pattern language. Every context -
free language, in addition to being recognizable by some pushdown automaton, which can be described
with a context-free grammar. For many important kinds of languages. context-free grammars are
sufficiently natural that they are commonly used as documentation tools. No corresponding tools exist
for the broader classes of decidable and semi decidable languages.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 12


Automata Theory & Computability [18CS54 CBCS]

Finite State Machines


The simplest and most efficient computational device that we will consider is the finite state machine (or
FSM).
Ex: A Vending Machine
Consider the problem of deciding when to dispense a drink from a vending machine. The cost of a drink is
$.25. The vending machine controller will receive a sequence of input, each of which corresponds to one of
the following events:
• A coin is deposited into the machine. We can use the symbols N (for nickel), D (for dime), and Q (for
quarter) to represent these events.
• The coin return button is pushed. We can use the symbol R (for return) to represent this event.
• A drink button is pushed and a drink is dispensed. We can use the symbol S (for soda) for this event.
After any finite sequence of inputs, the controller will be in either:
-A dispensing state, in which it is willing to dispense a drink if a drink button is pushed OR
-A nondispensing state, in which not enough money has been inserted into the machine.
We can design a controller that will simply reject any money that comes in after the amount required to buy a
drink has been recorded and before a drink has actually been dispensed. For example, the thirsty customer may
have only dimes. So we'll build a machine that will accept up to $.45. If more than the necessary $.25 is
inserted before a dispensing button is pushed, our machine will remember the difference and leave a “credit'' in
the machine. So, for example, if a customer inserts three dimes and then asks for drink, the machine will
remember the balance of $.05.
The drink controller that we have just described needs 10 states, corresponding to the possible values of the
credit that the customer has in the machine: 0, 5, 10, 15, 20, 25, 30, 35. 40, and 45 cents. The main structure of
the controller is then:

Deterministic Finite State Machines


A Finite State Machines (or FSM) is a computational device whose input is a string and whose output is one of
two values that we can call Accept and Reject. FSMs are also sometimes called finite state automata or FSAs.
If M is an FSM, an input string is fed to M one character at a time left to right. Each time it receives a
character. M considers its current state und the new character and chooses a next state. One or more of M's
states may be marked as accepting states. If M runs out of input and is in an accepting state, it accepts. If
however, M runs out or input and is not in an accepting state, it rejects. The number or steps that M executes
on input w is exactly equal to |w|, so M always halts and either accepts or rejects.
The Deterministic Finite State Machines (DFSM or DFA), is an Finite state machine with exactly one move
that can be made at each step; that move is determined by the current state and the next input character.

Definition:
Formally, a deterministic FSM (or DFSM) M is a quintuple (K, Σ , δ, s, A) where:
HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 13
Automata Theory & Computability [18CS54 CBCS]

• K is a finite set of states,


• Σ is the input alphabet,
• s C K is the start state, ∑
• A Š K is the set of accepting states, and
• δ is the transition function. It maps from;
K X ∑ to K
State input symbol to state

Terminologies used in DFSM


A configuration of a DFSM M is an element of K X Σ*. It contains two things:
• Its current state and
• The input that is still left to read.

The initial configuration of a DFSM M, on input w is (SM , w) where, SM is the start state of M. The transition
function δ defines the operation of a DFSM M one step at a time. We can use it to define the sequence of
configurations that M will enter. We start by defining the relation yields-in-one-step. written |-M· Yields-in- one-
step relates configuration1 to configuration2 iff M can move from configuration1 to configuration2 in one step.
Let c be any element of Σ and let w be any element of Σ*. Then,
(q1,cw) |- M (q2,w) iff ((q1,c),q2) ϵ δ
We can now define the relation yields, written |-M* to be the reflexive, transitive closure of |-M . So configuration
C1 yields configuration C2 iff M can go from C1 to C2 in zero or more steps. In this case, we will write: C1 |-M* C2

A computation by M is a finite sequence of configurations C0, C1, C2, ... , Cn for some n ≥ 0 such that:
• C0 is an initial configuration,
• Cn is of the form (q, ε), for some state q ϵ KM (i.e., the entire input string has been read}, and C0 |-M C1 |-M C2 |-
M ... |-M Cn.
Let w be an element of Σ*. Then we will say that:
• M accepts w iff (s, w) |-M* (q, ε), for some q C AM· Any configuration (q, ε), for some q C AM , is called an
accepting configuration of M.
• M rejects w iff (s, w) |-M* (q, ε), for some q Ø AM· Any configuration (q, ε), for some q Ø AM , is called a
rejecting configuration of M.
M halts whenever it enters either an accepting or a rejecting configuration. It will do so immediately after
reading the last character of its input.

The language accepted by M, denoted by L(M), is the set of all strings accepted by M.
Ex 1: Let L = {w ϵ {a, b}* : every a is immediately followed by a b}.

L can be accepted by the DFSM M = ( { q0, q1, q2}, {a, b }, δ, q0. {q0}), where:

δ= {((q0, a), q1),


((q0, b). q0),
((q1, a), q2),
((q1, b). q0).
((q2, a), q2),
((q2. b), q2))}.

The tuple notation that we have just used for δ is quite hard to read. We will generally find it useful to draw δ
as a transition diagram instead. When we do that. we will use two conventions:
1. The start state will be indicated with an unlabeled arrow pointing into it.
2. The accepting states will be indicated with double circles.
With those conventions, a DFSM can be completely specified by a transition diagram. So M is:

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 14


Automata Theory & Computability [18CS54 CBCS]

The transition shown by an edge with a label a or b.


As an example of M's operation, consider the input string abbabab.
M's computation is the sequence of configurations:
(q0, abbabab), (q1, bbabab),(q0, babab), (q0, abab ), (q1, bab ), (q0, ab ), (q1, b), (q0, ε).
Since q0 is an accepting state, M accepts.

If we look at the three states in M, the machine that we just built, we see that they are of three different sorts:
1. State q0 is an accepting state. Every string that drives M to state q0 is in L .
2. State q1 is not an accepting state. But every string that drives M to state q1 could turn out to be in L if it is
followed by an appropriate continuation string, in this case, one that starts with a ‘b’.
State q2 is what we will call a dead state or trap state. Once M enters state q2, it will never leave. State q2 is
not an accepting state, so any string that drives M to state q2 has already been determined not to be in L, no
matter what comes next. We will often name our dead states d.

Ex 2: Even number of a's


Let L = { w ϵ {a, b}* : num. of a’s in w is of even length}, L can be accepted by the DFSM M:

The Regular Languages

The languages accepted by DFSM are called Regular languages. All the above examples are regular
languages. Following are some more examples of Regular languages.
Ex 1:Let L = {w ϵ {a, b}* : w contains no more than one b}.
L is regular because it can be accepted by the DFSM M. L accepts { ε, a, b, ab, ba, aa, aba, baa,aab,aaaab,. }
L doesnot include { bb,abb,bab,. }

Any string with more than one b will drive M to the dead state d. All other strings will drive M to either q0 or
q1 both of which are accepting states.

Ex 2: Let L = {w ϵ {a, b}* : no two consecutive characters are the same}.


L is regular because it can be accepted by the DFSM M.
L accepts { ε, a, b, ab, ba, aba, bab, abab,baba, ....... }
L doesnot accepts { aa,bb,aab,aaa,bbbaa, ...... }

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 15


Automata Theory & Computability [18CS54 CBCS]

Ex 3: Let FLOAT = { w : w is the string representation of a floating point number}.


Assume the following syntax for floating point numbers:
• A floating point number has an optional sign, followed by a decimal number, followed by an optional
exponent.
• A decimal number may be of the form x or x.y, where x and y are nonempty strings of decimal digits.
• An exponent begins with E and is followed by an optional sign and then an integer.
• An integer is a nonempty string of decimal digits.
Following are the examples of strings represent floating point numbers:
+3.0, 3.0, 0.3El, 0.3E+l, -0.3E+l, -3E8
FLOAT is regular because it can be accepted by the DFSM:

In this diagram, we have used the shorthand d to stand for any one of the decimal digits (0 - 9). And we have
omitted the dead state to avoid arrows crossing over each other.

Ex 4:A Simple Communication Protocol


Let L be a language that contains all the legal sequences of messages that can be exchanged between a client
and a server using a simple communication protocol.

Let Σ L = {Open, Request, Reply, Close} .

Every string in L begins with Open and ends with Close. In addition, every Request, except possibly the last
must be followed by Reply and no unsolicited Reply's may occur.
L is regular because it can be accepted by the DFSM:

Note that we have again omitted the dead state.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 16


Automata Theory & Computability [18CS54 CBCS]

Ex 5: Let L ={w C {a, b}*: w contains an even number of a's and an odd number of b's}.

Note: states can be renamed as required

Ex 6: All the Vowels in Alphabetical Order


Let L = {w C {a - z} * : all five vowels, a, e, i, o, and u, occur in w in alphabetical order}.
So L contains words like abstemious, facetious, and sacrilegious.
But it does not contain tenacious, which does contain all the vowels, but not in the correct order.
It is hard to write a clear, elegant program to accept L. But designing a DFSM is simple. The following
machine M does the job. In this description of M, let the label “Σ-{a}” mean “all elements of Σ except a" and
let the label “Σ” mean “all elements of Σ”:

Ex 7: A Substring that Doesn't Occur Let L =, {w C {a, b }*: w does not contain the substring aab }.
It is straightforward to design an FSM that looks for the substring aab. So we can begin building a machine to
accept L by building the following machine to accept ¬L:

Then we can convert this machine into one that accepts L by making states q0, q1 and q2 accepting and state q3
nonaccepting as shown:

Nondeterministic FSMs
Definition:
A nondeterministic FSM (or NDFSM) M is a quintuple ( K. Σ, ∆. s, A ) where:
• K is a finite set of states,
• Σ is an alphabet,
• s C K is the start state,
• A Š K is the set of final states, and
• ∆ is the transition relation. It is a finite subset of : ( K x (Σ U {ε}) x K.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 17


Automata Theory & Computability [18CS54 CBCS]

ln other words, each element of ∆ contains a (state, input symbol or ε) pair, and a new state.
Let w be an element of Σ*. Then we will say that:
• M accepts w iff at least one of its computations accepts.
• M rejects w iff none of its computations accepts.

The language accepted by M, denoted L(M), is the set of all strings accepted by M.

Following are the differences between DFSMs and NDFSMs:


In every configuration, a DFSM can make exactly one move. Whereas that is not necessarily true for an
NDFSM. Instead
• An NDFSM M may enter a configuration in which there are still input symbols left to read but from which no
moves are available.
So there can be (state, input) pairs for which no next state is defined.
• An NDFSM M may enter a configuration from which two or more competing moves are possible. An
NDFSM M may have one or more transitions that are labelled ε.
Out of some state q, there may be more than one transition with a given label.

Ex:
If M is in state q0 and the next input character is an a, then there are three moves that M could make:
1. It can take the ε -transition to q1 before it reads the next input character,
2. It can read the next input character and take the transition to q2, or
3. It can read the next input character and take the transition to q3.

Following are few examples of NDFSM:


Ex 1:
Let L = {w ϵ {a, b} * : w is made up of an optional a followed by aa followed by zero or more b's}. The
following NDFSM M accepts L:

Ex 2:Two Different Sublanguages


Let L = {w ϵ {a, b }* : w = aba or |w| is even}. An easy way to build an FSM to accept this language is to
build FSMs for each of the individual sub languages and then “glue" them together with ε -transitions. In
essence, the machine guesses, when processing a string, which sublanguage the string might be in. So we have:

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 18


Automata Theory & Computability [18CS54 CBCS]

The upper machine accepts {w ϵ {a, b}* : w = aba}. The lower one accepts { w ϵ {a, b} * : | w| is even}.

Ex 3: The Missing Letter Language.


Let Σ = {a, b, c, d}. LMissing = { w : there is a symbol ai ϵ Σ: not appearing in w}.
The following simple NDFSM M accepts LMissing:

M works by guessing which letter is going to be the missing one. If any of its guesses is right, it will accept. If
all of them are wrong. then all paths will fail and M will reject.

NDFSMs for Pattern and Substring Matching


Nondeterministic FSMs are a particularly effective way to define simple machines to search a text string for
one or more patterns or substrings.

Ex 4:
Let L = {w ϵ {a,b,c}*: Ǝ x,y ϵ{a,b,c}* (w = x abcabb y)}.
In other words, w must contain at least one occurrence of the substring abcabb.
The following DFSM M1 accepts L:

While M1 works, and it works efficiently, designing machines like M1 and getting them right is hard.
But now consider the following NDFSM M2, which also accepts L:

The idea here is that, whenever M2 sees an a, it may guess that it is at the beginning of the pattern abcabb. Or,
on any input character (including a), it may guess that it is not yet at the beginning of the pattern (so it stays in
q0). If it ever reaches q6, it will stay there until it has finished reading the input. Then it will accept.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 19


Automata Theory & Computability [18CS54 CBCS]

So one effective way to build a correct and efficient string-searching machine is to build a simple NDFSM,
convert it to an equivalent DFSM, and then minimize the DFSM.

Ex 5: Multiple Keywords
Let L = { w ϵ {a, b} * : Ǝ x, y ϵ {a, b} * (( w = x abbaa y) ᴜ ( w = x baba y))}.
In other words, w contains at least one occurrence of the substring abbaa or the substring baba. The following
NDFSM M accepts L:

Ex 6: Other Kinds of Patterns


Let L = { w ϵ {a, b} * : the fourth from the last character is a}. The following
NDFSM M accepts L:

Handling ε-Transitions
The function eps: KM →Р (KM) is introduced to handle ε-Transitions in NFSM.

eps(q), where q is some state in M, is defined as the set of states of M that are reachable from q by following
zero or more ε -transitions.
eps(q) = {pϵK:(q,w) |-M * (p,w)}.
The following algorithm computes eps:
eps(q: state) =
1. result = {q }.
2. While there exists some p ϵ result and some r ∉ result and some transition (p, ε, r) ϵ Δ
do: Insert r into result.
3. Return result.

It will add all elements that are reachable from q following only ε -transitions.

Ex: Computing eps


Consider the following NDFSM M:

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 20


Automata Theory & Computability [18CS54 CBCS]

To compute eps(q0), we initially set result to {q0}.


Then q1 is added, producing { q0, q1}.
Then q2 is added, producing { q0, q1, q2}.
There is an ε -transition from q2 to q0, but q0 is already in result. So the computation of eps(q0) halts.

The result of running eps on each of the states of M is:


eps(q0) = {q0, q1, q2}·
eps(q1) = {q0, q1, q2}·
eps(q2) = {q0, q1, q2}·
eps(q3) = {q3}.
A Simulation Algorithm
With the eps function, we can now define an algorithm for tracing all paths in parallel through an NDFSM M:
ndfsmsimulate ( M: NDFSM, w: string) =
1. current-state = eps(s). /*Start in the set that contains M's start state and any other states that can be reached
from it following only ε -transitions.
2. While any input symbols in w remain to be read do:
c = get-next-symbol( w ).
next-state = Ø.
For each state q in current-state do:
For each state p such that (q, c, p) ϵ ∆ do:
next-state = next-state U eps(p).
current-state = next-state.
3. If current-state contains any states in A, accept. Else reject.

The Equivalence of Nondeterministic and Deterministic FSMs

THEORM: If There is a NDFSM for L, There is a DFSM for L.


Proof: The proof is by construction of an equivalent DFSM M'. The states of M' will correspond to sets of
states in M.
So M' = (K', Σ, δ', s', A'), where:
• K' contains one state for each element of Р(K).
• s' = eps(s).
• A' = { Q ⊆ K: Q ∩ A ≠ Ø}.
• δ'(Q, c) = p U {eps(p) : Ǝ q ϵ Q ((q, c, p) ϵ ∆)}.

The following algorithm computes M' given M:


ndfsmtodfsm(M: NDFSM) =
1. For each state q in K do:
Compute eps(q). /* These values will be used below.
2. s' = eps(s).
3. Compute δ':
a. active-states = { s'}. /* We will build a list of all states that are reachable
from the start state. Each element of
active-states is a set of states drawn from K.
b. δ' = Ø.
c. While there exists some element Q of active-states for which δ' has not yet been computed do:
For each character c in Σ do:
new-state = Ø.
For each state q in Q do:
For each state p such that ( q. c, p) ϵ ∆:
new-state = new-state U eps (p ).
Add the transition ( Q, c, new-state) to δ’
If new-state ∉ active-states then insert it into active-states.
HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 21
Automata Theory & Computability [18CS54 CBCS]

4. K ' = active-states.
5. A'= {Q ϵ K': Q ∩ A ≠ Ø}.

Problem: Build a Deterministic FSM for the following NDFSM M using ndfsmtodfsm

We can apply ndfsmtodfsm to M as follows:


1. Compute eps(q) for each state q in KM:
eps (q1) = {q1, q2, q7}, eps (q2) = {q2, q7}, eps (q3) = {q3}, eps (q4)= {q4},
eps (q5) = {q5}, eps (q6) = {q2, q6, q7}, eps (q7) = {q7}, eps (q8) = {q8}.

2. s' = eps (s) = {q1, q2, q7}

3. Compute δ':
Initially active-states = {{q1, q2, q7} } which is s' .
Consider transition for {q1, q2, q7} for each input symbol and then apply eps( )

We get:
(( { q1, q2, q7 }, a), Ø) Since result is null ,we can ignore it.
(({q1, q2, q7}, b),{q1, q2, q3, q5, q7, q8}) New state { q1, q2, q3, q5, q7, q8}
(({q1, q2, q7}, c), Ø) It is null. So ignore it.
Now, updated active-states = { {q1, q2, q7}, {q1, q2, q3, q5, q7, q8} }

Consider new state {q1, q2, q3, q5, q7, q8} and repeat the above step:
We get:
(({q1, q2, q3, q5, q7, q8}, a), {q2, q4, q6, q7} ).
(({q1, q2, q3, q5, q7, q8}, b), {q1, q2, q3, q5, q6, q7, q8} ).
(({q1, q2, q3, q5, q7, q8}, c), { q4} ).
Now active-states = { q1, q2, q7},{q1, q2, q3, q5, q7, q8}, {q2, q4, q6, q7},{q1, q2, q3, q5, q6, q7, q8}, {q4}
}.

Consider {q2, q4, q6, q7} :


(( { q2, q4, q6, q7 }, a), Ø).
(( { q2, q4, q6, q7 }, b), {q3,q5,q8}).
(( { q2, q4, q6, q7 }, c), {q2,q7}).
active-states= {q1, q2, q7},{q1, q2, q3, q5, q7, q8}, {q2, q4, q6, q7},{q1, q2, q3, q5, q6, q7, q8}, {q4},
{q3,q5,q8}, {q2,q7}}.

Consider {q1, q2, q3, q5, q6, q7, q8} :


(({q1, q2, q3, q5, q6, q7, q8}, a), {q2, q4, q6, q7}).
(({q1, q2, q3, q5, q6, q7, q8}, b), {q1, q2, q3, q5, q6, q7, q8} ).
(({q1, q2, q3, q5, q6, q7, q8}, c), {q2,q4,q7 } ).
HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 22
Automata Theory & Computability [18CS54 CBCS]

active-states={{ q1, q2, q7}, {q1, q2, q3, q5, q7, q8}, {q2, q4, q6, q7},{q1, q2, q3, q5, q6, q7, q8}, {q4},
{q3,q5,q8},{q2,q7}, {q2,q4,q7 } }.

Consider {q4}:
(( {q4}, a), Ø).
(({q4}, b). Ø).
(({q4}, c), {q2, q7}).
active-states did not change.

Consider {q3,q5,q8}:
(({q3,q5,q8}, a), {q2, q4, q6, q7} ).
( ({q3,q5,q8}, b), {q2, q6, q7}).
(({q3,q5,q8}, c), {q4} ).
active-states= { q1, q2, q7}, Ø, {q1, q2, q3, q5, q7, q8}, {q2, q4, q6, q7}, {q1, q2, q3, q5, q6, q7, q8}, {q4},
{q3,q5,q8}, {q2,q7}, {q2,q4,q7 }, {q2, q6, q7} }.

Consider {q2,q7}:
(( {q2, q7}, a), Ø ).
(({q2,q7}, b), {q3,q5,q8}).
(( { q2, q7}, c), Ø ).
active-states did not change.

Consider { q2, q4 , q7}:


(({ q2, q4 , q7}, a), Ø).
(({ q2, q4 , q7}, b), {q3,q5,q8}).
(({ q2, q4 , q7}, c), {q2,q7}).
active-states did not change.

Consider {q2, q6, q7}:


(({q2, q6, q7}, a), Ø).
(({q2, q6, q7}, b), {q3,q5,q8} ).
( ({q2, q6, q7}, c), {q2,q7}).
active-states did not change. δ has been computed for each element of active-states.

4. K' = { q1, q2, q7}, {q1, q2, q3, q5, q7, q8}, {q2, q4, q6, q7}, {q1, q2, q3, q5, q6, q7, q8}, {q4},
{q3,q5,q8}, {q2,q7}, {q2,q4,q7 }, {q2, q6, q7} }.
Rename the states in the same order as K' ={ A, B, C, D, E, F,G, H, I }

5. A' = { {q1, q2, q3, q5, q7, q8}, {q1, q2, q3, q5, q6, q7, q8}, {q3,q5,q8}}
Simulators for FSMs
Once we have created an FSM to solve a problem, we may want to simulate its execution.
Simulating Deterministic FSMs
Consider the following deterministic FSM M that accepts the language L = { w ϵ {a, b} * : w contains no more
than one b}.
We could view M as a specification for the following program:
Until accept or reject do:
S: s =get-next-symbol.
If s=end-of-file then accept.
Else if s = a then go to S.
Else if s = b then go to T.
T: s =get-next-symbol.
If s = end-of-file then accept.
HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 23
Automata Theory & Computability [18CS54 CBCS]

Else if s = a then go to T.
Else if s = b then reject.
End.

The biggest problem with this approach is that we must generate new code for every FSM that we wish to run.
Of course, we could write an FSM compiler that did that for us. But we don't need to. We can, instead, build an
interpreter that executes the FSM directly.

Here's a simple interpreter for a deterministic FSM M = (K, Σ, δ. s, A):


dfsmsimulate(M: DFSM, w: string) =
1. st = s.
2. Repeat:
c = get-next-symbol(w).If
c ≠ end-of-file then:
st = δ(st, c).
until c = end-of-file.
3. If st ϵ A then accept else reject.

Simulating Non-Deterministic FSMs


ndfsmsimulate(M: NDFSM, ·w: string) =
1. Declare the set st. /* st will hold the current state (a set of states from K).
2. Declare the set st1. /* stl will be built to contain the next state.
3. st = eps(s). /* Start in all states reachable from s via only e-transitions.
4. Repeat:
c = get-next-symbol (w).
If c ≠ end-of-file then do:
st1 = 0.
For all q ϵ st do: !* Follow paths from all states M is currently in.
For all r : (q, c, r) ϵ ∆ do: /* Find all states reachable from q via a
transition labelled ε
st1 = st1 U eps(r). /* Follow all ε-transitions from there.
st = st1. /* Done following all paths. So st becomes M's new state.
If st = Ø then exit. /* If all paths have died. quit.
until c = end-of-file.
5. If st ∩ A ≠ Ø then accept else reject

Minimizing FSMs

Building a Minimal DFSM for a Language


An effective way to think about the design a DFSM M to accept some language L, over an alphabet Σ is to
cluster the strings in Σ* in such a way that strings that share a future will drive M to the same state.
We will say that x and y are indistinguishable with respect to L, which we will write as
x ≈L y iff: ∀ z ϵ Σ* (either both xz and yz C L or neither is).
In other words, ≈L is a relation that is defined so that x ≈L y precisely in case, if x and y are viewed as prefixes of
some longer string, no matter what continuation string z comes next, either both xz and yz are in L or both are
not.

Ex: How ≈L depends on L


If L ={a}*, then a ≈L aa ≈L aaa.
But if L ={w ϵ {a, b}* : |w| is even}, then a ≈L aaa, but it is not the case that a ≈L aa because, if z = a, we have
aa ϵ L but aaa ∉ L.

So, if x and y are distinguishable, then there exists at least one string z such that one but not both of xz and yz
HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 24
Automata Theory & Computability [18CS54 CBCS]

is in L.

We will use three notations to describe the equivalence classes of ≈L:


• [1] ,[2], etc. will refer to explicitly numbered classes.
• [x] describes the equivalence class that contains the string x.
• [some logical expression P] describes the equivalence class of strings that satisfy P.

Since ≈L is an equivalence relation, its equivalence classes constitute a partition of the set Σ*. So:
• No equivalence class of ≈L is empty, and
• Every string in Σ* is in exactly one equivalence class of ≈L.

What we will see soon is that the equivalence classes of ≈ L, correspond exactly to the states of the minimum
DFSM that accepts L. So every string in Σ* will drive that DFSM to exactly one state.

Ex 1: Determining ≈L
Let Σ = {a, b }. Let L = {w ϵ Σ*: every a is immediately followed by a b }.

To determine the equivalence classes of ≈L, we begin by creating a first class [1] and arbitrarily assigning ε to
it.
Now consider a. It is distinguishable from ε since εab ϵ L but aab ∉ L. So we create a new equivalence class
[2] and put a in it.
Now consider b. b ≈L ε since every string is in L unless it has an a that is not followed by a b. Neither of these
has an a that could have that problem. So they are both in L as long as their continuation doesn't violate the
rule. If their continuation does violate the rule, they are both out. So b goes into [1 ).
Next we try aa. It is distinguishable from the strings in [1] because the strings in [1] are in L but aa is not. So,
consider ε as a continuation string. Take any string in [1] and concatenate ε. The result is still in L. But aaε is
not in L. We also notice that aa is distinguishable from a, and so cannot be in [2], because a still has a chance
to become in L if it is followed by a string that starts with a b. But aa is out, no matter what comes next. So, we
create a new equivalence class [3] and put aa in it.
We continue in this fashion until we discover the property that holds of each equivalence class.
The equivalence classes of ≈L are:
[1] [ε, b, abb, ... ] [all strings in L]
[2] [a, abbba, ... ] [all strings that end in a and have no prior a that is not followed
by a b]
[3] [aa, abaa,...] [all strings not in L which contain at least one instance of aa]

Even this simple example illustrates three key points about ≈L


• No equivalence class can contain both strings that are in L and strings that are not.This is clear if we considerthe
continuation string ε. If x ϵ L then xε ϵ L . If y ∉ L then yε ∉ L. So, x and y are distinguishable by ε.
• If there are strings that would take a DFSM for L to the dead state (in other words, strings that are out of L no
matter what comes next), then there will be one equivalence class of ≈L that corresponds to the dead state.
• Some equivalence class contains ε. It will correspond to the start state of the minimal machine that accepts L.

Ex 2: When More than One Class Contains Strings in L


Let Σ = {a, b}. Let L ={w ϵ {a, b}*: no two adjacent characters are the same}.
The equivalence classes of ≈L are:
[1] [ε] [ε]
[2] [a, aba, ababa, . . . ] [all nonempty strings that end in a and have no identical
adjacent characters].
[3] [b,ab,bab,abab,...] [all nonempty strings that end in b and have no identical
adjacent characters].
[4] [aa, abaa, ababb, ... ] [all strings that contain at least one pair of identical

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 25


Automata Theory & Computability [18CS54 CBCS]

Algorithm to find minDFSM(M:DFSM) =


1. classes= {A, K-A}. /* Initially, just two classes of states, accepting and rejecting.
2. Repeat until a pass at which no change to classes has been made:
newclasses = Ø. /* At each pass, we build a new set of classes, splitting the old ones as
necessary.
Then this new set becomes the old set, and the process is repeated.
For each equivalence class c in classes, if c contains more than one state, see if it needs to be split:
For each state q in e do: /* Look at each state and build a table of what it does. Then the
tables
for all states in the class can be compared to see if there are any
differences that force splitting.
For each character c in Σ do:
Determine which element of classes q goes to if c is read.
If there are any two states p and q such that there is any character c such that, when c is
read. p goes to one element of classes and q goes to another, then p and q must be split.
Create as many new equivalence classes as are necessary so that no state remains in the
same class with a state whose behavior differs from its. Insert those classes into
newclasses.
If there are no states whose behavior differs, no splitting is necessary. Insert e into
newclasses.
classes = newclasses. /* The states of the minimal machine will correspond exactly to the
elements of classes at this point. We use the notation [q] for the
element of classes that contains the original state q.
3. Return M' = (classes, Σ. δ, [sM], {[q: the elements of q are in AM]}), where δM is constructed as follows:
if δM (q, c) = p, then δM , ([q], c) = [p].
Clearly, no class that contains a single state can be split. So, if |K| is k, then the maximum
number of times that minDFSM can split classes is k - 1. Since minDFSM halts when no more splitting can
occur, the maximum number of times it can go through the loop is k - 1. Thus minDFSM must halt in a finite
number of steps. M' is the minimal DFSM that is equivalent to M since:
• M' is minimal: It splits classes and thus creates new states only when necessary to simulate M, and
• L(M') = L(M ): The proof of this is straightforward by induction on the length of the input string.

Ex: Using minDFSM to Find a Minimal Machine


Let Σ = {a, b}. Let M =

We will show the operation of minDFSM at each step:


Initially, classes = {[2, 4], [1. 3, 5, 6]} /*A class of acceptance states & a class of nonacceptance states
At step 1:
((2, a), [1, 3, 5, 6]) ((4, a), [1. 3. 5, 6])
((2, b), [1, 3, 5, 6]) ((4, b), [1, 3, 5, 6])
No splitting required here. Consider next class elements
((l,a),[2,4]) ((3, a), [2, 4]) ((5, a), [2, 4]) ((6, a),[1, 3, 5, 6])
((1,b), [2,4]) ((3, b),[2, 4]) ((5,b),[2,4]) ((6,b),[l, 3,5,6])

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 26


Automata Theory & Computability [18CS54 CBCS]

There are two different patterns, so we must split into two classes.[l, 3, 5] and [6].
Now, Classes= {[2,4], [1,3,5], [6]}

At step 2:
((2, a), [1, 3, 5]) ((4, a), [6]) These two must be split.
((2, b), [6]) ((4, b), [1,3, 5])
((1, a),[2, 4]) ((3, a), [2, 4]) ((5, a), [2, 4])
((1,b),[2, 4]) ((3, b),[2, 4]) ((5, b), [2,4])
No splitting required.

Now, Classes = {[2], [4], [1,3,5], [6]}

At step 3:
((l,a),[2]) ((3, a),[2]) ((5, a),[2])
((1, b), [4]) ((3, b), [4]) ((5, b), [4])
No splitting required. So, the process halts here.
So minDFSM returns M' =

A Canonical Form for Regular Languages

A canonical form for some set of objects C assigns exactly one representation to each class of "equivalent"
objects in C. Further. each such representation is distinct, so two objects in C share the same representation iff
they arc "equivalent" in the sense for which we define the form.
Suppose that we had a canonical form for FSMs with the property that two FSMs share a canonical form iff
they accept the same language. Further suppose that we had an algorithm that on input M. constructed M's
canonical form. Then some questions about FSMs would become easy to answer. For example, we could test
whether two FSMs are equivalent (i.e, they accept the same language). It would suffice to construct the
canonical form for each of them and test whether the two forms are identical.
The algorithm minDFSM constructs, from any DFSM M, a minimal machine that accepts L(M). We know
that, all minimal machines for L(M) are identical except possibly for state names. So, if we could define a
standard way to name states, we could define a canonical machine to accept L(M) (and thus any regular
language). The following
algorithm does this by using the state-naming convention.
buildFSMcanonicalform(M: FSM) =
1. M' = ndfsmtodfsm(M).
2. M# = minDFSM(M').
3. Create a unique assignment of names to the states of M# as follows:
Call the start state q0
Define an order on the elements of Σ
3.3 Until all states have been named do:
Select the lowest numbered named state that has not yet been selected. Call it q.
Create an ordered list of the transitions out of q by the order imposed on their labels.
Create an ordered list of the as yet unnamed states that those transitions enter by doing the following: If the
HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 27
Automata Theory & Computability [18CS54 CBCS]

first transition is (q, c1, p1 ), then put p1 first. If the second transition is (q, c2, p2) and p2 is not already on the
list, put it next. If it is already on the list, skip it. Continue until all transitions have been considered. Remove
from the list any states that have already been named.
Name the states on the list that was just created: Assign to the first one the name qk, where k is the smallest
index that hasn't yet been used. Assign the next name to the next state and so forth until all have been named.
4. Return M#.

Given two FSMs M1 and M2, buildFSMcanonicalform(M1) = buildFSMcanonicalform (M2) iff L(M1) = L
(M2). It provides the basis for a simple way to test whether an FSM accepts any strings or whether two FSMs
are equivalent.

Finite StateTransducers
Finite state machines are not used only as language recognizers but it also used to allow for output at each step
of a machine's operation which are called transducers. Many finite state transducers are loops that simply run
forever, processing inputs.
One simple kind of finite state transducer associates an output with each state of a machine M. That output is
generated whenever M enters the associated state. Deterministic finite state transducers of this sort are called
Moore machines ( named after their inventor Edward Moore).

Definition :
A Moore machine M is a seven-tuple (K, Σ , Ο, δ, D, s, A) where:
• K is a finite set of states,
• Σ is an input alphabet,
• Ο is an output alphabet,
• s ϵK is the start state,
• A⊆ K is the set of accepting states ,
• δ is the transition function. It is function from (K X Σ) to (K), and
• D is the display or output function. It is a function from (K) to (Ο*).

A Moore machine M computes a function f(w) iff, when it reads the input string w, its output sequence is f(w).

Ex: A Typical United States Traffic Light


Consider the following controller for a single direction of a very simple U.S. traffic light. We will ignore the
fact that a practical controller has to manage all directions for a particular intersection.
The states in this simple controller correspond to the light's colors: green, yellow, and red. Note that the
definition of the start state is arbitrary. There are three inputs, all of which are elapsed time.

A different definition for a deterministic finite state transducer permits each machine to output any finite
sequence: of symbols as it makes each transition FSMs that associate outputs with transitions are called Mealy
machines (named after their inventor George Mealy).

Definition:
A Mealy machine M is a six-tuple (K, Σ, Ο, δ, s, A) where:
• K is a finite set of states,
• Σ is an input alphabet,
• Ο is an output alphabet,
• s ϵ K is the start state.
• A⊆K is the set of accepting states, and

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 28


Automata Theory & Computability [18CS54 CBCS]

• δ is the transition function. It is a function from (K x Σ) to (K x Ο*).


A Mealy machine M computes a function f(w) iff, when it reads the input string w, its output sequence is f(w).

Ex: Generating Parity Bits


The following Mealy machine adds an odd parity bit after every four binary digits that it reads. We will use the
notation a/b on an arc to mean that the transition may be followed if the input character is a. If it is followed,
then the string b will be generated.

Ex: A Bar Code Reader


Bar codes are ubiquitous. We consider here a simplification: a bar code system that encodes just binary
numbers. Imagine a bar code such as:

It is composed of columns, each of the same width. A column can be either white or black. If two black
columns occur next to each other, it will look to us like a single, wide, black column, but the reader will see the
adjacent black columns of the standard width. The job of the white columns is to delimit the black ones. A
single black column encodes 0. A double black column encodes 1.
We can build a finite state transducer to read such a bar code and output a string of binary digits. We'll
represent a black bar with the symbol B and a white bar with the symbol W. The input to the transducer will be
a sequence or those symbols, corresponding to reading the bar code left to right. We'll assume that every
correct bar code starts with a black column, so white space ahead of the first black column is ignored. We'll
also assume that after every complete bar code there are atleast two white columns. So the reader should, at
that point, reset to be ready to read the next code. If the reader sees three or more black columns in a row, it
must indicate an error and stay in its error state until it is reset by seeing two white columns.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 29


Automata Theory & Computability [18CS54 CBCS]

Bidirectional Transducers
A process that reads an input string and constructs a corresponding output string can be described in a variety
of different ways. Why should we choose the finite state transducer model? One reason is that it provides a
declarative, rather than a procedural, way to describe the relationship between inputs and outputs. Such a
declarative model can then be run in two directions. For example:
• To read an English text requires transforming a word like "liberties” into the root word "liberty" and the affix
PLURAL. To generate an English text requires transforming a root word like “liberty” and the semantic
marker "PLURAL” into the surface word "liberties". If we could specify, in a single declarative model, the
relationship between surface words and underlying root words and affixes.
The facts about English spelling rules and morphological analysis can be described with a bidirectional finite
state transducer.

• The Soundex system, described below, groups names that sound alike. To create the Soundex representation
of a name requires a set of rules for mapping the spelling of the name to a unique four character code. To find
other names that sound like the one that generated a particular code requires running those same rules
backwards.
• Many things we call translators need to run in both directions. For example, consider translating between
Roman numerals Q and Arabic ones. A nondeterministic Mealy machine can be thought of as defining a
relation between one set of strings (for example, English surface words) and a second set of strings (for
example, English underlying root words, along with affixes).

Ex: Letter Substitution


When we define a regular language, it doesn't matter what alphabet we use. Anything that is true of a language
L defined over the alphabet {a, b} will also be true of the language L' that contains exactly the strings in L
except that every a has been replaced by a 0 and every b has been replaced by a 1. We can build a simple
bidirectional transducer that can convert strings in L to strings in L' and vice versa.

Of course, the real power of bidirectional finite state transducers comes from their ability to model more
complex processes.

Ex: Soundex: A Way to Find Similar Sounding Names


People change the spelling of their names. Sometimes the spelling was changed for them when they
immigrated to a country with a different language, a different set of sounds, and maybe a different writing
system. The Soundex system (was patented by Margaret O’Dell and Robert C. Russell in 1918) maps any
name to a four character code that is derived from the original name but that throws away details of the sort
that often get perturbed as names evolve.
So, to find related names, one can run the Soundex transducer in one direction, from a starting name to its
Soundex code and then, in the other direction, from the code to the other names that share that code, for
example, if we start with the name Kaylor, we will produce the Soundex code K460. If we then use that code
and run the transducer backwards, we can generate the names Kahler, Kaler, Kaylor, Keeler, Kellar, Kelleher,
Keller, Kelliher, Kilroe, Kilroy, Koehler, Kohler, Koller, and Kyler.

The Soundex system is described by the following set of rules for mapping from a name to a Soundex code:
1. If two or more adjacent letters (including the first in the name) would map to the same number if rule 3.1
were applied to them, remove all but the first in the sequence.
2. The first character of the Soundex code will be the first letter of the name.

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 30


Automata Theory & Computability [18CS54 CBCS]

3. For all other letters of the name do:


Convert the letters B, P, F, V, C, S, G, J, K, O, X, Z, D, T, L, M, N, and R to numbers using the
following correspondences:
B, P, F, V = 1.
C, S, G, J, K, O, X, Z = 2.
D, T = 3.
L= 4.
M, N = 5.
R = 6.
Delete all instances of the letters A, E, I, O, U, Y, H, and W.
4. If the string contains more than three numbers, delete all but the leftmost three.
5. 1f the string contains fewer than three numbers, pad with 0’s on the right to get three.

Here's an initial fragment of a finite-state transducer that implements the relationship between names and
Soundex codes. The complete version of this machine can input a name and output a code by interpreting each
transition labelled x/y as saying that the transition can be taken on input x and it will output y. Going the other
direction, it can input a code and output a name if it interprets each transition the other way: On input y, take
the transition and output x. To simplify the diagram, we've used two conventions:
The symbol # stands for any one of the letters A, E, I, O, U, Y, H, or W. And a label of the form x, y, z/a is a
shorthand for three transitions labelled x/a, y/a, and z/a. Also, the states are named to indicate how many code
symbols have been generated/read.

Note: For more problems w.r.t DFSM, NFDSM, Minimization of DFSM can be found in the class work
& practice the same

HN, SSK & PM, Dept. of ISE, RNSIT 2022-2023 Page 31

You might also like