PUSHDOWN
AUTOMATA AND
TURING MACHINES
UNIT IV
By Dr.T.p.Latchoumi
INTRODUCTION
 In the theory of computation, a branch of theoretical computer science a
Pushdown Automaton (PDA) is a type of automata that employs a stack.
 Pushdown automata are used in theories about what can be computed by
machines.
 They are more capable than finite-state machines but less capable than
Turing machines.
 Deterministic pushdown automata can recognize all deterministic
context-free languages while nondeterministic ones can recognize all
context-free languages, with the former often used in parser design.
CONT…
 A finite-state machine just looks at the input signal and the current
state: it has no stack to work with. It chooses a new state, the result of
following the transition.
 A PDA differs from a finite state machine in two ways:
 It can use the top of the stack to decide which transition to take.
 It can manipulate the stack as part of performing a transition.
CONT…
 If, in every situation, at most one such transition action is possible, then the automaton is
called a Deterministic Pushdown Automaton (DPDA).
 A given input string may drive a Nondeterministic Pushdown Automaton (NPA) to one of
several configuration sequences.
 If one of them leads to an accepting configuration after reading the complete input string.
 The latter is said to belong to the language accepted by the automaton.
 The following equation will help you to understand PDA,
 "Pushdown Automation" = "Finite State Machine" + "Stack”
A DIAGRAM OF A
PUSHDOWN
AUTOMATON
PDA has three
components
• An input tape
• A control unit
• A stack with infinite size.
EXPLANATION
 A PDA reads a given input string from left to right.
 In each step, it chooses a transition by indexing a table by
input symbol, current state, and the symbol at the top of the
stack.
 A PDA can also manipulate the stack, as part of performing
a transition.
 The manipulation can be to push a particular symbol to the
top of the stack, or to pop off the top of the stack.
 The automaton can alternatively ignore the stack, and leave
it as it is.
DEFINITIONS
•Thompson's Construction to
find out a Pushdown Automata is
a finite automata with extra
memory called stack, which
helps Pushdown automata to
recognize Context Free
Languages.
A Pushdown Automata (PDA)
can be defined as:
 Q is the set of states
 ∑is the set of input symbols
 Γ is the set of pushdown symbols (which can be pushed and popped
from stack)
 q0 is the initial state
 Z is the initial pushdown symbol (which is initially present in the
stack)
 F is the set of final states
 δ is a transition function which maps Q x {Σ ∪ ∈ } x Γ into Q x Γ*.
In a given state, the PDA will read input symbol and stock symbol
(top of the stack) and move to a new state and change the symbol of
stack.
GRAPHICAL
REPRESENTATION
OF PDA
 Transition diagram is the graphical representations of PDA in
which
 Nodes represent the states of PDA
 Start state is being indicated by an arrow
 Accepting states are indicated by double circles
 Arcs from one state to another state are labeled with input
and stack symbols.
 Arcs labeled with a,β|γ means that on input ‗a‘ the β on the
top of the stack has to be replaced by γ.
THEOREM
Equivalence of Regular
Expression and FA
INSTANTANEOUS DESCRIPTION (ID)
 Instantaneous Description (ID) is an informal notation of how a PDA ―computes‖ a input
string and make a decision that string is accepted or rejected.
An ID is a triple (q, w, α), where:
 q is the current state.
 w is the remaining input.
 α is the stack contents, top on the left.
TURNSTILE NOTATION
 ⊢ sign is called a ―turnstile notation‖ and represents one move.
 ⊢* sign represents a sequence of moves.
Eg- (p, b, T) ⊢ (q, w, α)
 This implies that while taking a transition from state p to state q, the input symbol ‗b‘ is consumed, and
the top of the stack ‗T‘ is replaced by a new string ‗α‘
LANGUAGES OF A
PUSH DOWN
AUTOMATA
CONT….
 A push down automata is similar to deterministic finite automata except that it has a few more properties
than a DFA.
 The data structure used for implementing a PDA is stack.
 A PDA has an output associated with every input.
 All the inputs are either pushed into a stack or just ignored.
 User can perform the basic push and pop operations on the stack which is used for PDA.
 One of the problems associated with DFAs was that could not make a count of the number of characters
which were given input to the machine.
 This problem is avoided by PDA as it uses a stack which provides us this facility also.
TERMINOLOGY
 Finite automata are highly standardized.
 There are many equivalent but different definitions of PDAs.
 The one we will use is a slight variant on the one described in Sipser.
 Sipser does not have a start stack symbol.
 Sipser does not allow transitions to push multiple symbols onto the stack.
 Feel free to use either this version or Sipser's; the two are equivalent to one another.
FINAL STATE ACCEPTABILITY
EMPTY STACK ACCEPTABILITY
EXAMPLE 1
Define the pushdown
automata for
language {anbn | n >
0}
Let us see how this
automaton works for
aaabbb.
Solution
 M = where Q = { q0, q1 } and Σ = { a, b } and Γ =
{ A, Z } and & delta is given by : &delta( q0, a, Z
) = { ( q0, AZ ) }
 &delta( q0, a, A) = { ( q0, AA ) }
 &delta( q0, b, A) = { ( q1, ε) }
 &delta( q1, b, A) = { ( q1, ε) }
 &delta( q1, ε, Z) = { ( q1, ε) }
EXAMPLE 2
Problem – Design a non
deterministic PDA for accepting
the language L ={w?{a,b}* | w
contains equal no. of a‘s and
b‘s}, i.e.,
L = {ab, aabb, abba, aababb,
bbabaa, baaababb, }
The number of a‘s and b‘s are
same in all the strings.
Stack transition functions-
CONT…
CONT……
EXAMPLE 3
CONT…
DIFFERENCE
BETWEEN DPDA
AND NPDA
EQUIVALENCE OF
PUSHDOWN
AUTOMATA AND
CFG
The goal is to prove that the following
three classes of the languages are all the
same class.
•The context-free languages (The
language defined by CFG‘s).
•The languages that are accepted by
empty stack by some PDA.
•The languages that are accepted by
final state by some PDA.
•If a grammar G is context-free, we can build an equivalent
nondeterministic PDA which accepts the language that is
produced by the context-free grammar G. A parser can be built
for the grammar G.
•Also, if P is a pushdown automaton, an equivalent context-free
grammar G can be constructed where L(G) = L(P)
•We will discuss how to convert from PDA to CFG and vice
versa.
FROM GRAMMAR
TO PUSHDOWN
AUTOMATA
 Step 1 − Convert the productions of the CFG into GNF.
 Step 2 − The PDA will have only one state {q}.
 Step 3 − The start symbol of CFG will be the start symbol in
the PDA.
 Step 4 − For non-terminal symbol, add the following rule:
 Step 5 - For each terminal symbols, add the following rule:
δ(q, a, a) = (q, ε) for every terminal symbol
Algorithm to find PDA
corresponding to a given CFG
Input − A CFG, G = (V, T, P, S)
Output − Equivalent PDA, P =
(Q, ∑, S, δ, q0, I, F)
EXAMPLE 1
EXAMPLE 2
EXAMPLE 3
CONT….
FROM PUSHDOWN
AUTOMATA TO
GRAMMAR
Algorithm to find CFG
corresponding to a given PDA
Input − A CFG, G = (V, T, P, S)
Output − Equivalent PDA, P =
(Q, ∑, S, δ, q0, I, F) such that the
non- terminals of the grammar
G will be {Xwx | w,x ∈ Q} and the
start state will be Aq0,F.
Step 1 − For every w, x, y, z ∈ Q, m ∈ S and a, b ∈ ∑, if δ (w, a,
ε) contains (y, m) and (z, b, m) contains (x, ε), add the
production rule Xwx → a Xyzb in grammar G.
Step 2 − For every w, x, y, z ∈ Q, add the production rule Xwx
→ XwyXyx in grammar G.
Step 3 − For w ∈ Q, add the production rule Xww → ε in
grammar G.
EXAMPLE 1
CONT…
EXAMPLE 2
CONT…
THEOREM
Equivalence of PDA
and Grammar
DIFFERENCE
BETWEEN PDA
AND FA
TURING
MACHINES (TM)
 A Turing Machine is an accepting device which accepts the
languages (recursively enumerable set) generated by type 0
grammars. It was invented in 1936 by Alan Turing.
 A Turing machine consists of a tape of infinite length on
which read and writes operation can be performed.
 The tape consists of infinite cells on which each cell either
contains input symbol or a special symbol called blank.
 It also consists of a head pointer which points to cell
currently being read and it can move in both directions.
WORKING
 A Turing Machine (TM) is a mathematical model which
consists of an infinite length tape divided into cells on
which input is given.
 It consists of a head, which reads the input tape.
 A state register stores the state of the Turing machine. After
reading an input symbol, it is replaced with another symbol,
its internal state is changed, and it moves from one cell to
the right or left. If the TM reaches the final state, the input
string is accepted, otherwise rejected.
DEFINITION
A TM can be formally described as a 7-tuple (Q, X, ∑, δ, q0, B, F) where −
 Q is a finite set of states
 X is the tape alphabet
 ∑ is the input alphabet
 δ is a transition function; δ : Q × X → Q × X × {Left_shift, Right_shift}.
 q0 is the initial state
 B is the blank symbol
 F is the set of final states
COMPARISON
WITH THE
PREVIOUS
AUTOMATON
The following table shows a
comparison of how a Turing
machine differs from Finite
Automaton and Pushdown
Automaton.
EXAMPLE 1
EXAMPLE 2
The language L = {0n1n2n | n≥1}
represents a kind of language where we
use only 3 character, i.e., 0, 1 and 2.
In the beginning language has some
number of 0‘s followed by equal
number of 1‘s and then followed by
equal number of 2‘s.
Any such string which falls in this
category will be accepted by this
language.
The beginning and end of string is
marked by $ sign.
CONT…
EXAMPLE 3
CONT…
CONT….
NON-
DETERMINISTIC
TM
TURING
RECOGNIZABLE
TURING
DECIDABLE
DESCRIBING TM
CONT…..
PROGRAMMING
TECHNIQUES FOR
TURING MACHINE
 The input to a Turing machine is a string. Turing machines
themselves can be written as strings. Since these strings can
be used as input to other Turing machines.
 A universal Turing machine is one whose input consists of a
description M of some arbitrary Turing machine, and some
input w to which machine M is to be applied, we write this
combined input as M + w.
 This produces the same output that would be produced by
M. This is written as
 Universal Turing Machine (M + w) = M (w).
The Halting
Problem
THEOREM
Turing Machine ―Will Halt (M, w)‖ does not exist.
Proof: This theorem is proved by contradiction. Suppose we could build a machine
Will Halt‖. Then we can certainly build a second machine,
 ―LoopIfHalts‖, that will go into an infinite loop if and only if
 ―Will Halt‖ accepts its input:
 Function LoopIfHalts (M, w):
 if WillHalt (M, w) then while true do { } else
 return false;
 We will also define a machine ―LoopIfHaltOnItSelf‖ that, for any given input M, representing a
Turing machine, will determine what will happen if M is applied to itself, and loops if M will halt in
this case.
 Function LoopIfHaltsOnItself (M): return LoopIfHalts (M, M): Finally, we ask what happens if we
try:
 Function Impossible:
 return LoopIfHaltsOnItself (LoopIfHaltsOnItself):
 This machine, when applied to itself, goes into an infinite loop if and only if it halts when applied
to itself. This is impossible. Hence the theorem is proved.
IMPLICATIONS OF
HALTING
PROBLEM
Sometimes a meta-program‖ is used to
check another program for potential
infinite loops, and get this meta-program to
work most of the time. The theorem says
that we cannot ever write such a meta -
program and have it work all of the time.
This result is also used to demonstrate that
certain other programs are also impossible.
The basic outline is as follows:
i) If we could solve a problem X, we
could solve the Halting problem
ii) We cannot solving the halting
problem.
 Storage in the state
 We can make a state a tuple with a fixed number of fixed-size
components.
 Components of the tuple can hold a fixed amount of data to
simplify the behavior of a TM program.
 Multiple tracks
 We can make each symbol of the input alphabet a tuple with a fixed
number of fixed-size components.
 Components of the tuple can hold marks and other information to
indicate that an input tape square has been previously visited or has
been given some fixed value.
 Sets of states as subroutines
 We can group states into "subroutines" where a subroutine has its
own start state and another state which can serve as a "return" state
The following programming
techniques can be used to
make the behavior of a TM
clearer, but none of these
techniques adds any additional
computational power to a
basic TM
STORAGE IN
FINITE CONTROL
 A state register stores the state of the Turing machine. After
reading an input symbol, it is replaced with another symbol, its
internal state is changed, and it moves from one cell to the right
or left.
 If the TM reaches the final state, the input string is accepted,
otherwise rejected.
 The finite control can be used to hold a finite amount of
information.
 To do so, the state is written as a pair of elements, one
exercising control and the other storing a symbol.
 It should be emphasized that this arrangement is for conceptual
purposes only.
 No modification in the definition of the Turing machine has
been made.
EXAMPLE 1
Keep track of an additional
symbol:
If the extra data can be 𝐴 or 𝐵,
and the state can be 𝑞0 or 𝑞1,
then the actual states of the TM
can be {[𝑞0, 𝐴],[𝑞1, 𝐴],[𝑞0, 𝐵], [𝑞
1, 𝐵]}.
CONT….
EXAMPLE 2
Consider the Turing
machine
MULTIPLE
TRACKS
 Multitrack Turing machines, a specific type of Multi-tape Turing
machine, contain multiple tracks, but just one tape head reads and
writes on all tracks.
 Here, a single tape head reads n symbols from n tracks at one step.
It accepts recursively enumerable languages like a normal single-
track, single-tape Turing Machine accepts.
 Multi-track Turing machines is called as a unique type of Multi-
tape Turing machine.
 It consists of multiple tracks with one tape head reads and writes
on all tracks.
 But a single tape head reads n symbols from n tracks in a single
step.
DEFINITION
A Multitrack Turing machine can be formally described as a 6-
tuple (Q, X, ∑, δ, q0, F) where −
 Q is a finite set of states
 X is the tape alphabet
 ∑ is the input alphabet
 δ is a relation on states and symbols where
 δ(Qi, [a1, a2, a3,....]) = (Qj, [b1, b2, b3,. ], Left_shift or
Right_shift)
 q0 is the initial state
 F is the set of final states
THEOREM
CONT…
EXAMPLE
CONT…
CONT…
CONT…
CHECKING OFF
SYMBOLS
CONT…
CONT…
EQUIVALENT
BETWEEN MULTI-
TAPE AND 1-TAPE
TM
CONT….
SUBROUTINE
 Just as complex programs are often broken down into
smaller functions and classes, complex TMs are often
broken down into smaller ―subroutines.
 A subroutine of a Turing machine is a small set of states in
the TM such that performs a small computation.
 ● Usually, a single entry state and a single exit state.
 ● Many very complicated tasks can be performed by TMs
by breaking those tasks into smaller subroutines.
CONT…
 Subroutines are extremely useful in standard programming
languages.
 They allow you to break a complex problem into simpler
and simpler sub problems.
 Standard Turing machines do not have subroutines, but it's
easy to fake them. We do not need to add any new features.
The basic idea is to use one state, or a small group of states,
to perform a single task
 Each subroutine performs some task that helps in the overall
task.
 The TM is then described by giving a collection of subroutines
and showing how they link up.
CONT…
In our TM, we need subroutines for the following:
 Copying the TM contents to another spot on the tape.
 Checking whether the number of 1's in that copy is a
multiple of the number of 0's in that copy (we already made
this!)
 Cleaning up the tape if the answer is no.
COPY
SUBROUTINE
CLEANUP
SUBROUTINE
EXAMPLE
For example, the following state can be used to find the left end of the input:
-------------------------------------------------------
q0 | a | a | L | q0
q0 | b | b | L | q0
q0 | # | # | R | q1
-------------------------------------------------------
This "subroutine" can be entered by going to state q0 (which isn't a problem) and it "exits" by
going to state q1 (which is a problem). We would like to have the subroutine exit to different
states, depending on where it was called from. The easy way to do this is to make multiple
copies of the subroutine, using the same structure but different state names, e.g.,
-------------------------------------------------------
q41 | a | a | L | q41
q41 | b | b | L | q41
q41 | # | # | R | q87
-------------------------------------------------------
This approach is cumbersome but theoretically adequate, so long as only a finite number of
copies are required.
Unit iv

Unit iv

  • 1.
  • 2.
    INTRODUCTION  In thetheory of computation, a branch of theoretical computer science a Pushdown Automaton (PDA) is a type of automata that employs a stack.  Pushdown automata are used in theories about what can be computed by machines.  They are more capable than finite-state machines but less capable than Turing machines.  Deterministic pushdown automata can recognize all deterministic context-free languages while nondeterministic ones can recognize all context-free languages, with the former often used in parser design.
  • 3.
    CONT…  A finite-statemachine just looks at the input signal and the current state: it has no stack to work with. It chooses a new state, the result of following the transition.  A PDA differs from a finite state machine in two ways:  It can use the top of the stack to decide which transition to take.  It can manipulate the stack as part of performing a transition.
  • 4.
    CONT…  If, inevery situation, at most one such transition action is possible, then the automaton is called a Deterministic Pushdown Automaton (DPDA).  A given input string may drive a Nondeterministic Pushdown Automaton (NPA) to one of several configuration sequences.  If one of them leads to an accepting configuration after reading the complete input string.  The latter is said to belong to the language accepted by the automaton.  The following equation will help you to understand PDA,  "Pushdown Automation" = "Finite State Machine" + "Stack”
  • 5.
    A DIAGRAM OFA PUSHDOWN AUTOMATON PDA has three components • An input tape • A control unit • A stack with infinite size.
  • 6.
    EXPLANATION  A PDAreads a given input string from left to right.  In each step, it chooses a transition by indexing a table by input symbol, current state, and the symbol at the top of the stack.  A PDA can also manipulate the stack, as part of performing a transition.  The manipulation can be to push a particular symbol to the top of the stack, or to pop off the top of the stack.  The automaton can alternatively ignore the stack, and leave it as it is.
  • 7.
    DEFINITIONS •Thompson's Construction to findout a Pushdown Automata is a finite automata with extra memory called stack, which helps Pushdown automata to recognize Context Free Languages. A Pushdown Automata (PDA) can be defined as:  Q is the set of states  ∑is the set of input symbols  Γ is the set of pushdown symbols (which can be pushed and popped from stack)  q0 is the initial state  Z is the initial pushdown symbol (which is initially present in the stack)  F is the set of final states  δ is a transition function which maps Q x {Σ ∪ ∈ } x Γ into Q x Γ*. In a given state, the PDA will read input symbol and stock symbol (top of the stack) and move to a new state and change the symbol of stack.
  • 8.
    GRAPHICAL REPRESENTATION OF PDA  Transitiondiagram is the graphical representations of PDA in which  Nodes represent the states of PDA  Start state is being indicated by an arrow  Accepting states are indicated by double circles  Arcs from one state to another state are labeled with input and stack symbols.  Arcs labeled with a,β|γ means that on input ‗a‘ the β on the top of the stack has to be replaced by γ.
  • 9.
  • 10.
    INSTANTANEOUS DESCRIPTION (ID) Instantaneous Description (ID) is an informal notation of how a PDA ―computes‖ a input string and make a decision that string is accepted or rejected. An ID is a triple (q, w, α), where:  q is the current state.  w is the remaining input.  α is the stack contents, top on the left.
  • 11.
    TURNSTILE NOTATION  ⊢sign is called a ―turnstile notation‖ and represents one move.  ⊢* sign represents a sequence of moves. Eg- (p, b, T) ⊢ (q, w, α)  This implies that while taking a transition from state p to state q, the input symbol ‗b‘ is consumed, and the top of the stack ‗T‘ is replaced by a new string ‗α‘
  • 12.
    LANGUAGES OF A PUSHDOWN AUTOMATA
  • 13.
    CONT….  A pushdown automata is similar to deterministic finite automata except that it has a few more properties than a DFA.  The data structure used for implementing a PDA is stack.  A PDA has an output associated with every input.  All the inputs are either pushed into a stack or just ignored.  User can perform the basic push and pop operations on the stack which is used for PDA.  One of the problems associated with DFAs was that could not make a count of the number of characters which were given input to the machine.  This problem is avoided by PDA as it uses a stack which provides us this facility also.
  • 14.
    TERMINOLOGY  Finite automataare highly standardized.  There are many equivalent but different definitions of PDAs.  The one we will use is a slight variant on the one described in Sipser.  Sipser does not have a start stack symbol.  Sipser does not allow transitions to push multiple symbols onto the stack.  Feel free to use either this version or Sipser's; the two are equivalent to one another.
  • 15.
  • 16.
  • 17.
    EXAMPLE 1 Define thepushdown automata for language {anbn | n > 0} Let us see how this automaton works for aaabbb. Solution  M = where Q = { q0, q1 } and Σ = { a, b } and Γ = { A, Z } and & delta is given by : &delta( q0, a, Z ) = { ( q0, AZ ) }  &delta( q0, a, A) = { ( q0, AA ) }  &delta( q0, b, A) = { ( q1, ε) }  &delta( q1, b, A) = { ( q1, ε) }  &delta( q1, ε, Z) = { ( q1, ε) }
  • 18.
    EXAMPLE 2 Problem –Design a non deterministic PDA for accepting the language L ={w?{a,b}* | w contains equal no. of a‘s and b‘s}, i.e., L = {ab, aabb, abba, aababb, bbabaa, baaababb, } The number of a‘s and b‘s are same in all the strings. Stack transition functions-
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
    EQUIVALENCE OF PUSHDOWN AUTOMATA AND CFG Thegoal is to prove that the following three classes of the languages are all the same class. •The context-free languages (The language defined by CFG‘s). •The languages that are accepted by empty stack by some PDA. •The languages that are accepted by final state by some PDA. •If a grammar G is context-free, we can build an equivalent nondeterministic PDA which accepts the language that is produced by the context-free grammar G. A parser can be built for the grammar G. •Also, if P is a pushdown automaton, an equivalent context-free grammar G can be constructed where L(G) = L(P) •We will discuss how to convert from PDA to CFG and vice versa.
  • 25.
    FROM GRAMMAR TO PUSHDOWN AUTOMATA Step 1 − Convert the productions of the CFG into GNF.  Step 2 − The PDA will have only one state {q}.  Step 3 − The start symbol of CFG will be the start symbol in the PDA.  Step 4 − For non-terminal symbol, add the following rule:  Step 5 - For each terminal symbols, add the following rule: δ(q, a, a) = (q, ε) for every terminal symbol Algorithm to find PDA corresponding to a given CFG Input − A CFG, G = (V, T, P, S) Output − Equivalent PDA, P = (Q, ∑, S, δ, q0, I, F)
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
    FROM PUSHDOWN AUTOMATA TO GRAMMAR Algorithmto find CFG corresponding to a given PDA Input − A CFG, G = (V, T, P, S) Output − Equivalent PDA, P = (Q, ∑, S, δ, q0, I, F) such that the non- terminals of the grammar G will be {Xwx | w,x ∈ Q} and the start state will be Aq0,F. Step 1 − For every w, x, y, z ∈ Q, m ∈ S and a, b ∈ ∑, if δ (w, a, ε) contains (y, m) and (z, b, m) contains (x, ε), add the production rule Xwx → a Xyzb in grammar G. Step 2 − For every w, x, y, z ∈ Q, add the production rule Xwx → XwyXyx in grammar G. Step 3 − For w ∈ Q, add the production rule Xww → ε in grammar G.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
    TURING MACHINES (TM)  ATuring Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type 0 grammars. It was invented in 1936 by Alan Turing.  A Turing machine consists of a tape of infinite length on which read and writes operation can be performed.  The tape consists of infinite cells on which each cell either contains input symbol or a special symbol called blank.  It also consists of a head pointer which points to cell currently being read and it can move in both directions.
  • 38.
    WORKING  A TuringMachine (TM) is a mathematical model which consists of an infinite length tape divided into cells on which input is given.  It consists of a head, which reads the input tape.  A state register stores the state of the Turing machine. After reading an input symbol, it is replaced with another symbol, its internal state is changed, and it moves from one cell to the right or left. If the TM reaches the final state, the input string is accepted, otherwise rejected.
  • 39.
    DEFINITION A TM canbe formally described as a 7-tuple (Q, X, ∑, δ, q0, B, F) where −  Q is a finite set of states  X is the tape alphabet  ∑ is the input alphabet  δ is a transition function; δ : Q × X → Q × X × {Left_shift, Right_shift}.  q0 is the initial state  B is the blank symbol  F is the set of final states
  • 40.
    COMPARISON WITH THE PREVIOUS AUTOMATON The followingtable shows a comparison of how a Turing machine differs from Finite Automaton and Pushdown Automaton.
  • 41.
  • 42.
    EXAMPLE 2 The languageL = {0n1n2n | n≥1} represents a kind of language where we use only 3 character, i.e., 0, 1 and 2. In the beginning language has some number of 0‘s followed by equal number of 1‘s and then followed by equal number of 2‘s. Any such string which falls in this category will be accepted by this language. The beginning and end of string is marked by $ sign.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
    PROGRAMMING TECHNIQUES FOR TURING MACHINE The input to a Turing machine is a string. Turing machines themselves can be written as strings. Since these strings can be used as input to other Turing machines.  A universal Turing machine is one whose input consists of a description M of some arbitrary Turing machine, and some input w to which machine M is to be applied, we write this combined input as M + w.  This produces the same output that would be produced by M. This is written as  Universal Turing Machine (M + w) = M (w). The Halting Problem
  • 53.
    THEOREM Turing Machine ―WillHalt (M, w)‖ does not exist. Proof: This theorem is proved by contradiction. Suppose we could build a machine Will Halt‖. Then we can certainly build a second machine,  ―LoopIfHalts‖, that will go into an infinite loop if and only if  ―Will Halt‖ accepts its input:  Function LoopIfHalts (M, w):  if WillHalt (M, w) then while true do { } else  return false;  We will also define a machine ―LoopIfHaltOnItSelf‖ that, for any given input M, representing a Turing machine, will determine what will happen if M is applied to itself, and loops if M will halt in this case.  Function LoopIfHaltsOnItself (M): return LoopIfHalts (M, M): Finally, we ask what happens if we try:  Function Impossible:  return LoopIfHaltsOnItself (LoopIfHaltsOnItself):  This machine, when applied to itself, goes into an infinite loop if and only if it halts when applied to itself. This is impossible. Hence the theorem is proved.
  • 54.
    IMPLICATIONS OF HALTING PROBLEM Sometimes ameta-program‖ is used to check another program for potential infinite loops, and get this meta-program to work most of the time. The theorem says that we cannot ever write such a meta - program and have it work all of the time. This result is also used to demonstrate that certain other programs are also impossible. The basic outline is as follows: i) If we could solve a problem X, we could solve the Halting problem ii) We cannot solving the halting problem.
  • 55.
     Storage inthe state  We can make a state a tuple with a fixed number of fixed-size components.  Components of the tuple can hold a fixed amount of data to simplify the behavior of a TM program.  Multiple tracks  We can make each symbol of the input alphabet a tuple with a fixed number of fixed-size components.  Components of the tuple can hold marks and other information to indicate that an input tape square has been previously visited or has been given some fixed value.  Sets of states as subroutines  We can group states into "subroutines" where a subroutine has its own start state and another state which can serve as a "return" state The following programming techniques can be used to make the behavior of a TM clearer, but none of these techniques adds any additional computational power to a basic TM
  • 56.
    STORAGE IN FINITE CONTROL A state register stores the state of the Turing machine. After reading an input symbol, it is replaced with another symbol, its internal state is changed, and it moves from one cell to the right or left.  If the TM reaches the final state, the input string is accepted, otherwise rejected.  The finite control can be used to hold a finite amount of information.  To do so, the state is written as a pair of elements, one exercising control and the other storing a symbol.  It should be emphasized that this arrangement is for conceptual purposes only.  No modification in the definition of the Turing machine has been made.
  • 57.
    EXAMPLE 1 Keep trackof an additional symbol: If the extra data can be 𝐴 or 𝐵, and the state can be 𝑞0 or 𝑞1, then the actual states of the TM can be {[𝑞0, 𝐴],[𝑞1, 𝐴],[𝑞0, 𝐵], [𝑞 1, 𝐵]}.
  • 58.
  • 59.
    EXAMPLE 2 Consider theTuring machine
  • 60.
    MULTIPLE TRACKS  Multitrack Turingmachines, a specific type of Multi-tape Turing machine, contain multiple tracks, but just one tape head reads and writes on all tracks.  Here, a single tape head reads n symbols from n tracks at one step. It accepts recursively enumerable languages like a normal single- track, single-tape Turing Machine accepts.  Multi-track Turing machines is called as a unique type of Multi- tape Turing machine.  It consists of multiple tracks with one tape head reads and writes on all tracks.  But a single tape head reads n symbols from n tracks in a single step.
  • 61.
    DEFINITION A Multitrack Turingmachine can be formally described as a 6- tuple (Q, X, ∑, δ, q0, F) where −  Q is a finite set of states  X is the tape alphabet  ∑ is the input alphabet  δ is a relation on states and symbols where  δ(Qi, [a1, a2, a3,....]) = (Qj, [b1, b2, b3,. ], Left_shift or Right_shift)  q0 is the initial state  F is the set of final states
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
    SUBROUTINE  Just ascomplex programs are often broken down into smaller functions and classes, complex TMs are often broken down into smaller ―subroutines.  A subroutine of a Turing machine is a small set of states in the TM such that performs a small computation.  ● Usually, a single entry state and a single exit state.  ● Many very complicated tasks can be performed by TMs by breaking those tasks into smaller subroutines.
  • 74.
    CONT…  Subroutines areextremely useful in standard programming languages.  They allow you to break a complex problem into simpler and simpler sub problems.  Standard Turing machines do not have subroutines, but it's easy to fake them. We do not need to add any new features. The basic idea is to use one state, or a small group of states, to perform a single task  Each subroutine performs some task that helps in the overall task.  The TM is then described by giving a collection of subroutines and showing how they link up.
  • 75.
    CONT… In our TM,we need subroutines for the following:  Copying the TM contents to another spot on the tape.  Checking whether the number of 1's in that copy is a multiple of the number of 0's in that copy (we already made this!)  Cleaning up the tape if the answer is no.
  • 76.
  • 77.
  • 78.
    EXAMPLE For example, thefollowing state can be used to find the left end of the input: ------------------------------------------------------- q0 | a | a | L | q0 q0 | b | b | L | q0 q0 | # | # | R | q1 ------------------------------------------------------- This "subroutine" can be entered by going to state q0 (which isn't a problem) and it "exits" by going to state q1 (which is a problem). We would like to have the subroutine exit to different states, depending on where it was called from. The easy way to do this is to make multiple copies of the subroutine, using the same structure but different state names, e.g., ------------------------------------------------------- q41 | a | a | L | q41 q41 | b | b | L | q41 q41 | # | # | R | q87 ------------------------------------------------------- This approach is cumbersome but theoretically adequate, so long as only a finite number of copies are required.

Editor's Notes

  • #2 NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image.