A note on the proof of a concurrent program

A note on the proof of a concurrent program

Volume9, number 3 INFORMATION PROCESSING LETTERS 5 October 3979 A NOTE ON THE PROOF OF A CONCURRENTPROGRAM E. MST &R@&w kbdmmtu~, Uniwersity of Ne...

639KB Sizes 9 Downloads 114 Views

Volume9, number 3

INFORMATION PROCESSING LETTERS

5 October 3979

A NOTE ON THE PROOF OF A CONCURRENTPROGRAM E. MST &R@&w kbdmmtu~,

Uniwersity of Newmstle&vne,

Newcostleh)vte

1. Woduction

nents yi, using a fixed vector-valuedfunction of vectors f wi*hN component functions fi. For the purposes of termination, an additional variableh with N boolean components hi is used. Initially, h is identically tzue and y has arbitrary values. The program consists of a set of N component programs, the i* component of which is givenby do(3j: h$+ Ll

ifkq~+hr:=false)

L2

II (-3

I-4

,

+Yi

= MY))

(1)

(hj: = true)

fI OdS where ‘eq#’is an abbreviation of ‘yi = fi(y)‘.

do(3j: hi)+ Ll

if (eqi + hi: = false)

L2

n(leQ-*yi:=fi(y);Vj:

v

3j: hi .

Sij:=fal*);

fi od (all

true initially). (ii) Define N boolean values Rj as the minimal solution of the set of equations (minimal in the sense of: as false as possible): !+j

Vj: -hi

V

Vi, j: -Ri

Rj , V Sij V

W

Rj

(4b)

(there exists a unique minimal solution). (iii) Show directly that V

Ri

(5)

is an invariant of (3). The proof of (5) makes crucial use of the fact that Vj: Sij

The claim cannot be proved dire&y (i.e. by showing that (2) is true initially and that its truth is preservedby each atomic command Lf , L2 and L2j). In [I], (2) is proved indirectly in four steps (i)-(iv) as follows:

(3)

Vj: (hj: = true; sij = true)

L2j

Vi: eqi

Claim. If and when (1) terminates, then y represents a fixpoint of c more formally, Vi: Ed

England

(i) Introduce auxiliary variables accordingly as

The program considered in this note is taken from [I). It operates on a vector variable > with N compo-

Vj:

1

(6) .

is true over Ll. (iv) If all hj’s are false, all Rj’s are false as well by (ii), and by (5) the left-hand term of (2) holds. This proves (2) for (3), and hence also for (1). 103

IYFORMATION

Volume 9, number 3 2.

PROCESSING LETTERS

Derivation of the proof

The way of deriving (i) -(iv) in [ 1] is compelling shall present an alternative line of reasoning which 1 believe to be equally strict; this, SO 1 would a :gue, leaves little room for simpler proofs. We start by observing that the fact that a# hj’S are set to true by L2j must crucially enter the proof (for example, (6) is based upon it). We introduce the sij in the first place as a means of expressing this fact. Next we . observe that

enough but I

Vi: eqi

VIli

,

(7)

being much stronger than (2), is not in general an invariant of (1) since ‘a component k # i may interfere’. We can, however, attempt to make (7) correct by guessing at an invariant of the form Vi: eqi

V

hi v Xi

(8)

where Xi covers the f’ding cases of (7). The interference of a kth component can be expressed formally by 3 k: 1 ski. Therefore the following first approximation suggests it self: vi:

eqi V

hi

V 3

k: -I Ski

.

(84

Indeed, @a) is an invariant. But there is no way of deriving (2) from (8a); we therefore attempt to strengthen (8a), and the next simplest approximation becomes Vi: eq;

V

hi

V

3k: hk A 7

Ski

.

@b)

Eq. (8b) implies (2) but, unfortunately, is not invariant over L2. Thus, (8a) is too weak, (8b)‘is too strong for our purposes. The offending term is the ‘hk’ in (8b); whatever this term is replaced by -, say, by rk: Vi: eqi

V hi V

3k: rk A 1 ski -- ,

w

proof of the invariance of (8~‘)over L2 must fail unless in addition

a

5 October 1979

Finally, the r’s should be minimal such that (8~) reduces to the left-hand term of (2) upon termination. This completes the alternative derivation, since (10) is equivalent to formulas (4a, b), which can be verified by replacing r, i, k by R, j, i, respectively. Thus, the r’sare equivalent to the R’s; finally, ,the proof of (8c) is rathersimilar to the proof of@).

3. Conclusiopl The reasoning that led up to (10) can be viewed as a specific instance of the following general recipe: find an invariantwhich is strongerthan the desired invariant. Tins time the discovery has taken place in successive approximations, and 1 believe that the degree of informality has been kept near minimum. E%ch new formula in the series (7) to (86) arises quite naturally from ..n analysis of the failure of the preceding formulas. The pivot of the proof - formula (10) - is then only a logical by-product of the analysis; the ease with which (10) can be stated is, I beliekz, a consequence of the fact that the analysis has been a rather formal one. The argument is also an example of general&ion; for, if there is only one programcomponent (1). teen (2) reduces to (7). It would be desirable to have means of generalisingprogramsin just as systematic:a way in which (7) was generalised;and it should be nice if there was d language simple enough to assist this process. I think that in this respect the conecpt of an atomic action will prove vital.

Acknowledgments I am gratefrvlto P.J. Smith who contributed tc my understanding Uf the problem, and to E.W. Rijkstra who provided the subject of our discussions and also commented on an earlierversion of this note. The research reported here has been sponsored by thu Science ResearchCouncil of Great Britain.

Vi: eqi ‘IJri

(9) cart be assumed. A comparison of (8c) and (9) reveals that the latter can, tndeed, be ensured if we choose the r’s such that vi: (hi 104

V

3k: rk A 1 ski) * ri .

w-9

Reference Dijkstra,Finding the correctnessproof of a concurrent program,Proc. &mink. Nederk Akad. Wetensch.

[ 1] E.W.

Ser. A 81 (2) (1978).

Volume 9, number 3

INFORMATIONPROCESSINGLETTERS

5 October 1979

COMMENTS ON THE ALL NEAREST-NEIGHBOR PROBLEM FOR CONVEX POLYGONS * Alain FOURNIER and Zvi KEDEM nts k Mathamticd

Sciences, University of Texas at Dollas, Richardson, TX 75080, U.S.A.

Nearest ne;ghbot, computational geometry, computational complexity, analysis of algorithms

1. lntmduction

vertices PO,put pi, pv for which respectively:

A recent paper by Lee and Preparata[3) presents an algorithm to fmd the all nearest-neighborsof the vertices of a convex polygon in O(N) time (N number of vertices of the polygon). It is indeed an interesting example in computational geometry of how the structpue of the data can be cleverly used to lower the complexity from the general case, and adds to the list of efficient algorithms to solve problems on simple and/or convex polygons, such as triangulating,finding the kernel, etc. In a note about this paper, Yang and tir: (41 suggested a simplification of the first step of the algorithm. We would iike to make a few comments on the o@inal paper, and add a caveat to the use of the simplification !

Y(Po) = M1Nti(PO)> Y(Pl), ..*pY(PN --I)) ,

2. Decomposing the convex polygons into polygons with the sm&&cle property As indicated by Yang and Lee [4], it is enough, in order to decompose an arbitraryconvex polygon into at most four polygons with the semi-circleproperty, to find its extremal vertices, that is the at most four

* This work was supported in part by the National Science Foundation under Grant KS-77-03905. 1 We will assume that the reader is familiar with the content of [ 3) and 641, and we will follow as closely as possible their terminology and notation.

‘(P”)

= MAX(x(pO),

x(pl),

Y(Pi) = MAWY(Po), Y(Pl), x(P”) = Ml.%(po),

x(pl),

**vx(pN-1))

,

l

***Y(PN-I)),

l

...Px(pN-1))

.

We would like to add though that while in the general case, finding both minimum and maximum requires [3N/2 - 2 1 comparisons [ 11, and this means (3N - 4) comparisons for the two ordinates ((3N - 3) if N is odd), we can, by a straightforward divide and conquer method, divide the array of (for instance) x-ordinates into two unimodal spans in at most 2 [log N 1 comparisons between ordinates, and then apply the technique of Fibonacci search [2J to find each extremum in F(m) comparisons, if a span has m vertices, where F(m) = n such that F, is the smallest Fibonacci number greater than m (Fo = F1 = 1). From the closed-form formula for Fibonacci numbers, it follows that F(m) < 2.1 log m + O(1). The location of ordinate extrema by Fibonacci search can be used to speed up steps in other algorithms on convex polygons. This seems not to have been used before in this context.

3. Updating the list of closest neighbors from the convex polygons with the semi-circleproperty The set of nearest neighbors for each of the polygons with the semi-circle property is then found as 105

Voimne 9, ~~~~~je~ 3

~~FOR~ATIO~ PROCESSING LETTERS

5 Octul3er 1979

PO

Fig. 1. ~~compo~itio~ of a convex polygon into four convex polygons with ~~i-c~cl~ property.

in 13). The next step is to update the fist of neaiest nei~bors fur each polygon by checking whether th:: nearest nei~bor of a vertex belongs to another poly gon, without loss of generality assume that we up date PI1 against Pra, P r2 against Pr r to form Pr) and similarly with P2 1, Pz2 to form Pz. Then the final stage is to update PI against P2 and P2 against PI to form the final list for P (see Fig* 1). The first stage fPr 1 vs. Pr 2, and PSI vs. P22) proceeds as in [3], except that it is not ne~essa~ to compute the projections of the vertices on a line, since the dividing line is parallel to the y-axis. For the seca ond stage (PI vs. P2) since in general the line going throu~ pu and pv will not be par~~el to either axis, a pruje~tion will be necessary. Actually it is better ~omputat~onally to rotate the whole figure so that pUpvis parallel to orle of the coordinate axes. The same transformation can be applied before the corresponding step in [3f. But at this stage we cannot, contrary to what is stated in 141, apply without mod~~~ations the algo~thm given in f3] for this task. I‘%isalgorithm works only if, for the two polygons invclved, the proje~tioit of the vertices along the line r;!separating them are ordered as the vertices in the polygon, Were, since the diagonal pup,* is rtot in gen~~ra~ tlte diar~eter, it is possible that the projections of the vertices on it are not ordered as the vertices in the corresponding poly gons (Fig. 2). But, since the polygons are convex, the projections of the vertices on the line going throu~l pup,, 106

have coordinates along this hne which are~ni~od~

functions of the indices of the vertices in the po~y~n. So we can identify the vertices such th tions are an extremum, again using for an O(log N) time step, and merge the two munotone lists obtained in linear time. We then obtain for each of Pr and Pz a list Lr and b respe~~ve~yof point projections on Qwhich we use in the updating algotithm given in [3] %usbg the list I.1 instead of Pr when updating Ps ag~nst Pr , and ~rn~ariy using h instead of Pz when upda~ng Pr against P2. This extra work is more than compen~ted by not ha~ng to dete~i~e the diameter of the ori~na~ polygon.

The authurs in 131obse boat my convey poly gon can be de~on~posedinto at most four polygons with the semi-cir~~eproper, aid that could be r&lee vant to other problems with convex poIygons. One can gener~ize the concepts using the fell sedation: a convex polygon with N sides ha a fixed independent of N) number of inte not larger than a given angle QI(0~6 #I+ To prove it, assunte that k (k G N) anglesare less than or equal to Q. The sum of these ogress Sk, is at d

Volume 9, number 3

INFORMATION PROCESSINGLETTERS

5 October 1979

the sum of the remaining N - k angles, SN_~, is less than (N - k)r. Since Sk + Sri___= (N - 2)1r,ka + (N - 2)n and k < 2n/(n - a) which is

References

of N. So we can decomposeany convex s with the a-property, *property is definedas a convexpolygon such that all its internalanglesexcept at most two adjacentones aregreaterthan an angleQI. Inthecasewherea=fn,k 4. Note that polygons with the semi-circlepropertyareproperlyincluded in the set of polygons with the f n-property.

and AnaIysis of Computer Algorithms (Addison-Wesley, Reading, MA, 1976) 73. 121R.E. Bellman and S.E. Dreyfus, Applied Dynamic Programming (Princeton University Press, 1962) 152-156. PI D.T. Lee and F.P. Preparata, The all nearest-neighbor problem for convex polygons, Information Processing Lett. 7 (1978) 189-192. 141C.C. Yang and D.T. Lee, A note on the all nearestneighbor problem for convex polygons, Information Processing Lett. 8 (1979) 193-194.

t

PI A.V. Aho, J.E. Hopcroft and J.D. Ullman, The’besign

107