taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.1-9

Exercise 1.1-9

not stated yet in Lean solution written

RatingM30
MarkersM (mathematical), recommended
KindInformal: the exercise has no formal statement, so Lean does not state it from the written solution
SectionSection 1.1 of Volume 1. Companion chapter: Algorithms

The task

Give a set-theoretic definition of "the computational method C2C_2 simulates the method C1C_1", such that each computation of C1C_1 appears as a part of a computation of C2C_2, which may be longer and may keep more information.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Think of three maps: one that sends an input of C1C_1 to an input of C2C_2, one that forgets the extra information of a state of C2C_2, and one that says how many steps of C2C_2 do one step of C1C_1.

Hint 2

The forgetting map must commute with the steps, up to the number of steps, and it must send outputs to outputs and non-outputs to non-outputs.

Solution

Show the solution

Let C1=(Q1,I1,Ω1,f1)C_1 = (Q_1, I_1, \Omega_1, f_1) and C2=(Q2,I2,Ω2,f2)C_2 = (Q_2, I_2, \Omega_2, f_2) be as in Section 1.1. Say that C2C_2 simulates C1C_1 if there are three functions

  • g ⁣:I1→I2g\colon I_1 \to I_2 (the coding of the input),
  • h ⁣:Q2→Q1h\colon Q_2 \to Q_1 (the forgetting of the extra information),
  • j ⁣:Q2→{1,2,3,…}j\colon Q_2 \to \{1, 2, 3, \ldots\} (the number of steps of C2C_2 for one step of C1C_1),

such that these three conditions hold:

  1. h(g(x))=xh(g(x)) = x for each x∈I1x \in I_1.
  2. f1(h(q))=h(f2 j(q)(q))f_1(h(q)) = h(f_2^{\,j(q)}(q)) for each q∈Q2q \in Q_2 that is reachable from some g(x)g(x). Here f2 jf_2^{\,j} means jj applications of f2f_2.
  3. q∈Ω2q \in \Omega_2 if and only if h(q)∈Ω1h(q) \in \Omega_1, for each reachable qq.

Why this works. Take x∈I1x \in I_1 with computation x0=x,x1,x2,…x_0 = x, x_1, x_2, \ldots in C1C_1. Put q0=g(x)q_0 = g(x) and qs+1=f2 j(qs)(qs)q_{s+1} = f_2^{\,j(q_s)}(q_s). Then h(q0)=x0h(q_0) = x_0 by condition 1. If h(qs)=xsh(q_s) = x_s, condition 2 gives h(qs+1)=f1(xs)=xs+1h(q_{s+1}) = f_1(x_s) = x_{s+1}. So by induction h(qs)=xsh(q_s) = x_s for each ss. The states qsq_s lie on the computation of C2C_2 that starts at g(x)g(x), so C2C_2 passes through states that hh turns into x0,x1,x2,…x_0, x_1, x_2, \ldots, with j(qs)j(q_s) steps from qsq_s to qs+1q_{s+1}. By condition 3, qs∈Ω2q_s \in \Omega_2 exactly when xs∈Ω1x_s \in \Omega_1. Thus C1C_1 stops from xx exactly when C2C_2 reaches an output state from g(x)g(x), and then hh of the output of C2C_2 is the output of C1C_1. An output state of C2C_2 is fixed by f2f_2, so a stop of C2C_2 is not missed between qsq_s and qs+1q_{s+1}.

An example. Let C1C_1 be a method with the states of Euclid's algorithm. Let C2C_2 have the states (m0,n0,q)(m_0, n_0, q) with q∈Q1q \in Q_1, so that each state keeps the first input. Let f2(m0,n0,q)=(m0,n0,f1(q))f_2(m_0, n_0, q) = (m_0, n_0, f_1(q)), and let the inputs and outputs be those triples whose qq is an input or an output of C1C_1. Take g(x)=(m,n,x)g(x) = (m, n, x) for the input x=(m,n)x = (m, n), take h(m0,n0,q)=qh(m_0, n_0, q) = q and j=1j = 1. The three conditions hold. A second simulation does the remainder of step E1 by repeated subtraction, and then j(q)j(q) is the number of subtractions plus the steps of E2 and E3 for that pass. The first example shows why hh must go from Q2Q_2 to Q1Q_1. A map from Q1Q_1 to Q2Q_2 cannot exist, since a state of C1C_1 has forgotten the original input and so it cannot decide the extra components.

Other facts. If C3C_3 simulates C2C_2 with maps (g′,h′,j′)(g', h', j'), then C3C_3 simulates C1C_1 with g′′=g′∘gg'' = g' \circ g and h′′=h∘h′h'' = h \circ h'. For the step count, start at q∈Q3q \in Q_3 and let C3C_3 do j(h′(q))j(h'(q)) simulated steps of C2C_2, each of j′j' steps of C3C_3. Then j′′(q)j''(q) is the sum of these j′j' values. So the relation is transitive. If the function jj is bounded, the simulation is slower by at most a fixed factor. Simulation with a bounded jj is a stronger relation, and it is closer to the idea that two methods are the same algorithm.

Remarks

This is the idea behind the statement that a program implements an algorithm. The Lean model TAOCP.CompMethod of the C1 chapter holds the quadruple (Q,I,Ω,f)(Q, I, \Omega, f), so the definition above can be written in it with the maps gg, hh and jj.

This solution is checked, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.