• No se han encontrado resultados

CAPÍTULO V: ANÁLISIS DE LOS DATOS

PROPUESTA RESOLUTIVA DE PARTE DEL INTERLOCUTOR

The fact that computer programs are compositions of functions acting on various arguments is even more apparent in assembly code than in a higher-level language such as PASCAL. In assembly code, the result obtained by applying one operation (function) usually ends up in a particular register, so that the next operation (function) can then be applied to this result. A sequence of consecutive assembly-code instructions operating on a particular register is a composition of functions. The value returned by the composition of functions is the value found in the register when the entire sequence of operations is executed.

If we were writing the computer program for cart centering using Knuth's (1981a) hypothetical symbolic assembly code for his hypothetical MIX computer, we might write something like table 7.1.

This hypothetical language program in symbolic assembly language starts at the program location labeled START on line 1 of table 7.1. The program performs the "load accumulator register A" (LDA) operation. The operand of the LDA operation on line 1 is a numerical variable (i. e., the velocity of the cart) stored in memory location v. This operation loads the variable v (from storage)

Table 7.1 MIX assembly code for optimal control strategy for the cart centering problem.

Program location Operation code Operand 1 START LDA V 2 JAP OK 3 LDAN V 4 OK MUL V 5 ADD X 6 JAN RETURN1 7 LDA -1.0 8 JMP DONE 9 RETURN1 LDA 1.0 10 DONE END Page 128 into the accumulator (arithmetic) register of our hypothetical computer. Control then passes sequentially to the next program location (line 2 of the program).

On line 2, this program performs the ''jump on accumulator positive" (JAP) operation. The operand of this operation is the program location labeled "OK." The JAP operation on line 2 causes control to jump down to the program location labeled OK (line 4) if the contents of the accumulator (which contains the velocity v of the cart) is positive. Otherwise, control passes sequentially to the next program location (line 3 of the program).

On line 3, the program performs the "load accumulator negative" (LDAN) on the variable v from memory. This operation loads the accumulator with the negative of the value of the variable v stored in memory. Since we can get to line 3 of this program only if we have already established that the variable v is negative, the effect of this operation is to load the accumulator with the absolute value of the variable v. Control passes sequentially to line 4 of the program.

When control has reached line 4 (either via the conditional jump operation on line 2 or via the usual sequential flow from line 3), the accumulator contains the absolute value of the velocity v of the cart. The program then performs the "multiply" (MUL) operation by multiplying the contents of the arithmetic register by the variable v. This operation multiplies the arithmetic register by the variable v (from storage). This completes the calculation of v2 Sign v. We assume here that all numbers are floating-point numbers and all the operations we used work appropriately on such numbers.

On line 5 the program performs the "add" (ADD) operation on the variable x. This operation adds the variable x (from storage) into the accumulator. The accumulator now contains the result of the composition of functions executed so far, namely x + v2 Sign v.

Then, on line 6, the "jump on accumulator negative" (JAN) operation branches to the program location labeled RETURN1 (line 9) if the arithmetic register is negative. Otherwise, control in the program proceeds in the ordinary sequential way to line 7.

On line 7, the "load accumulator register A" (LDA) operation loads the constant -1.0 from memory into the accumulator. Then, on line 8, the program "jumps unconditionally" (JMP) to the program location labeled DONE (line 10).

On line 9 (which is reached only via the conditional jump operation from line 6), the "load accumulator register A" (LDA) operation loads the constant +1.0 into the arithmetic register. Control then passes sequentially to the program location labeled END (line 10), where the program ends.

Line 10 is also reachable via the unconditional branching operation from line 8.

The reader familiar with another assembly language should be able to visualize how to write an equivalent program in that language.

Page 129 7.1.3 Program in LISP

The fact that a computer program is a composition of applications of functions to arguments is especially overt in a functional programming language. LISP is the most widely used language of this kind.

If we were writing the time-optimal computer program for solving the cart centering problem in LISP, we might write the parsimonious LISP S-expression

(GT (* -1 X) (* V (ABS V))).

In this S-expression, the greater-than function GT is a numerical-valued function of two arguments that returns +1 if its first argument is greater than its second argument and returns -1 otherwise (as described in subsection 6.1.1).

Figure 7.3 graphically depicts this S-expression as a rooted point-labeled tree with ordered branches.

The interpretation of this LISP computer program is as follows: Starting with x and v as inputs, take the absolute value of v and multiply it by v. Then, multiply x by -1. Then compare -x and v|v|. If -x is greater than v|v|, the S-expression evaluates to +1 and the bang-bang force F will be applied in the positive direction; otherwise, the S-expression evaluates to -1 and the bang-bang force F will be applied in the negative direction. Once this program has determined whether the bang-bang force is to be applied from the left or the right, the above-mentioned simulation involving Newton's equations of motion updates the state of the system for the next time step.