You are on page 1of 8

LOVELY PROFESSIONAL UNIVERSITY

HOME WORK: 4
Name:parteek
Roll no:-RE1804A16
Sec:- E1804

Course Title: Automata Theory

SOLUTIONS’

Q.1 What are Formal Languages? Elaborate on the aspects of formal languages.
Ans :-
Formal languages are studied in computer science and linguistics. Formal languages are
often used as the basis for richer constructs endowed with semantics. In computer science they
are used, among other things, for the precise definition of data formats and the syntax
of programming languages. Formal language is a set of words, i.e.
finite strings of letters, symbols, or tokens. The set from which these letters are taken is called
the alphabet over which the language is defined. A formal language is often defined by means of
a formal grammar (also called its formation rules); accordingly, words that belong to a formal
language are sometimes called well-formed words (or well-formed formulas). Since formal
languages alone do not have semantics, other formal constructs are needed for the formal
specification of program semantics. Formal languages are also used in logic and in foundations
of mathematics to represent the syntax of formal theories. Formal languages play a crucial role in
the development of compilers, typically produced by means of a compiler compiler, which may
be a single program or may be separated in tools like lexical analyzer generators (e.g. lex),
and parser generators (e.g. yacc).

The following rules describe a formal language L over the alphabet Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8,
9, +, =}:

 Every nonempty string that does not contain + or = and does not start with 0 is in L.
 The string 0 is in L.
 A string containing = is in L if and only if there is exactly one =, and it separates two
valid strings in L.
 A string containing + but not = is in L if and only if every + in the string separates two
valid strings in L.
 No string is in L other than those implied by the previous rules.

For finite languages one can simply enumerate all well-formed words. For example, we can
describe a language L as just L = {"a", "b", "ab", "cba"}.
However, even over a finite (non-empty) alphabet such as Σ = {a, b} there are infinitely many
words: "a", "abb", "ababba", "aaababbbbaab", …. Therefore formal languages are typically
infinite, and describing an infinite formal language is not as simple as writing L = {"a", "b", "ab",
"cba"}. Here are some examples of formal languages:

 L = Σ*, the set of all words over Σ;


 L = {a}* = {an}, where n ranges over the natural numbers and an means "a"
repeated n times (this is the set of words consisting only of the symbol "a");
 the set of syntactically correct programs in a given programming language (the syntax of
which is usually defined by a context-free grammar);
 the set of inputs upon which a certain Turing machine halts; or
 the set of maximal strings of alphanumeric ASCII characters on this line, (i.e., the set
{"the", "set", "of", "maximal", "strings", "alphanumeric", "ASCII", "characters", "on", "this",
"line", "i", "e"}).

Q.2 What is halting problem in Turing Machine? Explain in detail.


Ans :-
.The halting problem is a decision problem about properties of computer programs on a
fixed Turing-complete model of computation, i.e. all programs that can be written in some
given programming language that is general enough to be equivalent to a Turing machine. The
problem is to determine, given a program and an input to the program, whether the program will
eventually halt when run with that input. In this abstract framework, there are no resource
limitations on the amount of memory or time required for the program's execution; it can take
arbitrarily long, and use arbitrarily much storage space, before halting. The question is simply
whether the given program will ever halt on a particular input. The halting problem can be stated
as follows: Given a description of a computer program, decide whether the program finishes
running or continues to run forever. This is equivalent to the problem of deciding, given a
program and an input, whether the program will eventually halt when run with that input, or will
run forever.

For example, in pseudo code, the program

while True: continue


does not halt; rather, it goes on forever in an infinite loop. On the other hand, the program

print "Hello World!"


halts very quickly.
A more complex program might be harder to analyze. One could run the program for
some fixed time. If it stopped, fine, but if it did not, one wouldn't know if it was about
to stop in the next minute or would run forever.

Q.3 What is Cellular Automata? What are the different types of cellular automata?
Ans:-
For each cell, a set of cells called its neighborhood (usually including the cell itself) is
defined relative to the specified cell. For example, the neighborhood of a cell might be defined as
the set of cells a distance of 2 or less from the cell. An initial state (time t=0) is selected by
assigning a state for each cell. A cellular automaton is a discrete model studied in computability
theory, mathematics, physics, complexity science, theoretical biology and microstructure
modeling. It consists of a regular grid of cells, each in one of a finite number of states, such as
"On" and "Off" (in contrast to a coupled map lattice). The grid can be in any finite number of
dimensions. A new generation is created (advancing t by 1), according to some fixed rule
(generally, a mathematical function) that determines the new state of each cell in terms of the
current state of the cell and the states of the cells in its neighborhood. For example, the rule
might be that the cell is "On" in the next generation if exactly two of the cells in the
neighborhood are "On" in the current generation, otherwise the cell is "Off" in the next
generation. Typically, the rule for updating the state of cells is the same for each cell and does
not change over time, and is applied to the whole grid simultaneously, though exceptions are
known.

Types of Cellular Automata


Cellular automata can be classified in several different ways.Each of the different ways of
classification only classifies one particular feature of the automata, so each automata can belong
to several different classes.


Weather the automata is a series or parallel type
The number of dimensions the automata operates in
The level of complexity achieved

Series or Parallel
This is the most basic form of classification. And it's also probably the easiest to under
stand. Basically a series automata is one where things happen in a serial form. The rules
are applied to one (or perhaps many) squares and the 'state' of the universe is updated
straight away. This is opposite to parallel types where the whole universe (every square
on the grid) has the rules applied and then the whole lot is updated in one action, in other
words in parallel.
Another way of looking at this is to say series automata are like ants (hence digital
anthill), and only the squares that contain ants need updating. The ants look at the square
it's in or around it and then uses this to decide weather to move and where to move to. A
parallel automata could be looked as a single cell and each square in that cell is say a
chemical that may react with chemicals around it. So the whole grid is the entity with a
parallel automata where as a series automata can contain may entities.

Number of Dimensions

 . It merely tells us how 'far' around each square the rules 'look'. Automata could have any
number of dimensions, but as you'll see things get very complicated once you get over 3
or 4.
You may recall form geometry lessons at school a 0 dimensional shape is a dot, no
length, no width. And so a 0 dimensional automata looks no further than the square it's
currently on. Langtons ants and Turks ants are examples of this type of automata. And
despite the short-sightness of these ants, they can still display amazingly intricate
behavior.
Next is, guess what, 1 dimensional automata. A one dimensional shape is a line, it has
length but no width. So one dimensional automata can look either 'up' and 'down' or 'left'
and 'right', but both.

Moving up to the next higher dimension we come to 2 dimensional automata.As you may
guess these are capable of looking both 'horizontally' and 'vertically'. The Game of Life
and the Brain automata are examples of this type. With in this type there are serveral
subtypes, the difference between the sub types being in what directions the automata can
'look' and just how far it can 'see'. These two factors give rise to what is called a
neighborhood.

 This makes 1 dimensional automata particularly interesting to look at since you can have
a line of them across the width of our screen and then use the height to show a history of
the changes that have happened since the automata was started.This makes it much easier
to see what is actually going on. There are also a much smaller subset of possible rules
for this type. These two factors make 2 dimensional automata the most studied type.
Stephen Wolffram has studied these extensively.
Q.4 Compare LL and LR grammar on the basis of their representations and utilization.
Ans:-

LR parser is a parser that reads input from Left to right and produces a rightmost derivation.
The class of grammars which are parsable in this way is known as the LR grammars. The
term LR(k) parser is also used; where the k refers to the number of unconsumed "look ahead"
input symbols that are used in making parsing decisions. Usually k is 1 and the term LR
parser is often intended to refer to this case.

The syntax of many programming languages can be defined by a grammar that is LR(1), or close
to being so, and for this reason LR parsers are often used by compilers to perform syntax
analysis ofsource code.
An LL parser is a top-down parser for a subset of the context-free grammars. It parses
the input from Left to right, and constructs a Leftmost derivation of the sentence (hence LL,
compared with LR parser). The class of grammars which are parsable in this way is known as
the LL grammars. An LL parser is called an LL(k) parser if it uses k tokens of lookahead when
parsing a sentence. If such a parser exists for a certain grammar and it can parse sentences of this
grammar withoutbacktracking then it is called an LL(k) grammar. A language that has an LL(k)
grammar is known as an LL(k) language. There are LL(k+n) languages that are not LL(k)
languages. A corollary of this is that not all context-free languages are LL(k) languages.

An LR parser can be created from a context-free grammar by a program called a parser


generator or hand written by a programmer. A context-free grammar is classified as LR(k) if
there exists an LR(k) parser for it, as determined by the parser generator.

An LR parser is said to perform bottom-up parsing because it attempts to deduce the top level
grammar productions by building up from the leaves.

A deterministic context-free language is a language for which some LR(k) grammar exists. Every
LR(k) grammar for k > 1 can be mechanically transformed into an LR(1) grammar for the same
language, while an LR(0) grammar for the same language may not exist; the LR(0) languages are
a proper subset of the deterministic ones.
“Comparision on other factors”

Complexity
LL wins here, hands down. You can easily hand-write an LL parser. In fact, this is commonly
done: the Microsoft C# compiler is a hand-written recursive descent parser LR parsing uses a
rather counter-intuitive method to parse a text. It works, but it took me some time to wrap my
head around how it works exactly. Writing such a parser by hand is therefore hard: you'd be
more or less implementing an LR parser-generator.
Generality
LR wins here: all LL languages are LR languages, but there are more LR languages than LL
languages (a language is an LL language if it can be parsed with an LL parser, and a language is

LALR can complain about shift-reduce and reduce-reduce conflicts. This is caused by the table
hack: it 'folds' similar entries together, which works because most entries are empty, but when
they are not empty it generates a conflict. These kinds of errors are not natural, hard to
understand and the fixes are usually fairly weird.

Compiler errors and error recovery


LL wins here. In an LL parse, it's usually pretty easy to emit useful compiler errors, in particular
in hand-written parsers. You know what you're expecting next, so if it doesn't turn up, you
usually know what went wrong and what the most sensible error would be.

Also, in LL parsing, error recovery is a lot easier. If an input doesn't parse correctly, you can try
to skip ahead a bit and figure out if the rest of the input does parse correctly. If for instance some
programming statement is malformed, you can skip ahead and parse the next statement, so you
can catch more than one error.

Using an LR parser this is a lot more difficult. You can try to augment your grammar so that it
accepts erroneous input and prints errors in the areas where things went wrong, but this is usually
pretty hard to do. The chance you end up with a non-LR (or non-LALR) grammar also goes up.

Speed
Speed is not really an issue with the manner in which you parse your input (LL or LR), but rather
the quality of the resulting code and the use of tables (you can use tables for both LL and LR).
LL and LR are therefore comparable in this respect.
Q.5 Design Turing machine for the following languages

1. The set of string with an equal number of 0’s and 1’s.


Ans:-
Repeat the following steps:
(a) Place a mark on top of the leftmost tape symbol (say a dot). If that symbol is blank,
accept.
(b) Scan right until a symbol “different” than the symbol marked is found (that is, if
the symbol marked in (a) was 1, scan for 0; if it was a 0, scan for 1). Cross off the
found symbol. If no “different” symbol is found, reject.

(c) Go back left until a marked symbol (with a dot) is found. Remove the mark and
cross it off.
(d) Scan right to the next non-crossed-off (or blank) symbol.

2:-
{anbncn| n>=1}
3. {wwr | w is any string of 0’s and 1’s}

You might also like