CORRELACIÓN DE EJERCICIOS CON MODULACIÓN DEL DOLOR
B.- Percepción subjetiva del dolor:
3) Ejercicios y modulación del dolor (CPM).
All the simulations proceed by step-by-step simulation of program instructions. The process of establishing that one can correctly embed computations by modelLinto those ofMcan be summed up as follows, following the pattern of Definition 3.3.3:
1. Define a one-to-one data encodingc:L-data→M-data.
2. Define a representation of any store σ∈L-store by a storeσ∈M-store.
3. Define the construction of anM-programp=I0;I1;I2;. . .Ik;Ik+1from anL-program p=I1;I2;. . .;Ik.
Here I0and and Ik+1 (if present) are respectively “initialize” code needed to pre- pare the simulation, and “clean-up” code to deliver the result in the needed final format.
4. Prove thatpcorrectly simulates the actions ofp.
We will mostly gloss over the correctness problem except where the construction is non- trivial, hoping the reader will find the other constructions sufficiently straightforward not to need formal proof.
Coding functionc Definition ofc c01B : {0,1,B}∗→ID c01B(a1a2...ak) =(a†1a
†
2· · ·a
†
k)(in list notation)
whereB†=nil,0†= (nil.nil),1†= (nil.(nil.nil)) cpr : ID→IN cpr(nil) = 0 andcpr(d1.d2) = 1 + 2cpr(d1)·3cpr(d2) bin : IN→ {0,1}∗ bin(v) = the shortest binary representation ofv
c2CM : IN→IN c2CM(v) = 2v
Figure 8.5: Coding functions.
8.4
Compiling
RAM
to
TM
We begin with the most complex compilation, from the most complex machine type (the RAM) to the a quite simple one (the Turing machine).
First, to simplify the construction we reduceRAMinstructions to what might be called a RISC or “reduced instruction set” version using registerX0as an accumulator, and with instruction forms:
I ::= X0 := X0 + 1 | X0 := X0 .- 1 | if X0 = 0 goto `
| X0 := Xi|Xi := X0 | X0 := <Xi> | <X0>:= Xi
| Other operations: X0 := X0 Operation Xi
Clearly anyRAMprogram can be converted to an equivalent reduced form program, slow- ing down its running time by at most a small constant factor.
The Turing machine simulating a RISC RAM program pwill have 4 tapes as in the following table, using the binary encoding bin:IN → {0,1}∗ of Figure 8.5. With each
tape form we have marked, by underlining, the “standard scan position.” This is the position the scan heads are to occupy between simulation of any twoRAMinstructions.
The first two tapes represent the locations and values of nonzero entries in the RAM storeσ= [a07→c0, . . . , ak7→ck]. The third tape is the accumulatorX0, the fourth is an
auxiliary “scratch” tape for various purposes.
Note that “standard scan position” can easily be located: since all number encodings have at least one bit, it will always be the rightmostBin the first BBto the left of any tape’s nonblank contents.
Tape number Tape name Tape form, standard scan position 1 Addresses ...B B bin(a0) B bin(a1)...B bin(ak)BB...
2 Contents ...B B bin(c0) B bin(c1)...B bin(ck) BB...
3 AccumulatorX0 ...B · · · B...
4 Scratch ...B· · · B...
Initialization code: theRAMprogram inputbin(i) is on tape 1. This is first copied to tape 2 and0is placed on tape 1, signifying that cell 0 contains value bin(i). After this, both heads are moved one position left to assume standard position. Termination code: the first valuebin(c0) on tape 2 is copied onto tape 1, and all other information is erased.
The simulation is described by three examples; the reader can fill in the rest. 1. X0 := X0 + 1:
Find the right end of the (nonblank portion of the) Accumulator tape 3. Repeatedly replace1by0on it, and shift left one position, as long as possible. When a0orB is found, change it to1and move one left to stop in standard position..
2. X23 := X0:
Scan right on tapes 1 and 2, oneBblock at a time, until the end of tape 1 is reached or tape 1 contains a blockB10111B. (Note: 10111 is 23 in binary notation.) If the end of tape 1 was reached, location 23 has not been seen before. Add it, by writing10111at the end of tape 1, and copy tape 3 (the value ofX0) onto tape 2; and return to standard position.
If, however, B10111Bwas found on tape 1, then bin(c23) is scanned on tape 2. In this case it must be overwritten, done as follows:
• copybin(c24)...Bbin(ck)Bonto scratch tape 4;
• copy tape 3 (the value ofX0) in place ofbin(c23) on tape 2;
• writeBand copy tape 4 onto tape 2, thus reinstating, after the newbin(c23), the remainder bin(c24)...B bin(ck)B; and finally
• return to standard position. 3. X0 := <X23>:
Starting at the left ends of tapes 1 and 2, scan right on both, oneBblock at a time, until the end of tape 1 is reached or tape 1 contains a block withB10111B. If the end is reached do nothing, as c23= 0 and tape 3 already containsc0.
IfB10111Bwas found on tape 1, thenbin(c23) is scanned on tape 2. Copybin(c23) onto tape 4. As above, search tapes 1 and 2 in parallel until locationBbin(c23)Bis found on tape 1, or tape 1’s end is found. If the end was reached, write 0on tape 3, since cc23=c0. Otherwise copy the tape 2 block corresponding to tape 1 onto
tape 3, as the tape 2 block contains bin(c(c23)), and return to standard position. Finally, “other operations” X0 := X0 Operation Xi can be simulated as long as they denote Turing-computable functions on natural numbers. This holds for all operations in the variousRAMmodels which have been proposed.
8.5
Compiling
TM
to
GOTO
For simplicity of notation we describe how to compile one-tape Turing machine programs into equivalentGOTOprograms; the extension to multiple tapes is obvious and simple. We follow the “common pattern.” The encoding of Turing machine tapes as GOTO values uses the encodingc01Bdefined in Figure 8.5.
A Turing machine store σ=L S R will be represented by three GOTO variables Lf, C, Rt, whose values are related to the tape parts by C=S† (notation defined in Figure 8.5), Rt=c01B(R), and Lf=c01B˜L, where ˜L is L written backwards, last symbol first.
A Turing machine programp=I1;I2;. . .Ik is compiled into a simulatingGOTO-program
p=I1;I2;. . .Ik, where eachIiis the sequence ofGOTOcommands defined next (with some
syntactic sugar for readability).
TM command GOTO code must achieve
right if (=? Rt nil) then Rt := (nil . nil); Lf := cons C Lf; C := hd Rt; Rt := tl Rt;
left if (=? Lf nil) then Lf := (nil . nil); Rt := cons C Rt; C := hd Lf; Lf := tl Lf;
write S C := d whered=S†
if S goto ` if C = d then goto ` whered=S† The initialGOTOstore for Turing Machine inputBRis
[Rt7→c01B(R),C7→nil,Lf7→nil]