Chapter 1. Preliminaries: Example 1.1
Chapter 1. Preliminaries: Example 1.1
Preliminaries
In this chapter, we review some basic concepts required for
understanding the contents of this book.
Sets
A set is a collection of well-defined objects. Usually the elements of
a set have common properties. For example, all the students who
enroll for a course ‘Computability’ make up a set. Formally,
Definition 1.1
Example 1.1.
or
1.
The basis or basis clause that lists some elements in the set (which
are basic building blocks).
2.
3.
The induction or inductive clause which states how to produce new
elements from the existing elements of the set.
4.
5.
The extremal clause which asserts that no object is a member of
the set unless its being so follows from a finite number of
applications of the basis and inductive clauses.
6.
Example 1.2.
Basis clause: [ ] ∊W
Inductive clause: if x, y ∊W, xy ∊ W and [x] ∊W
Extrenal clause: No object is a member of W unless its being so
follows from a finite number of applications of the basis and the
inductive clauses.
A set A is a subset of a set B if each element of A is also an element
of B and is denoted by A ⊆ B. We also say that A is included in B.
If A is a subset of B and A is not same as B, then we say that A is a
proper subset B and is denoted by A ⊂ B. φ is a subset of every set.
Two sets A and B are equal if every element of A is also an element
of B and vice versa. We denote equal sets by A = B.
The power set of set S is the set of all subsets of S and is denoted
by . If S = { a, b, c} then,
A = {0, 1}, B = {x, y, z}, A × B = {(0, x), (0, y), (0, z), (1, x), (1, y), (1, z) }
K={(x, y)|x ∊ S, y ∊ T, x is the student of y}
K−1={(y, x)|x ∊ S, y ∊ T, y is the teacher of x}
Note that the inverse of a function need not be a function. A
function f: A → B may not have an inverse if there is some
element b ∊ B such that f(a)=b for no a ∊ A. But every bijective ‘f’
possesses an inverse f−1 (say), and f−1(f(a)) = a for each a ∊ A.
R is reflexive i.e., for every x, (x, x) ∊ R.
R is symmetric i.e., for every x and y, (x, y) ∊ R implies (y, x) ∊ R.
R is transitive i.e., for every x,y and z, (x, y) ∊ R and (y, z)
∊ R implies (x, z) ∊ R.
Equivalence relation on a set A partitions A into equivalence
classes. The number of equivalence classes is called the index or
rank of an equivalence relation. Index can be finite or infinite.
Example 1.3.
E11={0, 3, 6, ...},
E12={1, 4, 7, ...},
E13={2, 5, 8, ...},
Ordered Pairs
Ordered pairs of natural numbers can be represented by a single
natural number. That is we are not only interested in encoding
ordered pairs into natural numbers, but also in decoding the
natural numbers into ordered pairs. That is, we are interested to
get a 1–1 mapping from N2 to N. One of the simplest form of
bijection from N2 to N is as below:
Cantor-numbering scheme: Let π2 : N2 → N be such that
π2(x, y) is called the Cantor number of the ordered pair (x, y). For
example, the Cantor number of (2, 4) is 23. The following table
lists some Cantor numbers for some pairs.
x|y 0 1 2 3 4
0 0 1 3 6 10
1 2 4 7 11 16
2 5 8 12 17 23
3 9 13 18 – –
4 14 19 – – –
5 20 26 – – –
Closures
Closure is an important relationship among sets and is a general
tool for dealing with sets and relations of many kinds.
1.
R′ is reflexive (symmetric, transitive)
2.
3.
R′ ⊇ R
4.
5.
If R″ is a reflexive (symmetric, transitive) relation containing R,
then R″ ⊇ R′.
6.
The reflexive, transitive closure of R is denoted by R*. Reflexive,
transitive closure of a binary relation R is only one of the several
possible closures. R+ is a transitive closure of R which need not be
reflexive, unless R itself happens to be reflexive.
Methods of Proof
Here we introduce three basic methods of proofs:
(i) mathematical induction, (ii) pigeonhole principle, and (iii)
diagonalization.
Mathematical Induction
Let A be a set of natural numbers such that:
1.
0∊A
2.
3.
for each natural number n, if {0, 1, 2, ..., n} ∊ A, then n + 1 ∊ A.
Then A = N. In particular, induction is used to prove assertions of
the form “For all n ∊ N, the property P is valid.” i.e.,
4.
1.
In the basis step, one has to show that P(0) is true i.e., the property
is true for 0.
2.
3.
P holds for n will be the assumption.
4.
5.
Then one has to prove the validity of P for n + 1.
6.
Example 1.4.
1.
P is true for n = 0 as left-hand side and right-hand side of P will be
0.
2.
3.
Example 1.5.
Pigeonhole Principle
If A and B are two non-empty finite sets with #A> #B, then there
exists no 1–1 function from A to B. i.e., if we attempt to pair the
elements of A with the elements of B, sooner or later, we have to
put more than one element of A in the already paired group.
Example 1.6.
Among any group of 367 people, there must be at least two with
the same birthday, because there are only 366 possible birthdays.
Diagonalization Principle
Let R be a binary relation on a set A and let D = {a|a ∊ A, and (a, a)
∉ R}. For each a ∊ A, let Ra = {b|b ∊ A, and (a, b) ∊ R}. Then D is
distinct from Ra for all a ∊ A.
Example 1.7.
a b c
a X
b X X
c X
d X
Clearly, D ≠ Ra; Rb; Rc; Rd.
Graphs
An undirected graph or simply a graph is a set of points with lines
connecting some points. The points are called nodes or vertices.
The lines are called edges.
Example 1.8.
Example 1.9.
Definition 1.2
1.
2.
3.
In any graph G, a path forms a cycle if its starting vertex and end
vertex are same.
4.
5.
6.
Example 1.10.
Graphs (i) and (ii) are connected.
1 2 3 4 6 is a path in Graph (i)
Graph (i) contains a cycle 1 2 3 4 5 1.
Graph (ii) is a tree.
The following are the observations about a tree.
Let G = (V, E) be an undirected graph. Then the following
statements are equivalent.
1.
G is a tree.
2.
3.
Any two vertices in G are connected by a unique simple path.
4.
5.
G is connected, but if any edge is removed from E, the resulting
graph is disconnected.
6.
7.
G is connected and |E| = |V| − 1.
8.
9.
G is acyclic and |E| = |V| − 1.
10.
11.
G is acyclic, but if any edge is added to E, the resulting graph
contains a cycle.
12.
All the above properties can be proved; and this is left as an
exercise.
Definition 1.3
Σ1 = {a,b}
Σ2 = {0,1,2}
Σ3 = {0,1,2,3,4,5,6,7,8,9}.
L1 = {ε, a, b}
L2 = {ab, aabb, aaabbb, ...}
L3 = {w ε Σ*| number of a’s and number of b’s in w are equal.}
In the above example, L1 is finite, and L2 and L3 are infinite
languages. φ denotes an empty language.
Definition 1.4
1.
2.
3.
4.
5.
6.
Example 1.11.
Σ+ = {0, 1, 2, 00, 01, 02, 10, 11, 12, 20, 21, 22, ... }
Suppose we wish to include ‘ε’ in Σ+, we modify the above
definition as given below.
Definition 1.5
1.
Basis: ε ∊ Σ*.
2.
3.
4.
5.
6.
The right quotient and right derivative are the following sets,
respectively.
Definition 1.6
1.
2.
3.
4.
Example 1.12.
1.
Let f(n) = n, g(n) = n2. Then clearly f ∊ O(g) as n ≤ 1.n2,
whereas g ∉ O(f).
2.
3.
O(1) ⊂ O(logn) ⊂ O(n) ⊂ O(nlogn) ⊂ O(n2) ⊂ O(cn) ⊂ O(n!).
4.
Definition 1.7
1.
2.
3.
4.
Example 1.13.
Definition 1.8
1.
2.
3.
4.
Example 1.14.
Problem Use mathematical induction to prove for all positive integers n, n(n2 + 5) is an
2
Problem Suppose that we have a system of currency that has $3 and $5 bills. Show that
3 be paid with only $3 and $5 bills for each integer n ≥ 8. Do the same problem
and n ≥ 9.
Solution. Base: n = 8, clearly it can be paid with $3 and $5 bills.
Hypothesis: Assume that debt of $n can be with $3 and $5 bills.
Induction Step:
Consider a debt of $n + 1. Let n = 3k1 + 5k2
1.
If k1 ≥ 3, then n + 1 = (k1 − 3) 3 + (k2 + 2) 5.
2.
3.
If k1 = 2, then n + 1 = 4 × 3 + (k2−1) 5.
4.
5.
If k1 = 1, then n + 1 = 3 × 3 + (k2 − 1) 5.
6.
7.
If k1 = 0, then n + 1 = 2 × 3 + (k2 − 1) 5.
8.
(Note that k2 ≥ 1 in cases 2, 3 and 4 as we need to prove only for n ≥ 8.)
Hence n + 1 = k3. 3 + k4. 5 where k3 and k4 are integers. Hence the result.
Problem Let A be a set with n distinct elements. How many different binary relations on
4 1.
How many of them are reflexive?
2.
3.
How many of them are symmetric?
4.
5.
How many of them are reflexive and symmetric?
6.
7.
How many of them are total ordering relation?
8.
Problem Let R be a symmetric and transitive relation on set A. Show that if for every ‘a
5 exists ‘b’ in A, such that (a, b) is in R, then R is an equivalence relation.
Solution. Given that R is a symmetric and transitive relation on A. To prove that R is an
we need to prove that R is reflexive. By hypothesis we know that ∀a∃b(a, b ∊
Since R is symmetric, it follows that if (a, b) ∊ R then (b, a) ∊ R. Also given th
follows that (a, a) ∊ R. This implies that ∀a∊A, (a, a) ∊ R. This proves that R is
Therefore, R is an equivalence relation.
Exercises
1. Out of a total of 140 students, 60 are wearing hats to class, 51 are wearing scarves, a
both hats and scarves. Of the 54 students who are wearing sweaters, 26 are wearing h
scarves, and 12 are wearing both hats and scarves. Every one wearing neither a hat n
gloves.
1.
How many students are wearing gloves?
2.
3.
How many students not wearing a sweater are wearing hats but not scarves?
4.
5.
How many students not wearing a sweater are wearing neither a hat nor a scarf?
6.
3. At a family group meeting of 30 women, 17 are descended from George, 16 are desc
5 are not descended from George or John. How many of the 30 women are descende
and John?
4. 80 children went to a park where they can ride on three games namely A, B and C. It
them have taken all three rides, and 55 of them have taken at least two of the three ri
$0.50, and the total receipt of the park was $70. Determine the number of children w
the rides.
5. Use Induction to prove the following: If an = 5an−1 − 6an−2 for n ≥ 2 and a0 = 12 and
5(3n) + 7(2n).
7. 1.
Show that
2.
3.
Show that
4.
5.
Show that
6.
9. For each of the following check whether ‘R’ is reflexive, symmetric, antisymmetric,
equivalence relation.
1.
R = {(a, b)|a − b is an odd positive integer}.
2.
3.
R = {(a, b)|a = b2 where a, b ∊ I+}.
4.
5.
Let P be the set of all people. Let R be a binary relation on P such that (a, b) is in R i
6.
7.
Let R be a binary relation on the set of all strings of 0’s and 1’s, such that R = {(a, b)
that have same number of 0’s}.
8.
11. Let R1 and R2 be arbitrary relations on A. Prove or Disprove the following assertions
1.
if R1 and R2 are reflexive, then R1R2 is reflexive.
2.
3.
if R1 and R2 are irreflexive, then R1R2 is irreflexive.
4.
5.
if R1 and R2 are symmetric, then R1R2 is symmetric.
6.
7.
if R1 and R2 are antisymmetric, then R1R2 is antisymmetric.
8.
9.
if R1 and R2 are transitive, then R1R2 is transitive.
10.
14. Prove that the universal relation on any set A is an equivalence relation. What is the r
16. Name five situations (Games, activities, real-life problems etc.,) that can be represen
graphs. Explain what the vertices and the edges denote.
17. Prove that in a group of n-people there are two who have the same number of acquai
18. Let A = {ε, a}, B = {ab}. List the elements of the following sets.
1.
A2
2.
3.
B3
4.
5.
AB
6.
7.
A+
8.
9.
B*
10.
19. Under what conditions is the length function which maps Σ* to N a bijection?
20. Let A and B finite sets. Suppose |A| = m, |B| = n. State the relationship which must ho
‘n’ for each of the following to be true.
1.
There exists an injection from A to B.
2.
3.
There exists an surjection from A to B.
4.
5.
There exists an bijection from A to B.
6.
Copy
Add Highlight
Add Note
Chapter 2. Grammars
The idea of a grammar for a language has been known in India
since the time of Panini (about 5th century B.C). Panini gave a
grammar for the Sanskrit language. His work on Sanskrit had
about 4000 rules (Sutras). From that, it is clear that the concept of
recursion was known to the Indians and was used by them in very
early times.
We can see that the internal nodes of the parse trees are syntactic
categories like article, noun, noun phrase, verb phrase etc. (Figures
2.1 and 2.2). The leaves of the tree are words from these two
sentences.
S – sentence
NP – noun phrase
VP – verb phrase
Art – article
<S> → <NP1><VP>
<NP1> → <Art><Noun1>
<Art> → the
<Noun1> → man
<VP> → <Verb><NP2>
<Verb> → ate
<NP2> → <Art><Noun2>
<Noun2> → fruit
<S> ⇒ <NP1><VP>
⇒ <Art><Noun1><VP>
⇒ The <Noun1><VP>
⇒ The man <VP>
<S> → <NP1><VP>
<NP1> → <PropN>
<PropN> → Venice
<VP> → <Verb><NP2>
<Verb> → is
<NP2> → <Art><adj><N2>
<Art> → a
<adj> → beautiful
<N2> → city
Definition 2.1
Definition 2.2
Example 2.1.
Consider the grammar G = (N, T, P, S) where N = {S, A}, T = {a, b,
c}, production rules in P are:
1.
S → aSc
2.
3.
S → aAc
4.
5.
A → b
6.
A typical derivation in the grammar is:
S ⇒ aSc
⇒ aaScc
⇒ aaaAccc
⇒ aaabccc
L(G) = {anbcn|n ≥ 1}
Definition 2.3
NOTE
Example 2.2.
Let G = (N, T, P, S) where N = {S, B}, T = {a, b, c}, P has the
following rules:
1. S → aSBc
2. S → abc
3. cB → Bc
4. bB → bb
The above rules satisfy the condition that the length of the right-
hand side is greater or equal to the length of the left-hand side.
Hence, the grammar is length-increasing or type 1.
Let us consider the language generated. The number appearing
above ⇒ denotes the rule being used.
Similarly,
⇒ anbc(Bc)n−1 (rule 2 once)
anbBn−1cn (by applying rule times)
Definition 2.5
Definition 2.6
If the rules are of the form A → αB, A → β, A, B ∊ N, α, β ∊ T*, the
grammar is called a right-linear grammar or type 3 grammar and
the language generated is called a type 3 language or regular set.
We can even put the restriction that the rules can be of the form
A → aB, A → b, where A, B ∊ N, a ε T, b ε T ∪ ε. This is possible
because a rule A → a1...akB can be split into A → a1B1,
B1 → a2B2,..., Bk−1 → akB by introducing new non-terminals B1,...,
Bk−1.
Example 2.3.
1.
S → aS
2.
3.
S → bS
4.
5.
S → ε
6.
This grammar generates all strings in T*.
S ⇒ aS (rule 1)
⇒ abS (rule 2)
⇒ abbS (rule 2)
⇒ abbaS (rule 1)
⇒ abbaaS (rule 1)
⇒ abbaabS (rule 2)
⇒ abbaab (rule 3)
Derivation Trees
We have considered the definition of a grammar and derivation.
Each derivation can be represented by a tree called a derivation
tree (sometimes called a parse tree).
Example 2.4.
Consider the following CFG, G = (N, T, P, S), N = {S, A, B}, T = {a,
b}. P consists of the following productions:
1.
S → aB
2.
3.
B → b
4.
5.
B → bS
6.
7.
B → aBB
8.
9.
S → bA
10.
11.
A → a
12.
13.
A → aS
14.
15.
A → bAA
16.
The derivation tree for aaabbb is as follows (Figure 2.5):
The derivation tree has the structure of a rooted directed tree. Each
node has a label. The labels of internal nodes are non-terminals
and the labels of leaves are terminal symbols. The labels of the
leaves of the tree read from the left to right gives the string
generated, which is called the result or yield of the tree.
1.
if and only if w has equal number of a’s and b’s.
2.
3.
if and only if w has one more a than, it has b’s.
4.
5.
if and only if w has one more b than, it has a’s.
6.
Basis
Induction
S ⇒ aB or S ⇒ bA
and the derivation is:
or
where |w1| = |w2| = k and by inductive hypothesis w1 has one
more b than a’s and w2 has one more a than b’s and
so w = aw1 (or bw2) has equal number of a’s and b’s.
(or) .
Example 2.5.
Basis
|w| = 0, S ⇒ ε
|w| = 2, it is either ab or ba, then
Induction
1.
The string begins with ‘a’ and ends with ‘b’.
2.
3.
The string begins with ‘b’ and ends with ‘a’.
4.
5.
Other two cases (begins with a and ends with a, begins with b and
ends with b)
6.
In the first case, w = aw1b and w1 has equal numbers of a’s and b’s.
So, we have as by inductive
hypotheses. A similar argument holds for case 2. In case 3, the
graph mentioned above will cross the x axis.
Theorem 2.1
X1 ...Xm → Y1 ...Yn, 2 ≤ m ≤ n
X1 ... Xm → Z1X2 ... Xm
Z1X2 ... Xm → Z1Z2X3 ... Xm
⋮
Z1Z2 ... Zm−1Xm → Z1Z2 ... ZmYm+1 ... Yn
Z1Z2 ... ZmYm+1 ... Yn → Y1Z2 ... ZmYm+1 ... Yn
⋮
Y1Y2 ... Ym−1 ZmYm+1 ... Yn → Y1Y2 ... YmYm+1 ... Yn
Example 2.6.
A → aAX|aX
B → bBd |bYd
Xb → bX
XY → Yc
Y → c.
Sample Derivations
S ⇒ aB ⇒ abYd ⇒ abcd.
S ⇒ aB ⇒ abBd ⇒ abbYdd ⇒ ab2cd2.
⇒ aabXYd
⇒ aabYcd
⇒ a2bc2d.
S ⇒ aAB ⇒ aaAXB
⇒ aaaXXB
⇒ aaaXXbYd
⇒ aaaXbXYd
⇒ aaabXXYd
⇒ aaabXYcd
⇒ aaabYccd
⇒ aaabcccd.
Example 2.7.
Let L = {ww|w ∊ {0, 1}+}. The above CSL is generated by the type 1
grammar G = (N, T, P, S), where N = {S, X0, X1, L0, L1, R0, R1}, T =
{0, 1} and P consists of the following rules:
1.
S → 0SX0, S → 1SX1.
2.
3.
S → L0R0, S → L1R1.
4.
5.
R0X0 → X0R0.
6.
R0X1 → X1R0.
7.
R1X0 → X0R1.
8.
R1X1 → X1R1.
9.
10.
R0 → 0, R1 → 1.
11.
12.
L0X0 → L0R0.
13.
L0X1 → L0R1.
14.
L1X0 → L1R0.
15.
L1X1 → L1R1.
16.
17.
L0— 0, L1 → 1.
18.
Sample derivations
⇒ 01L0R0X1X0
⇒ 01L0X1R0X0
⇒ 01L0X1X0R0
⇒ 01L0R1X0R0
⇒ 01L0X0R1R0
⇒ 01L0R0R1R0
010010.
⇒ 001SX1X0X0
⇒ 001L0R0X1X0X0
⇒ 001L0X1R0X0X0
⇒ 001L0X1X0R0X0
⇒ 001L0X1X0X0R0
⇒ 001L0R1X0X0R0
⇒ 001L0X0R1X0R0
⇒ 001L0R0R1X0R0
⇒ 001L0R0X0R1R0
⇒ 001L0X0R0R1R0
⇒ 001L0R0R0R1R0
00100010.
Example 2.8.
S → aSBC
S → abc
C → c
CB → DB
DB → DC
DC → BC
bB → bb.
Ambiguity
Ambiguity in CFL is an important concept. It has applications to
compilers. Generally, when a grammar is written for an expression
or a programming language, we expect it to be unambiguous and
during compiling, a unique code is generated. Consider the
following English statement: “They are flying planes.” It can be
parsed in two different ways.
Figure 2.8. Parse tree 2
Definition 2.7
Definition 2.8
Let G = (N, T, P, S) be a CFG. A word w in L(G) is said to be
ambiguously derivable in G, if it has two or more different leftmost
derivations in G.
Definition 2.9
Example 2.9.
Example 2.10.
Example 2.11.
Definition 2.10
Example 2.12.
L1 = {anbncp|n,p ≥ 1}
L2 = {anbmcm|n,m ≥ 1}.
1.
L = {anbncmdm|n, m ≥ 1} ∪ {anbmcmdn|n, m ≥ 1}.
2.
3.
L = {anbmcndp|n, m, p ≥ 1} ∪ {anbmcqdm|n, m, q ≥ 1}.
4.
5.
L = {aibjck|i, j ≥ 1, k ≤ i} ∪ {aibjck|i, j ≥ 1, k ≤ j}.
6.
7.
L = {aibicjdjek|i, j, k ≥ 1} ∪ {aibjcjdkek|i, j, k ≥ 1}.
8.
Now the question arises: how do we find out whether a grammar is
ambiguous or not, or a language is inherently ambiguous or not.
Though for particular cases, it may be easy to find out, the general
problem is undecidable. We shall see the proofs of these theorems
in later chapters.
Theorem 2.2
Theorem 2.3
Definition 2.11
Theorem 2.4
S → AB
S → CD
A → aAb
A → ab
B → cB
B → c
C → aC
C → a
D → bDc
D → bc.
Definition 2.12
We can also use the idea of power series and find out the number
of different derivation trees a string can have. Consider the
grammar with rules S → SS, S → a, write an equation S = SS + a.
Initial solution is S = a, S1 = a.
= aa + a.
S3 = S2S2 + a
= (aa + a)(aa + a) + a
= a4 + 2a3 + a2 + a.
S4 = S3S3 + a
= (a4 + 2a3 + a2 + a)2 + a
E → E + E, E → E * E
E → id
Simplification of CFGs
Context-free grammars can be put in simple forms. The
simplification is done on productions and symbols of the grammar.
Such simplified grammars should be equivalent to the original
grammars started with. Such simplifications on CFGs are
important as CFGs have wide applications in compilers.
A given CFG may have rules and symbols which do not contribute
ultimately to its language. Hence, one can modify the grammar by
removing such rules and symbols. Another issue is the presence
of ε-rules in the productions. One may want to have a ε-free set of
context-free rules in the grammar whenever the underlying CFL
does not contain the empty string. We also give a simplified CFG
that has no unit rules, which are of the
form A → B where A and B are non-terminal symbols.
Definition 2.13
1.
2.
3.
Also X has to derive a string α ∊ T* i.e., .
4.
These two conditions are necessary. But they are not sufficient.
These two conditions maybe satisfied still α1 or α2 may contain a
non-terminal from which a terminal string cannot be derived. So,
the usefulness of a symbol has to be tested in two steps as above.
5.
Lemma 2.1
Let G = (N, T, P, S) be a CFG such that L(G) ≠ φ. Then there
exists an equivalent CFG G′= (N′, T′, P′, S) that does not contain
any useless symbol or productions.
Algorithm GENERATING
1.
Let GEN = T;
2.
3.
If A → α and every symbol of α belongs to GEN, then
add A to GEN.
4.
Remove from N all those symbols that are not in the set GEN and
all the rules using them.
5.
Let the resultant grammar be G2 = (N2, T, P2, S).
6.
Now eliminate all symbols in the grammar G2 that are not
occurring in any derivation from ‘S.’ i.e., .
Algorithm REACHABLE
Let REACH = {S}.
Theorem 2.5
Example 2.1.
N = {S, A, B, C}
T = {a, b} and
First ‘GEN’ set will be {S, A, B, a, b}. Then G2 = (N2, T, P2, S) where
N2 = {S, A, B}
In G2, REACH set will be {S, A, a}. Hence G′ = (N′, T′, P′, S) where
N′ = {S, A}
T′ = {a}
P′ = {S → Sa | A, A → a}
Definition 2.14
Theorem 2.6
Algorithm NULL
1.
Let NULL : = φ,
2.
3.
If A → ε ∊ P, then A ∊ NULL and
4.
5.
If A → B1 ...Bt ∊ P, and each Bi is in NULL, then A ∊ NULL.
6.
Run algorithm NULL for G and get the NULL set.
for A ∊ N.
Basis
If , then A → w ∊ G′. By the construction of G′, one can see
that there exists a rule A → α in G such that α and w differ only in
nullable symbols. Hence where for only ε-rules
are used.
Induction
Assume . Then let .
For the corresponding equivalent derivation by G will
be as some of the are nullable.
Hence, by induction hypothesis.
Hence A . Hence L(G) = L(G′).
Example 2.13.
P = {S → AB0C, A → BC, B → 1|ε, C → D|ε, D → ε} The set NULL = {A, B, C, D}. Then
P′ = {S → AB0C|AB0|A0C|B0C|A0|B0|0C|0, A → BC|B|C, B → 1, C → D}.
Procedure to Eliminate Unit Rules
Definition 2.15
Any rule of the form X → Y, X, Y ∊ N is called a unit rule. Note that
A → a with a ∊ T is not a unit rule.
Lemma 2.2
Let G be a CFG, then there exists a CFG G′ without unit rules such
that L(G) = L(G′).
Algorithm UNIT-PAIR
1.
(A, A) ∊ UNIT-PAIR, for every variable A ∊ N.
2.
3.
If (A, B) ∊ UNIT- PAIR and B → C ∊ P then (A, C) ∊ UNIT- PAIR
4.
Now construct G′ = (N, T, P′, S) as follows. Remove all unit
productions. For every unit-pair (X, Y), if Y → α ∊ P is a non-unit
rule, add to P′, X → α. Thus G′ has no unit rules.
Let us consider leftmost derivations in G and G′.
Example 2.14.
1.
Remove ε-rules;
2.
3.
Remove unit-rules and
4.
5.
Remove useless symbols.
6.
.
Remove symbols not deriving terminal strings.
.
.
Remove symbols not reachable from S.
.
Example 2.15.
L(G) = {a}
Applying step 3(ii) first removes nothing. Then apply step 3(i)
which removes B and S → ABC leaving S → a, A → a,
C → b. Though A and C do not contribute to the set L(G), they are
not removed.
Normal Forms
We have seen in Section 2.3, how a given CFG can be simplified. In
this section, we see different normal forms of CFG i.e., one can
express the rules of the CFG in a particular form. These normal
form grammars are easy to handle and are useful in proving
results. The most popular normal forms are Weak Chomsky
Normal Form (WCNF), Chomsky Normal Form (CNF), Strong
Chomsky Normal Form (SCNF), and Greibach Normal Form
(GNF).
Example 2.16.
Theorem 2.7
For any CFG G = (N, T, P, S) there exists a CFG G′ in WCNF such
that L(G) = L(G′).
Example 2.17.
Theorem 2.8
A → A1B1
B1 → A2A3.
A → A1B1
B1 → A2B2
⋮
Bn−2 → An−1An.
Example 2.18.
T = {a, b}
Hence G″ = (N″, T, P″, S) will be with N″ = {S, A, B, C, B1, B2, B3}, T = {a, b}
Clearly, G″ is in CNF.
1.
2.
3.
4.
Theorem 2.9
T = T
P′ = {AL → BLCR, AR → BLCR|A → BC ∊ P}
∪ {S′ → XLYR|S → XY ∊ P}
∪ {S′ → a|S → a ∊ P}
∪ {AL→ a, AR → a|A → a ∊ P, a ∊ T}.
T = {0, 1}
P′ = {S′ → ALBR|0, SL → ALBR|0,
SR → ALBR|0, AL →ALBR|0,
AR → ALBR|0, BL → BLAR|1,
BR → BLAR|1}.
TECHNIQUE 1
For any CFG G = (N, T, P, S) with a A-production A → α1Bα2 ∊ P,
and B-productions B → y1|y2|...yn, there exists an equivalent CFG
with new A-productions
TECHNIQUE 2
Let G = (N, T, P, S) be a CFG with A-productions,
1.
A →y1|y2| ... |ym.
2.
A → y1Z|y2Z| ... |ymZ.
3.
4.
Z → x1|x2| ... |xn
5.
Z → x1 Z|x2Z| ... |xnZ.
6.
7.
Remaining rules of P excluding original A-productions.
8.
Then G′ and G are equivalent. Left recursion is removed by
introducing right recursion. If w ∊ L(G), .
Theorem 2.4
For every CFL L with ε ∉ L, there exists a CFG in GNF such that
L(G) = L.
1.
2.
3.
4.
Basis
Induction
1.
2.
3.
4.
5.
6.
Hence G1 is in GNF.
Example 2.5.
1.
S = A1, A = A2, B = A3.
2.
Rules now become:
3.
.
A1 → A1A1
.
.
A1 → A2A1A3
.
.
A1 → A2A3
.
.
A2 → a
.
.
A3 → b.
.
4.
Convert the Ai rules such that they are of the
form Ai → aw or Ai → Ajw j > i.
5.
Taking rules 1, 2, and 3 they can be replaced by the following 6
rules:
6.
7. A1 → A2A1A3
8. A1 → A2A3
9. A1 → A2A1A3Z
10. A1 → A2A3Z
11. Z → A1Z
12. Z → A1.
7.
A2, A3 rules are already in GNF.
8.
9.
is not necessary here.
10.
11.
Convert Ai rules into GNF. Starting from An and going up to A1,
12.
A3 → b
13.
A2 → a are in GNF
14.
A1 rules become
15.
7′. A1 → aA1A3
16.
8′. A1 → aA3
17.
9′. A1 → aA1A3Z
18.
10′. A1 → aA3Z
19.
20.
Convert the Z rules into GNF
21.
11 is replaced by the 4 rules
13. Z → aA1A3Z
14. Z → aA3Z
15. Z → aA1A3ZZ
16. Z → aA3ZZ
13′. Z → aA1A3
14′. Z → aA3
15′. Z → aA1A3Z
16′. Z → aA3Z
22.
Note that 15′ and 16′ are repetition of 13 and 14.
23.
So we end up with:
24.
A1 → aA1A3
A1 → aA3
A1 → aA1A3Z
A1 → aA3Z
A2 → a
A3 → b
13. Z → aA1 A3Z
14. Z → aA3Z
15. Z → aA1A3ZZ
16. Z → aA3ZZ
13′. Z → aA1A3
14′. Z → aA3.
25.
Useless symbols and rules can be removed afterwards
(e.g. A2 → a).
26.
S ⇒ aSb
⇒ aaSbb
⇒ aaaSbbb
⇒ aaaaSbbbb
⇒ aaaaa bbbbb
b. {anbmcn|n, m ≥ 1}
Solution. The grammar G = (N, T, P, S), N = {S, A}, T = {a, b, c} P is given as follows:
1.
S → aSc
2.
3.
S → aAc
4.
5.
A → bA
6.
7.
A → b
8.
Rule 1 and 2 generate equal number of a’s and c’s; rule 2 makes sure at least o
generated. Rule 3 and 4 generate b’s in the middle. Rule 4 makes sure at least
is to be noted that a’s and c’s are generated first and b’s afterwards.
c. {anbncm|n, m ≥ 1}
d. {anbncmdm|n, m ≥ 1}
Solution.1.
S → AB
2.
3.
A → aAb
4.
5.
A → ab
6.
7.
B → cBd
8.
9.
B → cd
10.
e. {anbmcmdn|n, m ≥ 1}
Solution.1.
S → aSd
2.
3.
S → aAd
4.
5.
A → bAc
6.
7.
A → bc
8.
Solution.1.
S → aSb
2.
3.
S → aAb
4.
5.
A → aA
6.
7.
A → a
8.
Solution. {anbm|n, m ≥ 1,n ≠ m} = {anbm|n, m ≥ 1,n > m} ∪ {anbm|n, m ≥ 1, m > n} Rules a
1.
S → aSb
2.
3.
S → aAb
4.
5.
A → aA
6.
7.
A → a
8.
9.
S → aBb
10.
11.
B → bB
12.
13.
B → b
14.
Rules 1, 2, 3, and 4 generate more a’s than b’s. Rules 1, 5, 6, and 7 generate m
h. {wcwR|w ∊ {a,b}*}
b. {anbm|n, m ≥ 1}
Solution. We give below the rules only. Capital letters stand for non-terminals.
1.
S → aS
2.
3.
S → aA
4.
5.
A → bA
6.
7.
A → b
8.
c. {a2n|n ≥ 1}
Solution.1.
S → aA
2.
3.
A → aS
4.
5.
A → a
6.
d. {(ab)n|n ≥ 1}
Solution.1.
S → aA
2.
3.
A → bS
4.
5.
A → b
6.
e. {anbmcp|n, m, p ≥ 1}
Solution.1.
S → aS
2.
3.
S → aA
4.
5.
A → bA
6.
7.
A → bB
8.
9.
B → cB
10.
11.
B → c
12.
f. {(abc)n|n ≥ 1}
Solution.1.
S → aA
2.
3.
A → bB
4.
5.
B → cS
6.
7.
B → c
8.
Exercises
1. Find a CFG for the languages over {0, 1} consisting of those strings in which the rati
1’s to the number of 0’s is three to two.
6. Which of the following grammars are ambiguous? Are the languages generated inher
1.
.
S → ε
.
.
S → aSb
.
.
S → SS
.
2.
.
S → ε
.
.
S → aSb
.
.
S → bSa
.
.
S → SS
.
3.
.
S → bS
.
.
S → Sb
.
.
S → ε
.
4.
.
S → SaSa
.
.
S → b
.
5.
.
S → Sb
.
.
S → aSb
.
.
S → Sa
.
.
S → a
.
6.
.
S → a
.
.
S → aaS
.
.
S → aaaS
.
7.
.
S → A
.
.
S → aSb
.
.
S → bS
.
.
A → Aa
.
.
A → a
.
8.
.
S → AA
.
.
A → AAA
.
.
A → bA
.
.
A → Ab
.
.
A → a
.
9. Consider the grammars over the terminal alphabet Σ = {a, b} with rules
1.
S → wSS
2.
S → a
3.
S → b
4.
5.
S → aSS
6.
S → bSS
7.
S → w
8.
where w is some string over Σ. Show that each of these grammars is always ambiguo
be.
10. Consider the grammar S → aS|aSbS|ε. Prove that the grammar generates all and only
and b’s such that every prefix has at least as many a’s as b’s. Show that the grammar
an equivalent unambiguous grammar.
11. Consider the following grammar. E → +EE| * EE| − EE|x|y. Show that the grammar
What is the language generated?
12. Which of the following CFLs you think are inherently ambiguous? Give arguments.
1.
{aibjckdl|i, j, k, l ≥ 1,i ≠ j and k ≠ l}
2.
3.
{aibjckdl|i, j, k, l ≥ 1,i = k or j = l}
4.
5.
{aibjckdl|i, j, k, l ≥ 1, i = j and k = l or i = l and j = k}
6.
7.
{aibjckdl|i, j, k, l ≥ 1,i ≠ j or k ≠ l}
8.
16. Find a CFG with six productions (including ε productions) equivalent to the followin
S → b | bHF | bH | bF
H → bHc | bc
F → dFe | de | G
G → dG |d
19. Suppose G is a CFG and w ∊ L(G) and | w | = n. How long is a derivation of w in G if
1.
G is in CNF
2.
3.
G is in GNF
4.
20. Show that every CFL without ε is generated by a CFG whose productions are of the
A → aB and A → aBC.
21. An operator CFG represents an ε-free context-free grammar such that no production
non-terminals on its right-hand side. That is, an ε-free CFG, G = (N, T, P, S), is an op
all p ∊ P, rhs(p) ∉ (N ∪ T)*NN(N ∪ T)*. Prove that for every CFG G there exists an
such that L(G) = L(G′).
25. For each CFG G = (N, T, P, S) there is an invertible CFG, G′= (N′, T, P′, S′) such tha
Moreover
1.
A → ε is in P′ if and only if ε ∊ L(G) and A = S′
2.
3.
S′ does not appear on the right-hand side of any rule in P′
4.
26. Let L be a CFL. Then show that L can be generated by a CFG G = (N, T, P, S) with t
following forms:
S → ε
A → a, a ∊ T
A → B, B ∊ N− {S}
When the schedule allots time, the process goes from ‘start’ state to
‘run’ state. When the allotted time is finished, it goes from ‘run’
state to ‘wait’ state. When the job is finished, it goes to the ‘end’
state.
Time 654321
100101
100111
Figure 3.4. Representation of a transition
Figure 3.6. Parity checker
Figure 3.7. FSA as a recognizer
The input string is placed on the input tape. Each cell contains one
symbol. The tape head initially points to the leftmost symbol. At
any stage, depending on the state and the symbol read, the
automaton changes its state and moves its tape head one cell to the
right. The string on the input tape is accepted, if the automaton
goes to one of the designated final states, after reading the whole of
the input. The formal definition is as follows.
Definition 3.1
A DFSA is a 5-tuple
(q, ε) = q for all q in K
Example 3.1.
T(M) = {anbm|n, m ≥ 1}
There is a reason for naming the fourth state as D. Once the control
goes to D, it cannot accept the string, as from D the automaton
cannot go to a final state. On further reading, for any symbol the
state remains as D. Such a state is called a dead state or a sink
state.
If the machine is in q0 state and reads ‘a,’ then it has the choice of
going to q0 or q1.
Equation 3.1.
Definition 3.2
If P is a subset of K
Since δ (q. a) and (q. a) are equal for a ∊ Σ, we can use the
same symbol δ for also.
Figure 3.11. State table
There is a row corresponding to each state and a column
corresponding to each input symbol. The initial state is marked with
an arrow and the final state with a circle. In the case of NFSA,
each cell contains a subset of states and in the case of DFSA each
cell contains a single state.
Example 3.2.
Example 3.3.
Theorem 3.1
We show that:
Basis
Induction
Assume that the result is true for strings x of length upto m. We
have to prove for string of length m + 1. By induction hypothesis
Suppose
By our construction
Example 3.4.
Let us construct the DFSA for the NFSA given by the table
in Figure 3.11. We construct the table for DFSA.
Equation 3.2.
Other states [q1], [q2], [q0, q2], [q0, q1, q2] are not accessible from
[q0] and hence the transitions involving them are not shown.
NFSA with ε-transitions
Having defined NFSA, we now try to include ε-transition to NFSA.
We allow the automaton to change state without reading any
symbol. This is represented by an ε-transition (Figure 3.15).
Figure 3.15. ε-transition
Example 3.5.
In Figure 3.16, q0 is the initial state and q3 is final state. There is
an ε-transition from q0 to q1 and another from q2 to q3. It is not
difficult to see that the set of strings which take the automaton
from q0 to q3 can be represented by {anbmcpdq/m ≥ 1, n, p, q ≥ 0}.
Definition 3.3
δ can be extended as to K × Σ* as follows. First, we define the ε-
closure of a state q. It is the set of states which can be reached
from q by reading ε only. Of course, ε-closure of a state includes
itself.
Theorem 3.2
= F otherwise.
Induction
|x| > 1. Then x = ya for some y ∊ Σ* and a ∊ Σ.
Then δ′(q0, ya) = δ′(δ′(q0, y), a).
Let .
Therefore
Example 3.6.
ε-closure of (q0) = {q0, q1}
ε-closure of (q1) = {q1}
ε-closure of (q2) = {q2, q3}
ε-closure of (q3) = {q3}
It is not difficult to see that the language accepted by the above
NFSA = {anbmcpdq|m ≥ 1, n, p, q ≥ 0}.
Regular Expressions
Regular expressions are another way of specifying regular sets.
Definition 3.4
Example 3.7.
{(ab)ncd|n ≥ 1}
Example 3.8.
Theorem 3.3
Figure 3.19. M1 accepting R1
Figure 3.20. M2 accepting R2
For this NFSA, q0 is the ‘start’ state and qf is the ‘end’ state.
Figure 3.22. NFSA for R1R2
For this NFSA with ε-moves, q0 is the initial state and qf is the final
state. It can be seen that contains strings of the
form x1x2 . . . xk each xi ∊ R1. To accept this string, the control
goes from q0 to q01 and then after reading x1 and reaching qf1, it
goes to q01, by an ε-transition. From q01, it again reads x2 and goes
to qf1. This can be repeated a number (k) of times and finally the
control goes to qf from qf1 by an ε-transition. is accepted
by going to qf from q0 by an ε-transition.
Thus, we have seen that for a given regular expression one can
construct an equivalent NFSA with ε-transitions.
Example 3.9.
Figure 3.25. NFSA for a and b
a* and b* are accepted by NFSA with ε-moves given in Figure 3.26.
Figure 3.27. NFSA for aa*bb*
But we have already seen that a simple NFSA can be drawn easily
for this as in Figure 3.28.
Next, we see that for a given DFSA how the corresponding regular
expression can be found. (Figure 3.29).
Theorem 3.4
δ(q0, x) = qx,
δ(q0, xy) ∊ F ⇔ xy ∊ L,
δ(q0, xy) = δ(qx, y)
δ(qx, y) ∊ F ⇔ y ∊ Lx,
∴ M′ accepts Lx.
Lemma 3.1
Let Σ be an alphabet. The equation X = AX ∪ B where A, B ⊆
Σ* has a unique solution X = A*B if ε ∉ A.
Proof. Let
Equation 3.8.
Equation 3.9.
Algorithm
Let M = (K, Σ, δ, q0, F) be the DFSA.
1.
Write an equation for each state in K.
2.
q = a1 qi1 + a2 qi2 + ... + akqik
3.
if q is not a final state and δ(q, aj) = qij 1 ≤ j ≤ k
4.
q = a1 qi1 + a2 qi2 + ... + akqik + λ
5.
if q is a final state and δ(q, aj) = qij 1 ≤ j ≤ k.
6.
7.
Take the n equations with n variables qi, 1 ≤ i ≤ n, and solve
for q0 using Lemma 3.1 and substitution.
8.
9.
Solution for q0 gives the desired regular expression.
10.
Let us execute this algorithm for the following DFSA given
in Figure 3.30.
Figure 3.30. DFSA for aa*bb*
Step 1
Equation 3.10.
Equation 3.11.
Equation 3.12.
Equation 3.13.
Step 2
D = (a + b) D + φ
Equation 3.14.
Equation 3.15.
Equation 3.16.
Equation 3.17.
Note that we have got rid of one equation and one variable. In
Equation (3.17) using Lemma 3.4.1, we get
Equation 3.18.
Equation 3.19.
Equation 3.20.
Equation 3.21.
Let q be the state of the DFSA for which we are writing the
equation,
Equation 3.22.
Y = λ or φ.
Let L be the regular set accepted by the given DFSA. Let x be a
string such that starting from q0, after reading x, state q is reached.
Therefore q represents Lx, the derivative of L with respect to x.
From q after reading aj, the state qij is reached.
Equation 3.23.
Solution. It should be noted that the set of strings over Σ = {a, b} can be divided into
1.
having even number of a’s and even number of b’s.
2.
3.
having even number of a’s and odd number of b’s.
4.
5.
having odd number of a’s and even number of b’s.
6.
7.
having odd number of a’s and odd number of b’s.
8.
Strings in class (i) take the machine to q0, class (ii) to q3, class (iii) to q1, an
to q2 (Figure 3.31).
b. The set of strings over {a, b} whose length is divisible by 4 (Figure 3.32).
Problem 2. Describe the language accepted by the following DFSA in Figure 3.35.
a.
Problem 3. For the following NFSA find equivalent DFSA (Figure 3.39).
a.
The state table can be represented by the state diagram as given below (Figu
The state table can be represented by the state diagram given in Figure 3.13.
Solution.
The state table can be represented by the state diagram given in Figure 3.12.
The state table can be represented by the state diagram given below (Figure
Problem 4. Write regular expression for each of the following languages over the alphab
1.
The set of strings containing ab as a substring.
2.
3.
The set of strings having at most one pair of consecutive a’s and at most one
consecutive b’s.
4.
5.
The set of strings whose length is divisible by 6.
6.
7.
The set of strings whose 5th last symbol (5th symbol from the end) is b.
8.
Solution. 1.
A = (a + b)*ab(a + b)*
2.
3.
One pair of a’s but no pair of b’s B1 = (b + ε)(ab)*aa(ba)*(b + ε) One pair o
of a’s B2 = (a + ε)(ba)*bb(ab)*(a + ε) B = B1 + B2
4.
aa occurring before bb
5.
C = (b + ε)(ab)* aa(ba)* bb(ab)* (a + ε)
6.
bb occurring before aa
7.
D = (a + ε)(ba)* bb(ab)* aa(ba)* (b + ε)
8.
No pair of a’s and b’s
9.
E = (b + ε)(ab)* (a + ε)
10.
Required regular expression is B + C + D + E
11.
12.
[(a + b)6]*
13.
14.
(a + b)*b(a + b)4
15.
Exercises
1. The following are the state diagrams of two DFSA’s M1 and M2. Answer the followi
these machines (Figure 3.49)
1.
What is the start state of M1?
2.
3.
What are the accepting states of M1?
4.
5.
What is the start state of M2?
6.
7.
What is the sequence of states does M1 go through on input 0000111?
8.
9.
Does. M1 accept 00001111?
10.
11.
Does M2 accept ε?
12.
7. Let Σ = {a, b}. Consider the language consisting of all words that have neither conse
consecutive b’s. Draw a DFSA that accepts this language.
8. Let Σ = {a, b, c}. Let L = {x ∊ {a, b, c}*||x| = 0 mod 5}. Draw a DFSA that accepts L
9. Let Σ = {a, b, c}. Consider the language consisting of words that begin and end with
Draw a DFSA that accepts this language.
11. Suppose we alter the definition of a DFSA so that once the automaton leaves its start
to its start state. For such a DFSA, if an input w causes it to take a transition from a s
state q0, where p ≠ q0, then the DFSA immediately halts and rejects w. Call this new
return-DFSA. Prove that the class of languages recognized by no-return-DFSA is the
languages.
12. Construct a NFSA for each of the languages given in problem no. 1,3,5,6,7,8,9.
15. Let Σ = {a, b}. Find a NFSA for each of the following languages:
1.
{x|x contains an even number of a’s}.
2.
3.
{x|x contains an odd number of b’s}.
4.
5.
{x|x contains an even number of a’s and an odd number of b’s}
6.
7.
{x|x contains an even number of a’s or an odd number of b’s}
8.
16. Suppose we alter the definition of an NFSA so that we now identify two types of stat
the good states G ⊆ Q, and the bad states B ⊆ Q where G ∩ B = φ. (Note that a state
good nor bad, but no state is both good and bad). The automata accepts input w if, co
computations on w, some computation ends in G and no computation ends in B. Call
NFSA as a good-bad NFSA.
Prove that the class of languages recognized by good-bad NFSAs is the class of regu
17. In the questions below, given a language L we describe how to form a new language
in L. Prove that if L is regular then the new languages are regular by constructing an
languages.
1.
skip(L) = {xy|xcy ∊ L, where x and y are strings, c is a letter}
2.
3.
suffix(L) = {y|xy ∊ L, x, y are strings}.
4.
18. Convert the following two NFSA to equivalent DFSA using subset construction meth
20. Construct a NFSA accepting the language denoted by the following regular expressio
NFSA to an equivalent DFSA.
1.
a*ba*ab*
2.
3.
a*bb*(a + b)ab*
4.
5.
b((aab* + a4)b)*a
6.
21. Given the following DFSAs, construct equivalent regular expressions (Figure 3.52).
22. Give an NFSA with four states equivalent to the regular expression (01 + 011 + 0111
automaton to an equivalent DFSA using subset construction.
23. Give regular expressions that describe each of the following languages, which are ov
1}. Explain how you constructed your regular expressions.
1.
{w| w contains substrings 010 and 101}
2.
3.
{w|w does not contain substring 0110}
4.
5.
{w| w has an even number of 0’s and an even number of 1’s}
6.
7.
{w|w has the same number of occurrences of 10 and 01}
8.
Note that in (a) and (d) occurrences can overlap.
24. For each of the following languages, give two strings that are members and two strin
members – a total of four strings for each part. Let Σ = {a, b} in all parts.
1.
a*b*
2.
3.
a(ba)*b
4.
5.
a* ∪ b*
6.
7.
(aaa)*
8.
9.
Σ*aΣ*bΣ*aΣ*
10.
11.
aba ∪ bab
12.
13.
(Σ ∪ a)b
14.
15.
(a ∪ ba ∪ bb) Σ*
16.
25. Let Σ = {a, b}. Give (if possible) a regular expression that describes the set of all eve
26. Give examples of sets that demonstrate the following inequalities. Here, r1, r2, r3 are
1.
r1 + ∊ ≠ r1
2.
3.
r1 · r2 ≠ r2 · r1
4.
5.
r1 · r1 ≠ r1
6.
7.
r1 + (r2 · r3) ≠ (r1 + r2) · (r1 + r3)
8.
9.
(r1 · r2)* ≠ (r*1 · r*2)*
10.
27. Find examples of sets that show the following expressions maybe equal under some
Here, r1, r2, r3 are regular expressions.
1.
r1 + ∊ = r1
2.
3.
r1 · r2 = r2 · r1 (even if r1 ≠ r2)
4.
5.
r1 · r1 = r1
6.
7.
r1 + (r2 · r3) = (r1 + r2) · (r1 + r3) (even if r1 ≠ r2 and r3 = r1)
8.
28. Solve the following language equations for X1, X2, and X3 by eliminating X3 and then
Solve for X1 and then back-substitute to find X2 and X3.
X1 = φ + φX1 + (0 + 1)X2 + φX3
X3 = φ + φX1 + (0 + 1) X2 + φX3.
1.
Si → aSj if δ(qi, a) contains qj for qj ∉ F
2.
3.
Si → aSj and Si → a if δ(qi, a) contains qj, qj ∊ F.
4.
To prove L(G) = L = L(M).
1.
δ([A], ε) = {[α]|A → α ∊ P}
2.
3.
If a ∊ T or α ∊ T*N, then δ([aα], a) = {[α]}. Clearly, [α] ∊ δ([S], w) if
and only if where A → yα ∊ P and xy = w.
If w ∊ L(M), then α = ε. M accepts w if and only
if . Hence the converse follows.
4.
Example 4.1.
Example 4.2.
Σ = {0, 1}
F = {B}
δ: {δ(A, 0) = B, δ(B, 0) = D, δ(C, 0) = B, δ(A, 1) = D, δ(B, 1)
= C, δ(C, 1) = D, δ(D, 0) = D, δ(D, 1) = D}.
The corresponding regular grammar will be as follows:
G = ({A, B, C, D}, {0, 1}, P, A) where
P = {A → 0B|1D|0, B → 0D|1C|, C → 0B|1D|0, D → 0D|1D}.
Clearly, L(M) = L(G) = 0(10)*.
1.
|xy| ≤ k
2.
3.
|y| > 1
4.
5.
x yiz ∊ L ∀i ≥ 0
6.
Example 4.3.
Let L = {anbn| n ≤ 1}. If L is regular, then by the above lemma there
exists a constant ‘k’ satisfying the pumping lemma conditions.
Choose w = akbk. Clearly |w| > k. Then w = xyz, |xy| ≤ k and |y| ≥
1. If |x| = p, |y| = q, |z| = r, p + q + r = 2k, and p + q ≤ k.
Hence, xy consists of only a’s and since |y| ≥ 1, xz ∉ L as number
of a’s in x is less than k and |z|b = k. Hence, pumping lemma is not
true for i = 0 as xyiz must be in L for i ≥ 0. Hence L is not regular.
Example 4.4.
In the next chapter, we see that there is a simpler proof for this
using Myhill-Nerode theorem.
Example 4.5.
It should also be noted that it is not true that for arbitrarily long
strings z in a regular set L, z can be written in the form uviw for
large i.
Example 4.6.
Step 1: w1 = abba
Step 2: w2 = abbabaab
⋮
Closure Properties
Theorem 4.3
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
We prove that regular languages are also closed under
homomorphism and right quotient.
Theorem 4.4
Regular languages are closed under homomorphism.
Theorem 4.5
Let L1 and L2 be two regular languages. Then L1/L2 is also regular.
Theorem 4.6
Let h: be a homomorphism. If is regular,
then will be regular.
δ′(q, x) = δ(q, h(x))
δ′(q, x′ a) = δ′(δ′(q, x′), a)
= δ′(δ(q, h(x′)),a)
= δ(δ(q, h(x′)), h(a))
= δ(δ(q, h(x′)h(a))
= δ (q, h(x′ a)).
Hence, one can see that L(M′) = h-l(L(M)) for any input x ∊ Σ1. i.e.,
iff δ(q0, h(x)) ∊ F
iff h(x) ∊ L(M)
iff x ∊ h−1(L(M)).
Decidability Theorems
In this section, we address the basic decidability issues for regular
languages. They are membership problem, emptiness problem,
and equivalence problems.
Theorem 4.7
Theorem 4.8
One can see that the automaton accepts sentences of length less
than n (where n is the number of states of the DFSA), if and only
if L(M) is non-empty. One can prove this statement using pumping
lemma. That is, |w| < n for if w were the shortest and |w|
≥ n then w = xyz and xz is shorter than w that belongs to L.
Theorem 4.9
Solution 1.
. IΣ is closed under union. Let L1 and L2 be in IΣ. L1 and L2 are infinite sets L1 ∪
x ∊ L1 or x ∊ L2}. L1 ∪ L2 includes L1 and also L2. Hence L1 ∪ L2 is infinite.
2.
3.
IΣ is not closed under intersection. Consider Σ = {a}.
4.
L1 = {a2n|n ≥ 1} is an infinite set.
5.
L2 = {ap|p is a prime} is an infinite set.
6.
L1, L2 ∊ IΣ
7.
L1 ∩ L2 = {a2} which is a finite set and hence it is not in IΣ.
8.
Figure 4.3. Solution to Problem 3
Exercises
1. Let Σ be an alphabet. Define IΣ to be the collection of all infinite languages over Σ. N
include any finite language over Σ. Prove or give counter examples to the following:
1.
IΣ is closed under complementation
2.
3.
IΣ is closed under concatenation
4.
5.
IΣ is closed under Kleene closure
6.
3. If L is accepted by a NFSA, is it necessarily true that all subsets of L are accepted by
give counter examples.
5. We have shown that the union of two regular languages is regular. Is the union of a c
languages always regular? Justify your answer.
7. Let P = {x| |x| is prime} and let I(L) be defined by I(L) = L ∩ P. Let DΣ denote the co
languages recognized by a DFSA
1.
Show that DΣ is not closed under I
2.
3.
Prove or disprove NΣ is closed under I
4.
10. Given any alphabet Σ and a regular expression r1 over Σ, show that it is decidable wh
DFSA with less than 31 states that accepts the language described by r1.
12. Construct a regular grammar equivalent to each of the following NFSA (Figure 4.4).
Figure 4.4. State diagrams for Exercise 12
Myhill-Nerode Theorem
In an earlier chapter, we considered the examples of serial adder,
parity machine, acceptor accepting {anbm|n,m ≥ 1}, and many more
such examples. Consider the serial adder. After getting some input,
the machine can be in ‘carry’ state or ‘no carry’ state. It does not
matter what exactly the earlier input was. It is only necessary to
know whether it has produced a carry or not. Hence, the FSA need
not distinguish between each and every input. It distinguishes
between classes of inputs. In the above case, the whole set of inputs
can be partitioned into two classes – one that produces a carry and
another that does not produce a carry. Similarly, in the case of
parity checker, the machine distinguishes between two classes of
input strings: those containing odd number of 1’s and those
containing even number of 1’s. Thus, the FSA distinguishes
between classes of input strings. These classes are also finite.
Hence, we say that the FSA has finite amount of memory.
1.
2.
3.
4.
5.
Proof. We shall prove (1) ⇒ (2), (2) ⇒ (3), and (3) ⇒ (1).
(1) ⇒ (2)
∀x, y xRM y and yRMz ⇒ xRMz.
(2) ⇒ (3)
If this holds xwRLyw.
δ′([x], a) = δ′([y], a)
⇓ ⇓
[xa] = [ya]
if x ∊ L, [x] is a final state in M′, i.e., [x] ∊ F′. This automaton M′
accepts L.
Example 5.1.
1.
H1, set of strings which take M from q0 to q0 i.e., b*.
2.
3.
H2, set of strings which take M from q0 to q1, i.e., set of strings
which have odd numbers of a’s.
4.
5.
H3, set of strings which take M from q0 to q2, i.e., set of strings
which have even number of a’s.
6.
L = H2 ∪ H3 as can be seen.
1.
Let x ∊ H1 and y ∊ H2. Then, xb ∊ H1 and yb ∊ H2.
Then, xb ∉ L and yb ∊ L. Therefore x L y.
2.
3.
Let x ∊ H1 and y ∊ H3. Then, xb ∊ H1 and so xb ∉ L and yb ∊ H3 and
so xb ∊ L. Therefore x L y.
4.
5.
Let x ∊ H2 and y ∊ H3. Take any string z, xz belongs to
either H2 or H3 and so in L, yz belongs to either H2 or H3 and so
in L. Therefore xRL y.
6.
So, if we construct M′ as in the proof of the theorem, we have one
state corresponding to H1 and one state corresponding
to L = H2 ∪ H3.
Theorem 5.2
h(δ(q, a)) = δ′(q′, a).
This is achieved by defining h as follows: h(q0) = q′0 and if q ∊ K,
then there exists a string x such that δ(q0, x) = q. h(q) = q′
where δ(q′0, x) = q′. This definition of h is consistent. This can be
seen as follows: Let δ(q, a) = p and δ′(q′, a) = p′, δ(q0 xa) = p and δ′
(q′0, xa) = p′ and hence h(p) = p′.
Minimization of DFSA
In this section, we shall see how we can find the minimum state
automaton corresponding to a DFSA.
Step 1. Consider the set of states in K. Divide them into two
blocks F and K — F. (Any state in F is distinguishable from a state
in K — F by ε.) Repeat the following step till no more split is
possible.
Example 5.2.
Example 5.3.
Definition 5.1
Σ is a finite set of input alphabet
q0 in K is the initial state. Since, we are interested in the output for
an input, we do not specify any final state.
Input: a1a2 ... an
States: q0q1q2 ... qn
Output: b0b1b2 ... bn
Example 5.4.
Input: 100110110
States: q0q1q2q4q4q4q3q2q0q0
Output: ynnnnnnnyy
Figure 5.8. A Moore machine
Definition 5.2
For an input:
Input: a1a2 ... an
States: q0q1q2 ... qn
Output: b1 ... bn
Example 5.5.
The machine outputs y if the last two inputs symbols are 01, n,
otherwise (Figure 5.9). For a sample input 001101001, states
are q0q1q1q2q0q1q2q1q1q2 and output is nnynnynny.
Theorem 5.3
Theorem 5.4
ambn ≈ anbn
ambn ∊ L but anbn ∉ L
Therefore, we have a contradiction and the language is not regular.
2. Which of the following languages are regular sets? Prove your answer.
1.
L1 = {xxR|x ∊ {0, 1}+}
2.
3.
L2 = {xwxR|x,w ∊ {0, 1}+}
4.
5.
L3 = {xxRw|x,w ∊ {0, 1}+}
6.
Solution 1.
. L1 is not regular.
2.
Suppose L1 is regular.
3.
Let n be the constant of the pumping lemma. Consider 0n110n. The pump will o
first n 0’s. So, we shall get strings 0m 110n ∊ L, m ≠ n which is a contradiction.
4.
5.
L2 is regular.
6.
L2 can be represented by the regular expression
7.
0(0 + 1)+ 0 + 1(0 + 1)+ 1.
8.
9.
L3 is not regular. Suppose L3 is regular, (01)n(10)n0 ∊ L. x = (01)n, w = 0.
10.
By Myhill-Nerode theorem, since the number of equivalence classes is finite.
(01), (01)2, (01)3,... all cannot belong to different equivalence classes. For some
n (01)m and (01)n will belong to the same equivalence class. We write this as (0
Let m < n. Because of the right invariance,
(01)m(10)m0 ≈ (01)n(10)m0.
Since (01)m(10)m0 ∊ L3, we conclude (01)n(10)m0 ∊ L3. But (01)n(10)m0 is not of
Hence, we arrive at a contradiction. Therefore, L3 is not regular.
3. Construct a Mealy machine with Σ = Δ = {0, 1}. The output is 1 whenever the
read are 1111. Overlapping sequences are accepted. Output is 0 otherwise.
Solution
.
Figure 5.12. Solution to Problem 3
4. Use Myhill-Nerode theorem to show the following language is not regular {0i1
Solution L = {0i1j | gcd(i, j) = 1} is not regular. Suppose L is regular. Consider the sets o
. {p1, p2, ... .}. This is an infinite set. Consider the set of strings 0P1, 0P2, 0P3,... . B
theorem, all of them cannot be in different equivalence classes. For some pi an
be in the same equivalence class.
0Pi ≈ 0Pj
0Pi1Pj ≈ 0Pj1Pj
5. Minimize the following DFSA. Indicate clearly which equivalence class corres
of the new automaton.
a b
→ 1 6 3
2 5 6
4 5
3 2
5 2 1
6 1 4
Solution Splitting into non-final and final states , .
. Considering b successors of 1,2,5,6 is split into . Further split is not po
minimum state automaton is:
a b
Exercises
1. Construct a Moore machine with input alphabet Σ = {0, 1}. The output after reading
reminder when x, the number whose binary representation is x is divided by 3. Hence
Δ = {0, 1, 2} leading 0’s in x in the binary representation of x is allowed.
2. Construct a Mealy machine with Σ = Δ = {0, 1}. The output is 1 whenever the last fiv
contain exactly three 1’s and the 4th and 5th last symbols read are 11. After each sub
with two 1’s, analysis of the next string will not start until the end of this substring o
at the end 0 or 1 is output. For example, for input 11110100, output is 00000000. For
output is 00001000.
3. Find a Mealy machine with Σ = Δ = {0, 1} satisfying the following condition. The ou
the input at time t is the same as input at time t − 2.
4. Find a Mealy machine with Σ = Δ = {0, 1} satisfying the following condition: For ev
subsequence x3i+1x3i+2x3i+3 the output is x3i+3 if this substring consisted of 2 or 3 1’s.
5. Find a Mealy machine with Σ = {a, b, c, d, e} and Δ = {0, 1} satisfying the following
output is 1 if the last three symbols read are in alphabetical order i.e., abc, bcd or cde
6. Use Myhill-Nerode theorem to show the following languages are not regular.
1.
{anbcn|n ≥ 1}
2.
3.
{anbncn|n ≥ 1}
4.
5.
{anbn2|n ≥ 1}
6.
7.
(ww|w ∊ {0, 1}+}
8.
9.
{anbm|n ≤ m, n, m ≥ 1}
10.
→ 1 2 3
2 5 6
1 4
6 3
5 2 1
6 5 4
10. Using pumping lemma or Myhill-Nerode theorem show that the following languages
1.
L1 = {www|w ε {a, b}*}
2.
3.
L2 = {a2n|n ≥ 0}
4.
5.
L3 = {w|w has equal number of 0’s and 1’s}
6.
7.
L4 = {x ε {a, b, c}*| length of x is a square}.
8.
Chapter 6. Variants of Finite
Automata
We have seen that DFSA, NFSA, and NFSA with ε-moves have the
same power. They accept the family of regular sets. In this chapter,
we consider two generalized versions of FSA. While one of them
accepts only regular sets, the other accepts sets, which are not
regular. We also have a discussion on probabilistic finite automata
and weighted finite automata. These two models have applications
in image analysis.
The input tape head can move in both directions. The machine
starts on the leftmost symbol of the input in the initial state. At any
time, depending on the state and the symbol read, the automaton
changes its state, and moves its tape head left or right as specified
by the move. If the automaton moves off at the right end of the
input tape in a final state, the input is accepted. The input can be
rejected in three ways:
1.
moving off the right end of the input tape in a non-final state,
2.
3.
moving off the left end of the tape and
4.
5.
getting into a loop
6.
An instantaneous description (ID) of the automaton is a string in
Σ*K Σ*. If wqx is an ID, for the input wx and currently the
automaton is reading the first symbol of x in state q. If a1 ... ai −
1qaiai + 1 ... an is an ID and δ(q, ai) = (p, R) then the next ID is:
a1 ... ai−1 ai pai+1 ... an.
If, from IDi the automaton goes to IDi + 1 in one move, this is
represented as IDi is the reflexive, transitive closure of
⊢.
Definition 6.1
Example 6.1.
q0abb ⊢ aq1bb ⊢ abq3b ⊢ aq2bb ⊢ abq2b ⊢ abbq2
T(M) = {abn|n ≥ 2}
Definition 6.2
initially moving left, then left matches . The five conditions are:
1.
the null sequence left and right matches the null sequence.
2.
3.
4.
5.
6.
7.
8.
9.
If right matches and δ(p1,a) = (q1,L) then left matches .
10.
Theorem 6.1
M′ = (K′, Σ, δ′, q0′, F′)
where:
1.
2.
3.
4.
5.
F′ is the set of all crossing sequences of length one containing a
state in F. i.e., of the form [qf], qf ∊ F.
6.
7.
8.
1.
T(M) ⊆ T(M′).
2.
3.
4.
T(M)′ ⊆ T(M).
5.
6.
7.
1.
2.
3.
4.
Basis
(i = 0). As s0 = [q0], (1) is satisfied since M begins its computation
by moving right from position 0 in state q0. Since M never moves
off at the left end boundary, j cannot be 2 or more. Condition (2) is
vacously satisfied.
Induction
Assume that the hypothesis is true for i − 1. M′ is in
Example 6.2.
Let us consider the Example 6.1.1, where [q0], [q1], [q2], [q3] are
some of the valid crossing sequences among others. Let the
corresponding NFSA = (K′, {a, b}, δ′, [q0], [q2]), where K′
corresponds to all valid crossing sequences. Empty sequence right
and left matches the empty sequence.
That 2DFSA accept only regular sets that can be proved in another
way using Myhill-Nerode theorem, without actually constructing
the crossing sequences or NFSA.
Definition 6.3
Example 6.3.
(q0, aaabbb$, 1, 1)
⊢(q0, aaabbb$, 2, 1)
⊢(q0, aaabbb$, 3, 1)
⊢(q0, aaabbb$, 4, 1)
⊢(q1, aaabbb$, 5, 2)
⊢(q1, aaabbb$, 6, 3)
⊢(q1, aaabbb$, 7, 4)
⊢(q2, aaabbb$, 7, 5)
⊢(q2, aaabbb$, 7, 6)
⊢(q2, aaabbb$, 7, 7)
Definition 6.4
The initial distribution indicates that s1 is the initial state. From the
matrices M, we see that the state s1 changes to s2 with a probability
of 1/2 on reading y. This can be indicated in a diagram, with the
states being the nodes and the arcs having labels in the form x(p),
where x is the symbol, while p is the probability of transition from
one node to the other on scanning the symbol x. (Figure 6.1)
M (ε) = M
M (wx) = M (w)M (x)
Now, for a word w, the (i, j)th entry would denote the probability
that the automaton would move to state sj, if it were initially in
state si.
Definition 6.5
Definition 6.6
Theorem 6.2
Theorem 6.3
Definition 6.7
δ is a transition function as defined for a non-deterministic FSA.
The language recognized by A, L(A) = {w|w ∊ Σn, f(w) = 1} i.e., the
language recognized by the FSA consists of the addresses of the
black pixels.
Definition 6.8
1.
a row vector IA ∊ {0, 1}1 × m called the initial distribution ( if q is
an initial state, 0 otherwise.).
2.
3.
4.
5.
6.
1.
2.
3.
4.
5.
6.
Here, we consider only FSTs from Σ to Σ, Σ = {0, 1, 2, 3}. In order
to obtain a transformation of an image, we apply the
corresponding FST to the FSA representing the image to get a new
FSA. The application of an n state FST to an m state FSA A =
(IA, FA, , a ∊ Σ) produces an n × m state FSA B = (IB, FB, , b ∊
Σ) as follows:
IB = I ⊗ IA
FB = F ⊗ FA
, ∀ b ∊ Σ
where the operation ⊗ is the ordinary tensor product of matrices.
If T and Q are two matrices of size s × t and p × q then
Definition 6.10
1.
2.
3.
4.
5.
W is the set of weight matrices Wα: K × K → ℜ for all α ∊ Σ ∪ {ε},
the weights of edges labeled α.
6.
7.
8.
9.
10.
Here Wα is an n × n matrix, where n = | K |. I is considered to be
an 1 × n row vector and F is considered to be an n × 1 column
vector. When representing the WFAs as a figure, we follow a
format similar to FSAs. Each state is represented by a node in a
graph. The initial distribution and final distribution of each state is
written as a tuple inside the state. A transition labeled α is drawn
as a directed arc from state p to q if Wα (p, q) ≠ 0. The weight of
the edge is written in brackets on the directed arc. For an example
of WFA, see Figure 6.6. We use the notation Iq(Fq) to refer to the
initial(final) distribution of state q. Wα (p, q) refers to the weight of
the transition from p to q. Wα (p) refers to the pth row vector of the
weight matrix Wα. It gives the weights of all the transitions from
state p labeled α in a vector form. Also Wx refers to the
product Wα1 · Wα2 ... Wαk where x = α1α2 ... αk.
Figure 6.6. Example: WFA computing linear grayness function
Definition 6.11
Definition 6.12
Definition 6.13
Definition 6.14
Definition 6.15
Definition 6.16
where m =| Σ | .
We also consider the following definitions:
Definition 6.17
Definition 6.18
Definition 6.19
Definition 6.20
Example 6.4.
The RGB format of color images are such that the image in pixel
form contains the red, green, and blue values of the pixels.
Analogous to gray-scale images, we can use the WFA to represent a
color image by extracting the red, green, and blue pixel values and
storing the information in a WFA.
DE-INFERENCING
Assume, we are given a WFA M, (I, F, W0, W1, W2, W3), and we
want to construct a finite resolution approximation of the multi-
resolution image represented by M. Let the image to be
constructed be I of resolution 2k × 2k. Then, for all x ∊ Σk, we have to
compute f (x) = I · Wx · F. The algorithm is as follows. The
algorithm computes φp (x) for p ∊ Q for all x ∊ Σi, 0 ≤ i ≤ k.
Here, φp is the image of state p.
ALGORITHM: DE_INFER_WFA
begin
begin
end for
Step 5 : stop.
end
INFERENCING
Let I be the digital gray-scale image of finite resolution 2k × 2k. In
(Culik and Kari, 1994), an iterative algorithm is proposed to obtain
the WFA M representing the image I. It is also shown in (Culik and
Kari, 1994), that the WFA so obtained is a minimum state WFA.
The inference algorithm is given below. In the algorithm
Infer_WFA, N is the index of the last state created, i is the index of
the first unprocessed state, φp is the image represented by
state p, fx represents the sub-image at the sub-square labeled x,
while favg(x) represents the average pixel value of the sub-image at
the sub-square labeled x, and γ: Q → Σ* is a mapping of states to
sub-squares.
ALGORITHM INFER_WFA
begin
begin
and N ← N + 1.
end for
end
Example 6.5.
Consider then the images in the square 00, 01, 02 and 03. They
can be expressed as , , and . This gives
us the ap-WFA shown in Figure 6.7 The initial distribution is (1, 0).
⋮ =
⋮ =
⋮ =
APPROXIMATE REPRESENTATION
In image processing applications, it is not always required that the
images be exactly represented. We can see that by introducing an
error parameter in the above algorithm, the number of states
required for representation can be reduced. While solving the
linear equations in Step 3 of Algorithm Infer_WFA, we get a
solution with least mean square error. We can accept the solution if
this error is greater than a positive quantity δ. This way we can
represent the image approximately with a smaller automaton.
COMPRESSION
In a gray-scale image, eight bits are required per pixel. If the
resolution is 512 × 512, 512 × 512 bytes are required to store the
image. If the number of states is less in a WFA, it can be stored
with lesser file space than the image, and we get a compressed
representation of the image. It is not difficult to see that any WFA
can be made f-normal; further it can be made I-normal since we
need not bother about representing images of size 0. Further it was
observed that in most cases, the weight matrices obtained are
sparse. Hence, it is enough to store only the weights on the edges
in a file. This may help to keep an image in compressed form.
OBSERVATION
The inference algorithm applied to four images of size 256 × 256 is
given in Figure 6.8. It shows the compression obtained for the
images in cases where the error factor was equal to 0%, 5%, 10%,
and 15%. The re-constructed images are also shown in Figure 6.8.
It can be observed that while error up to 10% does not disturb the
figure much, using error of 15% distorts the figure pretty badly.
Also, it was observed that the number of states obtained depends
on the regularity of the image itself.
Definition 6.21
1.
weight matrices Wa, b ∊ ℜn×n for all a ∊ Σ ∪ {ε} and b ∊ Σ ∪ {ε};
2.
3.
4.
5.
a column vector, F ∊ ℜn×1, called the final distribution.
6.
The WFT M is called ε-free if the weight
matrices Wε,ε, Wa,ε and Wε,b are zero matrices for all a ∊ Σ and b ∊
Σ.
Definition 6.22
where
Equation 6.1.
where the summation is over all possible paths for x and the
operation ‘·’ is the matrix multiplication.
Definition 6.23
Equation 6.2.
of size sp × tq.
The color images in RGB format are stored in 24 bits per pixel with
one byte each for the value of the three primary colors, namely:
red, green, and blue. In representing the color image using
the WFA, we use three functions one each corresponding to the
three primary colors. So, the transformation of scaling for color
images is same as that mentioned for the gray-scale images except
that the WFA corresponding to the color image, defines three
functions one each for the three primary colors. We illustrate the
scaling up of the color image by a factor of 4 and the scaling of the
color image by a factor of using an example in Figure 6.10.
TRANSLATION
We define how translations can be performed on WFA
representing the gray-scale images using the WFT.
Rotation also can be done by WFT though the rotated image maybe
scaled down by a factor.
What is T(M)?
2. Consider the PA over the alphabet {a, b} with K = {q1, q2}. Initial distribution
and .
Solution
π M (a2) = 0.9375,
.
π M (b2) = 0.25,
π M (ab) = 0.1250,
π M (a2b) = 0.0313,
π M (b3a2) = 0.9609.
3. Consider the PA over the alphabet {a, b} with K = {q1, ..., q6}. Initial distribut
and S = (0, 0, 0, 1, 0, 0).
Solution
π M(ab) = 0,
.
πM(a2b2) = 0,
πM(bab) = 0.0625,
πM(b2ab3) = 0.0098,
πM(b4ab) = 0.1855.
For L(G) = {bna|n ≥ 1} the cut point η is 0.25.
Exercises
1 Consider the following 2DFSA. Give two strings in T(M) and two strings not in T(M)
. of M.
2 Show that adding the capability of 2DFSA to keep its head stationary (and change stat
. not give additional power.
3 Let M be a 2DFSA. T(M) is the set of strings which make M move off at the right end
. know T(M) is a regular set. Let Tnf(M) be the set of strings which make M move off at
non-final state; let Tleft(M) be the set of strings which make M move off at the left end
be the set of strings which make M loop. Show that Tnf (M), Tleft(M), Tloop (M) are reg
6 Construct FSA over the alphabet {0, 1, 2, 3} to represent the following black and whit
.
Chapter 7. Pushdown Automata
In the earlier chapters, we have considered the simplest type of automaton,
namely, the FSA. We have seen that a FSA has finite amount memory and
hence cannot accept type 2 languages like {anbn|n ≥ 1}. In this chapter, we
consider a class of automata, the pushdown automata, which accept exactly
the class of context-free (type 2) languages. The pushdown automaton is a
finite automaton with an additional tape, which behaves like a stack. We
consider two ways of acceptance and show the equivalence between them. The
equivalence between context-free grammars (CFG) and pushdown automata is
also proved.
The Pushdown Automaton
Let us consider the following language over the alphabet Σ = {a, b, c}: L =
{anbmcn|n, m ≥ 1}. To accept this, we have an automaton which has a finite
control and the input tape which contains the input. Apart from these, there is
an additional pushdown tape which is like a stack of plates placed on a spring.
Only the top most plate is visible. Plates can be removed from top and added
at the top only. In the following example, we have a red plate and a number of
blue plates. The machine is initially is q0 state and initially a red plate is on the
stack. When it reads a it adds a blue plate to the stack and remains in state q0.
When it sees the b, it changes to q1. In q1, it reads b’s without manipulating the
stack. When it reads a c it goes to state q2 and removes a blue plate.
In q2 state, it proceeds to read c’s and whenever it reads a c it removes a blue
plate. Finally, in q2 state without reading any input it removes the red plate.
The working of the automaton can be summarized by the following table.
q1 red — — —
1.
3.
4.
When it reads the first a in q0, it adds a blue plate to the stack. Now the
situation appears as follows:
5.
6.
7.
When its reads the second a, the automaton’s instantaneous description (ID)
can be represented by:
8.
9.
10.
12.
13.
15.
16.
In state q1, when it reads a c it removes a blue plate and goes to q2:
17.
18.
19.
21.
22.
Now, the whole input has been read. The automaton is in q2 and top plate is
red. Now, without looking for the next input it removes the red plate.
23.
24.
25.
27.
The whole input has been read and the stack has been emptied.
The string is accepted by the automaton if the whole input has been read and
the stack has been emptied. This automaton can accept in a similar manner
any string of the form anbmcn, n,m ≥ 1.
Definition 7.1
δ is the mapping from K × (Σ ∪ {ε}) × Γ into finite subsets of K × Γ*
δ(q, a, z) contains (p, γ) where p, q ∊ K, a ∊ Σ ∪ {ε}, z ∊ Γ, γ ∊ Γ* which means
that when the automaton is ins state q and reading a (reading nothing if
a = ε) and the top pushdown symbol is z, it can go to state p and replace z in
the pushdown store by the string γ. If γ = z1 ... zn; z1 becomes the new top
symbol of the pushdown store. It should be noted that basically the pushdown
automaton is non-deterministic in nature.
Definition 7.2
This means that any string w on the input tape will be accepted by the
PDA M by the empty store, if M started in q0 with its input head pointing to
the leftmost symbol of w and Z0 on its pushdown store, will read the whole
of w and go to some state q and the pushdown store will be emptied. This is
called acceptance by empty store. When acceptance by empty store is
considered, F is taken as the empty set.
Example 7.1.
Let us formally define the pushdown automaton for accepting {anbmcn | n, m ≥
1} described informally earlier.
δ(q0, a, R) = {(q0, BR)}
δ(q0, a, B) = {(q0, BB)}
δ(q0, b, B) = {(q1, B)}
δ(q1, b, B) = {(q1, B)}
δ(q1, c, B) = {(q2, ε)}
δ(q2, c, B) = {(q2, ε)}
δ(q2, ε, R) = {(q2, ε)}
It can be seen that the above PDA is deterministic. The general definition of
PDA is non-deterministic. In order that a PDA is deterministic, two conditions
have to be satisfied. At any instance, the automaton should not have a choice
between reading a true input symbol or ε; the next move should be uniquely
determined. These conditions may be stated formally as follows:
1.
In the following sections, we shall show the equivalence of the two modes of
acceptance and also the equivalence of non-deterministic PDA with CFG.
Non-deterministic PDA and DPDA are not equivalent. There are languages
which can be accepted by non-deterministic PDA but not by DPDA. For
example, consider the language {wwR|w ∊ {a, b}*}. Let us informally describe
a PDA accepting a string say abbabbabba. The pushdown store initially
contains a red plate (say). When a is read, a blue plate is added and when
a b is read a green plate is added. This happens, when the PDA reads the first
half of the input. During the second half, if a (a, blue plate) combination
occurs, the blue plate is removed and if a (b, green plate) combination occurs,
the green plate is removed. Finally, after the whole input is read, the red plate
can be removed. Now the question is, how does the automaton know when the
second half begins. Whenever bb or aa occurs in the input, when the
automaton looks at the second b or a, it should consider both possibilities –
whether it will be the continuation of the first half or the starting of second
half. This language cannot be accepted by any DPDA. It can be seen that any
inherently ambiguous context-free language cannot be accepted by DPDA.
Equivalence between Acceptance
by Empty Store and Acceptance by
Final State
In this section, we show that acceptance by empty store and acceptance by
final state are equivalent.
Theorem 7.1
1.
2.
3.
4.
5.
8.
The first move makes M1 go to the initial ID of M2 (except for the X0 in the
pushdown store). Using the second set of mappings M1 simulates M2.
When M2 reaches a final state using mapping 3, M1 goes to the erasing
state qe and using the set of mappings 4, entire pushdown store is erased.
M1 accepts w as follows:
Equation 7.1.
Hence, if w is accepted by M2, it will be accepted by M1. On the other hand,
if M1 is presented with an input, the first move it can make is using mapping 1
and once it goes to state qe, it can only erase the pushdown store and has to
remain in qe only. Hence, mapping 1 should be used in the beginning and
mapping 3 and 4 in the end. Therefore, mapping 2 will be used in between and
the sequence of moves will be as in Equation (7.1).
(ii) Next, we prove that if L is accepted by M1 by empty store, it will be accepted
by M2 by final state. Let M1 = (K, Σ, Γ, δ1, q0, Z0, φ). Then, M2 is constructed as
follows:
Two more states q0′ and qf are added to the set of states K. q0′ becomes the
new initial state and qf becomes the only final state. One more pushdown
symbol X0 is added which becomes the new initial pushdown symbol.
The δ mappings are defined as follows:
1.
2.
3.
4.
5.
δ2(q, ε, X0) contains (qf, X0) for each q ∊ K
6.
It is not difficult to see that w is accepted by M2, if and only if w is accepted
by M1.
It should be noted that X0 is added in the first part for the following
reason. M2 may reject an input w by emptying the store and reaching a nonfinal
state. If X0 were not there, M1 while simulating M2 will empty the store and
accept the input w. In the second part, X0 is added because for M2 to make the
last move and reach a final state, a symbol in the pushdown store is required.
Thus, we have proved the equivalence of acceptance by empty store and
acceptance by final state in the case of non-deterministic PDA.
Remark The above theorem is not true in the case of DPDA. Any regular set
can be accepted by DPDA by final state. The DPDA for a regular set R will
behave like a DFSA for R except that throughout the sequence of moves, the
pushdown store will contain Z0 without any change. But even simple regular
languages like {0}* cannot be accepted by DPDA by empty store. Suppose we
want to accept {0}* by a PDA by empty store. If the initial state is q0 and the
initial pushdown symbol is Z0, there should be an ε-move for (q0, Z0)
combination. To read a ‘a,’ δ(q0, a, Z0) cannot be empty. i.e., both δ(q0, ε, Z0)
and δ(q0, a, Z0) are non-empty and the machine cannot be deterministic.
Equivalence of CFG and PDA
In this section, we show the equivalence of CFG and non -deterministic PDA.
Theorem 7.2
Equation 7.2.
Basis
i = 0, = w, γi = S
Induction
Suppose the result holds up to i. i.e., (q, w, S) ⊢* (q, , γi).
To prove for i + 1
1.
γi will be
So, we get
Here and .
i.e., the PDA uses one ε-move to replace A by on the stack and matches
the symbols of yi with the symbols on the top of the stack popping them off
till B becomes the top of the stack. On the input tape yi has been read.
The symbols of η are matched with the top of the stack and popped off.
Finally, γn = ε; xn′ = ε
This can be proved by induction on i, the number of moves of the PDA.
Basis
If (q, x, A) ⊢ (q, ε, ε),
A ⇒ ε. i.e., .
Induction
Suppose the result is true upto i − 1 steps.
Let (q, x, A) ⊢* (q, ε, ε) in i steps. The first step would make use of a mapping
of the form δ(q, ε, A) contains (q, B1 ... Bm). So (q, x, A) ⊢ (q, x, B1 ... Bm)
⊢* (q, ε, ε). Now x can be written in the form x1 x2 ... xm. After the whole of x is
read, stack is emptied (Figure 7.1).
Let x1 be the portion (prefix) of x read at the end of which B2 becomes the top
of the stack (x1 can be ε).
Hence, we have
Now we have to note only that if w is in N(M) (q, x, S) ⊢* (q, ε, ε) and by what
we have proved just now . Hence, x ∊ L(G).
Example 7.3.
The corresponding PDA M = ({q}, {a, b}, {S, a, b}, δ, q, S, φ) is constructed.
δ is defined as follows:
1.
S ⇒ aSb ⇒ aaSbb ⇒ aaabbb
1.
Initially we have,
2.
3.
4.
6.
7.
9.
10.
12.
13.
a and a are matched. The ID becomes
14.
15.
16.
18.
In the next four moves, abbb on the input tape are matched with on the stack
and symbols on the stack are removed. After reading aaabbb on the input
tape, the stack is emptied.
L(G) = N(M).
Theorem 7.3
It should be noted that the variables and productions in the grammar are defined
in such a way that the moves of the PDA are simulated by a leftmost derivation
in G.
We prove that:
Basis
If (q, x, A) ⊢ (p, ε, ε) x = a or ε, where a ∊ Σ and there should be a
mapping δ(q, x, A) contains (p, ε).
Induction
Suppose the result holds up to n − 1 steps.
Now, we can write x = ax′, a ∊ Σ ∪ {ε} and the first move is (q, ax′, A) ⊢ (q1, x
′, B1 ... Bm)
Equation 7.3.
So,
Equation 7.4.
Therefore in G.
Basis
If [q, A, p] ⇒ x then x = a or ε where a ∊ Σ and (q, A, p) → x is a rule in P. This
must have come from the mapping δ(q, x, A) contains (p, ε) and hence (q, x,
A) ⊢ (p, ε, ε).
Induction
Suppose the hypothesis holds up to (n − 1) steps and suppose
in n steps. The first rule applied in the derivation must be of the form:
Equation 7.5.
such that .
This derivation must have taken less than n steps and so by the induction
hypothesis:
Equation 7.6.
Equation (7.5) must have come from a mapping δ(q, a, A) contains
(q, B1 ... Bm). Therefore,
⊢* (q2, x2 ... xm, B2 ... Bm)
⊢* (q3, x3 ... xm, B3 ... Bm)
⋮
⊢* (qm, xm, Bm)
⊢* (p, ε, ε)
This means w is generated by G if and only if w is accepted by M by empty
store.
Hence, L(G) = N(M).
Example 7.3.
1.
δ(q,1, X) = {(p, ε)}
10.
11.
The machine while reading 1n adds X’s to the stack and when it reads a 0,
changes to state p. In state p, it reads 1n again removing the X’s from the stack.
When it reads a 0, it goes to q keeping Z0 on the stack. It can remove Z0 by
using mapping 4 or repeat the above process several times. Initially,
also Z0 can be removed using mapping 4, without reading any input. Hence, ε
will also be accepted.
T = Σ
N = {[q, Z0, q], [q, X, q], [q, Z0, p], [q, X, p], [p, Z0, q], [p, X, q], [p, Z0, p], [p, X, p]} ∪{S}
r1. S → [q, Z0, q]
r2. S → [q, Z0, p]
So, we have ended up with 16 rules. Let us see whether we can remove some
useless non-terminals and rules here.
There is no rule with [p, X, q] on the left-hand side. So, rules involving it can
be removed i.e., r8, r11. Once r8 and r11 are removed, the only rule with [q, X,
q] on the left-hand side is r7 which will create more [q, X, q] whenever applied
and the derivation will not terminate. So rules involving [q, X, q] can be
removed. i.e., r3, r5, r7, r9. Now, we are left with
rules r1, r2, r4, r6, r10, r12, r13, r14, r15, r16. If you start with r2, r6 can be
applied. [q, Z0, p] will introduce [p, Z0, p] in the sentential form. Then r16 can
be applied which will introduce [q, Z0, p] and the derivation will not
terminate. Hence, [q, Z0, p] and rules involving it can be removed. i.e.,
rules r2, r6, r16 can be removed. So, we end up with
rules r1, r4, r10, r12, r13, r14, r15. Using non-terminals:
B for [q, X, p]
D for [p, X, p]
S → A
A → 1BC
B → 1BD
B → 0D
A → ε
D → 1
C → 0A
It can be easily checked that this grammar generates {1n 0 1n 0 | n ≥ 1}*.
Solution1.
. Hint: Push a’s and b’s into the stack and match them with each c and clear.
2.
The PDA M = ({q0, q1, q2, q3}, {a, b, c}, {a, b, $}, δ, q0, $, {q3})
3.
Transitions are:
4.
Solution This example is slightly different from the previous one as one can have interleaving
. occurrences of a’s, b’s and c’s.
The transitions are:
3. Give an example of a finite language that cannot be recognized by any one-state PDA
that accepts via final state.
This machine accepts L by empty stack. Taking q4 as the final state L is accepted by
final state also.
Solution1.
. M = ({q0}, {(,)}, {x, $}, δ, q0, $, φ)
2.
δ is given by:
3.
For one symbol strings, accept by emptying the stack and going to q2.
Change state: For strings with odd length, a symbol is read without changing the stack.
δ(q0, a, 0) contains (q1, 0)
δ(q0, a, 1) contains (q1, 1)
δ(q0, b, 0) contains (q1, 0)
δ(q0, b, 1) contains (q1, 1)
For strings with even length
Pop 0 when a is seen, pop 1 when b is seen.
δ(q0, a, 0) contains (q1, ε)
δ(q0, b, 1) contains (q1, ε)
If 0 is not found when a is seen or 1 is not found when b is seen, then pop the symbol
and change state to q2. Then continue to clear out all the symbols including $.
Solution
M =({q0, q1, q2}, {0, 1}, {X, $}, δ, q0, $, φ}
.
where δ is given by:
δ(q0, 0, $) contains (q0, X$)
δ(q0, 0, X) contains (q0, X X)
δ(q0, 1, $) contains (q0, X$)
δ(q0, 1, X) contains (q0, X X)
δ(q0, 0, $) contains (q1, $)
δ(q0, 0, X) contains (q1, X)
δ(q1, 0, X) contains (q1, ε)
δ(q1, 1, X) contains (q1, ε)
δ(q1, 1, $) contains (q2, ε)
Acceptance is by empty stack. We can also look at it as acceptance by final state by
taking q2 as the final state.
Exercises
1. Design a PDA which accepts strings of the form 1*0n1n and one which accepts strings which
contain twice as many zeros as ones.
2. Find a PDAs which accepts set of strings composed of zeros and ones which are:
1.
not of the form ww
2.
3.
of the form 0n1n or 0n12n
4.
3. Show that the language {0m 1n|m ≤ n ≤ 2m} is context-free by giving a PDA that accepts it.
5. Let M be a PDA such that M = (K, Σ, Γ, δ, q0, Z, F) where K = {q0, q1, q2, q3}, Σ = {a, b}, Γ
= {A, Z}, F = φ
δ: δ (q0, a, Z) = (q0, AZ)
δ(q0, b, A) = (q1, ε)
δ(q0, a, A) = (q3, ε)
δ(q1, ε, Z) = (q2, ε)
δ(q3, ε, Z) = (q0, AZ)
Construct a CFG accepting L(M).
7. Show that if L is a CFL and ε ∉ L, then there is a PDA M accepting L by final state such
that M has at most two states and makes no ε-moves.
9. The PDA’s defined in this chapter make moves on the input tape oneway only. By allowing
it to move two-ways on the input tape by having end markers on the input tape, one can
define a two-way PDA or 2PDA. Show that the following languages are recognized by a
2PDA.
1.
{anbncn|n ≥ 1}
2.
3.
{ww|w ∊ {0, 1}*}
4.
10 For a PDA M, let there exist a constant k such that M can never have more than k symbols on
. its pushdown stack at any time. Show that L(M) is a regular language.
δ(q0, a, Z0) = {(q1, AZ0)}
δ(q0, a, A) = {(q1, AA)}
δ(q1, a, A) = {(q0, AA)}
δ(q1, ε, A) = {(q2, AA)}
δ(q2, b, A) = {(q2, ε)}
Copy
Add Highlight
Add Note
Chapter 8. Context-Free
Grammars–Properties and Parsing
Pumping lemma for regular sets presented in an earlier chapter
was used to prove that some languages are non-regular. Now, we
give another pumping lemma for context-free languages (CFL)
whose application will be to show that some languages are non-
context-free. The idea behind this lemma is that longer strings in a
CFL, have substrings which can be pumped to get infinite number
of strings in the language.
1.
|υy| > 0
2.
3.
|υxy| ≤ k
4.
5.
6.
We have .
Hence, .
Therefore, we have .
Both υ and y simultaneously cannot be empty as we consider the
grammar in CNF. The lower A will occur in the left or right subtree.
If it occurs in the left subtree, y cannot be ε and if it occurs in the
right subtree, υ cannot be ε.
One can use pumping lemma for showing that some languages are
not context-free. The method of proof will be similar to that of
application of pumping lemma for regular sets.
Example 8.1.
Theorem 8.2
2.
3. P′ consists of:
all productions in Pa for a ∊ T
all productions in P, but for each terminal a occurring in any rule of P, is to be replac
by Sa. i.e., in A → α, every occurrence of a (∊ T) in α is replaced by Sa.
Any derivation tree of G′ will typically look as in the following figure
(Figure 8.2).
Figure 8.2. A derivation tree showing a string obtained by substitution
Theorem 8.3
CFLs are closed under union, catenation, catenation
closure (*), catenation +, and homomorphism.
Proof
1.
2.
3.
4.
5.
6.
7.
8.
9.
Homomorphism: This follows as homomorphism is a particular
case of substitution.
10.
Theorem 8.4
Theorem 8.5
Theorem 8.6
Clearly for each move of the PDA M′, there exists a move by the
PDA M and a move by A. The input a may be in Σ or a = ε.
When a is in Σ, and when a = ε, , i.e., A does
not change its state while M′ makes a transition on ε.
1.
2.
3.
4.
.
.
.
.
.
The set of accepting states are of the form (f, ε) where f ∊ F.
From the construction of M′, one can see that, for the new PDA M,
.
.
.
.
.
.
.
.
Hence, we can see that if and only
if , ((p, ε), ε, γ). The proof that T(M′) = h−1(L) follows
from the above argument. The whole action of M′ having M as its
part can be depicted pictorially as shown:
Since the family of CFL is closed under the six basic operations of
union, concatenation, Kleene closure, arbitrary homomorphism,
intersection with regular sets, and inverse homomorphism, the
family of CFL is a full abstract family of languages (AFL). It is also
a full trio.
Theorem 8.8
Given a CFL L, there exists an algorithm to test whether L is
empty, finite or infinite.
Proof. To test whether L is empty, one can see whether the start
symbol S of the CFG G = (N, T, S, P) which generates L is useful
or not. If S is a useful symbol, then L ≠ φ.
CYK Algorithm
We fill a triangular table where the horizontal axis corresponds to
the positions of an input string w = a1 a2 ... an. An entry Xij which
is an ith column entry will be filled by a set of variables A such
that . The triangular table will be filled row wise in
upward fashion. For Example, if w = a1a2a3a4a5, the table will look
like:
X15
X14 X25
a1 a2 a3 a4
First row (from bottom): Since the strings beginning and ending
position is i, they are simply those variables for which we
have A → ai, and listed in Xii. We assume that the given CFG in
CNF generates L.
Theorem 8.8
The algorithm described above correctly computes Xij for all i and j.
Hence w ∊ L(G), for a CFL L = L(G) if and only if S ∊ X1n.
Example 8.2.
S0 → AB|SA
S → AB|SA|a
A → AB|SA|a|b
B → SA
We shall test the membership of aba in L(G) using CYK algorithm.
The table thus produced on application of CYK algorithm is as
below:
Since X13 has S0, aba is in L(G).
SubFamilies of CFL
In this section, we consider the special cases of CFLs.
Definition 8.1
A CFG G = (N, T, P, S) is said to be linear if all rules are of the
form A → x By or A → x, x, y ∊ T*, A, B ∊ N. i.e., the right-hand
side consists of at most one non-terminal.
Example 8.3.
Definition 8.2
Example 8.4.
Definition 8.3
Definition 8.4
A minimal linear grammar is a linear grammar with the initial letter
S as the only non-terminal and with S → a, for some terminal
symbol a, as the only production with no non-terminal on the right
side. Furthermore, it is assumed that a does not occur in any other
production.
Example 8.5.
Definition 8.5
Definition 8.6
X → aYυ X → a, a ∊ T, υ ∊ T*
Definition 8.7
Definition 8.8
Definition 8.9
Theorem 8.9
Theorem 8.10
Definition 8.10
A CFG G = (N, T, P, S) is said to be ultralinear (sometimes called
non-terminal bounded) if and only if there exists an integer k such
that any sentential form α with, , contains at most k-non-
terminals (whether leftmost, rightmost or any derivation is
considered). A language is ultralinear (non-terminal bounded) if
and only if it is generated by an ultralinear grammar.
Theorem 8.11
Definition 8.11
D: S = α0 ⇒ α1 ⇒ α1 ... ⇒ αr = w
Example 8.7.
Example 8.8.
Definition 8.12
Theorem 8.12
NE = FI.
Semi-linear Sets
Let N denote the set of non-negative integers. For each integer n ≥
1, let
If x = (x1, ..., xn), and y = (y1, ..., yn) ∊ Nn, they are called vectors of
order n or n-vectors. We can talk about linear dependence, linear
independence of such vectors.
Definition 8.14
Example 8.9.
Then L((0, 0,1); (2, 0, 0), (0, 2, 0)) is a linear set. It has elements of
the form (0, 0,1) + k1 (2, 0, 0) + k2(0, 2, 0) i.e., (2k1, 2k2, 1)
where k1, k2 ∊ N.
Definition 8.15
A subset of Nn is said to be semi-linear if it is a finite union of linear
sets.
Let L1 = ((0, 0, 1); (2, 0, 0), (0, 2, 0)) be a linear set having
elements of the form (2k1, 2k2, 1).
L2 = ((0, 0, 2); (1, 1, 0)) be another linear set having elements of
the form (k3, k3, 2) where k1, k2, k3 ∊ N.
Parikh Mapping
Let Σ = {ai |1 ≤ i ≤ n} be an alphabet. That is, we are considering
an ordering among the elements of Σ.
Definition 8.16
Example 8.10.
Let Σ = {a, b, c}
z = aabbaaccb
Then ψ(z) = (4, 3, 2).
Theorem 8.13
1.
2.
3.
6.
1.
w is in T*.
2.
3.
4.
Each Cj is linear.
nodes with the same label. For each i ≥ 1, let be the
set of those non-terminals which are node names in Tβ1, but not
in Tβi+1. Let p ≥ 1 be the smallest integer such that:
(6) .
show .
Let τ″ be the tree thus obtained. Then, the result of τ″ is a word w″
in L′ such that . Thus is in ψ(L′).
Hence,
L = {anbn|n ≥ 1}
ψ(L) = L (C; P)
ψ(anbn) = (n, n)
Example 8.12.
C = (0, 0, 1)
P1 = (2, 0, 0)
P2 = (0, 2, 0)
Period P1 comes from S → aSa.
Period P2 comes from S → bSb.
Example 8.13.
Example 8.14.
Self-embedding Property
In this section, we consider the self-embedding property which
makes CFL more powerful than regular sets. Pumping lemma for
CFL makes use of this property. By this property, it is possible to
pump equally on both sides of a substring which is lacking in
regular sets.
Definition 8.17
Theorem 8.14
S′ = [S]
Theorem 8.15
Example 8.15.
Homomorphic Characterization
Earlier, we saw that the family of CFL is a full AFL. For an AFL F, if
there exists a language L0 ∊ F, such that any language L in F can be
obtained from L0 by means of some of these six operations,
then L0 is called a generator for the AFL F. Any regular set is a
generator for the family of regular sets. Let R be any regular set.
Any other regular set R′ can be got by (Σ*∪ R) ∩ R′. Next, we show
that the Dyck set is a generator for the family of CFL.
Definition 8.18
Example 8.16.
a stands for (,
b stands for [,
a′ stands for ),
b′ stands for ].
1.
For w1, w2 ∊ Dn, w1w2 ∊ Dn.
2.
3.
For w1 ∊ Dn, for i = 1, 2, ..., n.
4.
5.
Each word w ≠ ε in Dn is of the form , for
some w1, w2 ∊ Dn for some i ∊ {1, 2, ..., n}.
6.
7.
If , then w ∊ Dn.
8.
One can see that all the above properties are satisfied for Dn and
this can be proved from the definition of Dyck set. We have the
following result for CFLs.
Theorem 8.15
G′ = (N, T′, P′, S),
where
j = 1, ..., t + m.
Now to prove L = h(Dt+m ∩ R).
1.
L ⊆ h(Dt+m ∩ R).
2.
If , where A ∊ N, w ∊ T*, is a
Hence,
1.
2.
A = α0 ⇒ α1 ⇒ ... αn = α,
Then .
Equation 8.1.
That is,
Equation 8.2.
Solution 1.
. L1 = {ap|p is a prime}.
2.
Suppose L1 is context-free.
3.
Then, by pumping lemma there exists k such that for all z ∊ L1 and |z| ≥ k. z can
form uvxyz such that uυixyiz ∊ L for all i ≥ 0. Consider some p > k. ap ∊ L1
4.
ap = uυxyz
5.
Now u, υ, x, y, z ∊ a*. Therefore, by pumping lemma:
6.
uxz(υy)i ∊ L1 for all i ≥ 0
Let |υy| = r
uxz(ar)i ∊ L1 for all i ≥ 0
or
z(ar)i − 1 ∊ L1 for all i ≥ 0
ap+ r(i − 1) ∊ L1 for all i ≥ 0
Choose i such that p + r(i − 1) is not a prime. Select i − 1 = p. Therefore, i = p
ap+ rp ∊ L1.
But, ap + rp = ap (r + 1).
p(r + 1) is not a prime. So, we come to the conclusion that as where s is not a p
This is a contradiction.
Therefore, L1 is not context-free.
7.
L2 = {a, b}* − {anbn2| n ≥ 0}.
8.
Suppose L2 is context-free.
9.
Since the family of context-free languages is closed under intersection with reg
is context-free.
10.
This contains strings of the form L3 = {anbm| m ≠ n2}.
11.
We shall show this is not context-free. If L3 is context-free, then by pumping l
constant k which satisfies the conditions of pumping lemma. Choose z = anbm w
12.
z = uυxyz where |υxy| ≤ k, |υy| ≥ 1 such that uυixyiz ∊ L3 for all i ≥ 0. If υ or y co
then by pumping we shall get a string which is not of the form aibj. If υ ∊ a*, y
show by pumping that we can get a string not in L3. Let υ = ap and y = bq. Then
13.
Choose m = (n − p)2 + q. i.e., we started with anb(n−p)2+q. Then an−pb(n−p)2+ q−q = a(n−p)
14.
This is a contradiction.
15.
L3 is not context-free and hence L2 is not context-free.
16.
2. Which of the following sets are context-free and which are not? Justify your an
a. L1 = {anbmck|n, m, k ≥ 1 and 2n = 3k, or 5n = 7m}.
Solution
S → A S → BD
.
A → a3 Ac2 D → cD
A → a3Cc2 D → c
C → bC B → a7Bb5
C → b B → a7b5
This CFG generates L1.
S → aAd
A → bAc
A → bc
a9b7 ∊ L4
a12b12 ∊ L4
a15b17 ∊ L4
S → a3Sb5, S → a6b2 which generates L4.
e. L5 = {ambn |n ≠ m}.
Solution No.
.
L1 = {ap|p is a prime}.
Solution No.
.
L = {x|x ∊ {a, b}*} and not of the form ww is CFL.
Solution No.
.
L1 = {ap|p is a prime}.
L2 = {a2n | n ≥ 0}.
Solution No.
.
L1 = {ap|p is a prime}.
L1 = {a2, a3, a5, a7, a11, ...}.
L2 = {a, a4, a6, a8, a9, a10, a12, ...}.
L1 L2 = {a3, a4, a6, a7, a8, a9, a10, a11, ...}
= a* − {a, a2, a5} is CFL.
Solution No.
. is CFL.
is CFL.
Solution Yes.
.
S → xSy
S → xSyy
S → ε
generates L1 ∪ L2 ∪ ... Lk.
Infinite union of CFL is not CFL
Li = {ai|i is a particular prime}.
Li are CFL.
But is not a CFL.
A → SA|AS|a
For strings abaab and bab, bbb.
Construct the CYK parsing table.
Are these strings in L(G)?
Solution
.
Exercises
1. Consider L = {y ∊ {0, 1}*| |y|0 = |y|1}. Prove or disprove that L is context-free.
D → BA|0
E → SD
A → AA|1
B → BB|0
C → FS
F → AB|1
Use CYK algorithm to determine which of the following strings are in L(G).
10110, 0111010, 0110110.
For each of the above strings present the final table, state if the string is in L(G) and i
derivation.
4. S → SS|AA|b, A → AS|AA|a
Give CYK parsing tables for:
aabb, and bbaba.
Are these strings in L(G)?
B → CC|b
C → AB|a
Construct CYK parsing tables for:
1.
ababb
2.
3.
bbbaaa
4.
8. Let L be in DCFL and R a regular set. Show that it is decidable whether R is containe
9. Using a cardinality argument show that there must be languages that are not context-
10. Let LIN be a family of linear languages. Pumping lemma for linear languages can be
Let L ⊆ Σ* be in LIN. Then, there exists a constant p > 0 such that for all words z in
expressed as z = uxwyυ for some u, υ, x, y, w ∊ Σ* such that:
1.
|uxyυ| < p
2.
3.
|xy| ≥ 1
4.
5.
for all i ≥ 0, uxiwyiυ ∊ L
6.
1.
Prove the LIN language pumping lemma.
2.
3.
Using the LIN language pumping lemma, prove that the following languages are not
4.
1.
{aibicjdj|i, j ≥ 1}
2.
3.
{x|x is in {a, b}* and #a(x) = #b(x)}
4.
5.
{aibici|i ≥ 1}
6.
12. A language L consists of all words w over the alphabet {a, b, c, d} which satisfy each
conditions:
1.
#a(w) + #b(w) = 2(#c(w) + #d(w)).
2.
3.
aaa is a subword of w but abc is not a subword of w.
4.
5.
The third letter of w is not c.
6.
Prove that L is context-free.
13. Compare the family of minimal linear languages with the family regular languages. C
languages belonging to the intersection of these two families.
14. Prove that there is a linear language which is not generated by any deterministic line
15. A Parikh mapping ψ depends on the enumeration of the basic alphabet; another enum
different mapping ψ′. Prove that if ψ (L) is semi-linear for some ψ, then ψ′(L) is semi
16. Consider languages over a fixed alphabet T with at least two letters. Prove that, for a
there is a CFL Ln which is not generated by any type-2 grammar containing fewer th
X1 → bX1b|bdX0db.
Prove that L(G) is not sequential. This shows that not all linear languages are sequen
an Example of a sequential language which is not metalinear.
18. Let G be a CFG with the production S → AB, A → a, B → AB|b. Run the CYK algor
string aab.
19.1.
Modify the CYK algorithm to count the number of parse trees of a given string and t
number is non-zero.
2.
3.
Test your algorithm of part (i) above on the following grammar:
4.
S → ST |a
T → BS
B → +
5.
and string a + a + a.
6.
20. Use closure under union to show that the following languages are CFL.
1.
{ambm|m ≠ n}
2.
3.
{a, b}* − {anbn|n ≥ 0}
4.
5.
{w ∊ {a, b}*|w = wR}
6.
7.
{ambncpdq|n = q or m ≤ p or m + n = p + q}
8.
22. Show that the class of DCFL is not closed under homomorphism.
Chapter 9. Turing Machines
We have seen earlier that FSA have finite amount of memory and
hence cannot do certain things. For example, no FSA can accept
{anbn|n ≥ 1}. Though, it is possible to have FSA for adding two
arbitrarily long binary numbers, we cannot have an FSA which can
multiply two arbitrarily long binary numbers. Hence the question
arises. What happens when we leave this restriction of finite
memory? What problems can be solved by mechanical process
with unlimited memory? By mechanical process, it is meant a
procedure so completely specified that a machine can carry it out.
Are there processes that can be precisely described yet still cannot
be realized by a machine (computer)?
Often, one also hears a kind of converse statement to the effect that
“any procedure which can be precisely described, can be
programmed to be performed by a computer.” This statement is
the consequence of the work of Alan M. Turing and is called
Turing’s thesis or Church – Turing thesis or Turing hypothesis. A.
M. Turing put forth his concept of computing machine in his
famous 1936 paper, which was an integral part of the formalism of
the theory of computability. These machines are called Turing
machines (TM) and are still the subject of research in computer
science.
Turing also stated the halting problem for TMs and showed that it
is undecidable. The concept of ‘undecidability’ was one of the
major breakthroughs in mathematics (theoretical computer
science) in the first half of twentieth century. After this, many
problems like the Hilbert’s 10th problem have been seen to be
undecidable and the long search for an algorithm for these
problems was given up. But, it also became clear that problems like
Fermat’s last theorem were decidable, even though at that time
nobody could prove or disprove it. Recently, in the last decade, this
conjecture has been proved to be true.
Figure 9.1. Initial configuration
The input a1 ... an is placed at the left end of the tape. The rest of
the cells contain the blank symbol . Initially, the tape head points
to the leftmost cell in the initial state q0. At any time, the tape head
will point to a cell and the machine will be in a particular state.
Suppose the machine is in state q and pointing to a cell containing
the symbol a, then depending upon the δ mapping (transition
function) of the TM it will change state to p and write a
symbol X replacing a and move its tape head one cell to the left or
to the right. The TM is not allowed to move-off the left end of the
tape. When it reaches a final state it accepts the input. Now, we will
consider the formal definition.
Definition 9.1
Γ is a finite set of tape symbols, Σ ⊆ Γ, ∊ Γ is the blank symbol;
NOTE
1.
2.
3.
In some formulations the head remaining stationary is
allowed. i.e., δ: K × Γ → K × Γ × {L, S, R}. But we shall stick to
{L, R} as remaining stationary can be achieved by two moves,
first moving right and then moving back left.
4.
Definition 9.2
Definition 9.3
NOTE
1.
2.
3.
6.
Example 9.1.
Σ = {a, b, c}
Γ = {a, b, c, X, Y, Z, }
δ is defined as follows:
δ(q0, a) = (q1, X, R)
δ(q1, a) = (q1, a, R)
δ(q1, b) = (q2, Y, L)
δ(q2, a) = (q2, a, L)
δ(q2, Y) = (q2, Y, L)
δ(q2, X) = (q0, X, R)
δ(q1, Y) = (q3, Y, R)
δ(q3, Y) = (q3, Y, R)
δ(q3, b) = (q2, Y, L)
δ(q3, c) = (q4, Z, L)
δ(q4, a) = (q4, a, L)
δ(q4, X) = (q0, X, R)
δ(q3, Z) = (q5, Z, R)
δ(q5, c) = (q4, Z, L)
δ(q5, Z) = (q5, Z, R)
δ(q4, Z) = (q4, Z, L)
δ(q0, Y) = (q6, Y, R)
δ(q6, Y) = (q6, Y, R)
δ(q6, Z) = (q7, Z, R)
δ(q7, Z) = (q7, Z, R)
Let us see how a string aaabbcc will be rejected. Let us trace the
sequence of IDs on aaabbcc
q0aaabbcc ⊢ Xq1aabbcc ⊢ Xaq1abbcc ⊢ Xaaq1bbcc ⊢ Xaq2aYbcc
⊢ Xq2aaYbcc ⊢ q2XaaYbcc ⊢ Xq0aaYbcc ⊢ XXq1aYbcc
⊢ XXaq1Ybcc ⊢ XXaYq3bcc ⊢ XXaYYcc ⊢ XXq2aYYcc
⊢ Xq2XaYYcc ⊢ XXq0aYYcc ⊢ XXXq1YYcc ⊢ XXXYq3Ycc
⊢ XXXYYq3cc ⊢ XXXYq4YZc⊢ XXXq4YYZc ⊢ XXq4XYYZc
⊢ XXXq0YYZc ⊢ XXXYq6YZc ⊢ XXXYYq6Zc ⊢ XXXYYZq7c
q0aaabc ⊢ Xq1aaabc ⊢ Xaq1aabc ⊢ Xaaq1abc ⊢ Xaaaq1bc
⊢ Xaaq2aYc ⊢ Xaq2aaYc ⊢ Xq2aaaYc ⊢ q2XaaaYc
⊢ Xq0aaaYc ⊢ XXq1aaYc ⊢ XXaq1aYc ⊢ XXaaq1Yc
⊢ XXaaYq3c ⊢ XXaaq4YZ⊢ XXaq4aYZ ⊢ XXq4aaYZ
⊢ Xq4XaaYZ ⊢ XXq0aaYZ ⊢ XXXq1aYZ ⊢ XXXaq1YZ
⊢ XXXaYq3Z ⊢ XXXaYZq5
Example 9.2.
M = (K, Σ, Γ, δ, q0, F) where
Σ = {a, b} Γ {a, b, X, }
δ(q0, a) = (q1, X, R)
δ(q1, a) = (q1, X, R)
δ(q1, b) = (q2, X, R)
δ(q2, a) = (q1, X, R)
δ(q2, b) = (q2, X, R)
Example 9.3.
K = { , q0, q1, q2, q3, q4, q5} F =
Σ = {(,), #}
Γ = {(,), X, #, }
δ( , #) = (q0, #, R)
δ(q1, X) = (q1, X, L)
δ(q1, ( ) = (q0, X, R)
δ(q0, X) = (q0, X, R)
δ(q4, X) = (q4, X, L)
δ(q0, a) = (q1, X, L)
δ(q1, X) = (q1, X, L)
δ(q0, X) = (q0, X, R)
δ(q0, a) = (qa, X, R)
δ(qa, a) = (qa, a, R)
δ(q0, b) = (qb, Y, R)
δ(qb, a) = (qb, a, R)
δ(qa, b) = (qa, b, R)
δ(qa, ) = (q1, a, L)
δ(qb, b) = (qb, b, R)
δ(qb, ) = (q1, b, L)
δ(q1, a) = (q1, a, L)
δ(q1, b) = (q1, b, L)
δ(q1, X) = (q0, X, R)
δ(q1, Y) = (q0, Y, R)
δ(q2, a) = (q2, a, R)
δ(q2, b) = (q2, b, R)
δ(q3, a) = (q3, a, L)
δ(q3, b) = (q3, b, L)
δ(q4, X) = (q4, a, L)
δ(q4, Y) = (q4, b, L)
⊢ q5#abb#abb#.
Example 9.6.
Output is #wR#.
δ(q0, a) = (qa, X, R)
δ(q0, b) = (qb, X, R)
δ(qa, a) = (qa, a, R)
δ(qa, b) = (qa, b, R)
δ(qb, a) = (qb, a, R)
δ(qb, b) = (qb, b, R)
δ(qa, X) = (qa, X, R)
δ(qb, X) = (qb, X, R)
δ(qa, ) = (q1, a, L)
δ(qb, ) = (q1, b, L)
δ(q1, a) = (q1, a, L)
δ(q1, b) = (q1, b, L)
δ(q1, #) = (q0, #, L)
δ(q0, X) = (q0, X, L)
δ(q2, a) = (q2, a, R)
δ(q2, b) = (q2, b, R)
Example 9.7.
Given two integers i and j, i > j, to compute the quotient and
reminder when i is divided by j.
The input is
with the tape head positioned on the leftmost ‘b’ in the initial
state q0.
The output is
δ(q0, b) = (q1, Y, L)
δ(q1, Y) = (q1, Y, L)
δ(q1, #) = (q2, #, L)
δ(q2, a) = (q2, a, L)
moves left.
δ(q2, X) = (q3, X, R)
when the leftmost # or an X is seen, the head starts moving right.
δ(q3, a) = (q4, X, R)
δ(q4, a) = (q4, a, R)
δ(q5, Y) = (q5, Y, R)
moves right
δ(q5, b) = (q1, Y, L)
δ(q6, c) = (q6, c, R)
δ(q6, ) = (q7, c, L)
one ‘c’ is printed
δ(q7, c) = (q7, c, L)
δ(q7, #) = (q8, #, L)
moves left
δ(q8, Y) = (q8, b, L)
all ‘a’s have been changed. Now the number of ‘c’s represents the
quotient. Y’s represent the remainder.
δ(q9, Y) = (q9, Y, R)
δ(q9, b) = (q9, b, R)
δ(q10, c) = (q10, c, R)
moves right
δ(q11, c) = (q11, c, L)
δ(q12, b) = (q12, b, L)
δ(q12, Y) = (q13, b, R)
δ(q13, b) = (q13, b, R)
δ(q14, c) = (q14, c, R)
δ(q15, d) = (q15, d, R)
δ(q15, ) = (q16, d, L)
δ(q16, d) = (q16, d, L)
after all Y’s have been copied as ‘d’s the process starts finishing
δ(q17, b) = (q17, b, R)
δ(q18, c) = (q18, c, R)
δ(q19, d) = (q19, d, R)
The state diagram for Example 9.2.2 (copy) can be represented as:
There is only one tape head. In the above figure, there are three
tracks. The head is pointing to a cell which contains A on the first
track, B on the second track, and C on the third track. The tape
symbol is taken a 3-tuple [A, B, C]. Some computation can be done
in one track by manipulating the respective component of the tape
symbol. This is very useful in checking off symbols.
Example 9.8.
w#w#w, w ∊ {a, b}*
The first track contains the input. When the TM reads the first a in
state q0, it stores it in its memory (by taking the state as a pair),
checks off ‘a’ by printing a √ in the second track below a, moves
right and after the # symbol checks whether the symbol is a ‘a.’ If
so, marks it by putting a √ in the second track, moves right and
again checks the first symbol after # is a ‘a’ and if so it marks also.
It then moves left and repeats the process with each unmarked
leftmost symbols in each block. When all the symbols in the first
block match with the second and third blocks, the machine halts
accepting the string.
The head passes through symbols in the first block to the right:
In the third block, it checks whether all symbols have already been
checked. If so, it halts in accepting state qy. Otherwise, halts in
non-accepting state qn.
If the input has more symbols in the first block (than second
block), it moves in the second block in state [p, a] or [p, b] and
encounters [#, ]. Then it halts rejecting the input:
δ([p, a], [#, ]) = (qn, [#, ], R)
If the input has equal symbols in the first and second block but less
symbols in the third block, the machine encounters [ , ] in state
[s, b] or [s, a] and halts without accepting:
Thus, we find that having two tracks and using the second track to
check off symbols is a useful technique.
Shifting over
Sometimes, we may have to shift symbols on the tape to the right
or left to allow for some symbols to be written. Suppose the
contents of the tape are a1... ai − 1 Aai + 1 ... an at some instant. A has
to be replaced by abcd say. Then, ai + 1 ... an have to be shifted three
cells to the right and then in the space created abcd can be printed.
We can use the state as a tuple to store some information and shift
symbols. Suppose the head is reading ai + 1 in state q and the
shifting process has to start. Then, the TM reads ai + 1 and goes to a
state [q, –, –, ai + 1] and prints X over ai.
The ID
changes to
Next, the TM reads ai + 2, storing it in the fourth component, and
shifting ai + 1 from fourth component to the third component.
In general:
Subroutines
Just as a computer program has a main procedure and
subroutines, the TM can also be programmed to have a main TM
and TMs which serve as subroutines. Suppose we have to
make n copies of a word w. Input is #w# and the output
is .
3.
4.
What happens when it is started on:
5.
1.
2.
3.
4.
6.
Solution
a.
.
q0 1 1 1 1 0 0 0 1 1
0 q1 1 1 1 0 0 0 1 1
0 1 q1 1 1 0 0 0 1 1
0 1 1 q1 1 0 0 0 1 1
0 1 1 1 q1 0 0 0 1 1
0 1 1 1 1 q2 0 0 1 1
0 1 1 1 q3 1 0 0 1 1
0 1 1 q3 1 1 0 0 1 1
0 1 q3 1 1 1 0 0 1 1
0 q3 1 1 1 1 0 0 1 1
q3 0 1 1 1 1 0 0 1 1
0 q0 1 1 1 1 0 0 1 1
0 0 q1 1 1 1 0 0 1 1
0 0 1 q1 1 1 0 0 1 1
0 0 1 1 q1 1 0 0 1 1
0 0 1 1 1 q1 0 0 1 1
0 0 1 1 1 1 q2 0 1 1
0 0 1 1 1 q3 1 0 1 1
0 0 1 1 q3 1 1 0 1 1
0 0 1 q3 1 1 1 0 1 1
0 0 q3 1 1 1 1 0 1 1
0 q3 0 1 1 1 1 0 1 1
0 0 q0 1 1 1 1 0 1 1
0 0 0 q1 1 1 1 0 1 1
0 0 0 1 q1 1 1 0 1 1
0 0 0 1 1 q1 1 0 1 1
0 0 0 1 1 1 q1 0 1 1
0 0 0 1 1 1 1 q2 1 1
The first block of 1’s is shifted step by step to the right till it becomes adjacen
second block of 1’s.
b.
1.
First block of 1’s will be shifted to the right till it is adjacent to the second bl
third block of 1’s is not affected.
2.
When there is only one block of 1’s it gets shifted one cell to the right and th
repeats. It never stops as there is no second block of 1’s.
3.
Since the machine starts with the third 1 in the first block, the portion of the f
from this point is shifted to the right till it becomes adjacent to the second blo
4.
There is only one block of 1’s. The portion of the block from the initial positi
one cell to the right and this process starts repeating and never stops as there
block 1’s. The portion of the block of 1’s to the left of the initial tape head po
unaffected.
2. Construct a TM with three characters 0, 1, and # which locates a ‘1’ under the
There is only one # on the tape and somewhere to the right of it is a ‘1.’ The re
blank. The head starts at or to the left of the #. When the TM halts, the tape is
stops at the ‘1.’ Zero is taken as the blank symbol.
Solution The transition table is as follows. Here q3 is the (halt or) final state:
.
0 1 #
q2 (q3, 0, L) – –
q3 – – –
3. Construct a TM over an alphabet {0, 1, #}, where 0 indicates blank, which tak
1’s and #’s and transfers the rightmost symbol to the left-hand end. Thus, ...00
becomes ...0001#1#1#000.... The head is initially at the leftmost non-blank sym
Solution The machine mainly has to move to the right-hand end, read the character, to i
. 1 or #. Then, move it to the leftmost end and halt. The transitions are:
0 1 #
q4 (q5, 0, R) – –
4. Design a TM with one track, one head, and three characters 0, 1, # to compute
functions. Input and output are to be in binary form as follows. Zero is represe
represented as # 1 1 1 #. That is the binary string represented by ‘n’ is enclosed
left and right of it. is the blank symbol.
1.
f(n)= n + 1
2.
3.
g(n) = 2n.
4.
Input is #n#
Output is #n + 1# in (a) and #2n# in (b)
Solution 1.
. The function to be computed is f(n) = n + 1.
2.
Input is
3.
Output is
4.
The transition table is given below:
5.
0 1 #
q0 – – (q1, #, L) –
q3 – – – (q4, #, L
q4 – – – –
6.
7.
The function to be computed is g(n) = 2n.
8.
Input is
9.
Output is
10.
0 1 #
q1 – – – (q2, #, L
q2 – – – –
11.
Exercises
1. Draw a state diagram for a TM accepting each of the following languages:
1.
{x ∊ {0, 1}*|#1(x) = 2#0(x) + 1}.
2.
3.
The language of all non-palindromes over {a, b}.
4.
1.
Determine the behavior of the machine for each of the following initial configuration
2.
.
...000000000000...
.
.
...00000100101100...
.
.
...01100010000000...
.
3.
Describe as clearly and concisely as you can the initial tape configurations for which
eventually halt.
4.
4. Design a TM for the following job. When started anywhere on a tape that is blank ex
the machine eventually halts with that 1 under its reading head. The remainder of the
when the machine halts.
δ(q1, a) = (q1, b, R)
δ(q1, b) = (q1, a, R)
δ(q3, b) = (q3, b, R)
δ(q4, a) = (q1, b, R)
1.
Give four words accepted by the TM together with their configuration sequences.
2.
3.
Give four words that are not accepted by the TM and in each case explain why not.
4.
9. Using the TM of problem (8) as a submachine, design a new TM that behaves as foll
any pattern of the form:
...01m01n00... (m, n > 0)
the machine is eventually to halt with the pattern
...01mn0...
on its tape. The location of this final pattern may be chosen to make the design of the
as possible.
10. For each of the following languages, construct a TM that recognizes the language:
1.
{xyx|x and y are in {a, b}*and|x| > 1}
2.
3.
{aibicjdj|i ≠ j}
4.
5.
{aba2b2a3b3 ... anbn|n ≥ 0}
6.
11. Consider the TM with input alphabets {a, b}, start state q0 with the following transiti
δ(q0, ) = (q1, , R)
δ(q1, a) = (q1, a, R)
δ(q1, b) = (q1, b, R)
δ(q3, ) = (q4, a, R)
δ(q4, a) = (q4, a, R)
δ(q4, b) = (q4, b, R)
δ(q4, ) = (q7, a, L)
δ(q5, ) = (q6, b, R)
δ(q6, a) = (q6, a, R)
δ(q6, b) = (q6, b, R)
δ(q6, ) = (q7, b, L)
δ(q7, a) = (q7, a, L)
δ(q7, b) = (q7, b, L)
15. Construct a TM to compute the following functions. Let the input x be represented in
1.
f (x) = x + 2
2.
3.
f (x) = 2x
4.
5.
f (x) = x mod 2.
6.
16. Give informal arguments which explain why TMs are more powerful than PDAs.
Chapter 9. Turing Machines
We have seen earlier that FSA have finite amount of memory and
hence cannot do certain things. For example, no FSA can accept
{anbn|n ≥ 1}. Though, it is possible to have FSA for adding two
arbitrarily long binary numbers, we cannot have an FSA which can
multiply two arbitrarily long binary numbers. Hence the question
arises. What happens when we leave this restriction of finite
memory? What problems can be solved by mechanical process
with unlimited memory? By mechanical process, it is meant a
procedure so completely specified that a machine can carry it out.
Are there processes that can be precisely described yet still cannot
be realized by a machine (computer)?
Often, one also hears a kind of converse statement to the effect that
“any procedure which can be precisely described, can be
programmed to be performed by a computer.” This statement is
the consequence of the work of Alan M. Turing and is called
Turing’s thesis or Church – Turing thesis or Turing hypothesis. A.
M. Turing put forth his concept of computing machine in his
famous 1936 paper, which was an integral part of the formalism of
the theory of computability. These machines are called Turing
machines (TM) and are still the subject of research in computer
science.
Turing also stated the halting problem for TMs and showed that it
is undecidable. The concept of ‘undecidability’ was one of the
major breakthroughs in mathematics (theoretical computer
science) in the first half of twentieth century. After this, many
problems like the Hilbert’s 10th problem have been seen to be
undecidable and the long search for an algorithm for these
problems was given up. But, it also became clear that problems like
Fermat’s last theorem were decidable, even though at that time
nobody could prove or disprove it. Recently, in the last decade, this
conjecture has been proved to be true.
Figure 9.1. Initial configuration
The input a1 ... an is placed at the left end of the tape. The rest of
the cells contain the blank symbol . Initially, the tape head points
to the leftmost cell in the initial state q0. At any time, the tape head
will point to a cell and the machine will be in a particular state.
Suppose the machine is in state q and pointing to a cell containing
the symbol a, then depending upon the δ mapping (transition
function) of the TM it will change state to p and write a
symbol X replacing a and move its tape head one cell to the left or
to the right. The TM is not allowed to move-off the left end of the
tape. When it reaches a final state it accepts the input. Now, we will
consider the formal definition.
Definition 9.1
A TM M = (K, Σ, Γ, δ, q0, F) is a 6-tuple, where
Γ is a finite set of tape symbols, Σ ⊆ Γ, ∊ Γ is the blank symbol;
NOTE
1.
2.
3.
4.
Definition 9.2
q0X1 ... Xm is the initial ID. Initially, the tape head points to the
leftmost cell containing the input. If qX1 ... Xm is an ID and δ(q, X1)
= (p, Y, L), machine halts. i.e., moving off the left end of the tape is
not allowed. If X1 ... Xmq is an ID, q is reading the leftmost blank
symbol. If δ(q, ) = (p, Y, R) next ID will be X1 ... Xm Yp. If δ(q, )
= (p, Y, L) next IΔ will be X1... Xm − 1pXmY. ⊢* is the reflexive,
transitive closure of ⊢. i.e., ID0 ⊢ ID1 ⊢ ... ⊢ IDn is denoted as
ID0 ⊢* IDn, n ≥ 0. An input will be accepted if the TM reaches a
final state.
Definition 9.3
NOTE
1.
2.
3.
4.
5.
6.
Example 9.1.
Σ = {a, b, c}
Γ = {a, b, c, X, Y, Z, }
δ(q0, a) = (q1, X, R)
δ(q1, a) = (q1, a, R)
δ(q1, b) = (q2, Y, L)
δ(q2, a) = (q2, a, L)
δ(q2, Y) = (q2, Y, L)
δ(q2, X) = (q0, X, R)
When it sees a X, it moves right in q0 and the process repeats.
δ(q1, Y) = (q3, Y, R)
δ(q3, Y) = (q3, Y, R)
δ(q3, b) = (q2, Y, L)
δ(q3, c) = (q4, Z, L)
δ(q4, Y) = (q4, Y, L)
δ(q4, a) = (q4, a, L)
δ(q4, X) = (q0, X, R)
δ(q3, Z) = (q5, Z, R)
δ(q5, c) = (q4, Z, L)
δ(q5, Z) = (q5, Z, R)
δ(q4, Z) = (q4, Z, L)
δ(q0, Y) = (q6, Y, R)
δ(q6, Y) = (q6, Y, R)
δ(q6, Z) = (q7, Z, R)
δ(q7, Z) = (q7, Z, R)
Let us see how a string aaabbcc will be rejected. Let us trace the
sequence of IDs on aaabbcc
q0aaabbcc ⊢ Xq1aabbcc ⊢ Xaq1abbcc ⊢ Xaaq1bbcc ⊢ Xaq2aYbcc
⊢ Xq2aaYbcc ⊢ q2XaaYbcc ⊢ Xq0aaYbcc ⊢ XXq1aYbcc
⊢ XXaq1Ybcc ⊢ XXaYq3bcc ⊢ XXaYYcc ⊢ XXq2aYYcc
⊢ Xq2XaYYcc ⊢ XXq0aYYcc ⊢ XXXq1YYcc ⊢ XXXYq3Ycc
⊢ XXXYYq3cc ⊢ XXXYq4YZc⊢ XXXq4YYZc ⊢ XXq4XYYZc
⊢ XXXq0YYZc ⊢ XXXYq6YZc ⊢ XXXYYq6Zc ⊢ XXXYYZq7c
q0aaabc ⊢ Xq1aaabc ⊢ Xaq1aabc ⊢ Xaaq1abc ⊢ Xaaaq1bc
⊢ Xaaq2aYc ⊢ Xaq2aaYc ⊢ Xq2aaaYc ⊢ q2XaaaYc
⊢ Xq0aaaYc ⊢ XXq1aaYc ⊢ XXaq1aYc ⊢ XXaaq1Yc
⊢ XXaaYq3c ⊢ XXaaq4YZ⊢ XXaq4aYZ ⊢ XXq4aaYZ
⊢ Xq4XaaYZ ⊢ XXq0aaYZ ⊢ XXXq1aYZ ⊢ XXXaq1YZ
⊢ XXXaYq3Z ⊢ XXXaYZq5
Example 9.2.
M = (K, Σ, Γ, δ, q0, F) where
Σ = {a, b} Γ {a, b, X, }
δ(q0, a) = (q1, X, R)
δ(q1, a) = (q1, X, R)
δ(q1, b) = (q2, X, R)
δ(q2, a) = (q1, X, R)
δ(q2, b) = (q2, X, R)
Example 9.3.
K = { , q0, q1, q2, q3, q4, q5} F =
Σ = {(,), #}
Γ = {(,), X, #, }
δ( , #) = (q0, #, R)
δ(q1, X) = (q1, X, L)
δ(q1, ( ) = (q0, X, R)
δ(q0, X) = (q0, X, R)
δ(q4, X) = (q4, X, L)
δ(q0, a) = (q1, X, L)
δ(q1, X) = (q1, X, L)
δ(q0, X) = (q0, X, R)
δ(q0, a) = (qa, X, R)
δ(qa, a) = (qa, a, R)
δ(q0, b) = (qb, Y, R)
δ(qb, a) = (qb, a, R)
δ(qa, b) = (qa, b, R)
δ(qa, ) = (q1, a, L)
δ(qb, b) = (qb, b, R)
δ(qb, ) = (q1, b, L)
δ(q1, a) = (q1, a, L)
δ(q1, b) = (q1, b, L)
δ(q1, X) = (q0, X, R)
δ(q1, Y) = (q0, Y, R)
δ(q2, a) = (q2, a, R)
δ(q2, b) = (q2, b, R)
δ(q3, a) = (q3, a, L)
δ(q3, b) = (q3, b, L)
δ(q4, X) = (q4, a, L)
δ(q4, Y) = (q4, b, L)
⊢ q5#abb#abb#.
Example 9.6.
Output is #wR#.
δ(q0, a) = (qa, X, R)
δ(q0, b) = (qb, X, R)
δ(qa, a) = (qa, a, R)
δ(qa, b) = (qa, b, R)
δ(qb, a) = (qb, a, R)
δ(qb, b) = (qb, b, R)
δ(qa, X) = (qa, X, R)
δ(qb, X) = (qb, X, R)
δ(qa, ) = (q1, a, L)
δ(qb, ) = (q1, b, L)
δ(q1, a) = (q1, a, L)
δ(q1, b) = (q1, b, L)
δ(q1, #) = (q0, #, L)
δ(q0, X) = (q0, X, L)
δ(q2, a) = (q2, a, R)
δ(q2, b) = (q2, b, R)
Example 9.7.
Given two integers i and j, i > j, to compute the quotient and
reminder when i is divided by j.
The input is
with the tape head positioned on the leftmost ‘b’ in the initial
state q0.
The output is
δ(q0, b) = (q1, Y, L)
δ(q1, Y) = (q1, Y, L)
δ(q1, #) = (q2, #, L)
δ(q2, a) = (q2, a, L)
moves left.
δ(q2, X) = (q3, X, R)
when the leftmost # or an X is seen, the head starts moving right.
δ(q3, a) = (q4, X, R)
δ(q4, a) = (q4, a, R)
δ(q5, Y) = (q5, Y, R)
moves right
δ(q5, b) = (q1, Y, L)
δ(q6, c) = (q6, c, R)
δ(q6, ) = (q7, c, L)
one ‘c’ is printed
δ(q7, c) = (q7, c, L)
δ(q7, #) = (q8, #, L)
moves left
δ(q8, Y) = (q8, b, L)
all ‘a’s have been changed. Now the number of ‘c’s represents the
quotient. Y’s represent the remainder.
δ(q9, Y) = (q9, Y, R)
δ(q9, b) = (q9, b, R)
δ(q10, c) = (q10, c, R)
moves right
δ(q11, c) = (q11, c, L)
δ(q12, b) = (q12, b, L)
δ(q12, Y) = (q13, b, R)
δ(q13, b) = (q13, b, R)
δ(q14, c) = (q14, c, R)
δ(q15, d) = (q15, d, R)
δ(q15, ) = (q16, d, L)
δ(q16, d) = (q16, d, L)
after all Y’s have been copied as ‘d’s the process starts finishing
δ(q17, b) = (q17, b, R)
δ(q18, c) = (q18, c, R)
δ(q19, d) = (q19, d, R)
The state diagram for Example 9.2.2 (copy) can be represented as:
There is only one tape head. In the above figure, there are three
tracks. The head is pointing to a cell which contains A on the first
track, B on the second track, and C on the third track. The tape
symbol is taken a 3-tuple [A, B, C]. Some computation can be done
in one track by manipulating the respective component of the tape
symbol. This is very useful in checking off symbols.
Example 9.8.
w#w#w, w ∊ {a, b}*
The first track contains the input. When the TM reads the first a in
state q0, it stores it in its memory (by taking the state as a pair),
checks off ‘a’ by printing a √ in the second track below a, moves
right and after the # symbol checks whether the symbol is a ‘a.’ If
so, marks it by putting a √ in the second track, moves right and
again checks the first symbol after # is a ‘a’ and if so it marks also.
It then moves left and repeats the process with each unmarked
leftmost symbols in each block. When all the symbols in the first
block match with the second and third blocks, the machine halts
accepting the string.
The head passes through symbols in the first block to the right:
In the third block, it checks whether all symbols have already been
checked. If so, it halts in accepting state qy. Otherwise, halts in
non-accepting state qn.
If the input has more symbols in the first block (than second
block), it moves in the second block in state [p, a] or [p, b] and
encounters [#, ]. Then it halts rejecting the input:
δ([p, a], [#, ]) = (qn, [#, ], R)
If the input has equal symbols in the first and second block but less
symbols in the third block, the machine encounters [ , ] in state
[s, b] or [s, a] and halts without accepting:
Thus, we find that having two tracks and using the second track to
check off symbols is a useful technique.
Shifting over
Sometimes, we may have to shift symbols on the tape to the right
or left to allow for some symbols to be written. Suppose the
contents of the tape are a1... ai − 1 Aai + 1 ... an at some instant. A has
to be replaced by abcd say. Then, ai + 1 ... an have to be shifted three
cells to the right and then in the space created abcd can be printed.
We can use the state as a tuple to store some information and shift
symbols. Suppose the head is reading ai + 1 in state q and the
shifting process has to start. Then, the TM reads ai + 1 and goes to a
state [q, –, –, ai + 1] and prints X over ai.
The ID
changes to
Next, the TM reads ai + 2, storing it in the fourth component, and
shifting ai + 1 from fourth component to the third component.
In general:
Subroutines
Just as a computer program has a main procedure and
subroutines, the TM can also be programmed to have a main TM
and TMs which serve as subroutines. Suppose we have to
make n copies of a word w. Input is #w# and the output
is .
3.
4.
What happens when it is started on:
5.
1.
2.
3.
4.
6.
Solution
a.
.
q0 1 1 1 1 0 0 0 1 1
0 q1 1 1 1 0 0 0 1 1
0 1 q1 1 1 0 0 0 1 1
0 1 1 q1 1 0 0 0 1 1
0 1 1 1 q1 0 0 0 1 1
0 1 1 1 1 q2 0 0 1 1
0 1 1 1 q3 1 0 0 1 1
0 1 1 q3 1 1 0 0 1 1
0 1 q3 1 1 1 0 0 1 1
0 q3 1 1 1 1 0 0 1 1
q3 0 1 1 1 1 0 0 1 1
0 q0 1 1 1 1 0 0 1 1
0 0 q1 1 1 1 0 0 1 1
0 0 1 q1 1 1 0 0 1 1
0 0 1 1 q1 1 0 0 1 1
0 0 1 1 1 q1 0 0 1 1
0 0 1 1 1 1 q2 0 1 1
0 0 1 1 1 q3 1 0 1 1
0 0 1 1 q3 1 1 0 1 1
0 0 1 q3 1 1 1 0 1 1
0 0 q3 1 1 1 1 0 1 1
0 q3 0 1 1 1 1 0 1 1
0 0 q0 1 1 1 1 0 1 1
0 0 0 q1 1 1 1 0 1 1
0 0 0 1 q1 1 1 0 1 1
0 0 0 1 1 q1 1 0 1 1
0 0 0 1 1 1 q1 0 1 1
0 0 0 1 1 1 1 q2 1 1
The first block of 1’s is shifted step by step to the right till it becomes adjacen
second block of 1’s.
b.
1.
First block of 1’s will be shifted to the right till it is adjacent to the second bl
third block of 1’s is not affected.
2.
When there is only one block of 1’s it gets shifted one cell to the right and th
repeats. It never stops as there is no second block of 1’s.
3.
Since the machine starts with the third 1 in the first block, the portion of the f
from this point is shifted to the right till it becomes adjacent to the second blo
4.
There is only one block of 1’s. The portion of the block from the initial positi
one cell to the right and this process starts repeating and never stops as there
block 1’s. The portion of the block of 1’s to the left of the initial tape head po
unaffected.
2. Construct a TM with three characters 0, 1, and # which locates a ‘1’ under the
There is only one # on the tape and somewhere to the right of it is a ‘1.’ The re
blank. The head starts at or to the left of the #. When the TM halts, the tape is
stops at the ‘1.’ Zero is taken as the blank symbol.
Solution The transition table is as follows. Here q3 is the (halt or) final state:
.
0 1 #
q2 (q3, 0, L) – –
q3 – – –
3. Construct a TM over an alphabet {0, 1, #}, where 0 indicates blank, which tak
1’s and #’s and transfers the rightmost symbol to the left-hand end. Thus, ...00
becomes ...0001#1#1#000.... The head is initially at the leftmost non-blank sym
Solution The machine mainly has to move to the right-hand end, read the character, to i
. 1 or #. Then, move it to the leftmost end and halt. The transitions are:
0 1 #
q4 (q5, 0, R) – –
4. Design a TM with one track, one head, and three characters 0, 1, # to compute
functions. Input and output are to be in binary form as follows. Zero is represe
represented as # 1 1 1 #. That is the binary string represented by ‘n’ is enclosed
left and right of it. is the blank symbol.
1.
f(n)= n + 1
2.
3.
g(n) = 2n.
4.
Input is #n#
Output is #n + 1# in (a) and #2n# in (b)
Solution 1.
. The function to be computed is f(n) = n + 1.
2.
Input is
3.
Output is
4.
The transition table is given below:
5.
0 1 #
q0 – – (q1, #, L) –
q3 – – – (q4, #, L
q4 – – – –
6.
7.
The function to be computed is g(n) = 2n.
8.
Input is
9.
Output is
10.
0 1 #
q1 – – – (q2, #, L
q2 – – – –
11.
Exercises
1. Draw a state diagram for a TM accepting each of the following languages:
1.
{x ∊ {0, 1}*|#1(x) = 2#0(x) + 1}.
2.
3.
The language of all non-palindromes over {a, b}.
4.
1.
Determine the behavior of the machine for each of the following initial configuration
2.
.
...000000000000...
.
.
...00000100101100...
.
.
...01100010000000...
.
3.
Describe as clearly and concisely as you can the initial tape configurations for which
eventually halt.
4.
4. Design a TM for the following job. When started anywhere on a tape that is blank ex
the machine eventually halts with that 1 under its reading head. The remainder of the
when the machine halts.
δ(q1, a) = (q1, b, R)
δ(q1, b) = (q1, a, R)
δ(q3, b) = (q3, b, R)
δ(q4, a) = (q1, b, R)
1.
Give four words accepted by the TM together with their configuration sequences.
2.
3.
Give four words that are not accepted by the TM and in each case explain why not.
4.
9. Using the TM of problem (8) as a submachine, design a new TM that behaves as foll
any pattern of the form:
...01m01n00... (m, n > 0)
the machine is eventually to halt with the pattern
...01mn0...
on its tape. The location of this final pattern may be chosen to make the design of the
as possible.
10. For each of the following languages, construct a TM that recognizes the language:
1.
{xyx|x and y are in {a, b}*and|x| > 1}
2.
3.
{aibicjdj|i ≠ j}
4.
5.
{aba2b2a3b3 ... anbn|n ≥ 0}
6.
11. Consider the TM with input alphabets {a, b}, start state q0 with the following transiti
δ(q0, ) = (q1, , R)
δ(q1, a) = (q1, a, R)
δ(q1, b) = (q1, b, R)
δ(q3, ) = (q4, a, R)
δ(q4, a) = (q4, a, R)
δ(q4, b) = (q4, b, R)
δ(q4, ) = (q7, a, L)
δ(q5, ) = (q6, b, R)
δ(q6, a) = (q6, a, R)
δ(q6, b) = (q6, b, R)
δ(q6, ) = (q7, b, L)
δ(q7, a) = (q7, a, L)
δ(q7, b) = (q7, b, L)
15. Construct a TM to compute the following functions. Let the input x be represented in
1.
f (x) = x + 2
2.
3.
f (x) = 2x
4.
5.
f (x) = x mod 2.
6.
16. Give informal arguments which explain why TMs are more powerful than PDAs.
Chapter 10. Variations of Turing
Machines
In Chapter 9, we defined the computability model called “Turing
Machine” (TM). This model is one of the most beautiful, simple,
and an useful abstract model. We had elaborate discussion of this
model through various examples. One can think of variations of the
basic model in many ways. For example, one can work with two
tapes, instead of a single tape. These models are got by adding
extra components and power to the control and hence, appear to
be more powerful than the basic model, but they are not. We could
also consider some restricted version of the basic model. In this
chapter we are considering such variants and discuss their
computing capabilities. We note that the power is not increased by
adding extra components and not decreased by considering the
restricted versions.
Generalized Versions
In this section, we consider the following generalized versions of
the basic model and show that they are equivalent to the basic
model as far as accepting power is concerned. The variants are:
1.
Turing machines with two-way infinite tapes
2.
3.
Multitape TM
4.
5.
Multihead TM
6.
7.
Non-deterministic TMs
8.
9.
Turing machines with 2-dimensional tapes
10.
Theorem 10.1
a0 a1 a2 ...
a0 a1 ... an
Σ′ = Σ×{ }
Γ′ = Γ × (Γ ∪{#})
δ′ is defined as follows:
If δ (q, a)= (q′, c, L/R) and if the head of MD is to the right of a0 we
have: δ([q, 1], [a, b]) = ([q′, 1], [c, b], L/R); simulation is done on the
upper track 1.
If δ(q, b) = (q′, c, L/R)
if δ(q0, a0) = (q, A, R).
if δ(q0, a0) = (q, A, L).
If δ(q, a) = (p, A, R)
If δ(q, a) = (p, A, L)
δ′([q, 1/2], [a, #]) = ([p, 2], [A, #], R).
Multi-tape TM
Definition 10.1
Theorem 10.2
... A ...
... X ...
... ... B
... ... X
C ... ...
X ... ...
Multi-head TM
Definition 10.2
Theorem 10.3
Theorem 10.4
Let us see how the implementation works on a DTM with the tapes.
There is an input tape containing input which is never altered.
Second tape will be a simulation tape which contains a copy of N’s
tape content on some branch of its non-deterministic computation.
The third tape keeps track of the location of the DTM in NTM’s
computation tree. The three tapes may be called as input tape,
simulation tape, and address tape.
symbols on address tape are all used;
Two-Dimensional TM
The TM can have 2-dimensional tapes. When the head is scanning
a symbol, it can move left, right, up or down. The smallest
rectangle containing the non-blank portion is m × n, then it
has m rows and n columns. A 1-dimensional TM, which tries to
simulate this 2-dimensional TM will have two tapes. On one tape,
this m rows of n symbols each will be represented as m blocks of
size n each separated by markers. The second tape is used as
scratch tape. When the 2-dimensional TM’s head moves left or
right, it is simulated in a block of the 1-dimensional TM. When the
2-dimensional TM’s head moves up or down, the 1-dimensional
TM’s head moves to the previous block or the next block. To move
to the correct position in that block, the second tape is used.
If m or n increases, number of blocks or the size of the blocks is
increased.
Restricted Turing Machines
In this section we can discuss some more variations of TMs, which
are in the form of restrictions. For example, we have an offline TM
that has a restriction on the input tape. One can view the
development of TM from finite state automata in a hierarchical
way. When viewed as language recognizers FSA, PDA models could
not recognize some languages, whereas a TM can do so. One can
view the tape of the basic TM as input tape, output tape, and
processing space. For example, a PDA is equivalent to a NTM with
input tape, resembling the input tape of the PDA, the storage tape
resembling the stack of the PDA. Now the processing of NTM can
simulate the processing of the PDA. Hence, any computing can be
simulated by a TM. But there are some standard ways a TM can be
restricted leading to multi-stack TMs, counter machines, etc,
without losing out on accepting power.
Definition 10.3
Theorem 10.5
Theorem 10.6
Now by the above exercise, one is able to identify the stack symbol
on the stack from the two counters thus designed. That
is k mod t is the index in and hence, Xin is the top symbol of the
stack.
Theorem 10.7
For a basic TM, there exists an equivalent 3-counter TM.
Theorem 10.8
Theorem 10.9
There exists a TM with one tape and tape alphabet {0, 1, } to
recognize any recursively enumerable language L over {0, 1}.
We now have to design another TM M′ with Γ = {0, 1, }. The tape
of M′ will consists of coded symbols of Γ and the input over {0, 1}.
The simulation of one move of M by k moves of M′ is as follows.
The tape head of M′ is initially at the leftmost symbol of the coded
input. M′ has to scan the next k − 1 symbols to its right to make a
decision of change of state or overwrite or move left or right as
per M. The TM M′ stores in its finite control the state of M and the
head position of M′ which is a number between 0 to k−1. Hence, M′
clearly indicates at the end of a block of moves whether one move
of M is made or not. Once the finite control indicates ‘0’ as head
position, it means this is time for the change on the tape, state as
per M’s instruction. If the thus changed state is an accepting state
of M, M′ accepts.
One observation is that on the tape of M′, there has to be code for
the blank symbol of M. This is essential for simulating the blank
of M by M′. Second observation is that any tape symbol of M is
directly coded in terms of 0s and 1s and as any string w is placed
on the tape of M, the codes for each symbol of w is concatenated
and placed on the tape of M′.
One can see from the previous result that even if the input for L is
not over {0, 1}, the above TM construction will work, because the
input of L over some other alphabet will be now coded and placed
as input for a TM with tape alphabet {0, 1, }.
Also one can see that one can construct a multi-tape TM that uses
only two symbols 0 and 1 as tape alphabet to simulate any TM. One
has to keep the input tape fixed with the input. There will be a
second tape with tape symbols coded as binary symbols. This
simulates moves of the original TM. The newly constructed TM
must have positions on the tape to indicate the present head
position, cells to indicate that the binary representation of the
symbol under scan is already copied. Each ID is copied on the third
tape after simulation of one move. If we take the input alphabet {0,
1}, we start with the second tape (first tape is not necessary). In the
third tape, IDs are copied one by one without erasing. Thus, we
have the following result.
Theorem 10.10
Theorem 10.11
1.
2.
3.
4.
That is, accepts only those strings that appear on the output
tape of M. Hence .
1.
2.
3.
4.
5.
6.
Theorem 10.12
Theorem 10.13
1.
S1 → q0S2
2.
3.
4.
5.
6.
S2 → S3
7.
8.
S3 → (ε, ε)S3
9.
10.
S3 → ε
11.
12.
q(a, X) → (a, Y)p
13.
(b, Z)q(a, X) → p(b, Z)(a, Y)
16.
17.
18.
19.
Linear-Bounded Automata
A linear-bounded automata (LBA) is a NTM with a bounded,
finite-input tape. That is, input is placed between two special
symbols ¢ and $.
¢ a1 a2 ... an
But, all the other actions of a TM are allowed except that the
read/write head cannot fall off on left of ¢ and right of $. Also, ¢
and $ are not altered. One can say that this is a restricted version
of TM.
Definition 10.4
Theorem 10.14
Theorem 10.15
1.
S1 → (a, q0¢a)S2;
2.
3.
S1 → (a, q0¢a$);
4.
5.
6.
7.
8.
9.
The moves of the LBA are simulated by the following rules in the
second component.
10.
11.
12.
13.
14.
15.
16.
17.
(a, α)b → ab
18.
19.
Clearly, all the productions are context-sensitive. The simulation
leads to a stage where the first components emerge as the string
generated if the second components representing LBA ID has a
final state.
Gödel Numbering
In the construction of counter automata, we have used the concept
of Gödel numbering. Let us consider this topic more formally.
Perhaps the most famous and most important of the several deep
theorems about mathematical logic proved by Kurt Gödel (1931)
was his incompleteness theorem: for any sound logical axiomatic
system that is sufficiently rich to contain the theory of numbers,
there must be number-theoretic statements that can neither be
proved nor disproved in the system. Gödel’s theorem is one of the
most significant discoveries made in the twentieth century, since it
places a limit on the efficacy of mathematical reasoning itself.
During proving his result, Gödel used a numbering scheme which
is called Gödel numbering.
Example 10.1.
From the Gödel number, the sequence can be got back. For
example, if the Gödel number is 4200, the sequence is 3, 1, 2, 1.
This is obtained as follows. Divide 4200 by 2 as many times as
possible . So the first number in the sequence is
3. Divide 525 by 3 as many times as possible. is not
divisible by 3. Hence the second number in the sequence is 1.
Divide 175 by 5 as many times as possible. . So third
number in the sequence is 2 and the last number is 1 as 7 is
divisible by 7 once. So the sequence is 3, 1, 2, 1.
Consider the following graph, where the nodes are assigned prime
numbers
where
K0 = 32 * 5 * 7
K1 = 22
K2 = 2*7
K4 = 2 * 5 and
K5 = 1
From the Gödel numbering, the graph can be obtained. This idea
can be extended to labeled graphs, directed graphs, suitably.
Solution.
2. Construct a TM M with a 2-dimensional tape. M starts with initial ID:
...
X X X ... X X X
...
i.e., a row of n X’s surrounded by blanks. It has to halt with the final ID.
...
X ... X
X ... X
X ... X
...
i.e., above and below the row of n X’s, a row of (n−2) X’s is printed, centrally
Solution.
K = {q0, ..., q11}
Γ = {X, Y, }
δ is given by:
δ(q0, X) = (q1, Y, R)
δ(ql, X) = (q2, Y, U)
δ(q2, ) = (q3, X, D)
δ(q3, Y) = (q4, Y, D)
δ(q4, ) = (q5, X, U)
δ(q5, Y) = (q1, Y, R)
δ(q6, Y) = (q7, Y, U)
δ(q7, X) = (q8, , D)
δ(q8, Y) = (q9, Y, D)
δ(q10, Y) = (q10, X, L)
Exercises
1 Consider the following TM with two-way infinite tape.
. M = ({q0, q1, q2, q3}, {0, 1}, {0, 1}, δ, q0, {q3})
where δ is given by:
δ(q0, 0) = (q1, 1, R)
2 It is desired to design a TM that copies patterns of 1’s and 2’s in accordance with the f
.
1.
First, design the machine as a 2-track machine. Assume that the given pattern is initial
track and that the bottom track is initially blank. Let the machine use the bottom track
in the given pattern with an X as it is copied. Give the state diagram of the machine.
2.
3.
Now, convert the 2-track machine of (a) into an equivalent one-track machine by assig
to ordered pairs of upper and lower-track symbols. Choose this assignment so that the
meets the format specified at the beginning of the problem. How many tape symbols d
machine use? What are their roles?
4.
3 It is desired to design a 2-tape TM that behaves as follows. The machine’s first tape is
. with a pattern of the form
and the second tape is left blank. The machine is to determine which of the given bloc
longest and is to halt with a copy of that block on its second tape. The original pattern
unchanged on the first tape. The machine is to halt scanning the 0 to the right of the gi
first tape and the 0 to the left of the block formed on the second tape.
Design an appropriate machine, using the symbol alphabet {0, 1} for each tape. Descr
graphically, using the same conventions used for ordinary TM, except that: (1) the sym
written on the machine’s first and second tapes are to be represented by symbol pairs o
the case of two-track machines; and (2) each state is to be labeled with a pair of direct
form to indicate the directions that the machine is to move on its first and second ta
that state. Each of D1 and D2 may be either L, R, or –, where the symbol − indicates th
not shift the tape head in question.
4 Let M be any TM that operates on a doubly infinite tape. Show that there exists anothe
. machine that duplicates each of M’s computations in at most half as many steps as
initial and final tape patterns are properly encoded.
Describe a typical step in ’s computation. Hint: Let the squares of M’s tape be repre
of ’s tape according to the following scheme.
M’s tape: −5 −4 −3 −2 −1 0 1 2 3 4
−11 −9 −7 −5 −3 −1 1 3 5 7
’s tape: −10 −8 −6 −4 −2 0 2 4 6 8
−9 −7 −5 −3 −1 1 3 5 7 9
5 Construct a TM with two-dimensional tape which gives the following output for the g
. 1.
2.
Output is an array of X’s surrounded by blanks.
3.
4.
5.
Chapter 10. Variations of Turing
Machines
In Chapter 9, we defined the computability model called “Turing
Machine” (TM). This model is one of the most beautiful, simple,
and an useful abstract model. We had elaborate discussion of this
model through various examples. One can think of variations of the
basic model in many ways. For example, one can work with two
tapes, instead of a single tape. These models are got by adding
extra components and power to the control and hence, appear to
be more powerful than the basic model, but they are not. We could
also consider some restricted version of the basic model. In this
chapter we are considering such variants and discuss their
computing capabilities. We note that the power is not increased by
adding extra components and not decreased by considering the
restricted versions.
Generalized Versions
In this section, we consider the following generalized versions of
the basic model and show that they are equivalent to the basic
model as far as accepting power is concerned. The variants are:
1.
Turing machines with two-way infinite tapes
2.
3.
Multitape TM
4.
5.
Multihead TM
6.
7.
Non-deterministic TMs
8.
9.
Turing machines with 2-dimensional tapes
10.
Theorem 10.1
a0 a1 a2 ...
a0 a1 ... an
Σ′ = Σ×{ }
Γ′ = Γ × (Γ ∪{#})
δ′ is defined as follows:
If δ (q, a)= (q′, c, L/R) and if the head of MD is to the right of a0 we
have: δ([q, 1], [a, b]) = ([q′, 1], [c, b], L/R); simulation is done on the
upper track 1.
if δ(q0, a0) = (q, A, R).
if δ(q0, a0) = (q, A, L).
If δ(q, a) = (p, A, R)
If δ(q, a) = (p, A, L)
Multi-tape TM
Definition 10.1
In the first tape, A′ is printed over A and the tape head moves left.
In the second tape, B′ is printed over B and the tape head moves
right while in the third tape C′ is printed over C, the tape head
moving right.
Theorem 10.2
A multi-tape TM can be simulated by a single tape TM.
... A ...
... X ...
... ... B
... ... X
C ... ...
X ... ...
Multi-head TM
Definition 10.2
Theorem 10.3
Theorem 10.4
Let us see how the implementation works on a DTM with the tapes.
There is an input tape containing input which is never altered.
Second tape will be a simulation tape which contains a copy of N’s
tape content on some branch of its non-deterministic computation.
The third tape keeps track of the location of the DTM in NTM’s
computation tree. The three tapes may be called as input tape,
simulation tape, and address tape.
Two-Dimensional TM
The TM can have 2-dimensional tapes. When the head is scanning
a symbol, it can move left, right, up or down. The smallest
rectangle containing the non-blank portion is m × n, then it
has m rows and n columns. A 1-dimensional TM, which tries to
simulate this 2-dimensional TM will have two tapes. On one tape,
this m rows of n symbols each will be represented as m blocks of
size n each separated by markers. The second tape is used as
scratch tape. When the 2-dimensional TM’s head moves left or
right, it is simulated in a block of the 1-dimensional TM. When the
2-dimensional TM’s head moves up or down, the 1-dimensional
TM’s head moves to the previous block or the next block. To move
to the correct position in that block, the second tape is used.
If m or n increases, number of blocks or the size of the blocks is
increased.
Definition 10.3
Theorem 10.5
Theorem 10.6
Now by the above exercise, one is able to identify the stack symbol
on the stack from the two counters thus designed. That
is k mod t is the index in and hence, Xin is the top symbol of the
stack.
Theorem 10.7
Theorem 10.9
There exists a TM with one tape and tape alphabet {0, 1, } to
recognize any recursively enumerable language L over {0, 1}.
Proof. Let M = (K, {0, 1}, Γ, δ, q0, F) be a TM recognizing L. Now
the tape alphabet Γ can be anything. Our aim is to construct an
equivalent TM with Γ = {0, 1, }. For that we encode each symbol of
Γ. Suppose Γ has ‘t’ symbols. We use binary codes to code each
symbol of Γ by ‘k’ bits where 2k − 1 < t < 2k.
We now have to design another TM M′ with Γ = {0, 1, }. The tape
of M′ will consists of coded symbols of Γ and the input over {0, 1}.
The simulation of one move of M by k moves of M′ is as follows.
The tape head of M′ is initially at the leftmost symbol of the coded
input. M′ has to scan the next k − 1 symbols to its right to make a
decision of change of state or overwrite or move left or right as
per M. The TM M′ stores in its finite control the state of M and the
head position of M′ which is a number between 0 to k−1. Hence, M′
clearly indicates at the end of a block of moves whether one move
of M is made or not. Once the finite control indicates ‘0’ as head
position, it means this is time for the change on the tape, state as
per M’s instruction. If the thus changed state is an accepting state
of M, M′ accepts.
One observation is that on the tape of M′, there has to be code for
the blank symbol of M. This is essential for simulating the blank
of M by M′. Second observation is that any tape symbol of M is
directly coded in terms of 0s and 1s and as any string w is placed
on the tape of M, the codes for each symbol of w is concatenated
and placed on the tape of M′.
One can see from the previous result that even if the input for L is
not over {0, 1}, the above TM construction will work, because the
input of L over some other alphabet will be now coded and placed
as input for a TM with tape alphabet {0, 1, }.
Also one can see that one can construct a multi-tape TM that uses
only two symbols 0 and 1 as tape alphabet to simulate any TM. One
has to keep the input tape fixed with the input. There will be a
second tape with tape symbols coded as binary symbols. This
simulates moves of the original TM. The newly constructed TM
must have positions on the tape to indicate the present head
position, cells to indicate that the binary representation of the
symbol under scan is already copied. Each ID is copied on the third
tape after simulation of one move. If we take the input alphabet {0,
1}, we start with the second tape (first tape is not necessary). In the
third tape, IDs are copied one by one without erasing. Thus, we
have the following result.
Theorem 10.10
Theorem 10.11
1.
2.
3.
4.
That is, accepts only those strings that appear on the output
tape of M. Hence .
1.
4.
5.
6.
Theorem 10.12
Theorem 10.13
1.
S1 → q0S2
2.
3.
4.
That is, G produces every time two copies of symbols from Σ.
5.
6.
S2 → S3
7.
8.
S3 → (ε, ε)S3
9.
10.
S3 → ε
11.
12.
q(a, X) → (a, Y)p
13.
14.
15.
(b, Z)q(a, X) → p(b, Z)(a, Y)
16.
if δ(q, X) = (p, Y, L) for each a, b ∊ Σ ∪ {ε}, each q ∊ Q, X, Y, Z ∊
Γ. This rule does the same job as rule 6.
17.
18.
19.
Linear-Bounded Automata
A linear-bounded automata (LBA) is a NTM with a bounded,
finite-input tape. That is, input is placed between two special
symbols ¢ and $.
¢ a1 a2 ... an
But, all the other actions of a TM are allowed except that the
read/write head cannot fall off on left of ¢ and right of $. Also, ¢
and $ are not altered. One can say that this is a restricted version
of TM.
Definition 10.4
A LBA is a 8-tuple M = (K, Σ, Γ, δ, q0, ¢, $, F) where K,Σ, Γ, q0, F
and δ are as in any TM. The language recognized by M is L(M) =
{w|w ∊ Σ* and for some p ∊ F}.
Theorem 10.14
Theorem 10.15
1.
S1 → (a, q0¢a)S2;
2.
3.
S1 → (a, q0¢a$);
4.
5.
6.
7.
8.
9.
The moves of the LBA are simulated by the following rules in the
second component.
10.
11.
14.
15.
16.
17.
(a, α)b → ab
18.
19.
Gödel Numbering
In the construction of counter automata, we have used the concept
of Gödel numbering. Let us consider this topic more formally.
Perhaps the most famous and most important of the several deep
theorems about mathematical logic proved by Kurt Gödel (1931)
was his incompleteness theorem: for any sound logical axiomatic
system that is sufficiently rich to contain the theory of numbers,
there must be number-theoretic statements that can neither be
proved nor disproved in the system. Gödel’s theorem is one of the
most significant discoveries made in the twentieth century, since it
places a limit on the efficacy of mathematical reasoning itself.
During proving his result, Gödel used a numbering scheme which
is called Gödel numbering.
Definition 10.5
Example 10.1.
From the Gödel number, the sequence can be got back. For
example, if the Gödel number is 4200, the sequence is 3, 1, 2, 1.
This is obtained as follows. Divide 4200 by 2 as many times as
possible . So the first number in the sequence is
3. Divide 525 by 3 as many times as possible. is not
divisible by 3. Hence the second number in the sequence is 1.
Divide 175 by 5 as many times as possible. . So third
number in the sequence is 2 and the last number is 1 as 7 is
divisible by 7 once. So the sequence is 3, 1, 2, 1.
Consider the following graph, where the nodes are assigned prime
numbers
where
K0 = 32 * 5 * 7
K1 = 22
K2 = 2*7
K4 = 2 * 5 and
K5 = 1
From the Gödel numbering, the graph can be obtained. This idea
can be extended to labeled graphs, directed graphs, suitably.
Solution.
X X X ... X X X
...
i.e., a row of n X’s surrounded by blanks. It has to halt with the final ID.
...
X ... X
X ... X
X ... X
...
i.e., above and below the row of n X’s, a row of (n−2) X’s is printed, centrally
Solution.
K = {q0, ..., q11}
Γ = {X, Y, }
δ is given by:
δ(q0, X) = (q1, Y, R)
δ(ql, X) = (q2, Y, U)
δ(q2, ) = (q3, X, D)
δ(q3, Y) = (q4, Y, D)
δ(q4, ) = (q5, X, U)
δ(q5, Y) = (q1, Y, R)
δ(q6, Y) = (q7, Y, U)
δ(q8, Y) = (q9, Y, D)
δ(q10, Y) = (q10, X, L)
2 It is desired to design a TM that copies patterns of 1’s and 2’s in accordance with the f
.
1.
First, design the machine as a 2-track machine. Assume that the given pattern is initial
track and that the bottom track is initially blank. Let the machine use the bottom track
in the given pattern with an X as it is copied. Give the state diagram of the machine.
2.
3.
Now, convert the 2-track machine of (a) into an equivalent one-track machine by assig
to ordered pairs of upper and lower-track symbols. Choose this assignment so that the
meets the format specified at the beginning of the problem. How many tape symbols d
machine use? What are their roles?
4.
3 It is desired to design a 2-tape TM that behaves as follows. The machine’s first tape is
. with a pattern of the form
and the second tape is left blank. The machine is to determine which of the given bloc
longest and is to halt with a copy of that block on its second tape. The original pattern
unchanged on the first tape. The machine is to halt scanning the 0 to the right of the gi
first tape and the 0 to the left of the block formed on the second tape.
Design an appropriate machine, using the symbol alphabet {0, 1} for each tape. Descr
graphically, using the same conventions used for ordinary TM, except that: (1) the sym
written on the machine’s first and second tapes are to be represented by symbol pairs o
the case of two-track machines; and (2) each state is to be labeled with a pair of direct
form to indicate the directions that the machine is to move on its first and second ta
that state. Each of D1 and D2 may be either L, R, or –, where the symbol − indicates th
not shift the tape head in question.
4 Let M be any TM that operates on a doubly infinite tape. Show that there exists anothe
. machine that duplicates each of M’s computations in at most half as many steps as
initial and final tape patterns are properly encoded.
Describe a typical step in ’s computation. Hint: Let the squares of M’s tape be repre
of ’s tape according to the following scheme.
M’s tape: −5 −4 −3 −2 −1 0 1 2 3 4
−11 −9 −7 −5 −3 −1 1 3 5 7
’s tape: −10 −8 −6 −4 −2 0 2 4 6 8
−9 −7 −5 −3 −1 1 3 5 7 9
5 Construct a TM with two-dimensional tape which gives the following output for the g
. 1.
2.
Output is an array of X’s surrounded by blanks.
3.
4.
5.
Chapter 10. Variations of Turing
Machines
In Chapter 9, we defined the computability model called “Turing
Machine” (TM). This model is one of the most beautiful, simple,
and an useful abstract model. We had elaborate discussion of this
model through various examples. One can think of variations of the
basic model in many ways. For example, one can work with two
tapes, instead of a single tape. These models are got by adding
extra components and power to the control and hence, appear to
be more powerful than the basic model, but they are not. We could
also consider some restricted version of the basic model. In this
chapter we are considering such variants and discuss their
computing capabilities. We note that the power is not increased by
adding extra components and not decreased by considering the
restricted versions.
Generalized Versions
In this section, we consider the following generalized versions of
the basic model and show that they are equivalent to the basic
model as far as accepting power is concerned. The variants are:
1.
Turing machines with two-way infinite tapes
2.
3.
Multitape TM
4.
5.
Multihead TM
6.
7.
Non-deterministic TMs
8.
9.
Turing machines with 2-dimensional tapes
10.
Theorem 10.1
a0 a1 a2 ...
a0 a1 ... an
Σ′ = Σ×{ }
Γ′ = Γ × (Γ ∪{#})
δ′ is defined as follows:
If δ (q, a)= (q′, c, L/R) and if the head of MD is to the right of a0 we
have: δ([q, 1], [a, b]) = ([q′, 1], [c, b], L/R); simulation is done on the
upper track 1.
If δ(q, b) = (q′, c, L/R)
if δ(q0, a0) = (q, A, R).
if δ(q0, a0) = (q, A, L).
If δ(q, a) = (p, A, R)
If δ(q, a) = (p, A, L)
Multi-tape TM
Definition 10.1
In the first tape, A′ is printed over A and the tape head moves left.
In the second tape, B′ is printed over B and the tape head moves
right while in the third tape C′ is printed over C, the tape head
moving right.
Theorem 10.2
... A ...
... X ...
... ... B
... ... X
C ... ...
X ... ...
Theorem 10.3
Let us see how the implementation works on a DTM with the tapes.
There is an input tape containing input which is never altered.
Second tape will be a simulation tape which contains a copy of N’s
tape content on some branch of its non-deterministic computation.
The third tape keeps track of the location of the DTM in NTM’s
computation tree. The three tapes may be called as input tape,
simulation tape, and address tape.
Suppose every node in the tree has at most b children. Let every
node in the tree has address, which is a string over the alphabet
Σb = {1, 2,..., b} (say). To obtain a node with address 145, start at
the root going to its child numbered 1, move to its 4th child and
then move to the nodes that corresponds to its 5th child. Ignore
addresses that are meaningless. Then, in a breath-first manner
check the nodes (configurations) in canonical order as ε, 1, 2,
3,..., b, 11, 12, 13,...,1b, 21, 22,...,2b,...,111, 112, ... (if they exist).
Then, DTM on input w = a1 ... an works as follows. Place w on the
input tape and the others are empty. Copy the contents of the input
tape to simulation tape. Then, simulate NTM’s one non-
deterministic branch on the simulation tape. On each choice,
consult the address tape for the next move. Accept if the accepting
configuration is reached. Otherwise abort this branch of simulation.
The abortion will take place for the following reasons.
Definition 10.3
Theorem 10.5
Theorem 10.6
Now by the above exercise, one is able to identify the stack symbol
on the stack from the two counters thus designed. That
is k mod t is the index in and hence, Xin is the top symbol of the
stack.
Theorem 10.7
Theorem 10.8
Theorem 10.9
There exists a TM with one tape and tape alphabet {0, 1, } to
recognize any recursively enumerable language L over {0, 1}.
We now have to design another TM M′ with Γ = {0, 1, }. The tape
of M′ will consists of coded symbols of Γ and the input over {0, 1}.
The simulation of one move of M by k moves of M′ is as follows.
The tape head of M′ is initially at the leftmost symbol of the coded
input. M′ has to scan the next k − 1 symbols to its right to make a
decision of change of state or overwrite or move left or right as
per M. The TM M′ stores in its finite control the state of M and the
head position of M′ which is a number between 0 to k−1. Hence, M′
clearly indicates at the end of a block of moves whether one move
of M is made or not. Once the finite control indicates ‘0’ as head
position, it means this is time for the change on the tape, state as
per M’s instruction. If the thus changed state is an accepting state
of M, M′ accepts.
One observation is that on the tape of M′, there has to be code for
the blank symbol of M. This is essential for simulating the blank
of M by M′. Second observation is that any tape symbol of M is
directly coded in terms of 0s and 1s and as any string w is placed
on the tape of M, the codes for each symbol of w is concatenated
and placed on the tape of M′.
One can see from the previous result that even if the input for L is
not over {0, 1}, the above TM construction will work, because the
input of L over some other alphabet will be now coded and placed
as input for a TM with tape alphabet {0, 1, }.
Also one can see that one can construct a multi-tape TM that uses
only two symbols 0 and 1 as tape alphabet to simulate any TM. One
has to keep the input tape fixed with the input. There will be a
second tape with tape symbols coded as binary symbols. This
simulates moves of the original TM. The newly constructed TM
must have positions on the tape to indicate the present head
position, cells to indicate that the binary representation of the
symbol under scan is already copied. Each ID is copied on the third
tape after simulation of one move. If we take the input alphabet {0,
1}, we start with the second tape (first tape is not necessary). In the
third tape, IDs are copied one by one without erasing. Thus, we
have the following result.
Theorem 10.10
Theorem 10.11
2.
3.
4.
That is, accepts only those strings that appear on the output
tape of M. Hence .
1.
2.
3.
6.
Theorem 10.12
Theorem 10.13
1.
S1 → q0S2
2.
3.
4.
5.
6.
S2 → S3
7.
8.
S3 → (ε, ε)S3
9.
10.
S3 → ε
11.
12.
q(a, X) → (a, Y)p
13.
14.
15.
(b, Z)q(a, X) → p(b, Z)(a, Y)
16.
17.
18.
19.
Linear-Bounded Automata
A linear-bounded automata (LBA) is a NTM with a bounded,
finite-input tape. That is, input is placed between two special
symbols ¢ and $.
¢ a1 a2 ... an
But, all the other actions of a TM are allowed except that the
read/write head cannot fall off on left of ¢ and right of $. Also, ¢
and $ are not altered. One can say that this is a restricted version
of TM.
Definition 10.4
A LBA is a 8-tuple M = (K, Σ, Γ, δ, q0, ¢, $, F) where K,Σ, Γ, q0, F
and δ are as in any TM. The language recognized by M is L(M) =
{w|w ∊ Σ* and for some p ∊ F}.
Theorem 10.14
Theorem 10.15
1.
S1 → (a, q0¢a)S2;
2.
3.
S1 → (a, q0¢a$);
4.
5.
6.
7.
8.
9.
The moves of the LBA are simulated by the following rules in the
second component.
10.
11.
14.
15.
16.
17.
(a, α)b → ab
18.
19.
Gödel Numbering
In the construction of counter automata, we have used the concept
of Gödel numbering. Let us consider this topic more formally.
Perhaps the most famous and most important of the several deep
theorems about mathematical logic proved by Kurt Gödel (1931)
was his incompleteness theorem: for any sound logical axiomatic
system that is sufficiently rich to contain the theory of numbers,
there must be number-theoretic statements that can neither be
proved nor disproved in the system. Gödel’s theorem is one of the
most significant discoveries made in the twentieth century, since it
places a limit on the efficacy of mathematical reasoning itself.
During proving his result, Gödel used a numbering scheme which
is called Gödel numbering.
Definition 10.5
Example 10.1.
From the Gödel number, the sequence can be got back. For
example, if the Gödel number is 4200, the sequence is 3, 1, 2, 1.
This is obtained as follows. Divide 4200 by 2 as many times as
possible . So the first number in the sequence is
3. Divide 525 by 3 as many times as possible. is not
divisible by 3. Hence the second number in the sequence is 1.
Divide 175 by 5 as many times as possible. . So third
number in the sequence is 2 and the last number is 1 as 7 is
divisible by 7 once. So the sequence is 3, 1, 2, 1.
Consider the following graph, where the nodes are assigned prime
numbers
where
K0 = 32 * 5 * 7
K1 = 22
K2 = 2*7
K4 = 2 * 5 and
K5 = 1
From the Gödel numbering, the graph can be obtained. This idea
can be extended to labeled graphs, directed graphs, suitably.
Solution.
X X X ... X X X
...
i.e., a row of n X’s surrounded by blanks. It has to halt with the final ID.
...
X ... X
X ... X
X ... X
...
i.e., above and below the row of n X’s, a row of (n−2) X’s is printed, centrally
Solution.
K = {q0, ..., q11}
Γ = {X, Y, }
δ is given by:
δ(q0, X) = (q1, Y, R)
δ(ql, X) = (q2, Y, U)
δ(q2, ) = (q3, X, D)
δ(q3, Y) = (q4, Y, D)
δ(q4, ) = (q5, X, U)
δ(q5, Y) = (q1, Y, R)
δ(q6, Y) = (q7, Y, U)
δ(q8, Y) = (q9, Y, D)
δ(q10, Y) = (q10, X, L)
2 It is desired to design a TM that copies patterns of 1’s and 2’s in accordance with the f
.
1.
First, design the machine as a 2-track machine. Assume that the given pattern is initial
track and that the bottom track is initially blank. Let the machine use the bottom track
in the given pattern with an X as it is copied. Give the state diagram of the machine.
2.
3.
Now, convert the 2-track machine of (a) into an equivalent one-track machine by assig
to ordered pairs of upper and lower-track symbols. Choose this assignment so that the
meets the format specified at the beginning of the problem. How many tape symbols d
machine use? What are their roles?
4.
3 It is desired to design a 2-tape TM that behaves as follows. The machine’s first tape is
. with a pattern of the form
and the second tape is left blank. The machine is to determine which of the given bloc
longest and is to halt with a copy of that block on its second tape. The original pattern
unchanged on the first tape. The machine is to halt scanning the 0 to the right of the gi
first tape and the 0 to the left of the block formed on the second tape.
Design an appropriate machine, using the symbol alphabet {0, 1} for each tape. Descr
graphically, using the same conventions used for ordinary TM, except that: (1) the sym
written on the machine’s first and second tapes are to be represented by symbol pairs o
the case of two-track machines; and (2) each state is to be labeled with a pair of direct
form to indicate the directions that the machine is to move on its first and second ta
that state. Each of D1 and D2 may be either L, R, or –, where the symbol − indicates th
not shift the tape head in question.
4 Let M be any TM that operates on a doubly infinite tape. Show that there exists anothe
. machine that duplicates each of M’s computations in at most half as many steps as
initial and final tape patterns are properly encoded.
Describe a typical step in ’s computation. Hint: Let the squares of M’s tape be repre
of ’s tape according to the following scheme.
M’s tape: −5 −4 −3 −2 −1 0 1 2 3 4
−11 −9 −7 −5 −3 −1 1 3 5 7
’s tape: −10 −8 −6 −4 −2 0 2 4 6 8
−9 −7 −5 −3 −1 1 3 5 7 9
5 Construct a TM with two-dimensional tape which gives the following output for the g
. 1.
2.
Output is an array of X’s surrounded by blanks.
3.
4.
5.
Skip to content
Home
Your O'Reilly
Profile
History
Playlists
Highlights
Featured
Navigating Change
For Government
Recommended
Explore
All Topics
Early Releases
Shared Playlists
Most Popular Titles
Resource Centers
Practice
Katacoda Scenarios
Jupyter Notebooks
Sandboxes
Kubernetes
Python
TensorFlow
Ubuntu
Attend
Certifications
Newsletters
Settings
Support
Sign Out
Introduction to Formal
Languages, Automata Theory and Computationby Kamala
Krithivasan; R RamaPublished by Pearson India, 2009
. Copyright (01:09 mins)
. About the Authors (01:09 mins)
. Preface (04:36 mins)
. Acknowledgements (01:09 mins)
. 1. Preliminaries (24:09 mins)
. 2. Grammars (44:51 mins)
. 3. Finite State Automata (37:57 mins)
. 4. Finite State Automata: Characterization, Properties, and
Decidability (16:06 mins)
. 5. Finite State Automata with Output and Minimization (17:15
mins)
. 6. Variants of Finite Automata (51:45 mins)
. 7. Pushdown Automata (25:18 mins)
. 8. Context-Free Grammars–Properties and Parsing (42:33
mins)
. 9. Turing Machines (40:15 mins)
. 10. Variations of Turing Machines (28:45 mins)
. 11. Universal Turing Machine and Decidability (39:06 mins)
. 12. Time and Space Complexity (52:54 mins)
. 13. Recent Trends and Applications (73:36 mins)
. 14. New Models of Computation (56:21 mins)
. Multiple Choice Questions (Set I) (05:45 mins)
. Multiple Choice Questions (Set II) (08:03 mins)
. Bibliography (14:57 mins)
. Illustrations (02:18 mins)
Search in book...
Toggle Font Controls
PREV Previous Chapter
10. Variations of Turing Machines
Chapter 11. Universal Turing
Machine and Decidability
In this chapter, we consider universal turing machine (TM), the
halting problem, and the concept of undecidability.
Encoding and Enumeration of
Turing Machines
The TM is specified by a 6-tuple M = (K, Σ, Γ, δ, q0, F)
(refer Definition 9.1). in Γ is a special symbol. The TM can be
encoded as a binary string. Without loss of generality, we can take
the state set as (q1,q2, ..., qs} where q1 is the initial state and q2 is
the final state. The tape symbol set can be taken as { ,0,1}. A move
of the TM is represented as:
δ(qi, Xj) = (qk, Xr, dl)
Note that we are considering deterministic TMs. This move means
that the TM while reading Xj in state qi, goes to state qk,
prints Xr over Xj and moves left or right as specified by dl. This can
be represented as a binary string 0i10j10k10r10l. Note that 1 ≤ i,
k ≤ s, 1 ≤ j, r ≤ 3, ℓ = 1 or 2. 0i denotes state qi; 0j denotes tape
symbol Xj; j = 1 denotes ;j = 2 denotes 0; j = 3 denotes 1;
0k denotes state qk and 0r denotes symbol Xr. If ℓ = 1, move is to the
left; if ℓ = 2, move is to the right. Thus, each move of the TM can be
represented as a binary string. Suppose the moves of the TM are
given by m1, m2, ..., mn. The encoding of these moves are given by
the binary strings dm1,dm2, ...,dmn. A binary string 111dm1 11dm2 11 ...
11dmn 111 specifies an encoding of the TM moves one separated
from another by two 1’s and the encoding begins with three 1’s and
ends with three 1’s. Note that any permutation of m1, ..., mn also
represents the same TM and hence, different encodings may
represent the same TM.
Enumeration of TMs
The binary encoding of a TM can be looked at as the binary
representation of an integer p. So, we can say that the binary
representation of integer p represents the TM Tp. Thus, we have an
enumeration T1,T2,T3, ..., Tp, ... of TMs. Some of these
representations may not be proper encodings. For example, strings
not beginning with three 1’s are not proper encodings. We take
them as representing TM with no moves and hence accepting the
empty set φ.
i = 1while true dobegin print i i = i + 1end.
Theorem 11.1
Theorem 11.2
Theorem 11.3
We have seen that the set of all TMs over the tape alphabets {0,1, }
can be enumerated and the set of strings over {0, 1} can be
enumerated. So, we can talk about the ith TM and the jth string
over {0, 1}. Consider an infinite Boolean matrix.
The entry on the jth row and ith column is 1 if wi is accepted
by Tj and 0 if wi is not accepted by Tj. Consider the diagonal
elements of this infinite Boolean matrix. Take those wi which
correspond to 0 elements in the matrix. Define:
Ld(the diagonal language) = {wi|wi is not accepted by Ti}
Theorem 11.5
Theorem 11.6
We have shown that Ld is not RE. Later, we show that is RE but
not recursive.
1.
2.
3.
4.
L and are not RE.
5.
6.
7.
8.
9.
Note that t is a string over {0, 1}. The second tape initially has a 0.
Without loss of generality, we can assume that T has states
{q1, ..., qk} where q1 is the initial state, and q2 is the final state. The
second tape contains the information about the state. If at any
instant T is supposed to be in state qi, U while simulating T will
have 0i in tape 2. Tape 3 is used for simulation. Pictorially, U can
be represented by the following figure.
If it finds that the string between the first 111 and the second 111 is
a proper encoding of a TM, then it copies the portion of the input
after the second 111 onto the third tape and positions the head of
the third tape on the leftmost non-blank symbol. The second tape
initially contains 0 denoting that the state is q1 initially. At any
instance, the second tape will contain 0i denoting that the current
state is qi. The third tape head will be positioned on the symbol
being read as (Xj say). Then, U will store i and j in its memory and
scan the encoding of T in the first tape looking for a block of the
form 0i10j10k10r10l. If it does not find one, U halts without
accepting. If it finds one, then it replaces 0i in the second tape by
0k, rewrites the symbol Xj scanned by the third tape head to Xr and
moves the third tape head left or right depending on whether l = 1
or 2. It should be noted that U may take more than one step to
simulate one step of T. If at any time T reaches the final state q2,
00 will be the content of tape 2 and U halts accepting the input.
If T halts on t without accepting, U also halts without accepting.
If T when started on t gets into a loop, U also gets into a loop. The
language accepted by U is Lu and consists of strings of the
form dTt where T accepts t.
Even though U has used three tapes, we can have a universal TM
with a single tape simulating U. It is known that there is a
universal TM with a single tape, 5 states, and 7 symbols.
Earlier, we have seen that Ld is not RE. Now, we show is RE but
not recursive.
Theorem 11.7
Theorem 11.8
Theorem 11.9
1.
dcontradict halts on dcontradict → In this case ‘contradict’ takes the
‘yes’ exit and gets into a loop and never halts.
2.
3.
4.
1.
2.
3.
4.
Rice’s Theorem
Let us recall that a language accepted by a TM is called a
recursively enumerable (RE) language. Without loss of generality
we consider TMs over the input alphabet {0, 1} and tape alphabet
{0,1, }.
Theorem 11.12
1.
2.
3.
4.
5.
6.
7.
context-freedom (Is L context-free?)
8.
9.
10.
11.
12.
13.
14.
1.
4.
5.
6.
Theorem 11.14
1.
L = φ
2.
3.
L = Σ*
4.
5.
L is recursive
6.
7.
L is nonrecursive
8.
9.
10.
11.
L is a regular set
12.
Theorem 11.15
1.
L ≠ φ
2.
3.
4.
5.
6.
Example 11.1.
For, we may take each machine T which does not ordinarily use the
symbol S0 and alter the machine so that before it halts, ‘it
prints S0 and halts.’ Then, the ‘printing problem’ for the new
machine is the same as the halting problem for the old machine.
Since any machine that does use S0 can first be converted to one
that does not (by renaming S0) and then altered as above, solution
of the printing problem would give solution to all halting problems,
and we know that this cannot be done.
Example 11.2.
Definition 11.1
w x
1. bbab a
2. ab abbb
3. baa aa
4. b bbb
w2w1w4w3 = x2x1x4x3 = abbbabbbaa
Example 11.4.
w x
1. aab aba
2. bb bba
3. aaaa b
If this instance has a solution, it has to begin with 2. Since the third
pair has different first letters and the first pair has different second
letters. Beginning the solution with 2, we have:
w: bb
x: bba
To proceed we have to select only the first pair, since second and
third pair will give different w and x strings. Selecting 1, we
continue to find a solution (Now, we have 21):
w: bbaab
x: bbaaba
w matches with x upto the fifth letter, but x has six symbols. To
continue the solution by a similar argument, we have to select only
the first pair. Now the processed strings are:
w: bbaabaab
x: bbaabaaba
Again, we get the same situation. If we try to get the same string,
we have to select the first pair only and we always
get w and x where |x| = |w| + 1 and w matches with x but for the
last symbol. At no point, we will be able to get x = w and hence this
instance of PCP has no solution.
Definition 11.2
Given two ordered sets of strings w1,... ,wk and x1,... ,xk, can we
find a sequence of integers i1,i2,...,in 1 ≤ ij ≤ k, such that
w1wi1wi2 ... win = x1xi1 ... xin
Theorem 11.16
Example 11.5.
w x
1. ab abbb
2. bbab a
3. baa aa
4. b bbb
y z
1. #a#b# #a#b#b#b
2. a#b# #a#b#b#b
3. b#b#a#b# #a
4. b#a#a# #a#a
5. b# #b#b#b
6. $ #$
#a#b#b#b#a#b#b#b#a#a#$.
Thus, if there is an algorithm to solve PCP, any instance of MPCP
can be converted to an instance of PCP by the above method and
solved. Hence, if the PCP were decidable, MPCP would be
decidable or in otherwords, MPCP can be reduced to PCP.
Theorem 11.17
¢ ¢q0w¢
We know that q0w is the initial ID. The other pairs are grouped as
follows:
¢ ¢
Group II: Pairs for moves.
qa Ap
If δ(q, ) = (p,C,R)
we have:
q¢ Cp¢
If δ(q, ) = (p,C,L,)
aqb q
aq q
qb q a, b ∊ Γ
q¢¢ ¢
:¢
:¢q0w¢
To proceed with the solution, we must get q0w# in the first string.
While we do that we get the second ID in the next string. At any
instance, the partial solution will be of the form:
:¢ID0¢ID1¢ ···¢IDn−1¢
:¢ID0¢ID1¢ ···¢IDn−1¢IDn¢
Once the final state is reached, strings from Group III will be used
in consuming the symbols and we shall get the same string in
and . Thus, the constructed instance of MPCP has a solution if
and only if M accepts w.
Theorem 11.18
Example 11.6.
Consider the following TM with the alphabets {0,1, } and state set
{q0, q1, q2, q3, q4}. q0 is the initial state and q4 is the final state. The
mappings are given by:
0 1
q0 (ql, 0, R) – –
q1 (q2, 0, R) – –
q4 – – –
q000 ⊢ 0q10 ⊢ 00q2 ⊢ 001q3 ⊢ 00q211 ⊢ 0q3011 ⊢ q20111 ⊢
1q3111 ⊢ 11q411
The two sets of strings of the MPCP to be constructed are given by:
W
First pair 1. ¢
Group I: 2. 0
3. 1
4. ¢
Group II:
9. 1q21
12. 1q30
15. 1q3¢
18. 0q41
19. 1q40
20. 1q4
21. 0q4
21. q41
22. q40
¢q000¢
using 5, 2, 4
¢q000¢
¢q000¢0q10¢
using 2, 6, 4
¢q000¢0q10¢
¢q000¢0q10¢00q2¢
using 2, 2, 10
¢q000¢0q10¢00q2¢
¢q000¢0q10¢00q2¢001q3¢
using 2, 2, 15
¢q000¢0q10¢00q2¢001q3¢
¢q000¢0q10¢00q2¢001q3¢00q211¢
using 2, 8, 3, 4
¢q000¢0q10¢00q2¢001q3¢00q211¢
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢
using 11, 3, 3, 4
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢
using 7, 3, 3, 3, 4
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢1q3111¢
using 3, 13, 3, 3, 4
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢1q3111¢
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢1q3111¢11q411¢
using 3, 17, 3, 4
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢1q3111¢11q411¢
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢1q3111¢11q411¢1q41¢
using 17, 4
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢1q3111¢11q411¢1q41¢
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢1q3111¢11q411¢1q41¢q4¢
using 23
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢1q3111¢11q411¢1q41¢q4¢¢
¢q000¢0q10¢00q2¢001q3¢00q211¢0q3011¢q20111¢1q3111¢11q411¢1q41¢q4¢¢
Note that successive IDs appear between ¢’s and once the final
state is reached, symbols are consumed to make both strings equal.
Theorem 11.19
S → SA
S → SB
SA → wiSAai
SB → xiSBai
SA → wiai
SB → xiai, 1 ≤ i ≤ k
wi1 ... win = xi1 ... xin,
Computable Functions
In an earlier chapter, we have looked at a TM as a computing
device. It computes a function. The TM M starts with input 1n. It
halts in an accepting state ha and at that time if the contents of the
tape is 1f(n), if f is defined at n. It halts at a non-accepting state or
goes into a loop if f(n) is not defined at n. The partial function f is
computed by M. A function which can be computed by a TM is
called a Turing computable function. Here, we are restricting
ourselves where the domain and range of the functions are tuples
of integers. The focus on numerical function values is not as
restrictive as it might sound, because any function from strings to
strings can be described by encoding both arguments and values of
the function as numbers.
1.
Constant functions: For each k ≥ 0 and each a ≥ 0, the constant
function : is defined by the formula:
2.
for every
3.
In the case k = 0, we may identify the function with the number
a.
4.
5.
6.
s(x) = x+1
7.
8.
9.
10.
Definition 11.4 (Composition)
f(X, k + 1) = h(X, k, f(X, k))
1.
2.
3.
For any k ≥ 0 and m ≥ 0, if f: and g1,g2, ...,gk: are
elements of PR, then the function f (g1, g2, ..., gk) obtained from f
and g1, g2, ..., gk by composition is an element of PR.
4.
5.
6.
7.
starting from the initial functions all functions obtained by the
application of composition and primitive recursion are in PR.
8.
Example 11.7.
Theorem 11.20
Theorem 11.21
is primitive recursive.
mp(X,k) = μky[P(X,y)]
Theorem 11.22
For m, n ∊
A(n, 0) = n + 1
A(0, m + 1) = A(1, m)
The notation μy[P(X, y)] is also used for MP(X). In the special case
in which P(X, y) = (f(X, y) = 0), we write MP = Mf and refer to this
function as the unbounded minimalization of f.
2.
3.
4.
5.
6.
7.
is an element of M.
8.
9.
10.
Theorem 11.23
Let us define this function slightly differently. Let σ: → be
defined as follows: σ(0) = 0. For n > 0, σ(n) is obtained by
considering TMs having n non-halting states and tape alphabet {1,
0} (0 is taken as blank). We can take the non-halting set of states
as {q0,..., qn − 1} with q0 as the initial state. Since the number of
non-halting states and number of tape symbols are finite, there are
only a finite number of TMs of this type. We restrict our attention
to those which halt on input 1n. σ(n) denotes the largest number of
1’s that can be printed when any of these machines halt.
Solution 1.
. This is RE.
2.
Let S = {L1, L2,... } each L in S contains at least two strings. LS = {< M > |T(M
3.
LS will be accepted by a TM MS which halts accepting < M > if < M > is in LS
< M > is not in LS. MS takes as input < M > and uses a pair generator and simu
of M on string xi for j steps. It also keeps a counter, which initially contains 0.
4.
If M accepts xi in j steps, it increases the counter by 1. If the counter reads 2, M
< M >. Otherwise, it keeps on generating pair after pair and keeps testing. Sinc
nontrivial. LS is not recursive.
5.
6.
This is not RE.
7.
Let S = {L1, L2,...} each L in S is infinite.
8.
LS = {< M > |T(M) = L and L ∊ S}.
9.
If LS is RE, it should satisfy the three conditions of Theorem 11.13. But condit
violated. LS is not RE.
10.
Solution 1.
. This is decidable.
2.
Construct a TM T halting on all inputs which stops saying ‘yes’ if x ∊ S or stop
if x ∉ S.
3.
T has one input tape which initially contains x. It has six more tapes
4.
Tu, T1, T2, T3, T0, Tlist.
5.
Tu initially contains nothing (blank meaning 0)
6.
T1 initially contains 1
7.
T2 initially contains 2
8.
T3 initially contains 1
9.
T1ist contains in the increasing order a list of numbers separated by #’s. Initiall
#.
10.
T0 is the output tape which is initially blank. When u is in Tu, T computes u2 +
on T2 and u! on T3, it then compares x with the contents of T1, T2 and T3. If the
match, T outputs ‘yes’ in T0 and halts. If there is no match, the contents of T1,
to the list in T1ist in the proper place. Next string from T1ist is taken and placed
process repeats. The process stops if a match between the input and the conten
found at any time with output ‘yes.’ If the contents of T1, T2, and T3 are greate
the process stops outputting ‘no.’ This is possible as the three functions compu
monotonically increasing. Hence, the problem is decidable.
11.
12.
This problem is undecidable.
13.
f is a non-total function and π2 is a total function.
14.
Any algorithm to solve the problem with inputs x1, x2, and x3 should have two
computing f(x1) and another computing π2(x2, x3). Since f is nontotal for some
algorithm will not come out of the subroutine for computing f(x1) and will not
Hence, the problem is undecidable.
15.
3. Fermat’s last theorem, until recently one of the most-famous unproved stateme
asserts that there are no integer solution (x, y, z, n) to the equation xn + yn = zn s
and n > 2. Show how a solution to the halting problem would allow you to det
falsity of the statement.
Solution Suppose the halting problem is decidable. Construct a TM T which will solve F
. as follows:
TM T has four tapes. In tape T1, it systematically generates ordered quadruples
1, z ≥ 1, n ≥ 3. Initial one is (1, 1, 1, 3).
In T2, it computes xn + yn.
In T3, it computes zn.
It compares contexts of T2 and T3 and if they match, outputs ‘yes’ in T4. If ther
quadruple is generated in T1 and the process repeats. If there is no solution for
theorem, T will not halt and will go on forever. Now if ‘Halt’ is the algorithm
problem, give T and the first quadruple as input. If ‘Halt’ says ‘yes’, then Ferm
a solution. If ‘Halt’ says ‘no’, then Fermat’s last theorem has no solution.
Exercises
1 Suppose the tape alphabets of all TMs are selected from some infinite set of symbols a
. each TM may be encoded as a binary string.
9.
10.
absolute difference |x – y|
11.
12.
Sign function
13.
14.
15.
comparison function
16.
17.
5 For each decision problem given, determine whether it is solvable or unsolvable and p
. 1.
Given a TM T, does it ever reach a state other than its initial state when it starts with a
2.
3.
Given a TM T and a non-halting state q of T, does T ever enter state q when it begins w
4.
5.
Given a TM T and a non-halting state q of T, is there an input string x that would caus
enter state q?
6.
7.
Given a TM T, does it accept the string ∊ in an even number of moves?
8.
9.
Given a TM T, is there a string which it accepts in an even number of moves?
10.
11.
Given a TM T and a string w, does T loop forever on input w?
12.
13.
Given a TM T, are there any input strings on which T loops forever?
14.
15.
Given a TM T and a string w, does T reject input w?
16.
17.
Given a TM T, are there any input strings rejected by T?
18.
19.
Given a TM T, does T halt within ten moves on every string?
20.
21.
Given a TM T, is there a string on which T halts within 10 moves?
22.
23.
Given TMs T1 and T2, is L(T1) ⊆ L(T2) or L(T2) ⊆ L(T1)?
24.
6 Which of the following problems about CFGs and their languages are decidable, and w
. decidable? Prove.
1.
the problem of determining whether an arbitrary string belongs to the language genera
2.
3.
the problem of determining whether a CFG generates a non-empty language.
4.
5.
the problem of determining whether the languages generated by two CFGs have any s
6.
7.
the problem of determining whether two CFGs generate the same language.
8.
9.
given two CFGs G1 and G2, L(G1) ⊆ L(G2).
10.
11.
given CFG G and a regular set R determine whether L(G) = R.
12.
13.
given CFG G and a regular set R determine whether R ⊆ L(G).
14.
15.
given CFG G determine whether is a CFL.
16.
17.
given two CFGs G1 and G2 determine whether L(G1) ∩ L(G2) is a CFL.
18.
SPACE = O(TIME2)
SPACETM = Θ (SPACERAM)
But, more time is required as the TM has to scan and find the
correct block and shift symbols if necessary. Nevertheless, for one
step of RAM, the TM may scan the non-blank portion of the tape a
finite number of times (maximum k say). Hence, TIMETM =
O(TIMERAM.SPACERAM).
Simulation of TM by RAM
Simulating a TM with a RAM requires representing the state of the
TM, as well as the contents of its tape and the position of tape head
only in registers. The state can be kept in one register and the RAM
program can decrement this register and use jump on zero to
simulate a move of the TM. The symbol scanned by the tape head
will be kept in one register. The symbols of the TM can be taken
as X1, ..., Xk−1, and if the current symbols scanned is Xi,
integer i will be stored in that register. In the next move, the tape
head will move left or right and scan Xj say. Then, the contents of
this register will be changed to integer j. This can be done using
‘decrement’ and ‘increment’ operations of the RAM. The ID of the
TM is given by α1qα2 or
Xi1 Xi2...Xij−1 qXij...Xin, where Xij is the symbol scanned by the tape
head. To store this and the symbol read, three registers R1, R2,
and R3 can be used.
R1 contains ij.
If Xa is read and Xb is to be printed in the cell and the move is left
the mapping will be δ(q, Xa) = (q’, Xb, L). This is simulated by the
RAM using the following instructions:
R1 ← b
R2 ← k. R2 + R1
R1 ← R3 mod k
R3 ← R3 ÷ k
Hence, we have:
SPACERAM = Θ (SPACETM)
TIMERAM = Ο(TIMETM · SPACE2TM)
Time Complexity
For considering the time complexity, we look at the following
variation of the TM. The TM M has k two-way infinite tapes. One of
them initially contains the input. Symbols in all tapes can be
rewritten.
The two different models for time and space complexity are
considered for making the proofs simpler. Also, time complexity
will be different if we use a single tape TM. In Chapter 10, we have
seen that when we simulate a multi-tape TM by a single tape,
number of steps may be squared. Consider the following example.
We would like to have a TM for accepting strings of the
form wcwcw. In a single tape, we can have two tracks, check off
the symbols moving the tape head left and right several times. If |
w| = n, the machine may make n left sweeps and n right sweeps.
Hence, the time complexity will be O(n2). If we use three tapes,
where one tape initially contains wcwcw, the tape head on this
tape moves right reading w and copying it on the second tape and
when it encounters a c, copies the portion after the first c till the
second c w onto the third tape, moves the second and third heads
to the leftmost non-blank symbols and moves all the heads right
checking that the symbols read under the three heads are the same
i.e., the input string is of the form wcwcw.
Assumptions
It should be clear that every TM uses atleast one cell on all inputs,
so if S(n) is a space complexity measure, S(n) ≥ 1 for all n. Space
complexity S(n) really means max(1, ⌈S(n)⌉). Suppose the space
complexity is log2 n, this does not make sense if input is of size 1 or
0 (string ε), whereas if we say max(1, ⌈S(n)⌉) it makes sense.
Complexity Classes
The family of languages accepted by deterministic TMs of space
complexity S(n) is denoted by DS(S(n)). The family of languages
accepted by non-deterministic TMs with space complexity S(n) is
denoted by NS(S(n)). The family of languages accepted by
deterministic (non-deterministic) TMs of time complexity T(n) is
denoted by DT(T(n)) (NT(T(n))).
1.
If L is accepted by an S(n) space-bounded TM with k storage tapes,
then for any c > 0, L is accepted by a cS(n) space bounded TM.
2.
3.
If a language L is accepted by a TM with k storage tapes with space
complexity S(n), it is accepted by a TM with a single tape with the
same space complexity S(n).
4.
5.
Linear speed-up like in 1 above can be given for time complexity
also.
6.
7.
If L is accepted by a multi-tape TM with time complexity T(n), it is
accepted by a single tape TM with time complexity (T(n))2.
8.
Space Hierarchy
What complexity functions are considered as ‘well behaved’? For
this we define ‘space constructible,’ ‘fully space constructible,’ ‘time
constructible,’ ‘fully time constructible’ functions.
1.
P = ∪i≥1 DT(ni)
We know that:
Equation 12.1.
Intractable Problems
We have already seen the connection between problems and
languages. Time complexity of an algorithm is measured in terms
of the size of the input to the algorithm. Looking at from the point
of view of TMs and languages accepted, we have seen that the time
complexity is measured in terms of the length of the input string.
Exponential time algorithms are not considered as “good”
algorithms. Most exponential time algorithms are merely variation
on exhaustive search, whereas polynomial-time algorithms
generally are made possible only through the gain of some deeper
insight into the structure of the problem. Generally, people agree
that a problem is not “well-solved” until a polynomial-time
algorithm is known for it. Hence, we shall refer to a problem as
intractable if it is so hard that no polynomial-time algorithm can
possibly solve it.
There are two different causes for intractability. The first one is
that the problem is so difficult that an exponential amount of time
is needed to find a solution. The second is that the solution itself is
required to be so extensive that it cannot be described with an
expression having length bounded by a polynomial function of the
input length. For example, if the input is a sequence of m distinct
integers i1, i2, ..., im and we want to output all possible
permutations of them; the length of the output itself cannot be a
polynomial function of the length of the input and so cannot be
computed in polynomial-time. The existence of this sort of
intractability is mostly apparent from the problem definition. So,
we shall consider the first type of intractability, i.e., we shall
consider only problem for which the solution length is bounded by
a polynomial function of the input length.
Theorem 12.1
1.
2.
3.
4.
Theorem 12.2
Definition 12.2
A log-space transducer is an off-line TM that always halts,
having log n scratch storage and a write-only output tape on which
the head never moves left. We say that L′ is log-space reducible to
L if there is a log-space transducer that given an input x, produces
an output string y that is in L if and only if x is in L′.
Definition 12.3
1.
2.
3.
4.
We can also define complete and hard problems with respect to
log-space reductions. The following definitions follow:
Definition 12.4
1.
L ∊ NP
2.
3.
4.
We can also define this in terms of decision problems.
Definition 12.5
1.
∏ ∊ NP
2.
3.
Theorem 12.3
1.
4.
Satisfiability-Cook’s Theorem
A Boolean expression is an expression composed of variables,
parentheses, and the operators ∧ (logical AND), ∨ (logical OR) and
¬ (negation). The order of precedence among this is ¬, ∧, ∨.
Variables take on values 0 (false) and 1 (true); so do expressions.
The truth table for AND, OR, NOT are given below.
Here E1 and E2 are expressions.
E1 E2 E1 ∧ E2 E1 ∨ E2
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
Equation 12.2.
Equation 12.3.
Theorem 12.4
The satisfiability problem is NP-complete.
1.
A〈i,j,t〉 – this is 1 if the ith cell of the TM M’s tape contains the jth
tape symbol Xj at time t. We can see that 1 ≤ i ≤p(n), 1 ≤ j ≤m, 0
≤ t ≤p(n). Hence, there are O(p2(n)) such variables.
2.
3.
4.
5.
6.
H〈i, t〉 - this is 1 if and only if at time t, the tape head is scanning
tape cell i. Here 1 ≤ i ≤ p(n), 0 ≤ t ≤ p(n). Therefore, there
are O(p2(n)) such variables. H〈1, 0〉 should be 1 as the tape
head of M starts on cell 1 initially.
7.
Equation 12.4.
1.
2.
3.
In each ID, each tape cell contains exactly one tape symbol.
4.
5.
6.
7.
The modification of the content of the tape takes place only in the
cell scanned by the tape head when the machine moves from one
ID to the next ID.
8.
9.
10.
11.
12.
13.
The final ID should have final state. (Note that we have taken q1 as
the initial state and q2 as the final state.)
14.
1.
2.
E1 = A0 A1 ... Ap(n)
3.
At = ψ(H 〈1, t〉, ..., H〈p(n), t〉)
4.
At tells that at time instant t, the head is scanning only one cell.
Length of At is O(p2(n)) and hence, length of E1 is O(p3(n))
and E1 can be written in that time.
5.
6.
At time instant t, the ith cell contains only one symbol. This can be
written as:
7.
8.
9.
10.
11.
Ct = ψ(S 〈1, t〉, S〈2, t〉, ..., S〈s, t〉)
12.
E3 = C0C1C2... Cp(n)
13.
14.
15.
From one ID to the next ID, only the symbol scanned by the head
can be changed:
16.
17.
and
18.
19.
20.
The next condition says that the change from one ID to the next ID
is effected by a move of M. This is represented by:
21.
22.
23.
24.
25.
26.
27.
In the initial ID, the state is q1, the head scans the first cell and the
first n cells contain the input while the remaining cells contain blank
symbol.
28.
29.
30.
E6 is of length O(p(n)).
31.
32.
33.
Theorem 12.5
3-SAT is NP-complete.
We do this as follows:
Each clause in is of the form (x1 ∨ x2 ... ∨ xk). If k = 3, we leave
the clause as it is. If k = 1, then introduce new
variables y1 and y2 and replace x1 by (x1 ∨ y1 ∨ y2) ∧ (x1 ∨
¬y1 ∨ y2) ∧ (x1 ∨ y1 ∨ ¬y2) ∧ (x1 ∨ ¬y1 ∨ ¬y2). Whatever value we
give for y1 and y2 one of the above four clauses will have two
literals (apart from x1) false and to make the clause evaluate to
1, x1 has to be 1. If k = 2, x1 ∨ x2 is replaced by (x1 ∨ x2 ∨ y1) ∧
(x1 ∨ x2 ∨ ¬y1) by introducing new variable y1. One of the above
two clauses will have the literal apart from x1 and x2 as 0
whether y1 = 0 or 1. Hence, to make the expression evaluate to
1, x1 ∨ x2 must evaluate to 1.
Equation 12.5.
We have introduced new variables y1, ..., yk −3. We show
that x1 ∨ x2 ... ∨ xk evaluates to 1 if and only if Equation (12.5)
evaluates to 1 for some assignment of the new variables.
Theorem 12.7
Proof
1.
2.
3.
4.
5.
The number of vertices of G is less than the length of e and the
number of edges will be atmost the square of it. Thus, G can be
encoded as a string whose length if bounded by a polynomial in the
length of e and can be computed in time bounded by a polynomial
in the length of e. We next show that G has a clique of size k if and
only if e is satisfiable.
1.
¬ xjm is not possible and there are edges between every pair of
j
variables. This will make the literal Xmi 1 and each clause will
evaluate to 1 and so will e. So e will be satisfiable.
4.
Example 12.1.
1.
Vertex cover: Let G = (V, E) be a graph. A vertex cover of G is a
subset S ⊆ V such that each edge of G is incident upon some vertex
in S.
2.
Problem: Does an undirected graph have a vertex cover of size k?
3.
4.
Hamiltonian circuit: A Hamiltonian circuit is a cycle
of G containing every vertex of V.
5.
Problem: Does an undirected graph have a Hamiltonian circuit?
6.
7.
Set cover: Given a family of sets S1, S2, ..., Sn does there exist a
subfamily of k sets Si1, Si2,..., Sik such that:
8.
9.
10.
Regular expression inequivalence: Given two regular
expressions E1 and E2 over the alphabet Σ, do E1 and E2 represent
different languages?
11.
12.
3-Dimensional matching: Given a
set M ⊆ W × X × Y where W, X, and Y are disjoint sets having the
same number q of elements, does M contain a subset M′
of q elements and no two elements of M′ agree in any coordinate?
13.
14.
Integer programming: Given a finite set X of pairs ( , b) where is
an m-tuple of integers, and b is an integer, an m-tuple of
integers, and an integer B, is there an m-tuple of integers such
that:
15.
, ≤ b for all ( , b) ∊ X and c.y ≥ B
If = (x1,...,xm) and = (y1, ..., ym), . = x1y1 + x2y2 + ... +xmym).
Beyond NP-completeness
We next see some hierarchy of problems. Let NPC denote the
family of NP-complete problems.
Definition 12.6
Definition 12.7
Definition 12.8
A language L is PSPACE complete if
1.
L is in PSPACE and
2.
3.
4.
We state a few results without proof.
∀ x(P(x) ∧ Q(y))
Here, x is a bound variable bounded by ∀ x, y is a free variable.
When an expression has free variables like R(y, z), it is called a
predicate, for example,
S(x, y, z): z = x + y
The variables can be bound by giving values to them or by using
quantifiers. If all variables are bound, the predicate becomes a
proposition and assumes value true (1) or false (0).
Theorem 12.8
Theorem 12.9
Definition 12.9
1.
2.
3.
If R1 and R2 are extended regular expressions denoting the
languages L1 and L2, respectively, then (R1 + R2), (R1 .R2), ( ),
(R1 ∩ R2) and (¬R1) are extended regular expressions denoting
L1 ∪ L2, L1L2, , L1 ∩ L2 and Σ* − L1, respectively.
4.
+∩¬.*
Definition 12.2.10
1.
g(0, n) = n
2.
3.
4.
Theorem 12.10
Many more complexity classes can be defined and this leads to the
introduction of ‘complexity theory.’ Oracle computations have also
been defined. ‘Complexity Theory’ is a field of study by itself and is
beyond the scope of this book.
Solution
.
By result 2 mentioned in “Some Results on Complexity Classes,” DT(22n+2n) pr
DT(22n).
b
.
4. Positive 1in3SAT problem is the 1in3SAT problem, where none of the literals
that it is NP-complete.
Solution Positive 3SAT problem is: Given a Boolean expression in 3SAT form, where n
. are negated, is the expression satisfiable?
This is a trivial problem as the assignment giving values 1 to all the variables m
satisfiable.
It is straightforward to see that positive 1in3SAT problem is in NP. It can be s
complete by reducing the 1in3SAT problem to it.
Let w0 = c1... ck be a Boolean expression in 3SAT form. From this, we constru
3SAT form where none of the literals are negated such that w0 is satisfiable wi
if and only if w is satisfiable with the 1in3 condition.
Also, given w0, w can be constructed in polynomial time.
Let x1, ..., xn be the variables used in w0. There are k clauses in w0. In w, we us
variables x1, ..., xn and also variables y1, ..., yn and z1, ..., zk, z′1, ..., z′k, z″1, ..., z
We shall now give the method of constructing w from w0.
For each clause ci in w0 some clauses c′i are constructed.
1.
If ci is of the form (xk + xl + xm) with no literal negated, this is kept as it is in c
2.
3.
If ci is of the form (¬xk + xl + xm) with one literal negated, c′i consists of (yk + x
(x1 + z′i + zi)(xm + z″i + zi) (yk in essence refers to ¬ xk). If (¬xk + xl + xm) is sat
condition, then c′i is satisfiable with the 1in3 condition and vice versa. It shoul
of yk or xk will be 0 and the other 1 and zi has to be 0. The values of z′i, z″i can
satisfy the 1in3 condition.
4.
5.
If ci is of the form (¬xk + ¬xl + xm) with two of the literals negated, c′i consists
(yk + xk + zi)(yl + xl + zi)(xm + z′i + zi).
6.
Again, it can be checked that if ci is satisfiable with the 1in3 condition then c′i
1in3 condition and vice versa. Note that one of yk, xk is 0 and the other 1 as als
the other 1 and zi = 0. z′i assumes suitable value to satisfy the 1in3 condition.
7.
8.
If ci is of the form (¬xk+¬xl+¬xm) will all three literals negated, c′i consists of (
(yk + xk + zi)(yl + xl + zi)(ym + xm + zi). Again, it can be checked that if ci is sati
condition c′i is satisfiable with the 1in3 condition and vice versa. Also zi = 0 an
l, m) is 0 and the other 1, and it is straightforward to see that w′ ca
from w0 in polynomial time. Hence, positive 1in3SAT is NP-complete.
9.
5. Exact cover by three-sets (X3C): Given a set with 3n elements for some natura
collection of subsets of the set, each of which contains exactly three elements,
collection n subsets that together cover the set?
Show that this problem is NP-complete.
Exercises
1 The notion of a crossing sequence – the sequence of states in which the boundary betw
. crossed – was introduced in Chapter 6 with regard to two-way FSA. The notion can be
Prove the following about crossing sequences.
1.
The time taken by single-tape TM M on input w is the sum of the lengths of the crossi
between each two cells of M’s tape.
2.
3.
Suppose M is a single tape TM which accepts an input after reading the whole input a
accepting state when the tape is in a cell to the right of the cells where the input was o
Show that if M accepts input w1w2, and the crossing sequence between w1 and w2 is th
between x1 and x2 when M is given input x1, x2, then M accepts x1w2.
4.
3 Show that the following functions are fully time and space constructible
. 1.
n2
2.
3.
2n
4.
5.
n!
6.
Regulated Re-writing
In a given grammar, re-writing can take place at a step of a
derivation by the usage of any applicable rule in any desired place.
That is, if A is a nonterminal occurring in any sentential form
say αAβ, the rules being A → γ, A → δ, then any of these two rules
are applicable for the occurrence of A in αAβ. Hence, one
encounters nondeterminism in its application. One way of
naturally restricting the nondeterminism is by regulating devices,
which can select only certain derivations as correct in such a way
that the obtained language has certain useful properties. For
example, a very simple and natural control on regular rules may
yield a non-regular language.
Matrix Grammar
A matrix grammar is a quadruple G = (N, T, P, S) where N, T,
and S are as in any Chomsky grammar. P is a finite set of
sequences of the form:
m = [α1 → β1, α2 → β2, ..., αn → βn]
Definition 13.1
Let G = (N, T, P, S) be α matrix grammar. For any two strings u, v
∊ (N ∪ T)+, we write u ⇒ v (or u ⇒ v if there is no confusion on
G), if and only if there are strings u0, u1, uG2, ..., un in (N ∪ T)+ and
a matrix m ∊ M such that u = u0, un = v and
ui−1 = u′i−1xiu″i−1, ui = u′i−1yiu″i−1
Definition 13.2
Example 13.1.
N = {S, A, B, C, D}
T = {a, b, c, d}
P = {P1, P2, P3, P4}, where
P1: [S → ABCD]
P2: [A → aA, B → B, C → cC, D → D]
P3: [A → A, B → bB, C → C, D → dD]
P4: [A → a, B → b, C → c, D → d]
Some sample derivations are:
Example 13.2.
N = {S, A, B, C}
T = {a, b}
P = {P1, P2, P3, P4, P5},
where
P1: [S → ABC]
PROGRAMMED GRAMMAR
A programmed grammar is a 4-tuple G = (N, T, P, S), where N, T,
and S are as in any Chomsky grammar. Let R be a collection of re-
writing rules over N ∪ T, lab(R) being the labels of R. σ and ϕ are
mappings from lab(R) to 2lab(R)
Definition 13.3
1.
2.
3.
4.
Here, σ(r) is called the success field as the rule with label r is used
in the derivation step. ϕ(r) is called the failure field as the rule with
label r cannot be applied and we move on to a rule with label in
ϕ(r). , are the reflexive and transitive closures of ⇒, and
, respectively.
Example 13.3.
N = {S, A, B, C, D}
T = {a, b, c, d}
P:
r σ(r)
1. S → ABCD 2, 3, 6
2. A → aA 4
3. B → bB 5
4. C → cC 2, 3, 6
5. D → dD 2, 3, 6
6. A → a 7
7. B → b 8
8. C → c 9
9. D → d φ
Example 13.4.
N = {S, A, B, C}
T = {a, b}
P:
r σ
1. S → ABC 2, 5, 8, 11
2. A → aA 3
3. B → aB 4
4. C → aB 2, 5, 8, 11
5. A → bA 6
6. B → bB 7
7. C → cB 2, 5, 8, 11
8. A → a 9
9. B → a 10
10. C → a φ
11. A → b 12
12. B → b 13
13. C → b φ
Definition 13.4
Example 13.5.
N = {S, A, B, C}
T = {a}
(D → a, φ, {S, A, B})}.
S ⇒ AA ⇒ DA ⇒ DD ⇒ aD ⇒ aa
S ⇒ AA ⇒ BA ⇒ BB ⇒ SB ⇒ SS
⇒ AAS ⇒ AAAA a4
TIME-VARYING GRAMMAR
Given a grammar G, one can think of applying set of rules only for
a particular period. That is, the entire set of rules in P is not
available at any step of a derivation. Only a subset of P is available
at any time ‘t’ or at any i-th step of a derivation.
Definition 13.5
1.
j = i + 1 and
2.
3.
4.
Definition 13.6
holds, if
Example 13.6.
Let (G, φ) be a periodically time-varying grammar with
T = {a, b}
φ (4) = {Z1 → aZ1, Z1 → bZ2, Z2 → aZ1, Z2 → bZ2, Z1 → ε, Z2 → ε}
φ (5) = {X2 → X2, Y1 → Y1}
φ (6) = {Y2 → Y2, Z1 → Z1}
Example 13.7.
, where
φ (2) = {A → aA1, A1 → A2, A → ε}
φ (3) = {B → B1, B → bB2, B → ε}
φ (4) = {C → cC1, C → C2, C → ε}
φ (5) = {D → D1, D → dD2, D → ε}
Definition 13.7
Let G = (N, T, P, S) be a grammar. Let lab(P) be the set of labels
of productions in P. Let F be a subset of P. Let D be a derivation of
G and K be word over lab(P). K is a control word of D, if and only if
one of the following conditions are satisfied:
1.
2.
3.
4.
5.
6.
Example 13.8.
N = {A, B, C, D, S}
T = {a, b, c, d}
P:
1. S → ABC
2. A → aA
3. B → bB
4. C → cC
5. D → dD
6. A → a
7. B → b
8. C → c
9. D → d
Then, lab(P) = {1, 2, 3, 4, 5, 6, 7, 8, 9}
Example 13.9.
N = {S, A, B, C}
T = {a, b}
P:
1. S → ABC
2. A → aA
3. B → aB
4. C → aC
5. A → bA
6. B → bB
7. C → bC
8. A → a
9. B → a
10. C → a
11. A → b
12. B → b
13. C → b
Theorem 13.1
i L = L(i, 3, 0) L = L(i, 3, 1)
0 L = L0 L = L0
1 L = L1 L = L1
2 L2 ⊆ L L = L0
3 L = L3 L = L3
Theorem 13.2
Let
Theorem 13.3
Definition 13.8
An Indian parallel grammar is a 4-tuple G = (N, T, P, S) where the
components are as defined for a CFG. We say that x ⇒ y holds in
G for strings x, y over N ∪ T, if
Example 13.10.
S ⇒ a,
S ⇒ SS ⇒ aa,
S ⇒ SS ⇒ SSSS ⇒ aaaa and
The other way round, the question is: Can all context-free
languages (CFL) be generated by Indian parallel grammars? Since
the first attempt to solve this was made in (Siromoney and
Krithivasan, 1974), this type of grammar is called an Indian
parallel grammar. We state the following theorem without proof.
Theorem 13.4
One can see that one can derive a collection of strings from a
specified set of rules by means of grammars. That is, grammars are
used to compute strings or words. There are various models to
generate a set of strings. Contextual grammars are one such
models to compute a specified set of strings. In this model, strings
are attached to the existing strings to generate longer strings.
Definition 13.9
The strings in A are called the axioms, the elements of C are of the
form (u, v) called as contexts. ψ is a selection or choice mapping.
Example 13.11.
Remark. In the above example, one can see that the same
grammar has been taken to act on two different derivation modes.
Hence, the languages generated are different.
Example 13.12.
a↑b↑a ⇒ aa↑b↑aa ⇒ aaabaaa.
Definition 13.11
Example 13.13.
Lex(G) = {anbn|n ≥ 0}
NOTATIONS
Let us represent the languages of contextual grammars in the
following way:
1.
TC = the family of languages generated by total contextual
grammars with choice.
2.
3.
ECC(EC) = the family of languages generated by contextual
grammars in the external mode with choice (without choice).
4.
5.
ICC(IC) = the family of languages generated by contextual
grammars in the internal mode with choice (without choice).
6.
7.
The families of finite, regular, linear, context-free, context-
sensitive, and recursively enumerable-languages are denoted
by FIN, REG, LIN, CF, CS, RE, respectively.
8.
Generative Capacity
In this section, we prove some basic results that show the
generative power of contextual grammars. In other words, we
obtain the relations between families of contextual languages with
families in the Chomskian hierarchy.
Theorem 13.5
Theorem 13.6
1.
2.
S → x1
S → x2
⋮
S → xk
3.
4.
S → u1Sv1
S → u2Sv2
S → unSvn
Clearly, G′ is context-free.
Theorem 13.8
X = Y abmcaZ,
where Y = ε and Z is of the form bk. Hence,
X = abmcab, m > 0.
Theorem 13.9
Example 13.14.
Here p = 2. Suppose x = anbn, then x can be put as a(an − 1 bn − 1)b
where uv = ab. Hence, L satisfies EBS property.
Example 13.15.
property.
Example 13.16.
Theorem 13.10
Example 13.17.
Example 13.18.
IC ⊊ ICC
Theorem 13.12
Example 13.19.
Theorem 13.13
EC ⊊ ECC.
Theorem 13.14
Example 13.20.
Theorem 13.15
ICC ⊊ TC.
Theorem 13.16
Example 13.21.
a↑b↑a ⇒ a↑b↑ba⇒a↑b↑bba ⇒ abbba.
Theorem 13.17
ECC ⊊ TC.
Theorem 13.18
Using this theorem, one can say that TC is closed under union,
catenation, Kleene +, finite substitution, and morphism. One can
see that for a language L1 = {1, 2}, L2 = {1, 2}, and L3 = 1+ are
in TC. Hence, if σ is a substitution with σ(1) = L, σ(2) = L′,
where L and L′ are any arbitrary TC languages, σ(L1) = L ∪ L
′, σ(L2) = LL′ and σ(L3) = L+. By the above theorem, all these are
in TC. Closure under morphism follows from the definition of
substitution.
Theorem 13.19
EC, IC, ICC are not closed under union and substitution.
Table 13.1.
IC EC ICC
Union No No No
Intersection No No No
Complement No No No
Concatenation No No No
Kleene+ No No No
Morphisms No Yes No
Substitution No No No
Inverse morphisms No No No
Shuffle No No No
Theorem 13.20
Emptiness problem is decidable for all contextual languages.
Theorem 13.21
Theorem 13.22
K0 (G) = A
Theorem 13.23
The membership problem is undecidable for grammars with
arbitrary selection mapping.
Lindenmayer Systems
L-systems were defined by Lindenmayer in an attempt to describe
the development of multi-cellular organisms. In the study of
developmental biology, the important changes that take place in
cells and tissues during development are considered. L-systems
provide a framework within which these aspects of development
can be expressed in a formal manner. L-systems also provide a way
to generate interesting classes of pictures by generating strings and
interpreting the symbols of the string as the moves of a cursor.
1.
Parallel re-writing of symbols is done at every step. This is the
major difference.
2.
3.
There is no distinction between nonterminals and terminals (In
extended L-system, we try to introduce the distinction).
4.
5.
Starting point is a string called the axiom.
6.
Definition 13.12
a1 ... an ⇒ w1 ... wn
Definition 13.13
A 0L system π = (V, w0, P) is deterministic if for every a ∊ V, there
is exactly one rule in P with a on the left-hand side. It is
propagating (ε-free), if ε is not on the right-hand side of any
production. Notations DOLS, P0LS, and DP0LS are used for these
systems.
Example 13.22.
ab ⇒ aabb ⇒ aaaabbbb ⇒...
L(π1) = {a2nb2n|n ≥ 0}
Example 13.23.
Consider the following DP0L system:
P has rules:
0 → 10
1 → 32
2. → 3(4)
3→3
4. → 56
5. → 37
6. → 58
7. → 3(9)
8. → 50
9. → 39
(→(
)→)
1 4
2 56
3 3758
4 33(9)3750
5 33(39)33(9)3710
6 33(339)33(39)33(9)3210
7 33(3339)33(339)33(39)33(4)3210
8 33(33339)33(3339)33(339)33(56)33(4)3210
9 33(333339)33(33339)33(3339)33(3758)33(56)33(4)3210
10 33(3333339)33(333339)33(33339)33(33(9)3750)33(3758)33(56)33(4)3210
8
9
10
This also shows that there are finite languages which are not 0L.
Theorem 13.24
{XwX| w ∊ L(π), where X ∉ V}.
G = (N, T, P, S)
X0 → Xw0 X
Xa → X < a, L >
< a, L > X → wa < R, X >
a< R, X > → < a, R > X
b < a, R > → < b, R > a
X < b, R> → Xb
The following result can be proved even though the proof is slightly
more involved.
Theorem 13.25
Definition 13.14
Example 13.24.
Consider the T0L system:
Extended System
Nondistinction between nonterminals and terminals affected the
closure properties. From formal-language theory point of view,
extended systems are defined which make the families defined
closed under many operations. Here, the system has two sets of
symbols, terminals and nonterminals, or total alphabet, and target
alphabet.
Definition 13.15
Example 13.25.
1.
2.
3.
(a, b, c) — α is in P if and only if for all d ∊ V ∪ {$} (d, b, c) → α is
in P.
4.
Example 13.26.
Consider 2L system:
H2 = ({a, b},a, P, $)
($, a, $) → a2| a3|a3b|ba3
(x, b, y) → b|b2
(a, a, a) → a
(a, a, b) → a
($, a, a) → a
x, y ∊ {a, b, $}
a, abcd5, abcd5bcd5cd6d5,....
Example 13.28.
The strings generated in a few steps and their lengths are given
below.
w0 a
step 1 abcc
step 2 abccbcccc
step 3 abccbccccbccccc
π is (1, 0, 0)
Applications
L-systems are used for a number of applications in computer
imagery. It is used in the generation of fractals, plants, and for
object modeling in three dimensions. Applications of L-systems
can be extended to reproduce traditional art and to compose
music.
+: Turn the turtle left by an angle δ. The next state of the turtle will be (x, y, A + δ). Posit
angle is taken as anti-clockwise.
Interpretation of a String
Let S be a string and (x0, y0, A0) be the initial state of the turtle,
and step size d, angle increment δ are the fixed parameters. The
pattern drawn by the turtle corresponding to the string S is called
the turtle interpretation of the string S.
Axiom: w: f + f + f + f
production: f → f + f − f − ff + f + f − f
Interpolation
Consecutive positions of the turtle can be considered as control
points specifying a smooth interpolating curve. B-spline
interpolation is used for most of the kolam patterns (Figure 13.2)
Candies
Figure 13.2 shows the kolam pattern ‘Candies’ which can the
generated by the following L-system.
Productions:
Grammar Systems
A grammar system is a set of grammars working in unison,
according to a specified protocol, to generate one language. These
are studied to model distribution, to increase the generative power,
to decrease the complexity etc. The study of grammar systems
probes into the functioning of such system under specific protocols
and the influence of various protocols on various properties of the
system are considered.
CD Grammar Systems
Definition 13.17
Definition 13.18
1.
2.
3.
4.
5.
component, denoted by , is defined by if and only if there
are x1, ..., xk + 1 ∊ (N ∪ T)* such that x = xi, y = xk + 1 and for each j,
1 ≤ j ≤ k
6.
7.
8.
9.
10.
11.
12.
13.
Let D = {*, t}∪{≤ k, ≥ k, = k|k ≥ 1}.
Definition 13.19
Example 13.29.
If f = * mode, the first component derives S ⇒ XY, the second component derives from
switch to first component or derive a X′ from X.
In the first component, X′ can be changed to X or Y′ can be changed to Y or both. The
similarly.
It is not difficult to see that the language generated is {ambncn\m, n ≥ 1}.
The same will be true for t mode, = 1 mode, ≥ 1 mode, ≤ k mode for k ≥ 1.
But, if we consider = 2 mode, each component should execute two steps. In the first c
S ⇒ S ⇒ XY. In the second component, XY ⇒ aX’ Y ⇒ aX’ bY’ c. Then, control goes b
one where X’ and Y’ are changed to X and Y in two steps. The derivation proceeds in
easy to see that the language generated by GS1 in the = 2 mode is {anbncn|n ≥ 1}. A sim
for ≥ 2-mode also and the language generated is the same.
At most, two steps of derivation can be done in each component. Hence, in the case o
where k ≥ 3, the language generated is the empty set.
P1 = {S → AA}
P2 = {A → S}
P3 = {A → a}
In the * mode, {an|n ≥ 2} is generated as the control can switch from component to co
A similar result holds for ≥ 1, ≤ k (k ≥ 1) modes. For = 1, = k, ≥ k (k ≥ 2), the languag
as S → AA can be used only once in P1 and A → a can be used once in P3.
In the t mode, in P1, S ⇒ AA and if the control goes to P3 from AA, aa is derived. If th
to P2 from AA, SS is derived. Now, the control has to go to P1 to proceed with the
derivation SS ⇒ AAAA, and if the control goes to P2, S4 is derived; if it goes to P3, a4 i
to see that the language generated in t mode is {a2n|n ≥ 1}.
P1 = {S → S, S → X1X1, X2 → X1}
P2 = {X1 → aX2, X1 → a}
1.
2.
3.
4.
5.
6.
7.
8.
9.
CD∞(≥) ⊆ CD∞(=).
10.
11.
12.
13.
Except for the inclusion CD∞(f) ⊆ MAT all the previous relations
are also true for CD grammar system with ε-rules
14.
15.
16.
PC Grammar Systems
Definition 13.20
Let VGP = N ∪ K ∪ T.
The sets Pi, are called components of the system. The index i of
Qi points to the ith component Pi of GP.
Definition 13.21
1.
2.
3.
4.
If |xij|K = 0, for all j, 1 ≤ j ≤ t, then yi = zixi1z2xi2...ztxitZt+1 and
yij = Sj (in returning mode) and yij = xij (in non-returning mode) 1
≤ j ≤ t. If for some j, 1 ≤ j ≤ t, |xij|K ≠ 0, then yi = xi. For all i, 1 ≤ i ≤ n,
such that yi is not specified above, we have yi = xi.
5.
6.
7.
Definition 13.22
The language generated by a PC grammar system GP
1.
2.
3.
4.
5.
6.
The first component is called the master and the language consists
of terminal strings derived there.
Example 13.30.
1.
Let GP1 = ({S1, , S2, S3}, {Q1, Q2, Q3}, {a, b}, (S1, P1), (S2, P2), (S3,
P3)), P1 consists of rules:
2.
1. S1 → abc
2. S1 → a2b2c2
3.
4. S1 → a3Q2
5. → aS
6. → a3Q2
7. S2 → b2Q3
8. S3 → c
P2 = {S2 → bS2}
P3 = {S3 → cS3}
3.
Lr(GP1) = Lnr(GP1) = {anbncn|n ≥ 1}
4.
This can be seen as follows:
5.
a3bS2 S2 cS3
a3b3c2S3 bS2 S3
S1 S2 S3
a4b2S2 S2 c2S3
S1 S2 S3
S1 aS2
S1 abS2
Q2Q2 abb
Distributed Automata[*]
Formal-language theory and automata theory are twins, in the
sense that the development of one triggers the other one, so as to
make them as close to each other as possible. Hence, we study co-
operative distributed automata here. We restrict ourselves to the
blackboard or sequential model here (Krithivasan et al., 1999),
though there is work on the parallel model also.
Distributed Nondeterministic FSA
Definition 13.23
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
where Kunion = ∪iKi. This notation is followed throughout this
section.
T -MODE ACCEPTANCE
Initially, the automaton which has the initial state begins the
processing of input string. Suppose that the system starts from the
component i. In component i, the system follows its transition
function as any “stand alone” FSA. The control is transfered from
the component i to component j only if the system arrives at a
state q ∉ Ki and q ∊ Kj. The selection of j is nondeterministic
if q belongs to more than one Kj. The process is repeated and we
accept the strings if the system reaches any one of the final states.
It does not matter which component the system is in.
Definition 13.24
2.
3.
4.
Definition 13.25
Lt(Γ) = {w ∊ V*|(q0, w, i) ⊢ (qf, ε, j) for some qf ∊ F, 1 ≤ j, i ≤ n and q0 ∊ Ki}
*-MODE ACCEPTANCE
Initially, the automaton which has the initial state begins the
processing of the input string. Suppose the system starts the
processing from the component i. Unlike the termination mode,
here there is no restriction. The automaton can transfer the control
to any of the component at any time if possible, i.e, if there is
some j, such that q ∊ Kj then the system can transfer the control to
the component j. The selection is done nondeterministically, if
there is more than one j.
The ID and the language accepted by the system in *-mode can be
defined analogously. The language accepted in *-mode is denoted
as L*(Γ).
Definition 13.26
Theorem 13.27
F′ = {[qf, i]|qf ∊ F, 1 ≤ i ≤ n}
1.
2.
3.
4.
5.
if qk ∊ Kj − Ki, then [qk, j] ∊ δ([qj, i], a), 1 ≤ j ≤ n
6.
Theorem 13.28
K′ = {[q, i]/q ∊ Kunion, 1 ≤ i ≤ n} ∪ { }
F′ = {[qf, i]/qf ∊ F, 1 ≤ i ≤ n}
1.
2.
3.
4.
{[qy, j]}⊆ δ ([qs, i], a), 1 ≤ j ≤ n and qy ∊ Kj.
5.
Theorem 13.29
1.
Theorem 13.30
1.
if j − 1 < k then:
2.
.
.
.
.
3.
4.
Theorem 13.31
2.
3.
if j−1 = k then:
4.
.
.
.
.
5.
{[qy, i]} ∊ δ([qs, i], a), qy ∊ Ki
6.
7.
8.
Definition 13.27
1.
2.
Kunion = UiKi
3.
4.
V is the finite set of input alphabet.
5.
6.
7.
8.
each
9.
10.
11.
12.
13.
14.
15.
T -MODE ACCEPTANCE
Initially, the component which has the initial state begins the
processing of the input string. Suppose the component i has the
start state. The ith component starts the processing with the stack
having the start symbol Zi. The processing proceeds in the
component i as in a stand alone PDA. Suppose in the
component i the system arrives at a state q where q ∉ Ki the system
goes to the jth component (1 ≤ j ≤ n) provided q ∊ Kj. If there is
more than one choice for j, we choose any one of them
nondeterministically. After choosing a particular jth component,
the automaton remains in this component until it reaches a state
outside the domain of its transition function and the above
procedure is repeated. The string is accepted if the automaton
reaches any one of the final states. It does not matter which
component the system is in, or the stacks of the components are
empty or not. The presence of multi-stacks increases the generative
capacity of the whole system.
*-MODE ACCEPTANCE
Initially, the automaton which has the initial state begins the
processing of the input string. Suppose the system starts the
processing from the component i. Unlike the termination mode,
here there is no restriction. The automaton can transfer the control
to any of the component at any time if possible, i.e, if there is
some j such that q ∊ Kj then the system can transfer the control to
the component j. The selection is done nondeterministically if
there is more than one j. The stacks for each component is
maintained separately.
Definition 13.28
if (q′, β) ∊ δi(q, a, X)
and
where
Definition 13.29
(q, aw, α1, α2, ..., Xαi, ..., αn, i, j) ⊢ (q′, w, α1, α2, ..., βαi, ..., αn, i, j+
1)
where
q ∊ Ki, q′ ∊ Kunion, a ∊ V ∪{ε}, w ∊ V*, 1 ≤ i ≤ n, ,1
≤ j ≤ n, , X ∊ Γi.
and if q′ ∊ Kj(j ≠ i)
Definition 13.31
L=k (M) = {w ∊ V* | (q0, w, Z1, Z2, ..., Zn i′, 0) ⊢* (qf, ε, α1, α2, ..., αn,
i, k) for some qf ∊ F, 1 ≤ i, i′ ≤ n, αi ∊ Γ*i and q0 ∊ Ki′}
M = ((K1, K2),V, (Γ1, Γ2), (δ1, δ2), {q0}, (Z1, Z2), {qf}),
where
V = {a, b, c}
Z1 = Z
Z2 = Z
F = {qf}
Γ1 = {Z, a}
Γ2 = {Z, b}
Equation 13.1.
L = {anbncn | n ≥ 1}
Explanation:
The first component starts the processing. When it uses the first
two transitions, it should have read an a. Then, it switches the
control to the second component where it is in the state q1. After
using the ε-transition to go to the state q2, it can either read
a a or b. Suppose it reads an a, then the system will be in the
state qp. The state qp is used here to put the already read a on to
the first-component stack. This task is carried out by rules 13.5 and
13.6. Suppose when in the second component it reads a b, then the
system will be in the state qs, which is used to see whether there is
one a for each b. This task is carried out by rules 13.8, 13.9, and
13.10. Immediately, after seeing there is no more a’s in the first
component’s stack then it realizes that number of b’s is equal to
number of b’s and it goes to the state qc, which is used to read c’s.
This task is carried out by rule 13.9. After reading each and
every c through rule 13.11, it will erase a b. When there is no b left
in the stack, the system will be in the final state qf. If there are
more b’s left in the second component stack, then the system will
be in the state qc. Then, it uses the last two ε-rules in the first
component and repeats the above procedure until it arrives at the
state qf.
Example 13.32.
Consider the t-mode 2-PDA:
where
V = {a, b}
F = {qf}
Γ1 = {Z, a, b}
Γ2 = {Z, a, b}
Δ = (δ1, δ2),
Explanation:
Equivalence
The equivalence of acceptance by final state and empty store in a n-
PDA in t-mode is proved by the following theorems:
Theorem 13.32
K = (K1, K2, ..., Kn)
2.
4. contains
6. For 1 ≤ i ≤ n − 1,
1.
contains (qi, ε), X ∊ Γi
2.
3.
contains (qi + 1, ε)
4.
7. contains (qn, ε)
Whenever the system enters a final state, string read by the system
should be accepted by the system, i.e., the stacks of the
components should be emptied. For this, as soon as the system
enters the final state it has the possibility of going to the first
component through the state q1. When in the state q1, the system
empties the first-component stack and enters the second
component through the state q2 and the procedure is repeated. In
the state qn, the system empties the stack of the nth component. It
is straightforward to prove that L(M2) = N(M1).
Theorem 13.33
3. , 1 ≤ i ≤ n
4.
5. contains
7.
For 1 ≤ i ≤ n, contains
8.
contains (q1, ZqiZn + 1)
9. contains , 1 ≤ i ≤ n − 1
12.
contains
13.
contains (q, X), 1 ≤ i ≤ n, X ∊ Γi
Whenever the system’s stacks are empty, the system enters the
new final state qf included in the newly added component . For
this, if the system in the state q in the component i sees its stack is
empty, the system enters the state rqi which is only in the newly
added state set . In the component in state rqi, Zqi is put
into its stack to store the information, which state and which
component the system has to go, if the system sees that some
stacks are non-empty. After stacking the Zqi, the system uses the
states qj to see whether the stack of the component j is empty or
not. If it is empty, it goes to the next component to check the
emptiness of the next component. If not, it enters the state qg which
is in the component n + 1 to get the information from which state
and component it has to continue the processing. This work is done
by the state .
Distributed k-turn PDA
In this section, we consider only *-mode acceptance.
Also, K = K1 = K2 = ··· = Kn. In this restricted version of distributed
PDA, the stacks of the component PDAs can perform at most
a k number of turns while accepting a string. A n-PDA in which the
stack of each of the components can perform at most k-turns each
is called a k-turn n-pushdown automata (k-turn n-PDA). If n is
not explicitly mentioned, then the system is called k-turn
distributed PDA and is denoted by the symbol k-turn *-PDA. The
following corollary immediately follows from this definition of k-
turn n-PDA and the fact that the family of languages accepted by k-
turn PDAs is the family of non-terminal bounded languages. The
proofs are omitted here.
Theorem 13.34
Theorem 13.35
1.
Morphism
2.
3.
4.
Theorem 13.37
For each L ∊ RE, there exists a 1-turn 2-PDA M such that L(M) = L
and conversely, for each 1-turn 2-PDA M, we have L(M) ∊ RE.
Chapter 14. New Models of
Computation
DNA Computing
Mathematical biology is a highly interdisciplinary area of research
that lies at the intersection of mathematics and biology. So far, in
this area, mathematical results have been used to solve biological
problems. The development of stochastic processes and statistical
methods are examples of such a development. In contrast, an
instance of the directed Hamilton path problem was solved solely
by manipulating DNA strings by Leonard Adleman. Hence, one can
see that biological technique is used to solve a mathematical
problem, thus paving way for a new line of research ‘DNA
computing.’ The resemblance between mathematics and biology is
that in both, simple operations are applied to initial information to
obtain a result. Hence, the use of biology to solve a mathematical
problem was demonstrated by a mathematician with adequate
knowledge in biology, to bring together these two fields. Adleman
thought that DNA strings can be used to encode an information
while enzymes can be employed to simulate simple computations.
The theory developed here does not require a concern for its
origins in molecular biology. We present only the details of
‘splicing rules’ and hence ‘splicing systems.’ We provide a new
generative device called ‘splicing system’ that allows a close
simulation of molecular recombination processes by corresponding
generative processes acting on strings. Here, first we start a brief
discussion on double stranded form of DNA and ‘splicing
operation.’
ACGT
T G C A.
Any DNA strand, for example, will consist of double strands like
the one given below:
A A A A A G A T C A A A
T T T T T C T A G T T T
Let us first explain what a splicing rule is. Any splicing rule
recognizes critical subwords in the double stranded DNA molecule.
For example in
A A A A A A A, G A T C, A A A A
T T T T T T T, C T A G, T T T T
GATC
CTAG
it cuts (in both strands of) the DNA molecule between A and T.
The ligase enzyme has the potential to bind together pairs of these
molecules. For example if:
Molecule 1
A A A A A A A G A T C A A A A
T T T T T T T C T A G T T T T
Molecule 2
C C C C C T G G C C A C C
G G G G G A C C G G T G G
then if the enzymes DpnI, which cuts between A and T and BalI,
which cuts between G and C act on molecules 1 and 2, to obtain
A A A A A A A G A T C A A A
and
T T T T T T T C T A G T T T
and
C C C C C T G G C C A C C
and
G G G G G A C C G G T G G
The ligase enzyme is put in the solution containing the above ‘cut
positions’ to recombine. Hence, one can see that new molecule 3 is
formed.
Molecule 3
A A A A A A A G A C C A C C
T T T T T T T C T G G T G G
1.
xu
2.
3.
υy
4.
5.
x′u′
6.
7.
υ′y′.
8.
Then, the presence of an appropriate ligase in the aqueous solution
results in molecule 3 which is xuv′y′. The whole operation defined
above is known as splicing operation.
Splicing Operation
In this section, we consider splicing systems with uniterated and
iterated modes.
r = u1#u2 $u3#u4,
where ui ∊ V*, 1 ≤ i ≤ 4.
Example 14.1.
(a10b,ca5) a15.
(amb,can) am+n.
Example 14.2.
Example 14.3.
R = {an#b$b#cn|n ≥ 1}
Example 14.4.
where .
Remarks
1.
From the splicing scheme, one can see that a splicing rule is
applicable to any two strings having the subwords that can be
subjected to splicing. Hence, the site of cutting is to be present in
the two strings. In such a case, the whole strings that are
considered need not be over the alphabet of splicing rule. But, the
alphabet of a splicing rule is a subset of the alphabet of the strings
to be spliced.
2.
3.
The scheme defined above considers a language L of strings subject
to splicing. That is, σ is defined as a unary operation with
languages. One can also think σ as binary operation. That is:
4.
σ(L1, L2) = {z ∊ V*|(x, y) z, x, y∊L1, r∊L2}
5.
Given any two families of languages F1 and F2 over V, we define
6.
S(F1, F2) = {σ(L)|L ∊ F1, σ = (V, R), with R ∊ F2}
7.
8.
One can see that each set of splicing rules is a language over the
basic alphabet and {#, $}. We say that F1 is closed under σ of F2-
type if S(F1, F2) ⊆ F1. Hence, we try to investigate the power of F2-
type splicing by investigating S(F1, F2) for various F1. Here, F1,
F2 will belong to {FIN, REG, LIN, CF, CS, RE}. In all the results,
the families of languages considered are supposed to contain
atleast the finite languages.
9.
Lemma 14.1
Lemma 14.2
If F1 is a family of languages closed under concatenation with
symbols, then F1 ⊆ S(F1, F2) for all F2.
Lemma 14.3
Theorem 14.1
Theorem 14.2
S(REG, REG) = REG.
CF CF CF RE RE RE RE
CS RE RE RE RE RE RE
RE RE RE RE RE RE RE
Iterated Splicing
Let σ = (V, R) be a splicing scheme where R ⊆ V*#V*$V*#V*, one
can apply σ to a language L ⊆ V* iteratively. That is:
σ0(L) = L
σ1(L) = σ0(L)∪σ(L)
σ2(L) = σ1(L)∪σ(σ1(L))
⋮
σi+1(L) = σi(L)∪σ(σi(L))
σ* (L) =
Example 14.5.
Consider,
Here, the vertical line ‘|’ indicates the position at which the splicing
rule r1 is used.
Consider,
Here,
L = {aba, abba}
σ0(L) = {abba, aba}
σ1(L) = {aba, abba, abbba}
Lemma 14.4
If and , then for all
families F1, , F2, .
Definition 14.1
Lemma 14.5
Theorem 14.4
Consider the H-scheme σ =
({a, b}, an+1#an$an+1#an}), .
Clearly .
There are also other ways for identifying u1, u2, u3, u4 in x and y so
that (x, y) ⊢ z and z is not of the form a2nb2nakb2na2n, k ≥ 2n + 1. We
arrive at strings not in Ln. Hence the result.
Lemma 14.6
L0 = {XBSY, XZ, ZY}∪{ZvY|u → υ ∊ P}∪{ZYα, X′αZ|α ∊ N∪Σ∪{B}}.
That is, L0 is the initial set of strings (axiom) available for splicing.
1.
2.
This set of rules is used to simulate rules in P. That is, they indicate
the application of the rule u → υ ∊ P for a string containing ‘u.’
3.
4.
5.
6.
7.
These rules move symbols from the right-hand end of the current
string to the left-hand end. The presence of B indicates the
beginning of the corresponding sentential form. For, if the current
string in σ is of the form β1 w1 Bw2 β2 for some β1, β2 markers of
type X, X′, Y, Yα, α ∊ N ∪ Σ ∪ {B}, w1, w2 ∊ (N ∪ Σ)*, then w2w1 is
a sentential form of G.
8.
9.
Let us actually see how the above rules simulate the sentential
forms. If:
10.
(XwαY, ZYα) ⊢ XwYα
11.
12.
(X′αZ, XwYα) ⊢ X′αwYα.
13.
This indicates the shifting of α to the left of w. The only possible
rule to be applied is rule 3. Hence,
14.
(X′αwYα, ZY) ⊢ X′αwY.
15.
16.
(XZ, X′αwY ⊢ XαwY).
17.
18.
19.
#ZYσXB#wY for w ∊ Σ*
.
.
#Y$XZ #.
(wY, XZ) ⊢ w.
RE RE RE RE RE RE
FIN REG RE RE RE
EH(F1, F2) FIN REG LIN CF
REG REG RE RE RE
LIN LIN, CF RE RE RE
CF CF RE RE RE
CS RE RE RE RE
RE RE RE RE RE
Theorem 14.5
EH(FIN, FIN) = REG
Theorem 14.6
EH(FIN, REG) = RE
Example 14.6.
R = {a#B $B #b,
a#$#aB,
a#B$#a,
Bb#$#b,
b#$B#b}.
Definition 14.2
Define
Example 14.7.
Definition 14.3
Theorem 14.7
Theorem 14.8
Membrane Computing
Membrane computing is a new computability technique which is
inspired from biochemistry. The model used for any computation
here resembles a membrane structure and it is a highly parallel,
distributed computing model. Several cell-like membranes are
recurrently placed inside a unique membrane called “skin”
membrane. The structure of this model may be placed as a Venn
diagram without intersected sets and with unique superset. Hence,
the structure or compartment of the computing model can be
diagrammatically represented as below:
1.
[] ∊ MS;
2.
3.
If μ1, ... , μn ∊ MS, n ≥ 1, then [μ1 ... μn] ∊ MS;
4.
5.
nothing else is in MS.
6.
Consider now the following relation over the elements
of MS: x ~ y if and only if we can write the two strings in the
form x = μ1μ2μ3μ4, y = μ1μ3μ2μ4, for μ2μ3 ∊ MS and μ2, μ3 ∊ MS(two
pairs of parentheses, which are neighbors at the same level are
interchanged, together with their contents). We also denote by ~
the reflexive and transitive closure of the relation ~. This is clearly
an equivalence relation. We denote by the set of equivalence
classes of MS with respect to this relation. The elements of are
called membrane structures.
Each matching pair of parentheses [,] appearing in a membrane
structure is called a membrane. The number of membranes in a
membrane structure μ is called the degree of μ and is denoted
by deg(μ) while the external membrane of a membrane
structure μ is called the skin membrane of μ. A membrane, which
appears in μ ∊ in the form [ ](no other membrane appears inside
the two parentheses) is called an elementary membrane.
1.
If μ = [ ], then dep(μ) = 1;
2.
3.
If μ = [μ1 ... μn], for some μ1, ... , μn ∊ MS, then dep(μ) =
max{dep(μi) | 1 ≤ i ≤ n} + 1.
4.
A membrane structure can be represented in a natural way as a
Venn diagram. This makes clear that the order of membrane
structures of the same level in a larger membrane structure is
irrelevant; what matters is the topological structure, the
relationship between membranes.
where:
1.
V is an alphabet; its elements are called objects;
2.
3.
T ⊆ V (the output alphabet);
4.
5.
C ⊆ V, C ∩ T = φ (catalysts);
6.
7.
μ is a membrane structure consisting of m membranes, with the
membranes and regions labeled in a one-to-one manner with
elements of a given set; here we use labels 1, 2, ... , m;
8.
9.
wi, 1 ≤ i ≤ m are strings representing multisets over V associated
with the regions 1, 2, ... , m of μ;
10.
11.
Ri, 1 ≤ i ≤ m, are finite sets of evolution rules over V associated
with the regions 1, 2, ... , m of μ; ρi is a partial order relation
over Ri, 1 ≤ i ≤ m, specifying a priority relation among rules of Ri.
12.
An evolution rule is a pair (u, υ), which we usually write in the
form of u → υ, where u is a string over V and υ = υ′ or υ = υ′δ,
where υ′ is a string over
13.
{ahere, aout, ainj | a ∊ V, 1 ≤ j ≤ m},
14.
and δ is a special symbol not in V. The length of u is called the
radius of the rule u → υ. (The strings u, υ are understood as
representations of multisets over V, in the natural sense.)
15.
16.
i0 specifies the output membrane of Π if it is a number
between 1 and m. If it is equal to ∞, it indicates that the output is
read in the outer region.
17.
When presenting the evolution rules, the indication “here” is in
general omitted. It may be remembered that the multiset
associated with a string w is denoted by M(w).
Π = (V, T, C, μ, w1, w2, w3, (R1, ρ1), (R2, ρ2), (R3, ρ3), 3),
V = {a, b, c, d, x},
T = {x},
C = φ,
μ = [1[2]2[3]3]1,
w1 =
φ, , ρ1=φ,
ρ2 = {ab → a > a → δ},
w3 = φ, R3 = φ, ρ3 = φ.
Rewriting P Systems
Now, we consider objects which can be described by finite strings
given over a finite alphabet, instead of objects of an atomic type.
The evolution of an object then corresponds to a transformation of
the string. The transformations take place in the form of rewriting
steps. Consequently, the evolution rules are given as rewriting
rules.
X → (υ, tar)
Note that each string is processed by one rule only, the parallelism
refers here to processing simultaneously all available strings by all
applicable rules. If several rules can be applied to a string, maybe
in several places each, then we take only one rule and only one
possibility to apply it and consider the obtained string as the next
state of the object described by the string. It is important to have in
mind that the evolution of strings is not independent of each other,
but interrelated in two ways:
1.
If rules which introduce both δ and τ are applied in a single step in
a membrane, then the membrane does not change its thickness.
2.
3.
If two or more rules involving τ are applied in a membrane in a
single step, the membrane becomes non-permeable.
4.
5.
If two or more rules involving δ are applied in a single step in a
non-permeable membrane or a membrane of thickness two or one,
the membrane dissolves.
6.
The actions of symbols δ, τ are illustrated in Figure 14.3.
7.
8.
Figure 14.3. The effect of actions δ, τ
9.
A P system based on sequential rewriting, with external output
and membranes of variable thickness is a construct:
Π = (V, T, μ, L1, L2,..., Ln, R1, R2,..., Rn, ∞)
We have two variables, x1, x2, and two clauses. It is easy to see that
it is satisfiable: any of the following truth-assignments makes the
formula true:
Theorem 14.9
The SAT problem can be solved by using replicated rewriting P
systems in a time linear in the number of variables and number of
clauses.
Theorem 14.10
Π = (V,T,H, μ, w1, ..., wm, R),
where:
1.
m ≥ 1;
2.
3.
V is an alphabet (the total alphabet of the system);
4.
5.
T ⊆ V (the terminal alphabet);
6.
7.
H is a finite set of labels for the membranes;
8.
9.
μ is a membrane structure, consisting of m membranes, labeled
(not necessarily in a one-to-one manner) with elements of H; all
membranes in μ are supposed to be neutral;
10.
11.
w1, ... , wm are strings over V, describing the multisets of
objects placed in the m regions of μ;
12.
13.
R is a finite set of developmental rules, of the following forms:
14.
.
, for α, αi ∊ {+, −,
0}, a ∊ V, ai ∊ V*, i = 1, ... ,n, h ∊ H, and n ≤ d (division rules for
elementary membranes),
.
.
,
for k ≥ 1, n > k, hi ∊ H, 0 ≤ i ≤ n, n ≤ d, and there exist i,j, 1 ≤ i,j ≤ n,
such that αi,αj ∊ {+, −}; moreover, βj, γj ∊ {+, −, 0}, 1
≤ j ≤ n (division of non-elementary membranes).
.
Note that in all rules of types (a) − (e), the objects do not directly
interact. In rule (a), an object is transformed into a string of
objects, and in the rest of the rules, an object is replaced with
another one.
1.
All the rules are applied in parallel: in a step, the rules of type (a)
are applied to all objects to which they can be applied, all other
rules are applied to all membranes to which they can be applied;
an object can be used by only one rule, non-deterministically
chosen (there is no priority relation among rules), but any object
which can evolve by a rule of any form, should evolve.
2.
3.
If a membrane is dissolved, then all the objects in its region are left
free in the region immediately above it. Because all rules are
associated with membranes, the rules of a dissolved membrane are
no longer available in subsequent steps. The skin membrane is
never dissolved.
4.
5.
Note that in a rule of type (f) at least two membranes in its left-
hand side should have opposite polarization. All objects and
membranes not specified in a rule and which do not evolve are
passed unchanged to the next step. For instance, if a membrane
with the label h is divided by a rule of type (e) which involves an
object a, then all other objects in membrane h which do not evolve
are introduced in each of the resulting membranes h. Similarly,
when dividing a membrane h by means of a rule of type (f), the
contents of each membrane is reproduced unchanged in each copy,
providing that no rule is applied to their objects.
6.
7.
If at the same time a membrane h is divided by a rule of type (e)
and there are objects in this membrane which evolve by means of
rules of type (a), then in the new copies of the membrane we
introduce the result of the evolution. That is, we may suppose that
first the evolution rules of type (a) are used, changing the objects,
and then the division is produced, so that in the new membranes
with label h we introduce copies of the changed objects. Of course,
this process takes only one step. The same assertions apply to the
division by means of a rule of type (f): always we assume that the
rules are applied “from bottom-up”. We first apply the rules of the
innermost region and then proceed level by level until the region of
the skin membrane is reached.
8.
9.
The rules associated with a membrane h are used for all copies of
this membrane, irrespective whether or not the membrane is an
initial one or it is obtained by division. At one step, a
membrane h can be the subject of only one rule of types (b) − (f).
10.
11.
The skin membrane can never divide. As any other membrane, the
skin membrane can be “electrically charged.”
12.
The membrane structure of the system at a given time, together
with all multisets of objects associated with the regions of this
membrane structure is the configuration of the system at that
time. The (m + 1)-tuple (M, W1, ..., wm) is the initial
configuration. We can pass from a configuration to another by
using the rules from R according to the principles given above. We
say that we have a (direct) transition among configurations.
A sequence of transitions which starts from the initial
configuration is called a computation with respect to Π. A
computation is complete if it cannot be continued: there is no rule
which can be applied to objects and membranes in the last
configuration.
Two facts are worth emphasizing: (1) the symbols not in T that
leave the skin membrane as well as all symbols from T, which
remain in the system at the end of a halting computation are not
considered in the generated strings and (2) if a computation goes
for ever, then it provides no output, it does not contribute to the
language L(Π).
1.
Start with a linear membrane structure. The central membrane is
always divided into an exponential number of copies.
2.
3.
In the central “parallel engine” one generates, making use of the
membrane division, a “data pool” of an exponential size; due to the
parallelism, this takes only a linear time. In parallel with this
process, a “timer” is simultaneously ticking, in general, for
synchronization reasons.
4.
5.
After finishing the generation of the “data pool”, one checks
whether or not any solution of our problem exists.
6.
7.
A message is sent out of the system at a precise moment telling
whether or not the problem has a solution.
8.
Theorem 14.11
Tissue P Systems
The tissue P system, a variant of P system is mainly concerned with
two things, intercellular communication (of chemicals, energy,
information) by means of complex networks of protein channels,
and the way the neurons co-operate, processing impulses in the
complex net established by synapses.
This model starts from a given initial configuration (that is, initial
states of cells and initial multisets of symbol-objects placed in
them) and proceeds until reaching a halting configuration, where
no further rule can be applied, and then associates a result with
this configuration. Because of the non-deterministic behavior of
a tP system, starting from the given initial configuration we can get
arbitrarily many outputs. Output will be defined by sending
symbols out of the system. For this purpose, one cell will be
designated as the output cell, and in its rules sM → s′M′ the
symbols from M′ are marked with the indication “out”; such a
symbol will immediately leave the system, contributing to the
result of the computation.
where:
O is a finite non-empty alphabet (of objects);
syn ⊆ {1, ..., m} × {1, ..., m} (synapses among cells);
iout ∊ {1, ..., m} indicates the output cell;
σi, 1 ≤ i ≤ m, are cells, where each σi = (Qi, si,0, wi,0, Pi), with:
Qi is a finite set of states;
si,0 ∊ Qi is the initial state;
wi,0 is the initial multiset of objects;
Pi is a finite set of rules of the form sw → s′xygozout, where s, s′ ∊
Qi, w, x ∊ O*, ygo ∊ (O × {go})* and Zout ∊ (O × {out})*, with the
restriction that zout = λ for all i ∊ {1, 2, ..., m} different from iout.
A tP system is said to be co-operative if it contains at least a
rule sw → s′w′ such that |w| > 1, and non-cooperative in the
opposite case. The objects which appear in the left-hand
multiset w of a rule sw → s′w′ are sometimes called impulses,
while those in w′ are also called excitations.
Using the rules from the sets Pi, 1 ≤ i ≤ m, we can define transitions
among the configurations of the system. For this purpose, we first
consider three modes of processing the impulse-objects and
three modes of transmitting excitation-objects from one cell to
another cell.
sx ⇒min s′y iff sw → s′ ∊ Pi, w ⊆ x, and y = (x − w) ∪ w′;
sx ⇒par s′y iff sw → s′w′ ∊ Pi, wk ⊆ x, wk+1 ⊈ x, for some k ≥ 1
and y = (x − wk) ∪ w′k;
sx ⇒max s′y iff sw1 → s′ w1, ..., swk → s′w′k ∊ Pi, k ≥ 1, such
that w1 ... wk ⊆ x, y = (x − w1 ... wk) ∪ w′1’ ... w′k, and there is
no sw → s′w′ ∊ Pi such that w1 ... wkw ⊆ x.
Intuitively, in the min mode, only one occurrence of the left-hand
side symbol of a rule is processed (replaced by the string from the
right-hand side of the rule, at the same time changing the state of
the cell). In the par mode, a maximal change is performed with
respect to a chosen rule, in the sense that as many as possible
copies of the multiset from the left-hand side of the rule are
replaced by the corresponding number of copies of the multiset
from the right-hand side. In the max mode, the change is
performed with respect to all rules, which use the current state of
the cell and introduce the same new state after processing the
multisets.
repl: each symbol a, for (a, go) appearing in w′, is sent to each of
the cells σj such that (i, j) ∊ syn;
one: all symbols a appearing in w′ in the form (a, go) are sent to
one for the cells σj such that (i, j) ∊ syn, nondeterministically
chosen;
spread: the symbols a appearing in w′ in the form (a, go) are
nondeterministically distributed among the cells σj such that (i, j)
∊ syn.
If we have at most two cells, three modes of transmitting the
processed multisets from a cell to another cell are coincide.
O = {a},
σ1 = ({s},s,a2,{sa → s(a, go), sa → s(a,out)}),
iout = 1.