• Home
  • Textbooks
  • Languages and Machines: An Introduction to the Theory of Computer Science
  • Numeric Computation

Languages and Machines: An Introduction to the Theory of Computer Science

Thomas A. Sudkamp

Chapter 12

Numeric Computation - all with Video Answers

Educators


Chapter Questions

Problem 1

Construct Turing machines with input alphabet $\{a, b\}$ that compute the specified functions. The symbols $u$ and $v$ represent arbitrary strings over $\{a, b\}^*$.
a) $f(u)=$ aaa
b) $f(u)= \begin{cases}a & \text { if length }(u) \text { is even } \\ b & \text { otherwise }\end{cases}$
c) $f(u)=u^R$
d) $f(u, v)= \begin{cases}u & \text { if length }(u)>\text { length }(v) \\ v & \text { otherwise }\end{cases}$

Check back soon!
06:44

Problem 2

Construct Turing machines that compute the following number theoretic functions and relations. Do not use macros in the design of these machines.
a) $f(n)=2 n+3$
b) half $(n)=\lfloor n / 2\rfloor$ where $\lfloor x\rfloor$ is the greatest integer less than or equal to $x$
c) $f\left(n_1, n_2, n_3\right)=n_1+n_2+n_3$
d) $\operatorname{even}(n)= \begin{cases}1 & \text { if } n \text { is even } \\ 0 & \text { otherwise }\end{cases}$
e) $e q(n, m)= \begin{cases}1 & \text { if } n=m \\ 0 & \text { fthwise }\end{cases}$
f) $\operatorname{lt}(n, m)=\{1$ if 1 otherwise
f) $l t(n, m)= \begin{cases}1 & \text { if } n<m \\ 0 & \text { otherwise }\end{cases}$
g) $n-m=\left\{\begin{array}{l}n-m \text { if } n \geq m \\ 0\end{array}\right.$

Chris Trentman
Chris Trentman
Numerade Educator
04:12

Problem 3

Construct Turing machines that perform the actions specified by the macros listed below. The computation should not leave the segment of the tape specified in the input configuration.
a) $\mathrm{ZR}$; input $\underline{B} B B$, output $\underline{B} \overline{0} B$
b) FL; input $B \bar{n} B^i \underline{B}$, output $\underline{B} \bar{n} B^i B$
c) $\mathrm{E}_2$; input $\underline{B} \bar{n} B \bar{m} B$, output $\underline{B} B^{n+m+3} B$
d) $\mathrm{T}$; input $\underline{B} B^i \bar{n} B$, output $\underline{B} \bar{n} B^i B$
e) BRN; input $\underline{B} \bar{n} B$, output $\underline{B} \bar{n} B$
f) INT; input $\underline{B} \bar{n} B \bar{m} B$, output $\underline{B} \bar{m} B \bar{n} B$

Chris Trentman
Chris Trentman
Numerade Educator
02:41

Problem 4

Use the macros and machines constructed in Sections 12.2 through 12.4 to design machines that compute the following functions:
a) $f(n)=2 n+3$
b) $f(n)=n^2+2 n+2$
c) $f\left(n_1, n_2, n_3\right)=n_1+n_2+n_3$
d) $f(n, m)=m^3$
e) $f\left(n_1, n_2, n_3\right)=n_2+2 n_3$

Chris Trentman
Chris Trentman
Numerade Educator
04:23

Problem 5

Design machines that compute the following relations. You may use the macros and machines constructed in Sections 12.2 through 12.4 and the machines constructed in Exercise 2.
a) $g t(n, m)= \begin{cases}1 & \text { if } n>m \\ 0 & \text { otherwise }\end{cases}$
b) $\operatorname{persq}(n)= \begin{cases}1 & \text { if } n \text { is a perfect square } \\ 0 & \text { otherwise }\end{cases}$
c) divides $(n, m)= \begin{cases}1 & \text { if } n>0, m>0, \text { and } m \text { divides } n \\ 0 & \text { otherwise }\end{cases}$

Chris Trentman
Chris Trentman
Numerade Educator

Problem 6

Trace the actions of the machine MULT for computations with input
a) $n=0, m=4$
b) $n=1, m=0$
c) $n=2, m=2$.

Check back soon!
04:04

Problem 7

Describe the mapping defined by each of the following composite functions:
a) $a d d \circ($ mult $\circ(i d, i d), a d d \circ(i d, i d))$
b) $p_1^{(2)} \circ\left(s \circ p_1^{(2)}, e \circ p_2^{(2)}\right)$
c) mult $\circ\left(c_2^{(3)}\right.$, add $\left.\circ\left(p_1^{(3)}, s \circ p_2^{(3)}\right)\right)$
d) $m$ ult $\circ\left(\right.$ mult $\left.\circ\left(p_1^{(1)}, p_1^{(1)}\right), p_1^{(1)}\right)$

Yujie Wang
Yujie Wang
College of San Mateo
01:18

Problem 8

Give examples of total unary number-theoretic functions that satisfy the following conditions.
a) $g$ is not $i d$ and $h$ is not $i d$ but $g \circ h=i d$
b) $g$ is not a constant function and $h$ is not a constant function but $g \circ h$ is a constant function

Carson Merrill
Carson Merrill
Numerade Educator
01:04

Problem 9

Give examples of unary number-theoretic functions that satisfy the following conditions:
a) $g$ is not one-to-one, $h$ is not total, $h \circ g$ is total
b) $g \neq e, h \neq e, h \circ g=e$, where $e$ is the empty function
c) $g \neq i d, h \neq i d, h \circ g=i d$, where $i d$ is the identity function
d) $g$ is total, $h$ is not one-to-one, $h \circ g=i d$

Carson Merrill
Carson Merrill
Numerade Educator
03:51

Problem 10

Let $\mathrm{F}$ be a Turing machine that computes a total unary number-theoretic function $f$. Design a machine that returns the first natural number $n$ such that $f(n)=0$. A
computation should continue indefinitely if no such $n$ exists. What will happen if the function computed by $\mathrm{F}$ is not total?

Chris Trentman
Chris Trentman
Numerade Educator
03:51

Problem 11

Let $\mathrm{F}$ be a Turing machine that computes a total unary number-theoretic function $f$. Design a machine that computes the function
$$
g(n)=\sum_{i=0}^n f(i) .
$$

Chris Trentman
Chris Trentman
Numerade Educator
02:41

Problem 12

Let $\mathrm{F}$ and $\mathrm{G}$ be Turing machines that compute total unary number-theoretic functions $f$ and $g$, respectively. Design a Turing machine that computes the function
$$
h(n)=\sum_{i=0}^n e q(f(i), g(i)) .
$$
That is, $h(n)$ is the number of values in the range 0 to $n$ for which the functions $f$ and $g$ assume the same value.

Chris Trentman
Chris Trentman
Numerade Educator

Problem 13

A unary relation R over $\mathbf{N}$ is Turing computable if its characteristic function is computable. Prove that every computable relation defines a recursive language. Hint: Construct a machine that accepts $\mathrm{R}$ from the machine that computes its characteristic function.

Check back soon!

Problem 14

Let $\mathrm{R} \subseteq\{I\}^{+}$be a recursive language. Prove that $\mathrm{R}$ defines a computable relation on N.

Check back soon!

Problem 15

Prove that there are unary relations over $\mathbf{N}$ that are not Turing computable.

Check back soon!

Problem 16

Let $\mathrm{F}$ be the set consisting of all total unary number-theoretic functions that satisfy $f(i)=i$ for every even natural number $i$. Prove that there are functions in $\mathrm{F}$ that are not Turing computable.

Check back soon!

Problem 17

Let $\mathrm{L}$ be a language over $\Sigma$ and $c h_{\mathrm{L}}$
$$
c h_{\mathrm{L}}(w)= \begin{cases}1 & \text { if } w \in \mathrm{L} \\ 0 & \text { otherwise }\end{cases}
$$
be the characteristic function of $\mathrm{L}$.
a) Let $\mathrm{M}$ be a Turing machine that computes $c h_{\mathrm{L}}$. Prove that $\mathrm{L}$ is recursive.
b) If $\mathrm{L}$ is recursive, prove that there is a Turing machine that computes $c h_{\mathrm{L}}$.

Check back soon!
02:47

Problem 18

Let $v_1, v_2, v_3, v_4$ be a listing of the variables used in a TM program and assume register 1 contains a value. Trace the action of the instruction STOR $v_2$. To trace the actions, use the technique in Example 12.3.2.

Nick Johnson
Nick Johnson
Numerade Educator
01:14

Problem 19

Give a TM program that computes the function $f\left(v_1, v_2\right)=v_1-v_2$.

Fuzail Shakir
Fuzail Shakir
Numerade Educator