Skip to content

EWD249 - 43

2b1(3)a  =
begin boolean jprime;
      repeat j:= j + 2;
             "give for odd j to jprime the meaning: j is a prime number";
      until jprime
end

The above oscillation between two levels of description is in fact nothing else but adjusting to our convenience the interface between the overall structure and the primitive operation that has to fit into this structure. This oscillation, this form of trial and error, is definitely not attractive, but with a sufficient lack of clairvoyance and being forced to take our decisions in sequence, I see no other way: we can regard our efforts as experiments to explore (at a rather low cost!) where the interface can probably be most conveniently chosen.

Remark. Both 2b1(2) and 2b1(3) can be loosely described as

begin "set table p and j at initial value";
      while "table p not full" do
      begin "increase j until next prime number to be added";
            "add j to table p"
      end
end

but we shall not do this as the sequencing in the two versions differs and -see "On comparing programs"- we regard them as "incomparable". By choosing 2b1(3) we decide that our trial 2b1(2) -as 2b1(1)- is no longer applicable and therefore rejected.

The change from 2b1(2) to 2b1(3) is justified by the efficiency gain at the levels of higher refinement. This efficiency gain is earned at level 2b2, because now j can be increased by 2 at a time. It will also manifest itself in the still open primitive at level 2b2(3) where the algorithm for "give for odd j to jprime the meaning: j is a prime number" has only to cater for the analysis of odd values of j.

Again: in 2b2(3) we have refined 2b1(3) with an algorithm which solves our