Title: CSE 3813 Introduction to Formal Languages and Automata
1CSE 3813Introduction to Formal Languages and
Automata
- Chapter 9
- The Standard Turing Machine
- These class notes are based on material from our
textbook, An Introduction to Formal Languages and
Automata, 4th ed., by Peter Linz, published by
Jones and Bartlett Publishers, Inc., Sudbury, MA,
2006. They are intended for classroom use only
and are not a substitute for reading the textbook.
2- Diagrams from some slides are from previous
years textbook Martin, John C., Introduction to
Languages and the Theory of Computation. Boston
WCG McGraw-Hill, 1991. - Slides are for use of this class only.
3Automata
- A Finite Automaton has only its states to serve
as memory - very limited in what languages it
could recognize - In a Pushdown Automaton we added a stack to a
Finite Automaton - this gave it better memory,
and allowed it to recognize more languages. But
it was still limited by the nature of the stack. - We could add another stack to a Pushdown
Automaton. This would allow it to accept some
non-context free languages (e.g., anbncn). - Or we could change the stack to a queue. This
would allow other languages to be accepted (e.g.,
ww).
4All of the automata we study in this class have
a finite number of states. They differ in the
auxiliary memory they have and how it is
organized. DFA NFA DPDA PDA Turing machine
finite memory
infinite stack memory
infinite tape memory (tape can be read forwards
and backwards without erasing)
5Hierarchy of automata
DTM, NTM
LBA
PDA
DPDA
DFA, NFA
6The Turing Machine
- Alan Mathison Turing, b. 1912, d. 1954.
Contributed much to the foundations of computing
theory. - Published the Turing machine model in 1937.
- Church-Turing Thesis - Any algorithmic procedure
that can be carried out by a human, a team of
humans, or a machine can be carried out by some
Turing machine. - Unproveable, because we dont have a precise
definition of what algorithmic procedure means,
but generally accepted as true. - Puts a limit on what can be computed.
7The Church-Turing Thesis
- No model of digital computation is more powerful
than a Turing machine. - By more powerful, we mean can recognize
languages that a TM cannot recognize. - This is not something that can be proved. But
everybody believes it because no one has been
able to devise a more powerful model of
computation.
8Definition Turing Machine
- A Turing machine (TM) is a 7-Tuple
- T (Q, S, G, d, q0, D, F), where
- Q a finite set of states not containing h (the
halt state) - S a finite set of symbols constituting the
input alphabet - S ? G D
- G a finite set of symbols constituting the
tape alphabet - d the transition function Q ? ? ? Q ? ? ? L,
R - q0 the start state (q0 ? Q)
- D is a special symbol, the blank symbol
- F ? Q is the set of final states
9Definition Turing Machine
- Turing machines can be thought of as a finite
state automaton with slightly different labels on
the arcs, plus a tape as auxiliary memory, and a
tape head (or read-write head).
10Definition Turing Machine
- The tape on a Turing machine can be thought of as
a linear structure marked off into squares or
cells. - It is usually defined as infinite in both
directions, but may be thought of as bounded on
the left side, but infinite on the right.
11Definition Turing Machine
- Each cell on the tape on a Turing machine can
hold - a symbol from the input alphabet, or
- a symbol from the tape alphabet (which may
include some symbols which are not in the input
alphabet), or - a blank symbol D, which is distinct from the
input alphabet.
12Standard Turing Machine
- The standard Turing machine described by our
textbook has several features - The TM has a tape that is unbounded in both
directions. - The TM is deterministic in the sense that ?
defines at most one move per configuration - There is no special input file the input is
copied onto the tape. - There is no special output device the tape
contains the output, if any.
13The TM tape head
- The Turing machine has a tape head which reads
from and writes to the tape during each move. - The tape head can move right or left, or may
stay in the same position. - The tape head can read a character from the cell
under which it is positioned, or it may write a
character to the cell.
14The TM transition function
- The TM transition function has the following
form - d(q, X) (r, Y, D)
- This says that
- when the TM is in state q, and
- the read-write head reads a certain symbol (X)
off the tape, - then the TM will
- change state to state r,
- write a Y onto the tape, and
- move in direction D.
15The TM transition function
- For example, d(q1, b) (q2, D, R) means
- we are currently in state q1
- read the cell above the tape head its a b.
- OK, great. Now we
- change state to q2,
- write a blank,
- and move right.
16The TM transition function
The TM transition function can be represented in
the form of a table
17The TM transition function
- We can label the arcs of a finite state machine
to indicate the moves of the TM
D / D, R
q0
q1
18Processing a string
- To process a string, we place the string onto
the tape, where it can be read by the read-write
head, surrounded by blank symbols on the left and
right ends of the input. - Once the string is on the tape, then processing
can begin. - We dont need a separate input string after that.
19Accepting a string
- There is only one way that a string may be
accepted by a TM - If a move causes the machine to move into an
accepting halt state, then we stop and accept the
string. (There are no moves out of a halt
state.) - This may occur even when we havent finished
processing the string yet.
20Accepting a string
For example, if our TM is processing all the
strings that have aabb in them somewhere, the TM
may halt in an accepting state after processing
the 6th character of this string bbaabbaaaabbbb
21Accepting a string
If T (Q, S, G, d, q0, D, F) is a Turing
machine, and w ? S, then w is accepted by T if,
starting in the initial configuration
corresponding to input w, T eventually enters a
final acceptance state and halts.
22Accepting a string
In other words, w is accepted if there exists y
and z ? G so that q0w -T yqfz, for some qf
?F In this situation, we say that T halts on
input w. The language accepted by T is the set
L(T) of input strings on which T halts.
23Crashing and Halting
- There are 2 ways a string may fail to be accepted
by a TM - Crashing
- Looping
- If the TM crashes, the string is explicitly
rejected. - If the TM loops forever, the string is implicitly
rejected.
24Crashing and Halting
- Crashing
- If a symbol is found on the tape for which the
transition function is undefined, and the current
state is not the accepting halt state, then we
crash. - If our TM has a bounded left end, and a move is
specified which causes the machine to move off of
the left end of the tape, then we crash.
25Crashing and Halting
- Looping
- If an input string causes the TM to enter an
infinite loop, then we loop forever.
26Exercises
- Design a TM that accepts L anbn n ? 1
- To do this, we can construct the transition table
for the TM. We can use a matrix as a short-hand
representation
27anbn n ? 1
28anbn n ? 1
- Replace the leftmost a with an x, and find the
first b and replace it with a y - ?(q0,a) (q1,x,R)
- ?(q1,a) (q1,a,R)
- ?(q1,y) (q1,y,R)
- ?(q1,b) (q2,y,L)
29anbn n ? 1
- Come back to the next left-most a
- ?(q2,x) (q0,x,R)
- ?(q2,y) (q2,y,L)
- ?(q2,a) (q2,a,L)
30anbn n ? 1
- Finally, check to see if all input has been
processed and the as and bs balance (and the
as precede the bs) - ?(q0,y) (q3,y,R)
- ?(q3,y) (q3,y,R)
- ?(q3, ?) (q4, ?,R)
31Exercises
Work through the processing of the string w
aaabbb in class. Is this string accepted by the
TM? Work through the processing of the string w
aaabb. Is this string accepted by the TM? How
does the TM reject the string?
32Exercises
- Recall that the following languages are not
context-free. - anbncn n ? 0
- ww w ? a,b
- In English, describe how a Turing machine could
accept each of these languages - Try to draw the transition diagrams for the
Turing machines
33anbncn n ? 1
34Homework Suggestions
- P. 236-237 2, 3, 5, 7(a,b)
35Model of computation
- A TM is an abstract model of a computer that lets
us define in a precise, mathematical way what we
mean by computation. - As before, we use the concept of a
configuration to define what we mean by
computation.
36Configuration
- A configuration of a TM is a pair,
- (q, xay)
- where q is a state, x and y are strings, and a is
the symbol at the current position of the tape
head. - We sometimes use
- (q, xw)
- To indicate that the tape head is under the first
symbol in the string w.
37Configuration
- A configuration of a TM includes everything we
need to know to continue a computation - current state
- symbol currently under the tape head
- string on tape to left of the head
- string on tape to right of the head (up to
rightmost non-blank symbol) - Example
- (q, ?bbabbba?)
38Computation
- A computation is a sequence of configurations
such that each configuration is obtained from the
previous configuration by some transition of the
TM - Given input string aabb, the TM that accepts the
language ab begins a computation as follows
- (s, ?aabb?) - (s, ?Aabb?) - (s, ?AAbb?) -
- Continue this computation to the end
39Example
- Here is the TM to process the language consisting
of strings containing any number of as, with a
single b at the end.
b / b, R
? / ?, R
? / ?, R
a / a, R
40Example
- An FA that accepts a, b aba a, b
41Example
- A TM that accepts a, b aba a, b
42Example
- An FA that accepts a, b aba
43Example
- A TM that accepts a, b aba
44Example
- A TM that accepts pal, the palindrome language
45A TM that accepts strings of L ss
46Computable
- A function f with domain D is said to be
Turing-computable or just computable if there
exist some Turing machine M (Q,
S, G, d, q0, D, F) such that - q0w -M qf f(w), qf ?F,
- for all w ?D.
47Combining Turing Machines
- You can combine several smaller TMs in order to
make a larger, more complicated TM. - The composite of two different TMs, T1 and T2, is
written as T1T2. It would be represented as - T1 ? T2
- What happens is that T1T2 begins by executing the
moves of T1, up to the point where T1 would halt.
Instead of halting, T1T2 moves to the initial
state of T2, where it begins executing the moves
of T2. - If T2 halts, then T1T2 halts. If T1 or T2
crashes, then T1T2 crashes.
48Combining Turing Machines
- You can also make the transition to T2
conditional. - a
- T1 ? T2
- Here, T1 would execute its moves up to the point
where it would normally halt. If the symbol on
the tape at that point is an a, then T1T2 will
begin executing the moves of T2. Otherwise T1T2
will crash.
49Designing complex Turing machines
- The book describes a language for combining
simple TMs into complex ones, using the sequence,
branching, and looping operators of imperative
programming languages. - If you were going to be a Turing machine
programmer, this would be useful. But . - So, you will not be tested on this. But you need
to understand how a Turing machine works and how
to design simple ones.
50Computing functions
- We use automata to recognize languages and
compute functions (although we havent talked
about computing functions until now). - In fact, computing functions allows language
recognition, since every language can be
represented by a characteristic function - if the input string is in the language, output 1
- otherwise output 0
51String and numeric functions
- A TM can compute functions on strings. Given an
input string, the output of the function is the
string left on the tape after the TM halts. - A TM can also compute numeric functions. Using a
binary alphabet for strings, the input string can
represent a binary number and the output string
can represent a binary number. - A TM can compute a function with multiple
arguments. Each argument is separated by a blank
on the tape. - We can create TMs that compute arithmetic
functions such as addition, subtraction,
multiplication, etc.
52Computing a Partial Function
- A Turing Machine can compute a function by
leaving a string on the tape when it enters the
halt state. - A partial function f on Smay be undefined at
certain points (the points not in the domain of
f). - A total function enters the halt state for all
inputs in the domain. - We say that a TM, T, computes f if T halts where
f is defined and fails to halt elsewhere. So f
is Turing-computable, or just computable, if
there exists some TM computing f.
53Computing a numerical function
- We can represent numbers on a TM by using the
unary representation, which just uses n 1s to
represent the number n. - Example 11111 5
- We can construct a TM to concatenate two strings
together. If we represent two numbers in unary
form, then a TM which concatenates these two
strings is actually performing addition!
54Computing a numerical function
- The addition of two numbers is as simple as the
concatenation of two strings. - Assume two integers are represented in unary form
on the tape of a Turing machine. - Assume the two integers are separated by a 0
between them. - Design a Turing machine that will add these two
numbers.
55Computing a numerical function
56Characteristic Function
- Computing the characteristic function ?L is very
similar to accepting a language. - The TM must always halt.
- The TM will leave a 1 on the tape if the string
is accepted, and a 0 otherwise. - HOWEVER A TM can accept a language if it halts
on all strings that are in the language, but
doesn't halt on strings which are not.
57Characteristic function
- In a standard TM, strings which are not accepted
can cause the TM to - crash if it enters a state where there are no
transitions for the current tape symbol, - crash if it tries to move left at the left end of
the tape, or - get into an infinite loop,
- A TM computing the characteristic function must
halt on all inputs
58Conclusion
- Anything that is effectively calculable can be
executed on a TM. - A universal TM can compute anything that any
other Turing machine can compute. - The universal TM is itself a standard TM.
- A CPU with RAM is a finite version of a TM it
has the power of a TM up to the point that it
runs out of memory. - Languages or hardware that provides compares,
loops, and increments are termed Turing complete
and can also compute anything that is effectively
calculable.