guarded commands. non-determinacy and a calculus for the derivation of programs, by edsger...

14
W418 uard omn. non-deteriacy d ulu r the dervti f pr g rms. by Edsgr WDjkst * ) )Ato' dre: BUROUGHS Pttt NUENEN - Te Neter Abt cl ude d" r tdued b b fo alernaiv ad t iti tt th w -dtit p pnt hh t t t tty o, but by e te f tte t eery uqey etere th t tt F t t p xp t t tut uu be ho Kword pi s pt p tc ror et dty sott tt t ct p t p p thodooy C-ty rdd oan, nontrina d fo t rato o rr. 1 Iuco. I eto 2 t ttet terte tt ret i tt i b tuc tt t tit (t) fitio thi c bic bili blc o th th -a d d o" stamt t p fxd by boe t p ty t th tteet t ebe f eeuto Te otet dete w u t tw (ty) ft p t g m tex,  circutc tat see lay ponbl f t ct th t 

Upload: xorxpto

Post on 06-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 1/14

W418

uard omn. non-deteriacy d ulu r the dervti f

prgrms.

by Edsgr WDjkst *)

) Ato' dre: BUROUGHS

Pttt

NUENEN -

Te Neter

Abt cl ude d" r tdued b b

fo alernaiv ad titi tt th w -dtit

p pnt hh t t t tty o, but by

e te f tte t eery uqey etere th t

tt F t t p xp t t

tut uu be ho

Kword pi s pt p tc

ror et dty sott

tt t ct p t p p

thodooy

C-ty

rdd oan, nontrina d fo t rato o

rr.

1 Iuco.

I eto 2 t ttet terte tt ret

i tt i b tuc tt t tit (t)

fitio thi c bic bili blc o th

th -a dd o" stamt �t pfxd by boe

t p ty t th

tteet t ebe f eeuto Te otet dete

w u t tw (ty) ft p t

gm tex,   circutc  tat  see lay  ponbl f t  ct tht 

Page 2: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 2/14

418

prgms ca e ed n a moe ssmat manner tha efo

n sectn t a prelude denng the notation oml d

nto he smts th stts wil be gen tot wt s ah th nstructs (wtout pro

n sn 4 t wl e s ow on te bo a fml ccuu

o the drtin f porams e oude W wod li t t

t e do not rset �a gorth" o th deriti of pram

ae sed th te lls for omal dipe t of ule

u tt i ppld ucssl

it wl hv ervd cort porm it will te hat w v chd uch l.

I choing the t clc w h ind b �ntgl

alu" nd the �tal alc we w he e smar

tutn

T ttmets d guarde mads.

I te eader ccpt othe ttet" dtin

gnmt sttmnts ad pd w giv t rlvn

n BNF [2] In th olw w hv etnded N with h nvt

tht th b {. . } hld ed "lwed b zr

it o th ed

<guardd mmd> gd > <guadd st >

<grd> booen express>

<gurded st> < statement>{; < sttmn><uded mmand set>: <gurded ommd> <rded mmnd>

<aternati onstuct>:= f < gdd commnd et>i

<eetti ctuct>= < rd cond t>£

<sttemt> trnt ct> <etv ctut> oth ttemet"

Th mclo th aded lit hv h sa ng wh t

d t  ctd fr executi it statms b xctd

suess t od m lt t a arded list wll e

Page 3: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 3/14

EWD48

ld r u n st sch t it gard rue, N ha

a gard md � a smn: it is ompone o

grded ond et frm same a b nscd If h

gadd cmd st oe o ar oan the r

utuly rd h ptr ; ou txt is the rtly

deed eme ndered . odr n whch gd

mds f set e in our x i aiay rrvn

Our ynt s r ocig se t o

uarded n e. T aeraiv rut wtten by g

i by te spci! bket a if f". If ·the l tte nn

t ur is ru, h pogr wil bot herwse aty

ded t wh tre rd w lc o co

ot. f h pty gaded comad t w aoed " f ld

ma taly eqva t bot of o

An exmpl -illusi he odeey a vry des asi-

w grm t fr fid nd   ssigns t he mi

e f y :

y

U y y

f

Th rptitv cut i ritt dn y eg ar

oa se b h ! He st

hih e he r i re wl d t rrenn; copleent e, owee a w ony er iae

hic o t rd i tru wh y o

mp eeto o eeted gad m g tu

nw se fo exio f a u ded i wth a r rd wll ak

c nd o on. Whe t pe st eed poly

e kno ll gd s

f h y rd d d e wee lwed "d Q" d esatcy l kp d o not.

Page 4: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 4/14

WD18 - 3

.An eaple g t -ty rat ly

i e progm tt asi t th aa 1 q 3 ad 4 a rtt

f t vl Q1, Q2 Q3d

Q4,such

t 2 < <q4 U

cncunt a ate f k of.convi,   ca a

q q2 3 q4 Q Q 2 Q Q4;

q > q2 1 q2 q2 q

2 > q q2 3 ·- q3, 2

q > 4 q3,  q4  q4,  q3 

cl   ti w iv a a y he ib a t ta s t ecsy dr. r

k tt fix va ( > o a x

fi defed fr < < , k a atiy

0 < < a N i   (k) > i)

(Eal h a a x)

k ; : 1

- fj) <f) j + 1 (j k k j

Ol iil a a a l h i f

pbl

3. f t

1 Nottinl ped.

I te li st sa u t bl P , d R

t t ia ii c l p

e; naty hl a "cii,

t y a a h t ft i t Tw spc

pdc t d y a a F" a

i : T dt t h by dft is satfed

by t, y ii t h t

Page 5: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 5/14

by tate t .

T ay s pret (s tool dig

a r na sa) ss aaa nss as b ry spr by Har [1 ], an

r beg a a n s a b Har

a ass n

prdu th r bt rmae r

eessry - - -- r-cdti

a te �m a rteed to prde te ht r

M s ay sa s an p S e a sa an R s sy

aks na sa ss s

a aan s aa a a py a

ay an sy a na a sasy s�n

R s "a a ra bas

t · ret y tit y

fwig properte.

1) Fr any a a sas

5,

sa E Mcl

any a any ns s a r a sa

p  =  C 

a a sas

p = wpS Q

3 ay a ay sns a Q a

aes n wS q P Q

ay a ay s a Q a r a

asp P) or pS Q

Tg s psa a a sa

n b b ab s ak

Page 6: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 6/14

EWD418 5

ole of the "rules f ineee1 as ioduc by Hoae [1 ].

We tke th psin ta h mnt enism S

el we if e prdc tranme, ca derv

p(S, R) y t- R

No Thi pto u ackowldgme of fc tha

n-rs , f pda

tar e c rn: t stes

cesly l oey nang avy e

kwld pee tasf d n g u y t

t t f t te ye g tl at p

t E

Example T as o py et et by "

e b he fon t t e

Example 2 T eat he x:= aegn b

w "x= E

w R� a y fg R w a

cuc th vbl b

Example ss f e seoo ;11 ota to

e gve byS; 52 (S1 wp2

32. u.

I o o ne e sq e ive su e

ee t b

Le

BB dnote �.\�=

n b n

$ _< :

Page 7: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 7/14

 

W 6

B ad N: in: B. =wp(SL,

The first em " q al rnv ot as such

o to ton on cc n f al gur f, e cn emeqir a ch gad lis lb lad o n

tl n t) dnton cn d sp

ubuon-

Theorm 1 From

C 1 : Q �) p(L R o

onc haQ and B wp IF o a s •

  dt so t con d sa pa

n l d t I dno k p-c vat

f 5 uteed o n a

s m nl s h h o s s b

a mr o i v). I "c e r

  s

To F

0 _< : d =wcSL., t) al s

ne

deI t) od or a

Nb� h skpp s edn e ee p s s y pont n st c c gd

s a utio w 0 unn L i e o 0 (X He e ad h xpl he Xe n p bo o t fal

h�c 5

n b d( X 1) <

E o no

Page 8: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 8/14

7

33 The roeitve cnu

As b xped, f f e u

h  w o b y DOLe H0 (R   k>0 :  HkR

=

SL1 B L or cpl.

(R  ! BE

wI k_1 (R £ 0R)

we IF des e � gae md e nle y 1

by d

pD, R 3k � : kR)Ivy e epe s eks - pe n e ms k ued l, ym nal a fg R .} Va h

dn w

Th 3 Fo

P EB ( d dcF P=   > f Bl s/

d f se

wpD B

ll e

N a eeen eem s h e sqen o a

esT

b ef ssfe b

sS T  s h k -oo r ee oe temo o

s l s mae a nav u

nc z.

em m

BB P de f ses

ae

nd w T wD B

I coo bo ho " s l h o"

Page 9: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 9/14

EWD418 8

ad "t is le h arian io

Formal evio of pograms.

Th forl rqirmn of o po poin H:= ax y"

f fixd an y t sbls ri

Nw h A A inn ll t Hm= H anda

a bihi h tut " = x" or id ih s a wy

f eg t rh o ir o R W do

j? I vsg t, w p

n ti et rodo a , Tm 1

- =

l puc rrc if ns sucy. Th diad

ana o oram ha B  � T, i t e abio

wk B ng hih de e

bvous na is annt y w h

pm y ?

a d o ou og a

x : y ? x : y

fi

n t BB T nd h

e te ha o xi o ale

dfd tt R d qut f s

u.)

A a xam of h diiaio o a etve cut ll

o o h a mmo dio o o b,

. or ixd os X ad w hve esa e l

Page 10: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 10/14

9

= gcd(X

Te ahe es i m ce e ve cse

iva et n u ai uct. he a thn es tce

esls he elati P e e va�;

d "dese s l s ssie ne vace

o P £

Sse tat e cse f te iat et

gc X, x y) d x > 0  a >

a la e e easl esaled

X; =

Th m geal "n o e d e vrn P is

e fx, y E1

d e ae teesd i a B tat

P B) px : 2

gcd(X d(E1 ad > 0 E2 > 0

ecase t u t e e boolan xprs d u

t ca comuio of d X -fr w e e�-

w u h e exprsion d E ho ta

e

cd(X Y : E2 )

s ml h u f

dc ) = gd E1 2

I he d e e ivted t sag te vae pai ) sc

a ash tha te g i nd. Beca nd s s e ac

ee t oze eica wege ab e cdn--

c, ) d

ib a l uld e

:= -

Dei

Page 11: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 11/14

EWD418 10

wp{"x:= - y R = gcdX, Y = { y x > 0 >

a omitng ll e te ju led by P e fin e uar

>

a te v f P is concerd. Bids w q

c the fuio ae e·e h

Fr 

w cu at

refe

": ,= x

" J

5

x + ·  0) (x < 0

e: y t = (x    < >

e reee f e pss o fu

e h gu b e= , u i

by P and w cm our st eft

x = X Y; > y l .!

Ala, hi ngl d c P � 8B e

n lw t o l  = X, . I cetely

erae x wil rer d >

d or e et

· X·t = Y·'

> y • )

0 > y y ' ·-

N i a   po r BB

(P � x = = x , Y bu (x, x x

  co f = x +y an ee ft heg a ymt uct u e e e p

Page 12: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 12/14

x:= X y Y

d > y - x: X

0 y >X y =

E8-

Th swp ", :� can ver : e ur  h l

guded is fll as b t rqt tht t is fctvel

 re.

In s fial g be fnd lar u et of

sch ude s ha B th dsju f r as w i

iy weak: t ae av p

ig n h c f p tv ou e s

tig B k uh P � B ron enu o

m t derd - io A

5. Concluding rmrks.

r te wh d i t was

gee b bt at Eci' Agrt � �

a rizg. t os " n "& = y-x o'

wy th ln 0 > u ra

u. It h srn t s a fr

ques we ad rad vd r h   ivo f yhz

ns a en th anus -a f (l) squnl

reses sch s c e fd h t atvi opPig

sms ud asrr , k d t t vmt

of sequtl ogs o t a. Th i

tt ie eqea a e a "a a f

sie a f ms rmii t ouc-.,

te t t n sm --f hr as a

e cnd rsn o u s nsis s erso

dsr pp mon s d

vat w  ls so c o rrg"

were-- w hi t f n e ead a fma

rine a cha f t e t e We t

d f erv nt w ss a so srgh-

Page 13: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 13/14

EYD48 - 12

fwd ctiv, at of epttv ntrut rqres wht I rgr

"the vo" f a ivain lan t F m ,

vlue of h call hwn in eon 4 s ta i s sr egt

d m kepicsm bo m f he g;l of 1automic grammig1; reg ca l o b td m

ugg i tha ll pgm hould b vlp wy: t j es

u dl.

T clulu doe, w, xi my r er r xom

of pmm ua ic vi pri f

ave dit qu: P fi fr�r

sm t e o r�y to r g nt a h

dc ty rgram .

Fn I ud k t y r w u e e

nn-deny. I n hs ne CA.RHre: m

w prmts s prm t cme c e rful

rls mnnne gier: "ly be lgtly

rae." i prl i t e chc r

w.) vrco a sidb men re r d e wll -e� rr iuly. It

, ver sy I od re us

w or vig rl d I lve i vom

wh t nn-deinacy is elly el y rin

cnialy n a i r r no ( s nvi

i og l be deint e -edcle

bu i pr a mie mlfon I ca al k

vir i pdb ur pra ev i u

auray d l alway rctl k n io ur

qu h tn a n-drmi og !

Ackowldgemnts.

I t m kwms u t th  mrs

e FP Wr Gp .23 g Mhg": , as

t Bln f W G n

October 19 3 that  e guard  comands  wer e  bth  bor and  shown  to  th 

Page 14: Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

8/3/2019 Guarded commands. non-determinacy and a calculus for the derivation of programs, by Edsger W.Dijkstra

http://slidepdf.com/reader/full/guarded-commands-non-determinacy-and-a-calculus-for-the-derivation-of-programs 14/14

EWD418 - 3

public. h it ebe R.Mst .R.

H, JHig .nl, D.T.os G.eegm6ler NWit d .

g dv k de the ...Feje, .Ku

d CSten e be decly hefl i e .I oud k he ances qe (otey NSF), S ie a xemour oesy Bo poat) he

e ter role o tica o o bod h i d

t e.

(] CA.. A Aomt a f pte omig o. 12

(O 96) 57 583.

[] a Pet Ed. Rep te oim L OL 0

CoA 3 19 2

th une 4

NUEN

o.drser WDjkstra

oh