Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Construct a Turing machine that computes the function \({\bf{f(n) = n - 3}}\) if \({\bf{n}} \ge {\bf{3}}\) and \({\bf{f}}\left( {\bf{n}} \right){\bf{ = 0}}\) for \({\bf{n = 0,1,2}}\) for all non-negative integers \({\bf{n}}\).

Short Answer

Expert verified

The constructed Turing machine that computes the function \(f{\rm{(}}n{\rm{)}} = n - 3\) if \(n \ge 3\) and \(f\left( n \right) = 0\) for \(n = 0,1,2\)for all non-negative integers n is

\(\begin{array}{c}{\bf{T = }}\left( {{\bf{S,I,f,}}{{\bf{s}}_{\bf{0}}}} \right)\\{\bf{S = }}\left\{ {{{\bf{s}}_{\bf{0}}}{\bf{,}}{{\bf{s}}_{\bf{1}}}{\bf{,}}{{\bf{s}}_{\bf{2}}}{\bf{,}}{{\bf{s}}_{\bf{3}}}{\bf{,}}{{\bf{s}}_{\bf{4}}}} \right\}\\{\bf{I = \{ 0,1,B\} }}\\\left( {{{\bf{s}}_{\bf{0}}}{\bf{,1,}}{{\bf{s}}_{\bf{1}}}{\bf{,B,R}}} \right)\\\left( {{{\bf{s}}_{\bf{1}}}{\bf{,1,}}{{\bf{s}}_{\bf{2}}}{\bf{,B,R}}} \right)\\\left( {{{\bf{s}}_{\bf{1}}}{\bf{,B,}}{{\bf{s}}_{\bf{4}}}{\bf{,1,R}}} \right)\\\left( {{{\bf{s}}_{\bf{2}}}{\bf{,1,}}{{\bf{s}}_{\bf{3}}}{\bf{,B,R}}} \right)\\\left( {{{\bf{s}}_{\bf{2}}}{\bf{,B,}}{{\bf{s}}_{\bf{4}}}{\bf{,1,R}}} \right)\\\left( {{{\bf{s}}_{\bf{3}}}{\bf{,1,}}{{\bf{s}}_{\bf{4}}}{\bf{,1,R}}} \right)\\\left( {{{\bf{s}}_{\bf{3}}}{\bf{,B,}}{{\bf{s}}_{\bf{4}}}{\bf{,1,R}}} \right)\end{array}\)

Step by step solution

Achieve better grades quicker with Premium

  • Unlimited AI interaction
  • Study offline
  • Say goodbye to ads
  • Export flashcards

Over 22 million students worldwide already upgrade their learning with Vaia!

01

Step \({\bf{1}}\):Definition

A Turing machine \(T = \left( {S,I,f,{s_0}} \right)\) consists of a finite set S of states, an alphabet I containing the blank symbol B, a partial function f from \(S \times I\) to \(S \times I \times {\rm{\{ }}R,L{\rm{\} }}\), and a starting state \({s_0}\).

Given:

\(f(n) = n - 3\)if \(n \ge 3\) and \(f\left( n \right) = 0\) if \(n = 0,1,2\)

n is represented by \(n + 1\) ones.

The Turing machine computes the function by subtracting 3 when it removes the three leading 1’s at the beginning of the number.

Note: The partial function f is often represented as 5-tuples.

02

Form of constructing machine

You will require 5 states \({s_0},{s_1},{s_2},{s_3}\) and \({s_4}\left( {{s_0}} \right)\) is the start state, \({s_1}\) will be the state that is used to remove the second1,\({s_2}\) is the state that will be used to remove the third 1, \({s_3}\) will be used to check if the input is 2 or not, and \({s_4}\) will be the final state), which will be contained in the set S.

\(S = \left\{ {{s_0},{s_1},{s_2},{s_3},{s_4}} \right\}\)

The alphabet I needs to contain the tape symbols. The tape symbols are given as 0,1 and B.

\(I = {\rm{\{ }}0,1,B{\rm{\} }}\)

03

Construction of Turing machine

Next, you will define the partial function as five tuples.

You remove the first leading one by replacing the first 1 in the string by B.

You then move to state \({s_1}\) (where you will remove the second 1) and move one position to the right.

\(\left( {{{\bf{s}}_{\bf{0}}}{\bf{,1,}}{{\bf{s}}_{\bf{1}}}{\bf{,B,R}}} \right)\)

Once you are at state \({s_1}\), you know that a 1 was removed at the beginning of the string. If the input is a 1, then you can remove the second 1 by replacing the 1 by B. You then also move to the state \({s_2}\) (where you will remove the third 1).

\(\left( {{s_1},1,{s_2},B,R} \right)\)

04

Construction of Turing machine

However, if the second element was a blank B instead, then the input was 0 and thus you then need to return 0 (while the string at this point will contain only B’s). This then means that it is sufficient to then move the machine to the final state \({s_4}\) while changing one of the B’s to 1.

\(\left( {{s_1},B,{s_4},1,R} \right)\)

Once you are at state \({s_2}\), you know that two 1’swere removed at the beginning of the string. If the input is a 1, then you can remove the third 1 by replacing the 1 by B. You then also move to the state \({s_3}\) (as the three leading 1’swere removed).

\(\left( {{s_2},1,{s_3},B,R} \right)\)

05

Construction of Turing machine

However, if the third element was a blank B instead, then the input was 1 and thus you then need to return 0 (while the string at this point will contain only B’s). This then means that it is sufficient to then move the machine to the final state \({s_4}\) while changing one of the B’s to 1.

\(\left( {{s_2},B,{s_4},1,R} \right)\)

Once you are at state \({s_3}\), you know that three1’swere removed at the beginning of the string. If the input is a 1, then you can leave the 1 untouched and simply move to the final state \({s_4}\).

\(\left( {{s_3},1,{s_4},1,R} \right)\)

06

Construction of Turing machine

If the first input is a blank B, then the input was a 2 was thus you then need to return 0 (while the string at this point will contain onlyB’s). This then means that it is sufficient to then move the machine to the final state \({s_4}\) while changing one of the B’sto 1.

\(\left( {{s_3},B,{s_4},1,R} \right)\)

Finally, you add no five-tuples that have \({s_3}\) as its first element such that the machine always halts when you arrive at state \({s_3}\). Note that the machine will halt in the final state \({s_3}\) when the string has the three leading 1’s removed (if they exist).

Therefore, the constructed Turing machine that computes the function \(f{\rm{(}}n{\rm{)}} = n - 3\) if \(n \ge 3\) and \(f\left( n \right) = 0\) for \(n = 0,1,2\)for all non-negative integers n is

\(\begin{array}{c}\left( {{{\bf{s}}_{\bf{0}}}{\bf{,1,}}{{\bf{s}}_{\bf{1}}}{\bf{,B,R}}} \right)\\\left( {{{\bf{s}}_{\bf{1}}}{\bf{,1,}}{{\bf{s}}_{\bf{2}}}{\bf{,B,R}}} \right)\\\left( {{{\bf{s}}_{\bf{1}}}{\bf{,B,}}{{\bf{s}}_{\bf{4}}}{\bf{,1,R}}} \right)\\\left( {{{\bf{s}}_{\bf{2}}}{\bf{,1,}}{{\bf{s}}_{\bf{3}}}{\bf{,B,R}}} \right)\\\left( {{{\bf{s}}_{\bf{2}}}{\bf{,B,}}{{\bf{s}}_{\bf{4}}}{\bf{,1,R}}} \right)\\\left( {{{\bf{s}}_{\bf{3}}}{\bf{,1,}}{{\bf{s}}_{\bf{4}}}{\bf{,1,R}}} \right)\\\left( {{{\bf{s}}_{\bf{3}}}{\bf{,B,}}{{\bf{s}}_{\bf{4}}}{\bf{,1,R}}} \right)\end{array}\)

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Express each of these sets using a regular expression.

  1. The set containing all strings with zero, one, or two bits
  2. The set of strings of two 0s, followed by zero or more 1s, and ending with a 0
  3. The set of strings with every 1 followed by two 0s
  4. The set of strings ending in 00 and not containing 11
  5. The set of strings containing an even number of 1s

Determine whether 1011 belongs to each of these regular sets.

  1. \({\bf{1}}0{\bf{*}}1{\bf{*}}\)
  2. \(0{\bf{*}}\left( {10 \cup 11} \right){\bf{*}}\)
  3. \(1\left( {01} \right){\bf{*1*}}\)
  4. \(1{\bf{*}}01\left( {0 \cup 1} \right)\)
  5. \(\left( {10} \right){\bf{*}}\left( {11} \right){\bf{*}}\)
  6. \(1\left( {00} \right){\bf{*}}\left( {{\bf{11}}} \right){\bf{*}}\)
  7. \(\left( {10} \right){\bf{*}}10{\bf{1}}1\)
  8. \(\left( {1 \cup 00} \right)\left( {01 \cup 0} \right)1{\bf{*}}\)

Construct a finite-state machine that delays an input string by two bits, giving 00 as the first two bits of output.

Use the set of productions to show that each of these sentences is a valid sentence.

a) The happy hare runs.

b) The sleepy tortoise runs quickly.

c) The tortoise passes the hare.

d) The sleepy hare passes the happy tortoise.

let \({{\bf{G}}_{\bf{1}}}\) and \({{\bf{G}}_{\bf{2}}}\) be context-free grammars, generating the language\({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right)\) and \({\bf{L}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\), respectively. Show that there is a context-free grammar generating each of these sets.

a) \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right){\bf{UL}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\)

b) \({\bf{L}}\left( {{{\bf{G}}_{\bf{1}}}} \right){\bf{L}}\left( {{{\bf{G}}_{\bf{2}}}} \right)\)

c) \({\bf{L}}{\left( {{{\bf{G}}_{\bf{1}}}} \right)^{\bf{*}}}\)

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free