Skip to content

EWD249 - 45

But the above version is written on the assumption that the value of ord, a function of j, is known. We could have started this refinement with

begin integer n, ord;
      ord:= 1; while p[ord] ↑ 2 ≤ j do ord:= ord + 1;
      .......

i.e. recomputing the value of "ord" afresh, whenever it is needed. Here some trading of storage space for computation time seems indicated: instead of recomputing this function whenever we need it, we introduce an additional variable ord for its current value: it has to be set when j is set, it has to be adjusted when j is changed.

This, alas, forces upon us some reprogramming. One approach would be to introduce, together with j, an integer variable ord and to scan the programs in order to insert the proper operations on ord, whenever j is operated upon. I do not like this because at the level at which j is introduced and has a meaning, the function "ord" is immaterial. We shall therefore try to introduce ord only at its appropriate level and we shall be very careful.

For 2b: "make for k from 1 through 1000 p[k] equal to the k-th prime number" we write (analogous to level 2b1(3))

level 2b1(4):
begin integer k, j; p[1]:= 2; k:= 1;
      "set j to one";
      while k < 1000 do
      begin "increase odd j until next odd prime number";
            k:= k + 1; p[k]:= j
      end
end

expressed in terms of

2b1(4)a     "increase odd j until next odd prime number"
2b1(4)b     "set j to one".

In our next level we only introduce the subcomputation for 2b1(4) a, the other is handed down.