Turing Machines: Examples

CS390, Fall 2021

Last modified: Sep 20, 2021
Contents:

Abstract

Practice designing and working with Turing machines.

1 JFlap

  1. Review the Turing machines section of the Tutorial.

  2. Construct the TM from examples 8.2/8.3. Use it to solve Exercise 8.2.1.

  3. Construct your own Turing machine to solve Exercise 8.2.2a. (Note that this language is not a CFL.)

2 New Ways to Solve Old Problems

2.1 Contains 101

 

We have previously designed this FA to accepts strings that contain 101.

Design a Turing machine for the same language

Reveal

2.2 Ends with 101

 
Here is a FA for accepting strings that end with 101.

In this automaton, we can enter the accepting state many times (e.g., 101010) but only accept the string if we are in the accepting state AND have processed all of the input.

Design a TM to accept the same language.

Reveal

2.3 $0^n1^n$

 

Now let’s consider a context-free language.

Consider the language of all strings of the form $0^n1^n$, i.e., some number of zeros followed by an equal number of ones. This is a typical “counting” problem for a PDA, as shown to the right.

Design a TM for this language.

Reveal

3 Recognizing TMs

Use a combination of inspection and of running test cases on each of the following Turing machines to determine what it does.

3.1 Recognizing the Language Accepted by a TM

 

What language does this TM accept?

 
Reveal

3.2 Recognizing the Function Computed by a TM

Often we think of TMs not so much as acceptors of languages as computers of functions. The input to the function is the initial content of the tape and the output is the final content of the tape when the TM reaches an accepting state.

 

What is the function computed by this TM when presented with inputs over the language {a,b}* ?

 
Reveal

3.3 TMs as Functions 2

 

What is the function computed by this TM?

 
Reveal

3.4 TMs as Functions 3

 

What is the function computed by this TM?

 
Answer

3.5 TMs as Functions 4

 

What is the function (over the input language $\{a,b\}^*$) computed by this TM?

 
Reveal

3.6 TMs as Functions 5

 

What is the function (over the input language $\{a,b\}^*$) computed by this TM?

 
Reveal

4 Turing Machines as Language Acceptors

Earlier we saw ways to use TMs to accept languages that we had seen with earlier, less powerful automata.

Next, we can consider problems that could not be solved using the automata we have had before.

4.1 $0^n1^n2^n$

Design a TM to recognize the language of strings of the form $0^n1^n2^n$.

(Although $0^n1^n$ is a CFL and can be recognized by a pushdown automaton, $0^n1^n2^n$ is not context-free and requires a more powerful approach.)

Reveal

4.2 $\alpha c\alpha$ where $\alpha \in \{a,b\}*$

4.2.1 Basic Implementation

Consider the problem of designing a TM to compare two strings over $\{a,b\}$ to see if they are equal.

All input to the TM must be on the tape, so we could choose to separate the two strings by a blank, e.g.,

aba abb

or by a separator character

abacabb

I’m going to choose the latter.

Another way to view this machine is to say that it recognizes strings over {a,b,c} of the form

\[ \{ \alpha c\alpha | \alpha \in \{a,b\}* \}, \]

which is definitely not a CFL.

Design a TM to recognize this language:

Reveal

4.2.2 Using Multiple Tapes

We can get an even simpler (IMO) TM by using multiple tapes.

Solve the same problem using a multi-tape TM.

Reveal

5 Turing Machines as Functions

5.1 Unary Form Integer Increment

Suppose that a tape contains an integer $k$ in unary form (i.e., a string of 1’s, where the value of the integer is the length of the string. Construct a TM to replace its input by the value of the function $f(k) = k+1$.

Reveal

5.2 Unary Form Integer Addition

Suppose that a tape contains pair of integers $m, k$ in unary form separated by a single ‘x’. Construct a TM to replace its input by the value of the function $f(m,k) = m+k$.

Reveal

5.3 Binary Addition - Multitape

Suppose that a TM has three tapes with a pair of integers $m, k$ in conventional binary form on tapes 1 and 2. Assume that m and k have the same number of binary digits. Construct a TM to compute the function $f(m,k) = m+k$, writing the output to the third tape.

For example, given the input tapes:

1
1 1 1

we would expect the output

1
1 1 1
1 1 1 1
Reveal